Index.vue 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. <template>
  2. <div class="chat-index">
  3. <!--左边选项-->
  4. <ul class="chat-menu">
  5. <li class="self">
  6. <img :src="userInfo.userimg">
  7. </li>
  8. <li :class="{active:chatTap=='dialog'}" @click="chatTap='dialog'">
  9. <Icon type="md-text" />
  10. <em v-if="unreadTotal > 0" class="chat-num">{{unreadTotal}}</em>
  11. </li>
  12. <li :class="{active:chatTap=='team'}" @click="chatTap='team'">
  13. <Icon type="md-person" />
  14. </li>
  15. </ul>
  16. <!--对话列表-->
  17. <ul class="chat-user" :style="{display:chatTap=='dialog'?'flex':'none'}">
  18. <li class="sreach">
  19. <Input placeholder="搜索" prefix="ios-search" v-model="dialogSearch"/>
  20. </li>
  21. <li class="lists">
  22. <ul>
  23. <li v-for="(dialog, index) in dialogListsS"
  24. :key="index"
  25. :class="{active:dialog.username==dialogTarget.username}"
  26. @click="openDialog(dialog)">
  27. <img :src="dialog.userimg">
  28. <div class="user-msg-box">
  29. <div class="user-msg-title">
  30. <span><user-view :username="dialog.username" placement="right" @on-result="(n)=>{dialog['nickname']=n}"/></span>
  31. <em>{{formatCDate(dialog.lastdate)}}</em>
  32. </div>
  33. <div class="user-msg-text">{{dialog.lasttext}}</div>
  34. </div>
  35. <em v-if="dialog.unread > 0" class="user-msg-num">{{dialog.unread}}</em>
  36. </li>
  37. <li v-if="dialogNoDataText==$L('数据加载中.....')" class="chat-none"><w-loading/></li>
  38. <li v-else-if="dialogLists.length == 0" class="chat-none">{{dialogNoDataText}}</li>
  39. </ul>
  40. </li>
  41. </ul>
  42. <!--联系人列表-->
  43. <ul class="chat-team" :style="{display:chatTap=='team'?'flex':'none'}">
  44. <li class="sreach">
  45. <Input placeholder="搜索" prefix="ios-search" v-model="teamSearch"/>
  46. </li>
  47. <li class="lists">
  48. <ul>
  49. <li v-for="(lists, key) in teamLists">
  50. <div class="team-label">{{key}}</div>
  51. <ul>
  52. <li v-for="(item, index) in teamListsS(lists)" :key="index" @click="openDialog(item, true)">
  53. <img :src="item.userimg">
  54. <div class="team-username"><user-view :username="item.username" placement="right" @on-result="(n)=>{item['nickname']=n}"/></div>
  55. </li>
  56. </ul>
  57. </li>
  58. <li v-if="teamNoDataText==$L('数据加载中.....')" class="chat-none"><w-loading/></li>
  59. <li v-else-if="Object.keys(teamLists).length == 0" class="chat-none">{{teamNoDataText}}</li>
  60. <li v-if="teamHasMorePages" class="chat-more" @click="getTeamLists(true)">加载更多...</li>
  61. </ul>
  62. </li>
  63. </ul>
  64. <!--对话窗口-->
  65. <div class="chat-message" :style="{display:(chatTap=='dialog'&&dialogTarget.username)?'block':'none'}">
  66. <div class="manage-title">
  67. <user-view :username="dialogTarget.username"/>
  68. <Dropdown class="manage-title-right" placement="bottom-end" trigger="click" @on-click="dialogDropdown" transfer>
  69. <Icon type="ios-more"/>
  70. <DropdownMenu slot="list">
  71. <DropdownItem name="delete">删除对话</DropdownItem>
  72. <DropdownItem name="clear">清除聊天记录</DropdownItem>
  73. </DropdownMenu>
  74. </Dropdown>
  75. </div>
  76. <ScrollerY ref="manageLists" class="manage-lists" @on-scroll="messageListsScroll">
  77. <div ref="manageBody" class="manage-body">
  78. <div v-if="messageHasMorePages" class="manage-more" @click="getDialogMessage(true)">加载更多...</div>
  79. <div v-if="messageNoDataText==$L('数据加载中.....')" class="manage-more"><w-loading/></div>
  80. <div v-else-if="messageNoDataText" class="manage-more">{{messageNoDataText}}</div>
  81. <chat-message v-for="(info, index) in messageLists" :key="index" :info="info"></chat-message>
  82. </div>
  83. <div class="manage-lists-message-new" v-if="messageNew > 0" @click="messageBottomGo(true)">有{{messageNew}}条新消息</div>
  84. </ScrollerY>
  85. <div class="manage-send" @click="clickDialog(dialogTarget.username)">
  86. <textarea ref="textarea" class="manage-input" v-model="messageText" placeholder="请输入要发送的消息" @keydown="messageSend($event)"></textarea>
  87. </div>
  88. <div class="manage-quick">
  89. <emoji-picker @emoji="messageInsertText" :search="messageEmojiSearch">
  90. <div slot="emoji-invoker" slot-scope="{ events: { click: clickEvent } }" @click.stop="clickEvent">
  91. <Icon class="quick-item" type="ios-happy-outline" />
  92. </div>
  93. <div slot="emoji-picker" slot-scope="{ emojis, insert, display }">
  94. <div class="emoji-box">
  95. <Input class="emoji-input" placeholder="搜索" v-model="messageEmojiSearch" prefix="ios-search"/>
  96. <div>
  97. <div v-for="(emojiGroup, category) in emojis" :key="category">
  98. <h5>{{ category }}</h5>
  99. <div class="emojis">
  100. <span v-for="(emoji, emojiName) in emojiGroup" :key="emojiName" @click="insert(emoji)" :title="emojiName">{{ emoji }}</span>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </emoji-picker>
  107. <Icon class="quick-item" type="ios-photos-outline" @click="$refs.messageUpload.handleClick()"/>
  108. <img-upload ref="messageUpload" class="message-upload" type="callback" @on-callback="messageInsertImage" num="3" :otherParams="{from:'chat'}"></img-upload>
  109. </div>
  110. </div>
  111. </div>
  112. </template>
  113. <style lang="scss">
  114. .chat-notice-box {
  115. display: flex;
  116. align-items: flex-start;
  117. .chat-notice-userimg {
  118. width: 42px;
  119. height: 42px;
  120. border-radius: 4px;
  121. }
  122. .ivu-notice-with-desc {
  123. flex: 1;
  124. padding: 0 12px;
  125. }
  126. .ivu-notice-desc {
  127. word-break:break-all;
  128. line-height: 1.3;
  129. text-overflow: ellipsis;
  130. display: -webkit-box;
  131. -webkit-line-clamp: 2;
  132. overflow:hidden;
  133. -webkit-box-orient: vertical;
  134. }
  135. }
  136. </style>
  137. <style lang="scss" scoped>
  138. .chat-index {
  139. display: flex;
  140. flex-direction: row;
  141. align-items: flex-start;
  142. position: absolute;
  143. top: 0;
  144. left: 0;
  145. right: 0;
  146. bottom: 0;
  147. .chat-none {
  148. height: auto;
  149. color: #666666;
  150. padding: 22px 8px;
  151. text-align: center;
  152. justify-content: center;
  153. margin: 0 !important;
  154. &:before {
  155. display: none;
  156. }
  157. }
  158. .chat-more {
  159. color: #666666;
  160. padding: 18px 0;
  161. text-align: center;
  162. cursor: pointer;
  163. margin: 0 !important;
  164. &:hover {
  165. color: #444444;
  166. }
  167. }
  168. .chat-menu {
  169. background-color: rgba(28, 29, 31, 0.92);
  170. width: 68px;
  171. height: 100%;
  172. padding-top: 20px;
  173. li {
  174. position: relative;
  175. padding: 12px 0;
  176. text-align: center;
  177. font-size: 28px;
  178. color: #919193;
  179. background-color: transparent;
  180. cursor: pointer;
  181. &.self {
  182. img {
  183. width: 36px;
  184. height: 36px;
  185. border-radius: 3px;
  186. }
  187. }
  188. &.active {
  189. color: #ffffff;
  190. background-color: rgba(255, 255, 255, 0.06);
  191. }
  192. .chat-num {
  193. position: absolute;
  194. top: 50%;
  195. left: 50%;
  196. height: auto;
  197. line-height: normal;
  198. color: #ffffff;
  199. background-color: #ff0000;
  200. text-align: center;
  201. border-radius: 10px;
  202. padding: 1px 5px;
  203. font-size: 12px;
  204. transform: scale(0.9) translate(5px, -20px);
  205. }
  206. }
  207. }
  208. .chat-user {
  209. display: flex;
  210. flex-direction: column;
  211. width: 248px;
  212. height: 100%;
  213. background-color: #ffffff;
  214. border-right: 1px solid #ededed;
  215. > li {
  216. position: relative;
  217. &.sreach {
  218. display: flex;
  219. flex-direction: row;
  220. align-items: center;
  221. height: 62px;
  222. margin: 0;
  223. padding: 0 12px;
  224. position: relative;
  225. cursor: pointer;
  226. &:before {
  227. content: "";
  228. position: absolute;
  229. left: 0;
  230. right: 0;
  231. bottom: 0;
  232. height: 1px;
  233. background-color: rgba(0, 0, 0, 0.06);
  234. }
  235. }
  236. &.lists {
  237. flex: 1;
  238. overflow: auto;
  239. transform: translateZ(0);
  240. > ul {
  241. > li {
  242. display: flex;
  243. flex-direction: row;
  244. align-items: center;
  245. height: 70px;
  246. padding: 0 12px;
  247. position: relative;
  248. cursor: pointer;
  249. &:before {
  250. content: "";
  251. position: absolute;
  252. left: 0;
  253. right: 0;
  254. bottom: 0;
  255. height: 1px;
  256. background-color: rgba(0, 0, 0, 0.06);
  257. }
  258. &.active {
  259. &:before {
  260. top: 0;
  261. height: 100%;
  262. }
  263. }
  264. img {
  265. width: 42px;
  266. height: 42px;
  267. border-radius: 4px;
  268. }
  269. .user-msg-box {
  270. flex: 1;
  271. display: flex;
  272. flex-direction: column;
  273. padding-left: 12px;
  274. .user-msg-title {
  275. display: flex;
  276. flex-direction: row;
  277. align-items: center;
  278. justify-content: space-between;
  279. line-height: 24px;
  280. span {
  281. flex: 1;
  282. max-width: 130px;
  283. color: #333333;
  284. font-size: 14px;
  285. white-space: nowrap;
  286. overflow: hidden;
  287. text-overflow: ellipsis;
  288. }
  289. em {
  290. color: #999999;
  291. font-size: 12px;
  292. }
  293. }
  294. .user-msg-text {
  295. max-width: 170px;
  296. color: #999999;
  297. font-size: 12px;
  298. line-height: 24px;
  299. white-space: nowrap;
  300. overflow: hidden;
  301. text-overflow: ellipsis;
  302. }
  303. }
  304. }
  305. }
  306. }
  307. .user-msg-num {
  308. position: absolute;
  309. top: 6px;
  310. left: 44px;
  311. height: auto;
  312. line-height: normal;
  313. color: #ffffff;
  314. background-color: #ff0000;
  315. text-align: center;
  316. border-radius: 10px;
  317. padding: 1px 5px;
  318. font-size: 12px;
  319. transform: scale(0.9);
  320. border: 1px solid #ffffff;
  321. }
  322. }
  323. }
  324. .chat-team {
  325. display: flex;
  326. flex-direction: column;
  327. width: 248px;
  328. height: 100%;
  329. background-color: #ffffff;
  330. border-right: 1px solid #ededed;
  331. > li {
  332. position: relative;
  333. &.sreach {
  334. display: flex;
  335. flex-direction: row;
  336. align-items: center;
  337. height: 62px;
  338. margin: 0;
  339. padding: 0 12px;
  340. position: relative;
  341. cursor: pointer;
  342. &:before {
  343. content: "";
  344. position: absolute;
  345. left: 0;
  346. right: 0;
  347. bottom: 0;
  348. height: 1px;
  349. background-color: rgba(0, 0, 0, 0.06);
  350. }
  351. }
  352. &.lists {
  353. flex: 1;
  354. overflow: auto;
  355. transform: translateZ(0);
  356. > ul {
  357. > li {
  358. margin-left: 24px;
  359. position: relative;
  360. .team-label {
  361. padding-left: 4px;
  362. margin-top: 6px;
  363. margin-bottom: 6px;
  364. height: 34px;
  365. line-height: 34px;
  366. border-bottom: 1px solid #efefef;
  367. }
  368. > ul {
  369. > li {
  370. display: flex;
  371. flex-direction: row;
  372. align-items: center;
  373. height: 52px;
  374. cursor: pointer;
  375. img {
  376. width: 30px;
  377. height: 30px;
  378. border-radius: 3px;
  379. }
  380. .team-username {
  381. padding: 0 12px;
  382. font-size: 14px;
  383. white-space: nowrap;
  384. overflow: hidden;
  385. text-overflow: ellipsis;
  386. }
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394. .chat-message {
  395. flex: 1;
  396. height: 100%;
  397. background-color: #F3F3F3;
  398. position: relative;
  399. .manage-title {
  400. position: absolute;
  401. top: 0;
  402. left: 0;
  403. z-index: 3;
  404. width: 100%;
  405. height: 62px;
  406. padding: 0 20px;
  407. line-height: 62px;
  408. font-size: 16px;
  409. font-weight: 500;
  410. text-align: left;
  411. background: #ffffff;
  412. border-bottom: 1px solid #ededed;
  413. .manage-title-right {
  414. position: absolute;
  415. top: 0;
  416. right: 0;
  417. z-index: 9;
  418. width: 62px;
  419. height: 62px;
  420. line-height: 62px;
  421. text-align: center;
  422. font-size: 22px;
  423. color: #242424;
  424. }
  425. }
  426. .manage-lists {
  427. position: absolute;
  428. left: 0;
  429. top: 62px;
  430. z-index: 1;
  431. bottom: 120px;
  432. width: 100%;
  433. overflow: auto;
  434. padding: 8px 0;
  435. background-color: #E8EBF2;
  436. .manage-more {
  437. color: #666666;
  438. padding: 8px 0;
  439. text-align: center;
  440. cursor: pointer;
  441. &:hover {
  442. color: #444444;
  443. }
  444. }
  445. .manage-lists-message-new {
  446. position: fixed;
  447. bottom: 130px;
  448. right: 20px;
  449. color: #ffffff;
  450. background-color: rgba(0, 0, 0, 0.6);
  451. padding: 6px 12px;
  452. border-radius: 16px;
  453. font-size: 12px;
  454. cursor: pointer;
  455. }
  456. }
  457. .manage-send {
  458. position: absolute;
  459. left: 0;
  460. bottom: 0;
  461. z-index: 2;
  462. display: flex;
  463. width: 100%;
  464. height: 120px;
  465. background-color: #ffffff;
  466. border-top: 1px solid #e4e4e4;
  467. .manage-input,.manage-input:focus {
  468. flex: 1;
  469. -webkit-appearance: none;
  470. font-size: 14px;
  471. box-sizing: border-box;
  472. padding: 0;
  473. margin: 38px 10px 6px;
  474. border: 0;
  475. line-height: 20px;
  476. box-shadow: none;
  477. resize:none;
  478. outline: 0;
  479. }
  480. .manage-join,
  481. .manage-spin {
  482. position: absolute;
  483. top: 0;
  484. left: 0;
  485. right: 0;
  486. bottom: 0;
  487. background: #ffffff;
  488. display: flex;
  489. align-items: center;
  490. justify-content: center;
  491. }
  492. }
  493. .manage-quick {
  494. position: absolute;
  495. z-index: 2;
  496. left: 0;
  497. right: 0;
  498. bottom: 79px;
  499. padding: 8px;
  500. display: flex;
  501. align-items: center;
  502. .quick-item {
  503. color: #444444;
  504. font-size: 24px;
  505. margin-right: 12px;
  506. }
  507. .emoji-box {
  508. position: absolute;
  509. left: 0;
  510. bottom: 40px;
  511. max-height: 320px;
  512. width: 100%;
  513. overflow: auto;
  514. background-color: #ffffff;
  515. padding: 12px;
  516. border-bottom: 1px solid #efefef;
  517. .emoji-input {
  518. margin: 6px 0;
  519. }
  520. h5 {
  521. padding: 0;
  522. margin: 8px 0 0 0;
  523. color: #b1b1b1;
  524. text-transform: uppercase;
  525. font-size: 14px;
  526. cursor: default;
  527. font-weight: normal;
  528. }
  529. .emojis {
  530. display: flex;
  531. flex-wrap: wrap;
  532. justify-content: space-between;
  533. &:after {
  534. content: "";
  535. flex: auto;
  536. }
  537. span {
  538. padding: 2px 4px;
  539. cursor: pointer;
  540. font-size: 22px;
  541. &:hover {
  542. background: #ececec;
  543. cursor: pointer;
  544. }
  545. }
  546. }
  547. }
  548. .message-upload {
  549. display: none;
  550. width: 0;
  551. height: 0;
  552. overflow: hidden;
  553. }
  554. }
  555. @media screen and (max-width: 768px) {
  556. .manage-lists {
  557. bottom: 96px;
  558. .manage-lists-message-new {
  559. bottom: 106px;
  560. }
  561. }
  562. .manage-send {
  563. height: 96px;
  564. }
  565. .manage-quick {
  566. bottom: 54px;
  567. .quick-item {
  568. font-size: 24px;
  569. margin-right: 8px;
  570. }
  571. }
  572. }
  573. }
  574. }
  575. </style>
  576. <script>
  577. import EmojiPicker from 'vue-emoji-picker'
  578. import DrawerTabsContainer from "../DrawerTabsContainer";
  579. import ScrollerY from "../../../_components/ScrollerY";
  580. import ChatMessage from "./message";
  581. import ImgUpload from "../ImgUpload";
  582. export default {
  583. name: 'ChatIndex',
  584. components: {ImgUpload, ChatMessage, EmojiPicker, ScrollerY, DrawerTabsContainer},
  585. props: {
  586. value: {
  587. default: 0
  588. },
  589. openWindow: {
  590. type: Boolean,
  591. default: false
  592. },
  593. },
  594. data () {
  595. return {
  596. loadIng: 0,
  597. userInfo: {},
  598. chatTap: 'dialog',
  599. dialogSearch: '',
  600. dialogTarget: {},
  601. dialogLists: [],
  602. dialogNoDataText: '',
  603. teamSearch: '',
  604. teamReady: false,
  605. teamLists: {},
  606. teamNoDataText: '',
  607. teamCurrentPage: 1,
  608. teamHasMorePages: false,
  609. autoBottom: true,
  610. messageNew: 0,
  611. messageText: '',
  612. messageLists: [],
  613. messageNoDataText: '',
  614. messageEmojiSearch: '',
  615. messageCurrentPage: 1,
  616. messageHasMorePages: false,
  617. unreadTotal: 0,
  618. }
  619. },
  620. created() {
  621. this.dialogNoDataText = this.$L("数据加载中.....");
  622. this.teamNoDataText = this.$L("数据加载中.....");
  623. this.messageNoDataText = this.$L("数据加载中.....");
  624. },
  625. mounted() {
  626. let resCall = () => {
  627. if ($A.getToken() === false) {
  628. return;
  629. }
  630. $A.WS.sendTo('unread', (res) => {
  631. if (res.status === 1) {
  632. this.unreadTotal = $A.runNum(res.message);
  633. } else {
  634. this.unreadTotal = 0;
  635. }
  636. });
  637. this.getDialogLists();
  638. this.messageBottomAuto();
  639. };
  640. this.userInfo = $A.getUserInfo((res, isLogin) => {
  641. if (this.userInfo.id != res.id) {
  642. this.userInfo = res;
  643. resCall();
  644. }
  645. }, false);
  646. resCall();
  647. //
  648. $A.WS.setOnMsgListener("chat/index", (msgDetail) => {
  649. if (msgDetail.sender == $A.getUserName()) {
  650. return;
  651. }
  652. if (msgDetail.messageType != 'send') {
  653. return;
  654. }
  655. //
  656. let data = $A.jsonParse(msgDetail.content);
  657. let lasttext;
  658. switch (data.type) {
  659. case 'text':
  660. lasttext = data['text'];
  661. break;
  662. case 'image':
  663. lasttext = '[图片]';
  664. break;
  665. default:
  666. lasttext = '[未知类型]';
  667. break;
  668. }
  669. this.addDialog({
  670. username: data.username,
  671. userimg: data.userimg,
  672. lasttext: lasttext,
  673. lastdate: data.indate
  674. }, msgDetail.sender != this.dialogTarget.username || !this.openWindow);
  675. if (msgDetail.sender == this.dialogTarget.username) {
  676. this.addMessageData(data, true);
  677. }
  678. if (!this.openWindow) {
  679. this.$Notice.close('chat-notice');
  680. this.$Notice.open({
  681. name: 'chat-notice',
  682. duration: 0,
  683. render: h => {
  684. return h('div', {
  685. class: 'chat-notice-box',
  686. on: {
  687. click: () => {
  688. this.$Notice.close('chat-notice');
  689. this.$emit("on-open-notice", data.username);
  690. this.clickDialog(data.username);
  691. }
  692. }
  693. }, [
  694. h('img', { class: 'chat-notice-userimg', attrs: { src: data.userimg } }),
  695. h('div', { class: 'ivu-notice-with-desc' }, [
  696. h('div', { class: 'ivu-notice-title' }, [
  697. h('UserView', { props: { username: data.username } })
  698. ]),
  699. h('div', { class: 'ivu-notice-desc' }, lasttext)
  700. ])
  701. ])
  702. }
  703. });
  704. }
  705. });
  706. },
  707. watch: {
  708. chatTap(val) {
  709. if (val === 'team' && this.teamReady == false) {
  710. this.teamReady = true;
  711. this.getTeamLists();
  712. } else if (val === 'dialog') {
  713. this.autoBottom = true;
  714. this.$nextTick(() => {
  715. this.messageBottomGo();
  716. });
  717. }
  718. },
  719. unreadTotal(val) {
  720. if (val < 0) {
  721. this.unreadTotal = 0;
  722. return;
  723. }
  724. this.$emit('input', val);
  725. },
  726. dialogTarget: {
  727. handler: function () {
  728. let username = this.dialogTarget.username;
  729. if (username === this.__dialogTargetUsername) {
  730. return;
  731. }
  732. this.__dialogTargetUsername = username;
  733. this.getDialogMessage();
  734. },
  735. deep: true
  736. }
  737. },
  738. computed: {
  739. dialogListsS() {
  740. return this.dialogLists.filter(item => {
  741. return (item.username + "").indexOf(this.dialogSearch) > -1 || (item.lasttext + "").indexOf(this.dialogSearch) > -1 || (item.nickname + "").indexOf(this.dialogSearch) > -1
  742. });
  743. },
  744. teamListsS() {
  745. return function (lists) {
  746. return lists.filter(item => {
  747. return (item.username + "").indexOf(this.teamSearch) > -1 || (item.nickname + "").indexOf(this.teamSearch) > -1
  748. });
  749. }
  750. }
  751. },
  752. methods: {
  753. formatCDate(v) {
  754. let string = '';
  755. if ($A.runNum(v) > 0) {
  756. if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
  757. string = $A.formatDate('H:i', v)
  758. } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
  759. string = $A.formatDate('m-d', v)
  760. } else {
  761. string = $A.formatDate('Y-m-d', v)
  762. }
  763. }
  764. return string || '';
  765. },
  766. getDialogLists() {
  767. this.loadIng++;
  768. this.dialogNoDataText = this.$L("数据加载中.....");
  769. $A.aAjax({
  770. url: 'chat/dialog/lists',
  771. complete: () => {
  772. this.loadIng--;
  773. },
  774. error: () => {
  775. this.dialogNoDataText = this.$L("数据加载失败!");
  776. },
  777. success: (res) => {
  778. if (res.ret === 1) {
  779. this.dialogLists = res.data;
  780. this.dialogNoDataText = this.$L("没有相关的数据");
  781. } else {
  782. this.dialogLists = [];
  783. this.dialogNoDataText = res.msg
  784. }
  785. }
  786. });
  787. },
  788. getDialogMessage(isNextPage = false) {
  789. if (isNextPage === true) {
  790. if (!this.messageHasMorePages) {
  791. return;
  792. }
  793. this.messageCurrentPage+= 1;
  794. } else {
  795. this.messageCurrentPage = 1;
  796. this.autoBottom = true;
  797. this.messageNew = 0;
  798. this.messageLists = [];
  799. }
  800. this.messageHasMorePages = false;
  801. //
  802. let username = this.dialogTarget.username;
  803. this.loadIng++;
  804. this.messageNoDataText = this.$L("数据加载中.....");
  805. $A.aAjax({
  806. url: 'chat/message/lists',
  807. data: {
  808. username: username,
  809. page: this.messageCurrentPage,
  810. pagesize: 30
  811. },
  812. complete: () => {
  813. this.loadIng--;
  814. },
  815. error: () => {
  816. this.messageNoDataText = this.$L("数据加载失败!");
  817. },
  818. success: (res) => {
  819. if (username != this.dialogTarget.username) {
  820. return;
  821. }
  822. if (res.ret === 1) {
  823. let tempId = "notice_" + $A.randomString(6);
  824. let tempLists = res.data.lists;
  825. if (isNextPage) {
  826. this.addMessageData({
  827. id: tempId,
  828. type: 'notice',
  829. notice: '历史消息',
  830. }, false, isNextPage);
  831. } else {
  832. tempLists = tempLists.reverse();
  833. }
  834. tempLists.forEach((item) => {
  835. this.addMessageData(Object.assign(item.message, {
  836. id: item.id,
  837. username: item.username,
  838. userimg: item.userimg,
  839. indate: item.indate,
  840. }), false, isNextPage);
  841. });
  842. if (isNextPage) {
  843. this.$nextTick(() => {
  844. let tempObj = $A('div[data-id="' + tempId + '"]');
  845. if (tempObj.length > 0) {
  846. this.$refs.manageLists.scrollTo(tempObj.offset().top - tempObj.height() - 24, false);
  847. }
  848. });
  849. }
  850. this.messageNoDataText = '';
  851. this.messageHasMorePages = res.data.hasMorePages;
  852. } else {
  853. this.messageNoDataText = res.msg
  854. this.messageHasMorePages = false;
  855. }
  856. }
  857. });
  858. },
  859. getTeamLists(isNextPage = false) {
  860. if (isNextPage === true) {
  861. if (!this.teamHasMorePages) {
  862. return;
  863. }
  864. this.teamCurrentPage+= 1;
  865. } else {
  866. this.teamCurrentPage = 1;
  867. }
  868. this.teamHasMorePages = false;
  869. //
  870. this.loadIng++;
  871. this.teamNoDataText = this.$L("数据加载中.....");
  872. $A.aAjax({
  873. url: 'users/team/lists',
  874. data: {
  875. sorts: {
  876. key: 'username',
  877. order: 'asc'
  878. },
  879. firstchart: 1,
  880. page: this.teamCurrentPage,
  881. pagesize: 100,
  882. },
  883. complete: () => {
  884. this.loadIng--;
  885. },
  886. error: () => {
  887. this.teamNoDataText = this.$L("数据加载失败!");
  888. },
  889. success: (res) => {
  890. if (res.ret === 1) {
  891. res.data.lists.forEach((item) => {
  892. if (typeof this.teamLists[item.firstchart] === "undefined") {
  893. this.$set(this.teamLists, item.firstchart, []);
  894. }
  895. this.teamLists[item.firstchart].push(item);
  896. });
  897. this.teamNoDataText = this.$L("没有相关的数据");
  898. this.teamHasMorePages = res.data.hasMorePages;
  899. //
  900. if (this.teamHasMorePages && res.data.currentPage < 5) {
  901. this.getTeamLists(true);
  902. }
  903. } else {
  904. this.teamLists = {};
  905. this.teamNoDataText = res.msg
  906. this.teamHasMorePages = false;
  907. }
  908. }
  909. });
  910. },
  911. addDialog(data, plusUnread = false) {
  912. if (!data.username) {
  913. return;
  914. }
  915. let lists = this.dialogLists.filter((item) => {return item.username == data.username});
  916. if (lists.length > 0) {
  917. data.unread = $A.runNum(lists[0].unread);
  918. this.dialogLists = this.dialogLists.filter((item) => {return item.username != data.username});
  919. } else {
  920. data.unread = 0;
  921. }
  922. if (plusUnread) {
  923. data.unread += 1;
  924. this.unreadTotal += 1;
  925. }
  926. this.dialogLists.unshift(data);
  927. },
  928. openDialog(user, autoAddDialog = false) {
  929. if (autoAddDialog === true) {
  930. let lists = this.dialogLists.filter((item) => {return item.username == user.username});
  931. if (lists.length === 0) {
  932. this.addDialog(user);
  933. }
  934. }
  935. this.chatTap = 'dialog';
  936. this.dialogTarget = user;
  937. if (typeof user.unread === "number" && user.unread > 0) {
  938. this.unreadTotal -= user.unread;
  939. this.$set(user, 'unread', 0);
  940. $A.WS.sendTo('read', user.username);
  941. }
  942. },
  943. clickDialog(username) {
  944. let lists = this.dialogLists.filter((item) => {return item.username == username});
  945. if (lists.length > 0) {
  946. this.openDialog(lists[0]);
  947. }
  948. },
  949. dialogDropdown(type) {
  950. switch (type) {
  951. case 'clear':
  952. case 'delete':
  953. this.$Modal.confirm({
  954. title: '确认操作',
  955. content: type === 'delete' ? '你确定要删除此对话吗?' : '你确定要清除聊天记录吗?',
  956. loading: true,
  957. onOk: () => {
  958. let username = this.dialogTarget.username;
  959. $A.aAjax({
  960. url: 'chat/dialog/clear',
  961. data: {
  962. username: username,
  963. delete: type === 'delete' ? 1 : 0
  964. },
  965. error: () => {
  966. this.$Modal.remove();
  967. alert(this.$L('网络繁忙,请稍后再试!'));
  968. },
  969. success: (res) => {
  970. this.$Modal.remove();
  971. if (res.ret === 1) {
  972. if (type === 'delete') {
  973. this.dialogLists = this.dialogLists.filter((item) => {return item.username != username});
  974. this.dialogTarget = {};
  975. } else {
  976. this.$set(this.dialogTarget, 'lasttext', '');
  977. this.getDialogMessage();
  978. }
  979. }
  980. setTimeout(() => {
  981. if (res.ret === 1) {
  982. this.$Message.success(res.msg);
  983. } else {
  984. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  985. }
  986. }, 350);
  987. }
  988. });
  989. }
  990. });
  991. break;
  992. }
  993. },
  994. messageListsScroll(res) {
  995. if (res.directionreal === 'up') {
  996. if (res.scrollE < 10) {
  997. this.autoBottom = true;
  998. }
  999. } else if (res.directionreal === 'down') {
  1000. this.autoBottom = false;
  1001. }
  1002. },
  1003. messageBottomAuto() {
  1004. let randString = $A.randomString(8);
  1005. window.__messageBottomAuto = randString;
  1006. setTimeout(() => {
  1007. if (randString === window.__messageBottomAuto) {
  1008. window.__messageBottomAuto = null;
  1009. if (this.autoBottom) {
  1010. this.messageBottomGo();
  1011. }
  1012. this.messageBottomAuto();
  1013. }
  1014. }, 1000);
  1015. },
  1016. messageBottomGo(animation = false) {
  1017. this.$nextTick(() => {
  1018. this.messageNew = 0;
  1019. if (typeof this.$refs.manageLists !== "undefined") {
  1020. this.$refs.manageLists.scrollTo(this.$refs.manageBody.clientHeight, animation);
  1021. this.autoBottom = true;
  1022. }
  1023. });
  1024. },
  1025. messageInsertText(emoji) {
  1026. this.messageText+= emoji;
  1027. },
  1028. messageInsertImage(lists) {
  1029. for (let i = 0; i < lists.length; i++) {
  1030. let item = lists[i];
  1031. if (typeof item === 'object' && typeof item.url === "string") {
  1032. let data = {
  1033. type: 'image',
  1034. username: this.userInfo.username,
  1035. userimg: this.userInfo.userimg,
  1036. indate: Math.round(new Date().getTime() / 1000),
  1037. url: item.url
  1038. };
  1039. $A.WS.sendTo('user', this.dialogTarget.username, data, (res) => {
  1040. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1041. });
  1042. //
  1043. this.addDialog(Object.assign(this.dialogTarget, {
  1044. lasttext: '[图片]',
  1045. lastdate: data.indate
  1046. }));
  1047. this.openDialog(this.dialogTarget);
  1048. this.addMessageData(data, true);
  1049. }
  1050. }
  1051. },
  1052. addMessageData(data, animation = false, isUnshift = false) {
  1053. data.self = data.username === this.userInfo.username;
  1054. let sikp = false;
  1055. if (data.id) {
  1056. this.messageLists.some((item, index) => {
  1057. if (item.id == data.id) {
  1058. this.messageLists.splice(index, 1, data);
  1059. return sikp = true;
  1060. }
  1061. });
  1062. if (sikp) {
  1063. return;
  1064. }
  1065. }
  1066. if (isUnshift) {
  1067. this.messageLists.unshift(data);
  1068. } else {
  1069. this.messageLists.push(data);
  1070. if (this.autoBottom) {
  1071. this.messageBottomGo(animation);
  1072. } else {
  1073. this.messageNew++;
  1074. }
  1075. }
  1076. },
  1077. messageSend(e) {
  1078. if (e.keyCode == 13) {
  1079. if (e.shiftKey) {
  1080. return;
  1081. }
  1082. e.preventDefault();
  1083. this.messageSubmit();
  1084. }
  1085. },
  1086. messageSubmit() {
  1087. let text = this.messageText.trim();
  1088. if ($A.count(text) > 0) {
  1089. let data = {
  1090. type: 'text',
  1091. username: this.userInfo.username,
  1092. userimg: this.userInfo.userimg,
  1093. indate: Math.round(new Date().getTime() / 1000),
  1094. text: text
  1095. };
  1096. $A.WS.sendTo('user', this.dialogTarget.username, data, (res) => {
  1097. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1098. });
  1099. //
  1100. this.addDialog(Object.assign(this.dialogTarget, {
  1101. lasttext: text,
  1102. lastdate: data.indate
  1103. }));
  1104. this.openDialog(this.dialogTarget);
  1105. this.addMessageData(data, true);
  1106. }
  1107. this.$nextTick(() => {
  1108. this.messageText = "";
  1109. });
  1110. },
  1111. }
  1112. }
  1113. </script>