App.vue 18 KB

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