App.vue 18 KB

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