Index.vue 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  1. <template>
  2. <div class="chat-index">
  3. <!--左边选项-->
  4. <ul class="chat-menu">
  5. <li class="self">
  6. <img :src="userInfo.userimg" onerror="this.src=window.location.origin+'/images/other/avatar.png'">
  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 ref="dialogLists" 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" onerror="this.src=window.location.origin+'/images/other/avatar.png'">
  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" onerror="this.src=window.location.origin+'/images/other/avatar.png'">
  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. if (autoAddDialog === true) {
  985. //自动滚到焦点
  986. this.$nextTick(() => {
  987. let dialogObj = $A(this.$refs.dialogLists);
  988. let activeObj = dialogObj.find("li.active");
  989. if (activeObj.length > 0) {
  990. let offsetTop = activeObj.offset().top;
  991. if (offsetTop < 0) {
  992. dialogObj.stop().scrollTop(activeObj[0].offsetTop)
  993. } else if (offsetTop > dialogObj.height()) {
  994. dialogObj.stop().scrollTop(activeObj[0].offsetTop + activeObj.height() - dialogObj.height())
  995. }
  996. }
  997. });
  998. }
  999. },
  1000. clickDialog(username) {
  1001. let lists = this.dialogLists.filter((item) => {return item.username == username});
  1002. if (lists.length > 0) {
  1003. this.openDialog(lists[0]);
  1004. }
  1005. },
  1006. dialogDropdown(type) {
  1007. switch (type) {
  1008. case 'clear':
  1009. case 'delete':
  1010. this.$Modal.confirm({
  1011. title: this.$L('确认操作'),
  1012. content: type === 'delete' ? this.$L('你确定要删除此对话吗?') : this.$L('你确定要清除聊天记录吗?'),
  1013. loading: true,
  1014. onOk: () => {
  1015. let username = this.dialogTarget.username;
  1016. $A.aAjax({
  1017. url: 'chat/dialog/clear',
  1018. data: {
  1019. username: username,
  1020. delete: type === 'delete' ? 1 : 0
  1021. },
  1022. error: () => {
  1023. this.$Modal.remove();
  1024. alert(this.$L('网络繁忙,请稍后再试!'));
  1025. },
  1026. success: (res) => {
  1027. this.$Modal.remove();
  1028. if (res.ret === 1) {
  1029. if (type === 'delete') {
  1030. this.dialogLists = this.dialogLists.filter((item) => {return item.username != username});
  1031. this.dialogTarget = {};
  1032. } else {
  1033. this.$set(this.dialogTarget, 'lasttext', '');
  1034. this.getDialogMessage();
  1035. }
  1036. }
  1037. setTimeout(() => {
  1038. if (res.ret === 1) {
  1039. this.$Message.success(res.msg);
  1040. } else {
  1041. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  1042. }
  1043. }, 350);
  1044. }
  1045. });
  1046. }
  1047. });
  1048. break;
  1049. }
  1050. },
  1051. messageListsScroll(res) {
  1052. if (res.directionreal === 'up') {
  1053. if (res.scrollE < 10) {
  1054. this.autoBottom = true;
  1055. }
  1056. } else if (res.directionreal === 'down') {
  1057. this.autoBottom = false;
  1058. }
  1059. },
  1060. messageBottomAuto() {
  1061. let randString = $A.randomString(8);
  1062. window.__messageBottomAuto = randString;
  1063. setTimeout(() => {
  1064. if (randString === window.__messageBottomAuto) {
  1065. window.__messageBottomAuto = null;
  1066. if (this.autoBottom) {
  1067. this.messageBottomGo();
  1068. }
  1069. this.messageBottomAuto();
  1070. }
  1071. }, 1000);
  1072. },
  1073. messageBottomGo(animation = false) {
  1074. this.$nextTick(() => {
  1075. this.messageNew = 0;
  1076. if (typeof this.$refs.manageLists !== "undefined") {
  1077. this.$refs.manageLists.scrollTo(this.$refs.manageBody.clientHeight, animation);
  1078. this.autoBottom = true;
  1079. }
  1080. });
  1081. },
  1082. messageInsertText(emoji) {
  1083. this.messageText+= emoji;
  1084. },
  1085. messageInsertImage(lists) {
  1086. for (let i = 0; i < lists.length; i++) {
  1087. let item = lists[i];
  1088. if (typeof item === 'object' && typeof item.url === "string") {
  1089. let data = {
  1090. type: 'image',
  1091. username: this.userInfo.username,
  1092. userimg: this.userInfo.userimg,
  1093. indate: Math.round(new Date().getTime() / 1000),
  1094. url: item.url
  1095. };
  1096. $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
  1097. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1098. });
  1099. //
  1100. this.addDialog(Object.assign(this.dialogTarget, {
  1101. lasttext: this.$L('[图片]'),
  1102. lastdate: data.indate
  1103. }));
  1104. this.openDialog(this.dialogTarget);
  1105. this.addMessageData(data, true);
  1106. }
  1107. }
  1108. },
  1109. addMessageData(data, animation = false, isUnshift = false) {
  1110. data.self = data.username === this.userInfo.username;
  1111. let sikp = false;
  1112. if (data.id) {
  1113. this.messageLists.some((item, index) => {
  1114. if (item.id == data.id) {
  1115. this.messageLists.splice(index, 1, data);
  1116. return sikp = true;
  1117. }
  1118. });
  1119. if (sikp) {
  1120. return;
  1121. }
  1122. }
  1123. if (isUnshift) {
  1124. this.messageLists.unshift(data);
  1125. } else {
  1126. this.messageLists.push(data);
  1127. if (this.autoBottom) {
  1128. this.messageBottomGo(animation);
  1129. } else {
  1130. this.messageNew++;
  1131. }
  1132. }
  1133. },
  1134. messageSend(e) {
  1135. if (e.keyCode == 13) {
  1136. if (e.shiftKey) {
  1137. return;
  1138. }
  1139. e.preventDefault();
  1140. this.messageSubmit();
  1141. }
  1142. },
  1143. messageSubmit() {
  1144. let dialogUser = this.dialogLists.filter((item) => { return item.username == this.dialogTarget.username });
  1145. if (dialogUser.length > 0) {
  1146. let user = dialogUser[0];
  1147. if (typeof user.unread === "number" && user.unread > 0) {
  1148. this.unreadTotal -= user.unread;
  1149. this.$set(user, 'unread', 0);
  1150. $A.WSOB.sendTo('read', user.username);
  1151. }
  1152. }
  1153. //
  1154. let text = this.messageText.trim();
  1155. if ($A.count(text) > 0) {
  1156. let data = {
  1157. type: 'text',
  1158. username: this.userInfo.username,
  1159. userimg: this.userInfo.userimg,
  1160. indate: Math.round(new Date().getTime() / 1000),
  1161. text: text
  1162. };
  1163. $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
  1164. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1165. });
  1166. //
  1167. this.addDialog(Object.assign(this.dialogTarget, {
  1168. lasttext: text,
  1169. lastdate: data.indate
  1170. }));
  1171. this.openDialog(this.dialogTarget);
  1172. this.addMessageData(data, true);
  1173. }
  1174. this.$nextTick(() => {
  1175. this.messageText = "";
  1176. });
  1177. },
  1178. userViewResult(user, data) {
  1179. this.$set(user, 'nickname', data.nickname);
  1180. this.$set(user, 'userimg', data.userimg);
  1181. },
  1182. }
  1183. }
  1184. </script>