Index.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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'"><Icon type="md-text" /></li>
  9. <li :class="{active:chatTap=='team'}" @click="chatTap='team'"><Icon type="md-person" /></li>
  10. </ul>
  11. <!--对话列表-->
  12. <ul v-if="chatTap=='dialog'" class="chat-user">
  13. <li class="sreach">
  14. <Input placeholder="搜索" prefix="ios-search"/>
  15. </li>
  16. <li v-for="(dialog, index) in dialogLists"
  17. :key="index"
  18. :class="{active:dialog.username==dialogTarget.username}"
  19. @click="openDialog(dialog)">
  20. <img :src="dialog.userimg">
  21. <div class="user-msg-box">
  22. <div class="user-msg-title">
  23. <span><user-view :username="dialog.username"/></span>
  24. <em>{{formatCDate(dialog.lastdate)}}</em>
  25. </div>
  26. <div class="user-msg-text">{{dialog.lasttext}}</div>
  27. </div>
  28. </li>
  29. <li v-if="dialogLists.length == 0" class="chat-none">{{dialogNoDataText}}</li>
  30. </ul>
  31. <!--联系人列表-->
  32. <ul v-else-if="chatTap=='team'" class="chat-team">
  33. <li class="sreach">
  34. <Input placeholder="搜索" prefix="ios-search"/>
  35. </li>
  36. <li v-for="(lists, key) in teamLists">
  37. <div class="team-label">{{key}}</div>
  38. <ul>
  39. <li v-for="(item, index) in lists" :key="index" @click="openDialog(item)">
  40. <img :src="item.userimg">
  41. <div class="team-username"><user-view :username="item.username"/></div>
  42. </li>
  43. </ul>
  44. </li>
  45. <li v-if="Object.keys(teamLists).length == 0" class="chat-none">{{teamNoDataText}}</li>
  46. </ul>
  47. <!--对话窗口-->
  48. <div v-if="chatTap=='dialog' && dialogTarget.username" class="chat-message">
  49. <div class="manage-title">
  50. <user-view :username="dialogTarget.username"/>
  51. <Dropdown class="manage-title-right" placement="bottom-end" trigger="click" transfer>
  52. <Icon type="ios-more"/>
  53. <DropdownMenu slot="list">
  54. <DropdownItem name="clear">清除聊天记录</DropdownItem>
  55. </DropdownMenu>
  56. </Dropdown>
  57. </div>
  58. <ScrollerY ref="manageLists" class="manage-lists" @on-scroll="messageListsScroll">
  59. <div ref="manageBody" class="manage-body">
  60. <chat-message v-for="(info, index) in messageLists" :key="index" :info="info"></chat-message>
  61. </div>
  62. <div class="manage-lists-message-new" v-if="messageNew > 0" @click="messageBottomGo(true)">有{{messageNew}}条新消息</div>
  63. </ScrollerY>
  64. <div class="manage-send">
  65. <textarea ref="textarea" class="manage-input" v-model="messageText" placeholder="请输入要发送的消息" @keydown="messageSend($event)"></textarea>
  66. </div>
  67. <div class="manage-quick">
  68. <emoji-picker @emoji="messageInsertText" :search="messageEmojiSearch">
  69. <div slot="emoji-invoker" slot-scope="{ events: { click: clickEvent } }" @click.stop="clickEvent">
  70. <Icon class="quick-item" type="ios-happy-outline" />
  71. </div>
  72. <div slot="emoji-picker" slot-scope="{ emojis, insert, display }">
  73. <div class="emoji-box">
  74. <Input class="emoji-input" placeholder="搜索" v-model="messageEmojiSearch" prefix="ios-search"/>
  75. <div>
  76. <div v-for="(emojiGroup, category) in emojis" :key="category">
  77. <h5>{{ category }}</h5>
  78. <div class="emojis">
  79. <span v-for="(emoji, emojiName) in emojiGroup" :key="emojiName" @click="insert(emoji)" :title="emojiName">{{ emoji }}</span>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </emoji-picker>
  86. <Icon class="quick-item" type="ios-photos-outline" @click="$refs.messageUpload.handleClick()"/>
  87. <img-upload ref="messageUpload" class="message-upload" type="callback" @on-callback="messageInsertImage" num="3" :otherParams="{from:'chat'}"></img-upload>
  88. </div>
  89. </div>
  90. </div>
  91. </template>
  92. <style lang="scss" scoped>
  93. .chat-index {
  94. display: flex;
  95. flex-direction: row;
  96. align-items: flex-start;
  97. position: absolute;
  98. top: 0;
  99. left: 0;
  100. right: 0;
  101. bottom: 0;
  102. .chat-none {
  103. height: auto;
  104. color: #666666;
  105. padding: 22px 8px;
  106. text-align: center;
  107. justify-content: center;
  108. &:before {
  109. display: none;
  110. }
  111. }
  112. .chat-menu {
  113. background-color: rgba(28, 29, 31, 0.92);
  114. width: 68px;
  115. height: 100%;
  116. padding-top: 20px;
  117. li {
  118. padding: 12px 0;
  119. text-align: center;
  120. font-size: 28px;
  121. color: #919193;
  122. background-color: transparent;
  123. cursor: pointer;
  124. &.self {
  125. img {
  126. width: 36px;
  127. height: 36px;
  128. border-radius: 3px;
  129. }
  130. }
  131. &.active {
  132. color: #ffffff;
  133. background-color: rgba(255, 255, 255, 0.06);
  134. }
  135. }
  136. }
  137. .chat-user {
  138. width: 248px;
  139. height: 100%;
  140. background-color: #ffffff;
  141. border-right: 1px solid #ededed;
  142. li {
  143. display: flex;
  144. flex-direction: row;
  145. align-items: center;
  146. height: 70px;
  147. padding: 0 12px;
  148. position: relative;
  149. cursor: pointer;
  150. &:before {
  151. content: "";
  152. position: absolute;
  153. left: 0;
  154. right: 0;
  155. bottom: 0;
  156. height: 1px;
  157. background-color: rgba(0, 0, 0, 0.06);
  158. }
  159. &.sreach {
  160. height: 62px;
  161. }
  162. &.active {
  163. &:before {
  164. top: 0;
  165. height: 100%;
  166. }
  167. }
  168. img {
  169. width: 42px;
  170. height: 42px;
  171. border-radius: 4px;
  172. }
  173. .user-msg-box {
  174. flex: 1;
  175. display: flex;
  176. flex-direction: column;
  177. padding-left: 12px;
  178. .user-msg-title {
  179. display: flex;
  180. flex-direction: row;
  181. align-items: center;
  182. justify-content: space-between;
  183. line-height: 24px;
  184. span {
  185. flex: 1;
  186. max-width: 130px;
  187. color: #333333;
  188. font-size: 14px;
  189. white-space: nowrap;
  190. overflow: hidden;
  191. text-overflow: ellipsis;
  192. }
  193. em {
  194. color: #999999;
  195. font-size: 12px;
  196. }
  197. }
  198. .user-msg-text {
  199. max-width: 170px;
  200. color: #999999;
  201. font-size: 12px;
  202. line-height: 24px;
  203. white-space: nowrap;
  204. overflow: hidden;
  205. text-overflow: ellipsis;
  206. }
  207. }
  208. }
  209. }
  210. .chat-team {
  211. width: 248px;
  212. height: 100%;
  213. background-color: #ffffff;
  214. border-right: 1px solid #ededed;
  215. > li {
  216. margin-left: 24px;
  217. position: relative;
  218. &.sreach {
  219. display: flex;
  220. flex-direction: row;
  221. align-items: center;
  222. height: 62px;
  223. margin: 0;
  224. padding: 0 12px;
  225. position: relative;
  226. cursor: pointer;
  227. &:before {
  228. content: "";
  229. position: absolute;
  230. left: 0;
  231. right: 0;
  232. bottom: 0;
  233. height: 1px;
  234. background-color: rgba(0, 0, 0, 0.06);
  235. }
  236. }
  237. .team-label {
  238. padding-left: 4px;
  239. margin-top: 6px;
  240. margin-bottom: 6px;
  241. height: 34px;
  242. line-height: 34px;
  243. border-bottom: 1px solid #efefef;
  244. }
  245. > ul {
  246. > li {
  247. display: flex;
  248. flex-direction: row;
  249. align-items: center;
  250. height: 52px;
  251. cursor: pointer;
  252. img {
  253. width: 30px;
  254. height: 30px;
  255. border-radius: 3px;
  256. }
  257. .team-username {
  258. padding: 0 12px;
  259. font-size: 14px;
  260. white-space: nowrap;
  261. overflow: hidden;
  262. text-overflow: ellipsis;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. .chat-message {
  269. flex: 1;
  270. height: 100%;
  271. background-color: #F3F3F3;
  272. position: relative;
  273. .manage-title {
  274. position: absolute;
  275. top: 0;
  276. left: 0;
  277. z-index: 3;
  278. width: 100%;
  279. height: 62px;
  280. padding: 0 20px;
  281. line-height: 62px;
  282. font-size: 16px;
  283. font-weight: 500;
  284. text-align: left;
  285. background: #ffffff;
  286. border-bottom: 1px solid #ededed;
  287. .manage-title-right {
  288. position: absolute;
  289. top: 0;
  290. right: 0;
  291. z-index: 9;
  292. width: 62px;
  293. height: 62px;
  294. line-height: 62px;
  295. text-align: center;
  296. font-size: 22px;
  297. color: #242424;
  298. }
  299. }
  300. .manage-lists {
  301. position: absolute;
  302. left: 0;
  303. top: 62px;
  304. z-index: 1;
  305. bottom: 120px;
  306. width: 100%;
  307. overflow: auto;
  308. padding: 8px 0;
  309. background-color: #E8EBF2;
  310. .manage-lists-message-new {
  311. position: fixed;
  312. bottom: 130px;
  313. right: 20px;
  314. color: #ffffff;
  315. background-color: rgba(0, 0, 0, 0.6);
  316. padding: 6px 12px;
  317. border-radius: 16px;
  318. font-size: 12px;
  319. cursor: pointer;
  320. }
  321. }
  322. .manage-send {
  323. position: absolute;
  324. left: 0;
  325. bottom: 0;
  326. z-index: 2;
  327. display: flex;
  328. width: 100%;
  329. height: 120px;
  330. background-color: #ffffff;
  331. border-top: 1px solid #e4e4e4;
  332. .manage-input,.manage-input:focus {
  333. flex: 1;
  334. -webkit-appearance: none;
  335. font-size: 14px;
  336. box-sizing: border-box;
  337. padding: 0;
  338. margin: 38px 10px 6px;
  339. border: 0;
  340. line-height: 20px;
  341. box-shadow: none;
  342. resize:none;
  343. outline: 0;
  344. }
  345. .manage-join,
  346. .manage-spin {
  347. position: absolute;
  348. top: 0;
  349. left: 0;
  350. right: 0;
  351. bottom: 0;
  352. background: #ffffff;
  353. display: flex;
  354. align-items: center;
  355. justify-content: center;
  356. }
  357. }
  358. .manage-quick {
  359. position: absolute;
  360. z-index: 2;
  361. left: 0;
  362. right: 0;
  363. bottom: 79px;
  364. padding: 8px;
  365. display: flex;
  366. align-items: center;
  367. .quick-item {
  368. color: #444444;
  369. font-size: 24px;
  370. margin-right: 12px;
  371. }
  372. .emoji-box {
  373. position: absolute;
  374. left: 0;
  375. bottom: 40px;
  376. max-height: 320px;
  377. width: 100%;
  378. overflow: auto;
  379. background-color: #ffffff;
  380. padding: 12px;
  381. border-bottom: 1px solid #efefef;
  382. .emoji-input {
  383. margin: 6px 0;
  384. }
  385. h5 {
  386. padding: 0;
  387. margin: 8px 0 0 0;
  388. color: #b1b1b1;
  389. text-transform: uppercase;
  390. font-size: 14px;
  391. cursor: default;
  392. font-weight: normal;
  393. }
  394. .emojis {
  395. display: flex;
  396. flex-wrap: wrap;
  397. justify-content: space-between;
  398. &:after {
  399. content: "";
  400. flex: auto;
  401. }
  402. span {
  403. padding: 2px 4px;
  404. cursor: pointer;
  405. font-size: 22px;
  406. &:hover {
  407. background: #ececec;
  408. cursor: pointer;
  409. }
  410. }
  411. }
  412. }
  413. .message-upload {
  414. display: none;
  415. width: 0;
  416. height: 0;
  417. overflow: hidden;
  418. }
  419. }
  420. @media screen and (max-width: 768px) {
  421. .manage-lists {
  422. bottom: 96px;
  423. .manage-lists-message-new {
  424. bottom: 106px;
  425. }
  426. }
  427. .manage-send {
  428. height: 96px;
  429. }
  430. .manage-quick {
  431. bottom: 54px;
  432. .quick-item {
  433. font-size: 24px;
  434. margin-right: 8px;
  435. }
  436. }
  437. }
  438. }
  439. }
  440. </style>
  441. <script>
  442. import EmojiPicker from 'vue-emoji-picker'
  443. import DrawerTabsContainer from "../DrawerTabsContainer";
  444. import ScrollerY from "../../../_components/ScrollerY";
  445. import ChatMessage from "./message";
  446. import ImgUpload from "../ImgUpload";
  447. export default {
  448. name: 'ChatIndex',
  449. components: {ImgUpload, ChatMessage, EmojiPicker, ScrollerY, DrawerTabsContainer},
  450. data () {
  451. return {
  452. loadIng: 0,
  453. userInfo: {},
  454. chatTap: 'dialog',
  455. dialogTarget: {},
  456. dialogLists: [],
  457. dialogNoDataText: '',
  458. teamReady: false,
  459. teamLists: {},
  460. teamNoDataText: '',
  461. autoBottom: true,
  462. messageNew: 0,
  463. messageText: '',
  464. messageLists: [],
  465. messageNoDataText: '',
  466. messageEmojiSearch: '',
  467. }
  468. },
  469. created() {
  470. this.dialogNoDataText = this.$L("数据加载中.....");
  471. this.teamNoDataText = this.$L("数据加载中.....");
  472. this.messageNoDataText = this.$L("数据加载中.....");
  473. },
  474. mounted() {
  475. this.userInfo = $A.getUserInfo((res) => {
  476. this.userInfo = res;
  477. }, false);
  478. //
  479. $A.WS.setOnMsgListener("chat/index", (msgDetail) => {
  480. if (msgDetail.sender == $A.getUserName()) {
  481. return;
  482. }
  483. if (msgDetail.messageType != 'send') {
  484. return;
  485. }
  486. //
  487. let data = $A.jsonParse(msgDetail.content);
  488. let lasttext;
  489. switch (data.type) {
  490. case 'text':
  491. lasttext = data['text'];
  492. break;
  493. case 'image':
  494. lasttext = '[图片]';
  495. break;
  496. default:
  497. lasttext = '[未知类型]';
  498. break;
  499. }
  500. this.openDialog({
  501. username: data.username,
  502. userimg: data.userimg,
  503. }, {
  504. lasttext: lasttext,
  505. lastdate: data.indate
  506. });
  507. if (msgDetail.sender == this.dialogTarget.username) {
  508. this.addMessageData(data, true);
  509. }
  510. })
  511. //
  512. this.getDialogLists();
  513. this.messageBottomAuto();
  514. },
  515. watch: {
  516. chatTap(val) {
  517. if (val === 'team' && this.teamReady == false) {
  518. this.teamReady = true;
  519. this.getTeamLists();
  520. } else if (val === 'dialog') {
  521. this.autoBottom = true;
  522. this.$nextTick(() => {
  523. this.messageBottomGo();
  524. });
  525. }
  526. },
  527. dialogTarget: {
  528. handler: function () {
  529. this.getDialogMessage();
  530. },
  531. deep: true
  532. }
  533. },
  534. methods: {
  535. formatCDate(v) {
  536. let string = '';
  537. if ($A.runNum(v) > 0) {
  538. if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
  539. string = $A.formatDate('H:i', v)
  540. } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
  541. string = $A.formatDate('m-d', v)
  542. } else {
  543. string = $A.formatDate('Y-m-d', v)
  544. }
  545. }
  546. return string || '';
  547. },
  548. getDialogLists() {
  549. this.loadIng++;
  550. this.dialogNoDataText = this.$L("数据加载中.....");
  551. $A.aAjax({
  552. url: 'chat/dialog/lists',
  553. complete: () => {
  554. this.loadIng--;
  555. },
  556. error: () => {
  557. this.dialogNoDataText = this.$L("数据加载失败!");
  558. },
  559. success: (res) => {
  560. if (res.ret === 1) {
  561. this.dialogLists = res.data;
  562. this.dialogNoDataText = this.$L("没有相关的数据");
  563. } else {
  564. this.dialogLists = [];
  565. this.dialogNoDataText = res.msg
  566. }
  567. }
  568. });
  569. },
  570. getDialogMessage() {
  571. let username = this.dialogTarget.username;
  572. if (username === this.__dialogTargetUsername) {
  573. return;
  574. }
  575. this.__dialogTargetUsername = username;
  576. this.autoBottom = true;
  577. this.messageNew = 0;
  578. this.messageLists = [];
  579. //
  580. this.loadIng++;
  581. this.messageNoDataText = this.$L("数据加载中.....");
  582. $A.aAjax({
  583. url: 'chat/message/lists',
  584. data: {
  585. username: username,
  586. pagesize: 30
  587. },
  588. complete: () => {
  589. this.loadIng--;
  590. },
  591. error: () => {
  592. this.messageNoDataText = this.$L("数据加载失败!");
  593. },
  594. success: (res) => {
  595. if (username != this.dialogTarget.username) {
  596. return;
  597. }
  598. if (res.ret === 1) {
  599. res.data.lists.reverse().forEach((item) => {
  600. this.addMessageData(Object.assign(item.message, {
  601. id: item.id,
  602. username: item.username,
  603. userimg: item.userimg,
  604. indate: item.indate,
  605. }));
  606. });
  607. this.messageNoDataText = this.$L("没有相关的数据");
  608. } else {
  609. this.messageNoDataText = res.msg
  610. }
  611. }
  612. });
  613. },
  614. getTeamLists() {
  615. this.loadIng++;
  616. this.teamNoDataText = this.$L("数据加载中.....");
  617. $A.aAjax({
  618. url: 'users/team/lists',
  619. data: {
  620. sorts: {
  621. key: 'username',
  622. order: 'asc'
  623. },
  624. firstchart: 1,
  625. pagesize: 100,
  626. },
  627. complete: () => {
  628. this.loadIng--;
  629. },
  630. error: () => {
  631. this.teamNoDataText = this.$L("数据加载失败!");
  632. },
  633. success: (res) => {
  634. if (res.ret === 1) {
  635. res.data.lists.forEach((item) => {
  636. if (typeof this.teamLists[item.firstchart] === "undefined") {
  637. this.$set(this.teamLists, item.firstchart, []);
  638. }
  639. this.teamLists[item.firstchart].push(item);
  640. console.log(this.teamLists);
  641. });
  642. this.teamNoDataText = this.$L("没有相关的数据");
  643. } else {
  644. this.teamLists = {};
  645. this.teamNoDataText = res.msg
  646. }
  647. }
  648. });
  649. },
  650. openDialog(user, lastMsg) {
  651. if (typeof lastMsg === "object") {
  652. user = Object.assign(user, lastMsg);
  653. this.dialogLists = this.dialogLists.filter((item) => {return item.username != user.username});
  654. }
  655. let lists = this.dialogLists.filter((item) => {return item.username == user.username});
  656. if (lists.length === 0) {
  657. this.dialogLists.unshift(user);
  658. }
  659. if (typeof lastMsg !== "object") {
  660. this.chatTap = 'dialog';
  661. this.dialogTarget = user;
  662. }
  663. },
  664. messageListsScroll(res) {
  665. if (res.directionreal === 'up') {
  666. if (res.scrollE < 10) {
  667. this.autoBottom = true;
  668. }
  669. } else if (res.directionreal === 'down') {
  670. this.autoBottom = false;
  671. }
  672. },
  673. messageBottomAuto() {
  674. let randString = $A.randomString(8);
  675. window.__messageBottomAuto = randString;
  676. setTimeout(() => {
  677. if (randString === window.__messageBottomAuto) {
  678. window.__messageBottomAuto = null;
  679. if (this.autoBottom) {
  680. this.messageBottomGo();
  681. }
  682. this.messageBottomAuto();
  683. }
  684. }, 1200);
  685. },
  686. messageBottomGo(animation = false) {
  687. this.$nextTick(() => {
  688. this.messageNew = 0;
  689. if (typeof this.$refs.manageLists !== "undefined") {
  690. this.$refs.manageLists.scrollTo(this.$refs.manageBody.clientHeight, animation);
  691. this.autoBottom = true;
  692. }
  693. });
  694. },
  695. messageInsertText(emoji) {
  696. this.messageText+= emoji;
  697. },
  698. messageInsertImage(lists) {
  699. for (let i = 0; i < lists.length; i++) {
  700. let item = lists[i];
  701. if (typeof item === 'object' && typeof item.url === "string") {
  702. let data = {
  703. type: 'image',
  704. username: this.userInfo.username,
  705. userimg: this.userInfo.userimg,
  706. indate: Math.round(new Date().getTime() / 1000),
  707. url: item.url
  708. };
  709. $A.WS.sendTo('user', this.dialogTarget.username, data, (res) => {
  710. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  711. });
  712. //
  713. this.openDialog(this.dialogTarget, {
  714. lasttext: '[图片]',
  715. lastdate: data.indate
  716. });
  717. this.addMessageData(data, true);
  718. }
  719. }
  720. },
  721. addMessageData(data, animation = false) {
  722. data.self = data.username === this.userInfo.username;
  723. let sikp = false;
  724. if (data.id) {
  725. this.messageLists.some((item, index) => {
  726. if (item.id == data.id) {
  727. this.messageLists.splice(index, 1, data);
  728. return sikp = true;
  729. }
  730. });
  731. if (sikp) {
  732. return;
  733. }
  734. }
  735. this.messageLists.push(data);
  736. //
  737. if (this.autoBottom) {
  738. this.messageBottomGo(animation);
  739. } else {
  740. this.messageNew++;
  741. }
  742. },
  743. messageSend(e) {
  744. if (e.keyCode == 13) {
  745. if (e.shiftKey) {
  746. return;
  747. }
  748. e.preventDefault();
  749. this.messageSubmit();
  750. }
  751. },
  752. messageSubmit() {
  753. let text = this.messageText.trim();
  754. if ($A.count(text) > 0) {
  755. let data = {
  756. type: 'text',
  757. username: this.userInfo.username,
  758. userimg: this.userInfo.userimg,
  759. indate: Math.round(new Date().getTime() / 1000),
  760. text: text
  761. };
  762. $A.WS.sendTo('user', this.dialogTarget.username, data, (res) => {
  763. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  764. });
  765. //
  766. this.openDialog(this.dialogTarget, {
  767. lasttext: text,
  768. lastdate: data.indate
  769. });
  770. this.addMessageData(data, true);
  771. }
  772. this.$nextTick(() => {
  773. this.messageText = "";
  774. });
  775. },
  776. }
  777. }
  778. </script>