Index.vue 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  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. 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.WS.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.WS.setOnMsgListener("chat/index", (msgDetail) => {
  661. if (msgDetail.sender == $A.getUserName()) {
  662. return;
  663. }
  664. if (msgDetail.messageType == 'open') {
  665. if (this.openWindow) {
  666. this.getDialogLists();
  667. this.getDialogMessage();
  668. } else {
  669. this.openAlready = false;
  670. this.dialogTarget = {};
  671. }
  672. return;
  673. }
  674. if (msgDetail.messageType != 'send') {
  675. return;
  676. }
  677. //
  678. let content = $A.jsonParse(msgDetail.content);
  679. if (['taskA'].indexOf(content.type) !== -1) {
  680. return;
  681. }
  682. let lasttext = $A.WS.getMsgDesc(content);
  683. let plusUnread = msgDetail.sender != this.dialogTarget.username || !this.openWindow;
  684. this.addDialog({
  685. username: content.username,
  686. userimg: content.userimg,
  687. lasttext: lasttext,
  688. lastdate: content.indate
  689. }, plusUnread && content.resend !== 1);
  690. if (msgDetail.sender == this.dialogTarget.username) {
  691. this.addMessageData(content, true);
  692. }
  693. if (!plusUnread) {
  694. $A.WS.sendTo('read', content.username);
  695. }
  696. if (!this.openWindow) {
  697. this.$Notice.close('chat-notice');
  698. this.$Notice.open({
  699. name: 'chat-notice',
  700. duration: 0,
  701. render: h => {
  702. return h('div', {
  703. class: 'chat-notice-box',
  704. on: {
  705. click: () => {
  706. this.$Notice.close('chat-notice');
  707. this.$emit("on-open-notice", content.username);
  708. this.clickDialog(content.username);
  709. }
  710. }
  711. }, [
  712. h('img', { class: 'chat-notice-userimg', attrs: { src: content.userimg } }),
  713. h('div', { class: 'ivu-notice-with-desc' }, [
  714. h('div', { class: 'ivu-notice-title' }, [
  715. h('UserView', { props: { username: content.username } })
  716. ]),
  717. h('div', { class: 'ivu-notice-desc' }, lasttext)
  718. ])
  719. ])
  720. }
  721. });
  722. }
  723. });
  724. $A.WS.setOnSpecialListener("chat/index", (content) => {
  725. this.addDialog({
  726. username: content.username,
  727. userimg: content.userimg,
  728. lasttext: $A.WS.getMsgDesc(content),
  729. lastdate: content.indate
  730. });
  731. });
  732. },
  733. watch: {
  734. chatTap(val) {
  735. if (val === 'team' && this.teamReady == false) {
  736. this.teamReady = true;
  737. this.getTeamLists();
  738. } else if (val === 'dialog') {
  739. this.autoBottom = true;
  740. this.$nextTick(() => {
  741. this.messageBottomGo();
  742. });
  743. }
  744. },
  745. openWindow(val) {
  746. if (val) {
  747. $A.WS.connection();
  748. if (!this.openAlready) {
  749. this.openAlready = true;
  750. this.getDialogLists();
  751. }
  752. }
  753. },
  754. unreadTotal(val) {
  755. if (val < 0) {
  756. this.unreadTotal = 0;
  757. return;
  758. }
  759. this.$emit('input', val);
  760. },
  761. dialogTarget: {
  762. handler: function () {
  763. let username = this.dialogTarget.username;
  764. if (username === this.__dialogTargetUsername) {
  765. return;
  766. }
  767. this.__dialogTargetUsername = username;
  768. this.getDialogMessage();
  769. },
  770. deep: true
  771. }
  772. },
  773. computed: {
  774. dialogListsS() {
  775. return this.dialogLists.filter(item => {
  776. return (item.username + "").indexOf(this.dialogSearch) > -1 || (item.lasttext + "").indexOf(this.dialogSearch) > -1 || (item.nickname + "").indexOf(this.dialogSearch) > -1
  777. });
  778. },
  779. teamListsS() {
  780. return function (lists) {
  781. return lists.filter(item => {
  782. return (item.username + "").indexOf(this.teamSearch) > -1 || (item.nickname + "").indexOf(this.teamSearch) > -1
  783. });
  784. }
  785. }
  786. },
  787. methods: {
  788. formatCDate(v) {
  789. let string = '';
  790. if ($A.runNum(v) > 0) {
  791. if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
  792. string = $A.formatDate('H:i', v)
  793. } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
  794. string = $A.formatDate('m-d', v)
  795. } else {
  796. string = $A.formatDate('Y-m-d', v)
  797. }
  798. }
  799. return string || '';
  800. },
  801. getDialogLists() {
  802. if (!this.openAlready) {
  803. return;
  804. }
  805. this.loadIng++;
  806. this.dialogNoDataText = this.$L("数据加载中.....");
  807. $A.aAjax({
  808. url: 'chat/dialog/lists',
  809. complete: () => {
  810. this.loadIng--;
  811. },
  812. error: () => {
  813. this.dialogNoDataText = this.$L("数据加载失败!");
  814. },
  815. success: (res) => {
  816. if (res.ret === 1) {
  817. this.dialogLists = res.data;
  818. this.dialogNoDataText = this.$L("没有相关的数据");
  819. } else {
  820. this.dialogLists = [];
  821. this.dialogNoDataText = res.msg
  822. }
  823. }
  824. });
  825. },
  826. getDialogMessage(isNextPage = false) {
  827. let username = this.dialogTarget.username;
  828. if (!username) {
  829. return;
  830. }
  831. //
  832. if (isNextPage === true) {
  833. if (!this.messageHasMorePages) {
  834. return;
  835. }
  836. this.messageCurrentPage+= 1;
  837. } else {
  838. this.messageCurrentPage = 1;
  839. this.autoBottom = true;
  840. this.messageNew = 0;
  841. this.messageLists = [];
  842. }
  843. this.messageHasMorePages = false;
  844. //
  845. this.loadIng++;
  846. this.messageNoDataText = this.$L("数据加载中.....");
  847. $A.aAjax({
  848. url: 'chat/message/lists',
  849. data: {
  850. username: username,
  851. page: this.messageCurrentPage,
  852. pagesize: 30
  853. },
  854. complete: () => {
  855. this.loadIng--;
  856. },
  857. error: () => {
  858. this.messageNoDataText = this.$L("数据加载失败!");
  859. },
  860. success: (res) => {
  861. if (username != this.dialogTarget.username) {
  862. return;
  863. }
  864. if (res.ret === 1) {
  865. let tempId = "notice_" + $A.randomString(6);
  866. let tempLists = res.data.lists;
  867. if (isNextPage) {
  868. this.addMessageData({
  869. id: tempId,
  870. type: 'notice',
  871. notice: this.$L('历史消息'),
  872. }, false, isNextPage);
  873. } else {
  874. tempLists = tempLists.reverse();
  875. }
  876. tempLists.forEach((item) => {
  877. this.addMessageData(Object.assign(item.message, {
  878. id: item.id,
  879. username: item.username,
  880. userimg: item.userimg,
  881. indate: item.indate,
  882. }), false, isNextPage);
  883. });
  884. if (isNextPage) {
  885. this.$nextTick(() => {
  886. let tempObj = $A('div[data-id="' + tempId + '"]');
  887. if (tempObj.length > 0) {
  888. this.$refs.manageLists.scrollTo(tempObj.offset().top - tempObj.height() - 24, false);
  889. }
  890. });
  891. }
  892. this.messageNoDataText = '';
  893. this.messageHasMorePages = res.data.hasMorePages;
  894. } else {
  895. this.messageNoDataText = res.msg
  896. this.messageHasMorePages = false;
  897. }
  898. }
  899. });
  900. },
  901. getTeamLists(isNextPage = false) {
  902. if (isNextPage === true) {
  903. if (!this.teamHasMorePages) {
  904. return;
  905. }
  906. this.teamCurrentPage+= 1;
  907. } else {
  908. this.teamCurrentPage = 1;
  909. }
  910. this.teamHasMorePages = false;
  911. //
  912. this.loadIng++;
  913. this.teamNoDataText = this.$L("数据加载中.....");
  914. $A.aAjax({
  915. url: 'users/team/lists',
  916. data: {
  917. sorts: {
  918. key: 'username',
  919. order: 'asc'
  920. },
  921. firstchart: 1,
  922. page: this.teamCurrentPage,
  923. pagesize: 100,
  924. },
  925. complete: () => {
  926. this.loadIng--;
  927. },
  928. error: () => {
  929. this.teamNoDataText = this.$L("数据加载失败!");
  930. },
  931. success: (res) => {
  932. if (res.ret === 1) {
  933. res.data.lists.forEach((item) => {
  934. if (typeof this.teamLists[item.firstchart] === "undefined") {
  935. this.$set(this.teamLists, item.firstchart, []);
  936. }
  937. this.teamLists[item.firstchart].push(item);
  938. });
  939. this.teamNoDataText = this.$L("没有相关的数据");
  940. this.teamHasMorePages = res.data.hasMorePages;
  941. //
  942. if (this.teamHasMorePages && res.data.currentPage < 5) {
  943. this.getTeamLists(true);
  944. }
  945. } else {
  946. this.teamLists = {};
  947. this.teamNoDataText = res.msg
  948. this.teamHasMorePages = false;
  949. }
  950. }
  951. });
  952. },
  953. addDialog(data, plusUnread = false) {
  954. if (!data.username) {
  955. return;
  956. }
  957. let lists = this.dialogLists.filter((item) => {return item.username == data.username});
  958. if (lists.length > 0) {
  959. data.unread = $A.runNum(lists[0].unread);
  960. this.dialogLists = this.dialogLists.filter((item) => {return item.username != data.username});
  961. } else {
  962. data.unread = 0;
  963. }
  964. if (plusUnread) {
  965. data.unread += 1;
  966. this.unreadTotal += 1;
  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.WS.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.WS.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.WS.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. }
  1154. }
  1155. </script>