App.vue 18 KB

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