App.vue 17 KB

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