Index.vue 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  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. if (['taskA'].indexOf(data.type) !== -1) {
  658. return;
  659. }
  660. let lasttext;
  661. switch (data.type) {
  662. case 'text':
  663. lasttext = data.text;
  664. break;
  665. case 'image':
  666. lasttext = '[图片]';
  667. break;
  668. case 'taskB':
  669. lasttext = data.detail + " [来自关注任务]";
  670. break;
  671. default:
  672. lasttext = '[未知类型]';
  673. break;
  674. }
  675. let plusUnread = msgDetail.sender != this.dialogTarget.username || !this.openWindow;
  676. this.addDialog({
  677. username: data.username,
  678. userimg: data.userimg,
  679. lasttext: lasttext,
  680. lastdate: data.indate
  681. }, plusUnread);
  682. if (msgDetail.sender == this.dialogTarget.username) {
  683. this.addMessageData(data, true);
  684. }
  685. if (!plusUnread) {
  686. $A.WS.sendTo('read', data.username);
  687. }
  688. if (!this.openWindow) {
  689. this.$Notice.close('chat-notice');
  690. this.$Notice.open({
  691. name: 'chat-notice',
  692. duration: 0,
  693. render: h => {
  694. return h('div', {
  695. class: 'chat-notice-box',
  696. on: {
  697. click: () => {
  698. this.$Notice.close('chat-notice');
  699. this.$emit("on-open-notice", data.username);
  700. this.clickDialog(data.username);
  701. }
  702. }
  703. }, [
  704. h('img', { class: 'chat-notice-userimg', attrs: { src: data.userimg } }),
  705. h('div', { class: 'ivu-notice-with-desc' }, [
  706. h('div', { class: 'ivu-notice-title' }, [
  707. h('UserView', { props: { username: data.username } })
  708. ]),
  709. h('div', { class: 'ivu-notice-desc' }, lasttext)
  710. ])
  711. ])
  712. }
  713. });
  714. }
  715. });
  716. },
  717. watch: {
  718. chatTap(val) {
  719. if (val === 'team' && this.teamReady == false) {
  720. this.teamReady = true;
  721. this.getTeamLists();
  722. } else if (val === 'dialog') {
  723. this.autoBottom = true;
  724. this.$nextTick(() => {
  725. this.messageBottomGo();
  726. });
  727. }
  728. },
  729. unreadTotal(val) {
  730. if (val < 0) {
  731. this.unreadTotal = 0;
  732. return;
  733. }
  734. this.$emit('input', val);
  735. },
  736. dialogTarget: {
  737. handler: function () {
  738. let username = this.dialogTarget.username;
  739. if (username === this.__dialogTargetUsername) {
  740. return;
  741. }
  742. this.__dialogTargetUsername = username;
  743. this.getDialogMessage();
  744. },
  745. deep: true
  746. }
  747. },
  748. computed: {
  749. dialogListsS() {
  750. return this.dialogLists.filter(item => {
  751. return (item.username + "").indexOf(this.dialogSearch) > -1 || (item.lasttext + "").indexOf(this.dialogSearch) > -1 || (item.nickname + "").indexOf(this.dialogSearch) > -1
  752. });
  753. },
  754. teamListsS() {
  755. return function (lists) {
  756. return lists.filter(item => {
  757. return (item.username + "").indexOf(this.teamSearch) > -1 || (item.nickname + "").indexOf(this.teamSearch) > -1
  758. });
  759. }
  760. }
  761. },
  762. methods: {
  763. formatCDate(v) {
  764. let string = '';
  765. if ($A.runNum(v) > 0) {
  766. if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
  767. string = $A.formatDate('H:i', v)
  768. } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
  769. string = $A.formatDate('m-d', v)
  770. } else {
  771. string = $A.formatDate('Y-m-d', v)
  772. }
  773. }
  774. return string || '';
  775. },
  776. getDialogLists() {
  777. this.loadIng++;
  778. this.dialogNoDataText = this.$L("数据加载中.....");
  779. $A.aAjax({
  780. url: 'chat/dialog/lists',
  781. complete: () => {
  782. this.loadIng--;
  783. },
  784. error: () => {
  785. this.dialogNoDataText = this.$L("数据加载失败!");
  786. },
  787. success: (res) => {
  788. if (res.ret === 1) {
  789. this.dialogLists = res.data;
  790. this.dialogNoDataText = this.$L("没有相关的数据");
  791. } else {
  792. this.dialogLists = [];
  793. this.dialogNoDataText = res.msg
  794. }
  795. }
  796. });
  797. },
  798. getDialogMessage(isNextPage = false) {
  799. if (isNextPage === true) {
  800. if (!this.messageHasMorePages) {
  801. return;
  802. }
  803. this.messageCurrentPage+= 1;
  804. } else {
  805. this.messageCurrentPage = 1;
  806. this.autoBottom = true;
  807. this.messageNew = 0;
  808. this.messageLists = [];
  809. }
  810. this.messageHasMorePages = false;
  811. //
  812. let username = this.dialogTarget.username;
  813. this.loadIng++;
  814. this.messageNoDataText = this.$L("数据加载中.....");
  815. $A.aAjax({
  816. url: 'chat/message/lists',
  817. data: {
  818. username: username,
  819. page: this.messageCurrentPage,
  820. pagesize: 30
  821. },
  822. complete: () => {
  823. this.loadIng--;
  824. },
  825. error: () => {
  826. this.messageNoDataText = this.$L("数据加载失败!");
  827. },
  828. success: (res) => {
  829. if (username != this.dialogTarget.username) {
  830. return;
  831. }
  832. if (res.ret === 1) {
  833. let tempId = "notice_" + $A.randomString(6);
  834. let tempLists = res.data.lists;
  835. if (isNextPage) {
  836. this.addMessageData({
  837. id: tempId,
  838. type: 'notice',
  839. notice: '历史消息',
  840. }, false, isNextPage);
  841. } else {
  842. tempLists = tempLists.reverse();
  843. }
  844. tempLists.forEach((item) => {
  845. this.addMessageData(Object.assign(item.message, {
  846. id: item.id,
  847. username: item.username,
  848. userimg: item.userimg,
  849. indate: item.indate,
  850. }), false, isNextPage);
  851. });
  852. if (isNextPage) {
  853. this.$nextTick(() => {
  854. let tempObj = $A('div[data-id="' + tempId + '"]');
  855. if (tempObj.length > 0) {
  856. this.$refs.manageLists.scrollTo(tempObj.offset().top - tempObj.height() - 24, false);
  857. }
  858. });
  859. }
  860. this.messageNoDataText = '';
  861. this.messageHasMorePages = res.data.hasMorePages;
  862. } else {
  863. this.messageNoDataText = res.msg
  864. this.messageHasMorePages = false;
  865. }
  866. }
  867. });
  868. },
  869. getTeamLists(isNextPage = false) {
  870. if (isNextPage === true) {
  871. if (!this.teamHasMorePages) {
  872. return;
  873. }
  874. this.teamCurrentPage+= 1;
  875. } else {
  876. this.teamCurrentPage = 1;
  877. }
  878. this.teamHasMorePages = false;
  879. //
  880. this.loadIng++;
  881. this.teamNoDataText = this.$L("数据加载中.....");
  882. $A.aAjax({
  883. url: 'users/team/lists',
  884. data: {
  885. sorts: {
  886. key: 'username',
  887. order: 'asc'
  888. },
  889. firstchart: 1,
  890. page: this.teamCurrentPage,
  891. pagesize: 100,
  892. },
  893. complete: () => {
  894. this.loadIng--;
  895. },
  896. error: () => {
  897. this.teamNoDataText = this.$L("数据加载失败!");
  898. },
  899. success: (res) => {
  900. if (res.ret === 1) {
  901. res.data.lists.forEach((item) => {
  902. if (typeof this.teamLists[item.firstchart] === "undefined") {
  903. this.$set(this.teamLists, item.firstchart, []);
  904. }
  905. this.teamLists[item.firstchart].push(item);
  906. });
  907. this.teamNoDataText = this.$L("没有相关的数据");
  908. this.teamHasMorePages = res.data.hasMorePages;
  909. //
  910. if (this.teamHasMorePages && res.data.currentPage < 5) {
  911. this.getTeamLists(true);
  912. }
  913. } else {
  914. this.teamLists = {};
  915. this.teamNoDataText = res.msg
  916. this.teamHasMorePages = false;
  917. }
  918. }
  919. });
  920. },
  921. addDialog(data, plusUnread = false) {
  922. if (!data.username) {
  923. return;
  924. }
  925. let lists = this.dialogLists.filter((item) => {return item.username == data.username});
  926. if (lists.length > 0) {
  927. data.unread = $A.runNum(lists[0].unread);
  928. this.dialogLists = this.dialogLists.filter((item) => {return item.username != data.username});
  929. } else {
  930. data.unread = 0;
  931. }
  932. if (plusUnread) {
  933. data.unread += 1;
  934. this.unreadTotal += 1;
  935. }
  936. this.dialogLists.unshift(data);
  937. },
  938. openDialog(user, autoAddDialog = false) {
  939. if (autoAddDialog === true) {
  940. let lists = this.dialogLists.filter((item) => {return item.username == user.username});
  941. if (lists.length === 0) {
  942. this.addDialog(user);
  943. }
  944. }
  945. this.chatTap = 'dialog';
  946. this.dialogTarget = user;
  947. if (typeof user.unread === "number" && user.unread > 0) {
  948. this.unreadTotal -= user.unread;
  949. this.$set(user, 'unread', 0);
  950. $A.WS.sendTo('read', user.username);
  951. }
  952. },
  953. clickDialog(username) {
  954. let lists = this.dialogLists.filter((item) => {return item.username == username});
  955. if (lists.length > 0) {
  956. this.openDialog(lists[0]);
  957. }
  958. },
  959. dialogDropdown(type) {
  960. switch (type) {
  961. case 'clear':
  962. case 'delete':
  963. this.$Modal.confirm({
  964. title: '确认操作',
  965. content: type === 'delete' ? '你确定要删除此对话吗?' : '你确定要清除聊天记录吗?',
  966. loading: true,
  967. onOk: () => {
  968. let username = this.dialogTarget.username;
  969. $A.aAjax({
  970. url: 'chat/dialog/clear',
  971. data: {
  972. username: username,
  973. delete: type === 'delete' ? 1 : 0
  974. },
  975. error: () => {
  976. this.$Modal.remove();
  977. alert(this.$L('网络繁忙,请稍后再试!'));
  978. },
  979. success: (res) => {
  980. this.$Modal.remove();
  981. if (res.ret === 1) {
  982. if (type === 'delete') {
  983. this.dialogLists = this.dialogLists.filter((item) => {return item.username != username});
  984. this.dialogTarget = {};
  985. } else {
  986. this.$set(this.dialogTarget, 'lasttext', '');
  987. this.getDialogMessage();
  988. }
  989. }
  990. setTimeout(() => {
  991. if (res.ret === 1) {
  992. this.$Message.success(res.msg);
  993. } else {
  994. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  995. }
  996. }, 350);
  997. }
  998. });
  999. }
  1000. });
  1001. break;
  1002. }
  1003. },
  1004. messageListsScroll(res) {
  1005. if (res.directionreal === 'up') {
  1006. if (res.scrollE < 10) {
  1007. this.autoBottom = true;
  1008. }
  1009. } else if (res.directionreal === 'down') {
  1010. this.autoBottom = false;
  1011. }
  1012. },
  1013. messageBottomAuto() {
  1014. let randString = $A.randomString(8);
  1015. window.__messageBottomAuto = randString;
  1016. setTimeout(() => {
  1017. if (randString === window.__messageBottomAuto) {
  1018. window.__messageBottomAuto = null;
  1019. if (this.autoBottom) {
  1020. this.messageBottomGo();
  1021. }
  1022. this.messageBottomAuto();
  1023. }
  1024. }, 1000);
  1025. },
  1026. messageBottomGo(animation = false) {
  1027. this.$nextTick(() => {
  1028. this.messageNew = 0;
  1029. if (typeof this.$refs.manageLists !== "undefined") {
  1030. this.$refs.manageLists.scrollTo(this.$refs.manageBody.clientHeight, animation);
  1031. this.autoBottom = true;
  1032. }
  1033. });
  1034. },
  1035. messageInsertText(emoji) {
  1036. this.messageText+= emoji;
  1037. },
  1038. messageInsertImage(lists) {
  1039. for (let i = 0; i < lists.length; i++) {
  1040. let item = lists[i];
  1041. if (typeof item === 'object' && typeof item.url === "string") {
  1042. let data = {
  1043. type: 'image',
  1044. username: this.userInfo.username,
  1045. userimg: this.userInfo.userimg,
  1046. indate: Math.round(new Date().getTime() / 1000),
  1047. url: item.url
  1048. };
  1049. $A.WS.sendTo('user', this.dialogTarget.username, data, (res) => {
  1050. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1051. });
  1052. //
  1053. this.addDialog(Object.assign(this.dialogTarget, {
  1054. lasttext: '[图片]',
  1055. lastdate: data.indate
  1056. }));
  1057. this.openDialog(this.dialogTarget);
  1058. this.addMessageData(data, true);
  1059. }
  1060. }
  1061. },
  1062. addMessageData(data, animation = false, isUnshift = false) {
  1063. data.self = data.username === this.userInfo.username;
  1064. let sikp = false;
  1065. if (data.id) {
  1066. this.messageLists.some((item, index) => {
  1067. if (item.id == data.id) {
  1068. this.messageLists.splice(index, 1, data);
  1069. return sikp = true;
  1070. }
  1071. });
  1072. if (sikp) {
  1073. return;
  1074. }
  1075. }
  1076. if (isUnshift) {
  1077. this.messageLists.unshift(data);
  1078. } else {
  1079. this.messageLists.push(data);
  1080. if (this.autoBottom) {
  1081. this.messageBottomGo(animation);
  1082. } else {
  1083. this.messageNew++;
  1084. }
  1085. }
  1086. },
  1087. messageSend(e) {
  1088. if (e.keyCode == 13) {
  1089. if (e.shiftKey) {
  1090. return;
  1091. }
  1092. e.preventDefault();
  1093. this.messageSubmit();
  1094. }
  1095. },
  1096. messageSubmit() {
  1097. let text = this.messageText.trim();
  1098. if ($A.count(text) > 0) {
  1099. let data = {
  1100. type: 'text',
  1101. username: this.userInfo.username,
  1102. userimg: this.userInfo.userimg,
  1103. indate: Math.round(new Date().getTime() / 1000),
  1104. text: text
  1105. };
  1106. $A.WS.sendTo('user', this.dialogTarget.username, data, (res) => {
  1107. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1108. });
  1109. //
  1110. this.addDialog(Object.assign(this.dialogTarget, {
  1111. lasttext: text,
  1112. lastdate: data.indate
  1113. }));
  1114. this.openDialog(this.dialogTarget);
  1115. this.addMessageData(data, true);
  1116. }
  1117. this.$nextTick(() => {
  1118. this.messageText = "";
  1119. });
  1120. },
  1121. }
  1122. }
  1123. </script>