Index.vue 47 KB

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