Index.vue 46 KB

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