App.vue 18 KB

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