App.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <template>
  2. <div id="app">
  3. <div class="imui-center">
  4. <lemon-imui
  5. :user="user"
  6. ref="IMUI"
  7. @change-menu="handleChangeMenu"
  8. @change-contact="handleChangeContact"
  9. @pull-messages="handlePullMessages"
  10. @send="handleSend"
  11. >
  12. <template #cover>
  13. <h1 style="text-indent:20px">自定义封面内容</h1>
  14. </template>
  15. <!-- <template #contact-info="contact">
  16. <span style="color:blue">contact-info {{ contact }}</span>
  17. </template> -->
  18. <!--
  19. <template #drawer="contact">
  20. <h1>自定义抽屉内容</h1>
  21. <p>{{ contact }}</p>
  22. </template>
  23. -->
  24. <template #contact-title="contact">
  25. <span>{{ contact.displayName }}</span>
  26. <small class="more" @click="changeDrawer(contact)">&#8230;</small>
  27. </template>
  28. </lemon-imui>
  29. <div class="action">
  30. <lemon-button @click="currentAppendMessage"
  31. >在当前窗口发送消息</lemon-button
  32. >
  33. <lemon-button @click="appendMessage">指定联系人发送消息</lemon-button>
  34. <lemon-button @click="updateContact">修改联系人信息</lemon-button>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. const getTime = () => {
  41. return new Date().getTime();
  42. };
  43. const generateRandId = () => {
  44. return Number(
  45. Math.random()
  46. .toString()
  47. .substr(3, length) + Date.now()
  48. ).toString(36);
  49. };
  50. const generateRandWord = () => {
  51. return Math.random()
  52. .toString(36)
  53. .substr(2);
  54. };
  55. const generateMessage = () => {
  56. return {
  57. id: generateRandId(),
  58. status: "succeed",
  59. type: "text",
  60. sendTime: getTime(),
  61. content: "随机回复:" + generateRandWord(),
  62. toContactId: "123",
  63. //fileSize: 1231,
  64. //fileName: "asdasd.doc",
  65. fromUser: {
  66. id: "222",
  67. displayName: "系统测试",
  68. avatar:
  69. "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1820523987,3798556096&fm=26&gp=0.jpg"
  70. }
  71. };
  72. };
  73. export default {
  74. name: "app",
  75. data() {
  76. return {
  77. user: {
  78. id: "superadmin",
  79. displayName: "IMUI super",
  80. avatar:
  81. "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4085009425,1005454674&fm=26&gp=0.jpg"
  82. }
  83. };
  84. },
  85. mounted() {
  86. const contactData1 = {
  87. id: "1",
  88. displayName: "工作协作群",
  89. avatar:
  90. "https://img.ivsky.com/img/tupian/li/201903/24/richu_riluo-015.jpg",
  91. type: "single",
  92. index: "A",
  93. unread: 0,
  94. lastSendTime: 1566047865417,
  95. lastContent: "2"
  96. };
  97. const contactData2 = {
  98. id: "2",
  99. displayName: "狗蛋Li。",
  100. avatar: "https://img.ivsky.com/img/tupian/li/201902/27/yanjing_meinv.jpg",
  101. type: "single",
  102. index: "B",
  103. click(next) {
  104. next();
  105. },
  106. renderContainer: () => {
  107. return <h1 style="text-indent:20px">自定义页面</h1>;
  108. },
  109. lastSendTime: 1345209465000,
  110. lastContent: "12312",
  111. unread: 2
  112. };
  113. const contactData3 = {
  114. id: "3",
  115. displayName: "铁牛",
  116. avatar:
  117. "https://img.ivsky.com/img/tupian/li/201903/21/huahuan_xiaonvhai.jpg",
  118. type: "many",
  119. index: "C",
  120. unread: 32,
  121. lastSendTime: 3,
  122. lastContent: "你好123"
  123. };
  124. const { IMUI } = this.$refs;
  125. setTimeout(() => {
  126. //IMUI.openDrawer();
  127. // IMUI.openDrawer(() => {
  128. // return [
  129. // <h1>123</h1>,
  130. // <h1>123</h1>,
  131. // <h1>123</h1>,
  132. // <h1>123</h1>,
  133. // <h1>123</h1>,
  134. // <h1>123</h1>,
  135. // <h1>123</h1>,
  136. // <h1>123</h1>,
  137. // <h1>123</h1>,
  138. // <h1>123</h1>,
  139. // <h1>123</h1>,
  140. // <h1>123</h1>,
  141. // <h1>123</h1>,
  142. // <h1>123</h1>
  143. // ];
  144. // });
  145. // setTimeout(() => {
  146. // IMUI.openDrawer(() => {
  147. // return <h1>124563</h1>;
  148. // });
  149. // }, 2000);
  150. }, 2000);
  151. //[contactData1, contactData2, contactData3]
  152. let data = [
  153. { ...contactData1 },
  154. { ...contactData2 },
  155. { ...contactData3 }
  156. //...Array(100).fill(contactData1)
  157. ];
  158. IMUI.initContacts(data);
  159. IMUI.initMenus([
  160. {
  161. name: "lastMessages"
  162. },
  163. {
  164. name: "contacts"
  165. },
  166. {
  167. title: "自定义按钮",
  168. unread: 0,
  169. click: () => {
  170. alert("点击了自定义按钮");
  171. },
  172. render: menu => {
  173. return <span>T</span>;
  174. },
  175. isBottom: true
  176. }
  177. ]);
  178. IMUI.initEmoji([
  179. {
  180. label: "表情",
  181. children: [
  182. {
  183. name: "1f600",
  184. title: "微笑",
  185. src: "https://twemoji.maxcdn.com/2/72x72/1f600.png"
  186. },
  187. {
  188. name: "1f62c",
  189. title: "微笑",
  190. src: "https://twemoji.maxcdn.com/2/72x72/1f62c.png"
  191. },
  192. {
  193. name: "1f601",
  194. title: "微笑",
  195. src: "https://twemoji.maxcdn.com/2/72x72/1f601.png"
  196. },
  197. {
  198. name: "1f602",
  199. title: "微笑",
  200. src: "https://twemoji.maxcdn.com/2/72x72/1f602.png"
  201. },
  202. {
  203. name: "1f923",
  204. title: "微笑",
  205. src: "https://twemoji.maxcdn.com/2/72x72/1f923.png"
  206. },
  207. {
  208. name: "1f973",
  209. title: "微笑",
  210. src: "https://twemoji.maxcdn.com/2/72x72/1f973.png"
  211. },
  212. {
  213. name: "1f603",
  214. title: "微笑",
  215. src: "https://twemoji.maxcdn.com/2/72x72/1f603.png"
  216. },
  217. {
  218. name: "1f604",
  219. title: "微笑",
  220. src: "https://twemoji.maxcdn.com/2/72x72/1f604.png"
  221. },
  222. {
  223. name: "1f605",
  224. title: "微笑",
  225. src: "https://twemoji.maxcdn.com/2/72x72/1f605.png"
  226. },
  227. {
  228. name: "1f606",
  229. title: "微笑",
  230. src: "https://twemoji.maxcdn.com/2/72x72/1f606.png"
  231. },
  232. {
  233. name: "1f607",
  234. title: "微笑",
  235. src: "https://twemoji.maxcdn.com/2/72x72/1f607.png"
  236. },
  237. {
  238. name: "1f609",
  239. title: "微笑",
  240. src: "https://twemoji.maxcdn.com/2/72x72/1f609.png"
  241. },
  242. {
  243. name: "1f60a",
  244. title: "微笑",
  245. src: "https://twemoji.maxcdn.com/2/72x72/1f60a.png"
  246. },
  247. {
  248. name: "1f642",
  249. title: "微笑",
  250. src: "https://twemoji.maxcdn.com/2/72x72/1f642.png"
  251. },
  252. {
  253. name: "1f643",
  254. title: "微笑",
  255. src: "https://twemoji.maxcdn.com/2/72x72/1f643.png"
  256. },
  257. {
  258. name: "1263a",
  259. title: "微笑",
  260. src: "https://twemoji.maxcdn.com/2/72x72/263a.png"
  261. },
  262. {
  263. name: "1f60b",
  264. title: "微笑",
  265. src: "https://twemoji.maxcdn.com/2/72x72/1f60b.png"
  266. },
  267. {
  268. name: "1f60c",
  269. title: "微笑",
  270. src: "https://twemoji.maxcdn.com/2/72x72/1f60c.png"
  271. },
  272. {
  273. name: "1f60d",
  274. title: "微笑",
  275. src: "https://twemoji.maxcdn.com/2/72x72/1f60d.png"
  276. },
  277. {
  278. name: "1f970",
  279. title: "微笑",
  280. src: "https://twemoji.maxcdn.com/2/72x72/1f970.png"
  281. },
  282. {
  283. name: "1f618",
  284. title: "微笑",
  285. src: "https://twemoji.maxcdn.com/2/72x72/1f618.png"
  286. },
  287. {
  288. name: "1f617",
  289. title: "微笑",
  290. src: "https://twemoji.maxcdn.com/2/72x72/1f617.png"
  291. },
  292. {
  293. name: "1f619",
  294. title: "微笑",
  295. src: "https://twemoji.maxcdn.com/2/72x72/1f619.png"
  296. },
  297. {
  298. name: "1f61a",
  299. title: "微笑",
  300. src: "https://twemoji.maxcdn.com/2/72x72/1f61a.png"
  301. },
  302. {
  303. name: "1f61c",
  304. title: "微笑",
  305. src: "https://twemoji.maxcdn.com/2/72x72/1f61c.png"
  306. },
  307. {
  308. name: "1f92a",
  309. title: "微笑",
  310. src: "https://twemoji.maxcdn.com/2/72x72/1f92a.png"
  311. },
  312. {
  313. name: "1f928",
  314. title: "微笑",
  315. src: "https://twemoji.maxcdn.com/2/72x72/1f928.png"
  316. },
  317. {
  318. name: "1f9d0",
  319. title: "微笑",
  320. src: "https://twemoji.maxcdn.com/2/72x72/1f9d0.png"
  321. },
  322. {
  323. name: "1f61d",
  324. title: "微笑",
  325. src: "https://twemoji.maxcdn.com/2/72x72/1f61d.png"
  326. },
  327. {
  328. name: "1f61b",
  329. title: "微笑",
  330. src: "https://twemoji.maxcdn.com/2/72x72/1f61b.png"
  331. },
  332. {
  333. name: "1f911",
  334. title: "微笑",
  335. src: "https://twemoji.maxcdn.com/2/72x72/1f911.png"
  336. },
  337. {
  338. name: "1f913",
  339. title: "微笑",
  340. src: "https://twemoji.maxcdn.com/2/72x72/1f913.png"
  341. },
  342. {
  343. name: "1f60e",
  344. title: "微笑",
  345. src: "https://twemoji.maxcdn.com/2/72x72/1f60e.png"
  346. },
  347. {
  348. name: "1f929",
  349. title: "微笑",
  350. src: "https://twemoji.maxcdn.com/2/72x72/1f929.png"
  351. },
  352. {
  353. name: "1f921",
  354. title: "微笑",
  355. src: "https://twemoji.maxcdn.com/2/72x72/1f921.png"
  356. },
  357. {
  358. name: "1f920",
  359. title: "微笑",
  360. src: "https://twemoji.maxcdn.com/2/72x72/1f920.png"
  361. },
  362. {
  363. name: "1f917",
  364. title: "微笑",
  365. src: "https://twemoji.maxcdn.com/2/72x72/1f917.png"
  366. },
  367. {
  368. name: "1f60f",
  369. title: "微笑",
  370. src: "https://twemoji.maxcdn.com/2/72x72/1f60f.png"
  371. },
  372. {
  373. name: "1f636",
  374. title: "微笑",
  375. src: "https://twemoji.maxcdn.com/2/72x72/1f636.png"
  376. },
  377. {
  378. name: "1f610",
  379. title: "微笑",
  380. src: "https://twemoji.maxcdn.com/2/72x72/1f610.png"
  381. },
  382. {
  383. name: "1f611",
  384. title: "微笑",
  385. src: "https://twemoji.maxcdn.com/2/72x72/1f611.png"
  386. },
  387. {
  388. name: "1f612",
  389. title: "微笑",
  390. src: "https://twemoji.maxcdn.com/2/72x72/1f612.png"
  391. },
  392. {
  393. name: "1f644",
  394. title: "微笑",
  395. src: "https://twemoji.maxcdn.com/2/72x72/1f644.png"
  396. },
  397. {
  398. name: "1f914",
  399. title: "微笑",
  400. src: "https://twemoji.maxcdn.com/2/72x72/1f914.png"
  401. },
  402. {
  403. name: "1f925",
  404. title: "微笑",
  405. src: "https://twemoji.maxcdn.com/2/72x72/1f925.png"
  406. },
  407. {
  408. name: "1f92d",
  409. title: "微笑",
  410. src: "https://twemoji.maxcdn.com/2/72x72/1f92d.png"
  411. },
  412. {
  413. name: "1f92b",
  414. title: "微笑",
  415. src: "https://twemoji.maxcdn.com/2/72x72/1f92b.png"
  416. },
  417. {
  418. name: "1f92c",
  419. title: "微笑",
  420. src: "https://twemoji.maxcdn.com/2/72x72/1f92c.png"
  421. },
  422. {
  423. name: "1f92f",
  424. title: "微笑",
  425. src: "https://twemoji.maxcdn.com/2/72x72/1f92f.png"
  426. },
  427. {
  428. name: "1f633",
  429. title: "微笑",
  430. src: "https://twemoji.maxcdn.com/2/72x72/1f633.png"
  431. },
  432. {
  433. name: "1f61e",
  434. title: "微笑",
  435. src: "https://twemoji.maxcdn.com/2/72x72/1f61e.png"
  436. },
  437. {
  438. name: "1f61f",
  439. title: "微笑",
  440. src: "https://twemoji.maxcdn.com/2/72x72/1f61f.png"
  441. },
  442. {
  443. name: "1f620",
  444. title: "微笑",
  445. src: "https://twemoji.maxcdn.com/2/72x72/1f620.png"
  446. },
  447. {
  448. name: "1f621",
  449. title: "微笑",
  450. src: "https://twemoji.maxcdn.com/2/72x72/1f621.png"
  451. }
  452. ]
  453. },
  454. {
  455. label: "武器",
  456. children: [
  457. {
  458. name: "wx",
  459. src: "http://"
  460. }
  461. ]
  462. }
  463. ]);
  464. },
  465. methods: {
  466. _addUnread(id, message) {
  467. const { IMUI } = this.$refs;
  468. IMUI.updateContact(id, {
  469. unread: "+1",
  470. lastSendTime: getTime(),
  471. lastContent: IMUI.lastContentRender(message)
  472. });
  473. },
  474. appendMessage() {
  475. const id = "3";
  476. const { IMUI } = this.$refs;
  477. const message = generateMessage();
  478. IMUI.appendMessage(message, id);
  479. this._addUnread(id, message);
  480. },
  481. currentAppendMessage() {
  482. const { IMUI } = this.$refs;
  483. const message = generateMessage();
  484. IMUI.appendMessage(message);
  485. this._addUnread(IMUI.currentContact.id, message);
  486. },
  487. updateContact() {
  488. this.$refs.IMUI.updateContact("3", {
  489. unread: 10,
  490. displayName: generateRandWord(),
  491. lastSendTime: getTime(),
  492. lastContent: "修改昵称为随机字母"
  493. });
  494. },
  495. changeDrawer(contact) {
  496. this.$refs.IMUI.changeDrawer(() => {
  497. return (
  498. <div class="drawer-content">
  499. <p>
  500. <b>自定义抽屉</b>
  501. </p>
  502. <p>{contact.displayName}</p>
  503. </div>
  504. );
  505. });
  506. },
  507. handleChangeContact(contact) {
  508. console.log("Event:change-contact");
  509. this.$refs.IMUI.updateContact(contact.id, {
  510. //displayName: "123",
  511. unread: 0
  512. });
  513. this.$refs.IMUI.closeDrawer();
  514. },
  515. handleSend(message, next, file) {
  516. console.log("Event:send");
  517. setTimeout(() => {
  518. next();
  519. }, 1000);
  520. },
  521. handlePullMessages(contact, next) {
  522. console.log("Event:pull-messages");
  523. const messages = [
  524. {
  525. id: "8ad7e98e-5225-4892-8131-4b2ee7797599",
  526. type: "text",
  527. status: "succeed",
  528. sendTime: 1564926674646,
  529. fromContactId: "superadmin",
  530. fromUser: {
  531. id: "hehe",
  532. displayName: "I KNOEW",
  533. avatar:
  534. "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4085009425,1005454674&fm=26&gp=0.jpg"
  535. },
  536. content: "测试消息哦..."
  537. },
  538. {
  539. id: "8ad7e98e-5225-4892-8131-4b2ee7797599",
  540. type: "text",
  541. status: "succeed",
  542. sendTime: 1564926674646,
  543. fromContactId: "superadmin",
  544. fromUser: {
  545. id: "superadmin",
  546. displayName: "超级飞机",
  547. avatar:
  548. "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4085009425,1005454674&fm=26&gp=0.jpg"
  549. },
  550. content: "测试消息哦..."
  551. },
  552. {
  553. id: "8ad7e98e-5225-4892-8131-4b2ee7797599",
  554. type: "text",
  555. status: "succeed",
  556. sendTime: 1564926674646,
  557. fromContactId: "superadmin",
  558. fromUser: {
  559. id: "hehe",
  560. displayName: "I KNOEW",
  561. avatar:
  562. "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4085009425,1005454674&fm=26&gp=0.jpg"
  563. },
  564. content: "测试消息哦..."
  565. },
  566. {
  567. id: "8ad7e98e-5225-4892-8131-4b2ee7797599",
  568. type: "text",
  569. status: "succeed",
  570. sendTime: 1564926674646,
  571. fromContactId: "superadmin",
  572. fromUser: {
  573. id: "superadmin",
  574. displayName: "超级飞机",
  575. avatar:
  576. "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4085009425,1005454674&fm=26&gp=0.jpg"
  577. },
  578. content: "测试消息哦..."
  579. },
  580. {
  581. id: "8ad7e98e-5225-4892-8131-4b2ee7797599",
  582. type: "text",
  583. status: "succeed",
  584. sendTime: 1564926674646,
  585. fromContactId: "superadmin",
  586. fromUser: {
  587. id: "hehe",
  588. displayName: "I KNOEW",
  589. avatar:
  590. "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4085009425,1005454674&fm=26&gp=0.jpg"
  591. },
  592. content: "测试消息哦..."
  593. },
  594. {
  595. id: "8ad7e98e-5225-4892-8131-4b2ee7797599",
  596. type: "text",
  597. status: "succeed",
  598. sendTime: 1564926674646,
  599. fromContactId: "superadmin",
  600. fromUser: {
  601. id: "superadmin",
  602. displayName: "超级飞机",
  603. avatar:
  604. "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4085009425,1005454674&fm=26&gp=0.jpg"
  605. },
  606. content: "测试消息哦..."
  607. }
  608. ];
  609. next(messages);
  610. },
  611. handleChangeMenu() {
  612. console.log("Event:change-menu");
  613. },
  614. openCustomContainer() {}
  615. }
  616. };
  617. </script>
  618. <style lang="stylus">
  619. body
  620. background #3d495c !important
  621. .action
  622. margin-top 30px
  623. button
  624. margin-right 10px
  625. .imui-center
  626. position absolute
  627. top 50%
  628. left 50%
  629. transform translate(-50%,-50%)
  630. .drawer-content
  631. padding 15px
  632. .more
  633. font-size 32px
  634. line-height 18px
  635. height 32px
  636. position absolute
  637. top 6px
  638. right 14px
  639. cursor pointer
  640. user-select none
  641. color #999
  642. &:active
  643. color #000
  644. </style>