Index.vue 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740
  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. :data-id="dialog.id"
  27. @click="openDialog(dialog)">
  28. <img :src="dialog.userimg" onerror="this.src=window.location.origin+'/images/other/avatar.png'">
  29. <div class="user-msg-box">
  30. <div class="user-msg-title">
  31. <span><user-view :username="dialog.username" placement="right" @on-result="userViewResult(dialog, $event)"/></span>
  32. <em>{{formatCDate(dialog.lastdate)}}</em>
  33. </div>
  34. <div class="user-msg-text">{{dialog.lasttext}}</div>
  35. </div>
  36. <em v-if="dialog.unread > 0" class="user-msg-num">{{dialog.unread}}</em>
  37. </li>
  38. <li v-if="dialogNoDataText==$L('数据加载中.....')" class="chat-none"><w-loading/></li>
  39. <li v-else-if="dialogLists.length == 0" class="chat-none">{{dialogNoDataText}}</li>
  40. </ul>
  41. </li>
  42. </ul>
  43. <!--联系人列表-->
  44. <ul class="chat-team" :style="{display:chatTap=='team'?'flex':'none'}">
  45. <li class="sreach">
  46. <Input :placeholder="$L('搜索')" prefix="ios-search" v-model="teamSearch"/>
  47. </li>
  48. <li class="lists">
  49. <ul>
  50. <li v-for="(lists, key) in teamLists">
  51. <div class="team-label">{{key}}</div>
  52. <ul>
  53. <li v-for="(item, index) in teamListsS(lists)" :key="index" @click="openDialog(item, true)">
  54. <img :src="item.userimg" onerror="this.src=window.location.origin+'/images/other/avatar.png'">
  55. <div class="team-username">{{item.nickname||item.username}}</div>
  56. </li>
  57. </ul>
  58. </li>
  59. <li v-if="teamNoDataText==$L('数据加载中.....')" class="chat-none"><w-loading/></li>
  60. <li v-else-if="Object.keys(teamLists).length == 0" class="chat-none">{{teamNoDataText}}</li>
  61. <li v-if="teamHasMorePages" class="chat-more" @click="getTeamLists(true)">{{$L('加载更多...')}}</li>
  62. </ul>
  63. </li>
  64. </ul>
  65. <!--对话窗口-->
  66. <div class="chat-message" :style="{display:(chatTap=='dialog'&&dialogTarget.username)?'block':'none'}">
  67. <div class="manage-title">
  68. <user-view :username="dialogTarget.username"/>
  69. <Dropdown class="manage-title-right" placement="bottom-end" trigger="click" @on-click="dialogDropdown" transfer>
  70. <Icon type="ios-more"/>
  71. <DropdownMenu slot="list">
  72. <DropdownItem name="delete">{{$L('删除对话')}}</DropdownItem>
  73. <DropdownItem name="clear">{{$L('清除聊天记录')}}</DropdownItem>
  74. </DropdownMenu>
  75. </Dropdown>
  76. </div>
  77. <ScrollerY ref="manageLists" class="manage-lists" @on-scroll="messageListsScroll">
  78. <div ref="manageBody" class="manage-body">
  79. <div v-if="messageHasMorePages" class="manage-more" @click="getDialogMessage(true)">{{$L('加载更多...')}}</div>
  80. <div v-if="messageNoDataText==$L('数据加载中.....')" class="manage-more"><w-loading/></div>
  81. <div v-else-if="messageNoDataText" class="manage-more">{{messageNoDataText}}</div>
  82. <chat-message v-for="(info, index) in messageLists" :key="index" :info="info"></chat-message>
  83. </div>
  84. <div class="manage-lists-message-new" v-if="messageNew > 0" @click="messageBottomGo(true)">{{$L('有%条新消息', messageNew)}}</div>
  85. </ScrollerY>
  86. <div class="manage-send" @click="clickDialog(dialogTarget.username)">
  87. <textarea ref="textarea" class="manage-input" maxlength="20000" v-model="messageText" :placeholder="$L('请输入要发送的消息')" @keydown="messageSend($event)"></textarea>
  88. </div>
  89. <div class="manage-quick">
  90. <emoji-picker @emoji="messageInsertText" :search="messageEmojiSearch">
  91. <div slot="emoji-invoker" slot-scope="{ events: { click: clickEvent } }" @click.stop="clickEvent">
  92. <Tooltip :content="$L('表情')" placement="top">
  93. <Icon class="quick-item" type="ios-happy-outline" />
  94. </Tooltip>
  95. </div>
  96. <div slot="emoji-picker" slot-scope="{ emojis, insert, display }">
  97. <div class="emoji-box">
  98. <Input class="emoji-input" :placeholder="$L('搜索')" v-model="messageEmojiSearch" prefix="ios-search"/>
  99. <div>
  100. <div v-for="(emojiGroup, category) in emojis" :key="category">
  101. <h5>{{ category }}</h5>
  102. <div class="emojis">
  103. <span v-for="(emoji, emojiName) in emojiGroup" :key="emojiName" @click="insert(emoji)" :title="emojiName">{{ emoji }}</span>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </emoji-picker>
  110. <Tooltip :content="$L('图片')" placement="top">
  111. <Icon class="quick-item" type="ios-photos-outline" @click="$refs.messageUpload.handleClick()"/>
  112. <img-upload ref="messageUpload" class="message-upload" type="callback" @on-callback="messageInsertImage" num="3" :otherParams="{from:'chat'}"></img-upload>
  113. </Tooltip>
  114. <template v-if="systemConfig.callav=='open'">
  115. <Tooltip :content="$L('语音聊天')" placement="top">
  116. <Icon class="quick-item voicecam" type="ios-call-outline" @click="videoConnect(null, false)"/>
  117. </Tooltip>
  118. <Tooltip :content="$L('视频聊天')" placement="top">
  119. <Icon class="quick-item videocam" type="ios-videocam-outline" @click="videoConnect(null, true)"/>
  120. </Tooltip>
  121. </template>
  122. </div>
  123. </div>
  124. <!--语音、视频通话-->
  125. <div class="chat-video" :style="{display:(videoUserName)?'block':'none',backgroundImage:'url(' + videoUserImg +')'}">
  126. <div v-if="videoChat" class="video-opacity">{{$L('正在视频通话...')}}</div>
  127. <div v-else class="video-opacity">{{$L('正在语音通话...')}}</div>
  128. <video ref="remoteVideo" class="video-active" autoplay></video>
  129. <video ref="localVideo" class="video-mini" autoplay muted="true"></video>
  130. <div class="video-close"><Icon type="ios-close-circle-outline" @click="videoClose(videoUserName)"/></div>
  131. </div>
  132. <!--提示音-->
  133. <audio class="chat-audio" ref="messageAudio" preload="none">
  134. <source :src="messageAudio + 'message.mp3'" type="audio/mpeg">
  135. <source :src="messageAudio + 'message.wav'" type="audio/wav">
  136. </audio>
  137. <audio class="chat-audio" ref="callAudio" preload="none">
  138. <source :src="messageAudio + 'call.mp3'" type="audio/mpeg">
  139. <source :src="messageAudio + 'call.wav'" type="audio/wav">
  140. </audio>
  141. </div>
  142. </template>
  143. <style lang="scss">
  144. .chat-notice-box {
  145. display: flex;
  146. align-items: flex-start;
  147. cursor: pointer;
  148. .chat-notice-userimg {
  149. width: 42px;
  150. height: 42px;
  151. border-radius: 4px;
  152. }
  153. .ivu-notice-with-desc {
  154. flex: 1;
  155. padding: 0 12px;
  156. }
  157. .chat-notice-btn-box {
  158. margin-top: 8px;
  159. margin-bottom: -4px;
  160. .ivu-btn {
  161. margin-right: 12px;
  162. font-size: 12px;
  163. min-width: 42px;
  164. }
  165. }
  166. .ivu-notice-desc {
  167. font-size: 13px;
  168. word-break: break-all;
  169. line-height: 1.3;
  170. text-overflow: ellipsis;
  171. display: -webkit-box;
  172. -webkit-line-clamp: 2;
  173. overflow: hidden;
  174. -webkit-box-orient: vertical;
  175. }
  176. }
  177. </style>
  178. <style lang="scss" scoped>
  179. .chat-index {
  180. display: flex;
  181. flex-direction: row;
  182. align-items: flex-start;
  183. position: absolute;
  184. top: 0;
  185. left: 0;
  186. right: 0;
  187. bottom: 0;
  188. .chat-none {
  189. height: auto;
  190. color: #666666;
  191. padding: 22px 8px;
  192. text-align: center;
  193. justify-content: center;
  194. margin: 0 !important;
  195. &:before {
  196. display: none;
  197. }
  198. }
  199. .chat-more {
  200. color: #666666;
  201. padding: 18px 0;
  202. text-align: center;
  203. cursor: pointer;
  204. margin: 0 !important;
  205. &:hover {
  206. color: #444444;
  207. }
  208. }
  209. .chat-menu {
  210. background-color: rgba(28, 29, 31, 0.92);
  211. width: 68px;
  212. height: 100%;
  213. padding-top: 20px;
  214. li {
  215. position: relative;
  216. padding: 12px 0;
  217. text-align: center;
  218. font-size: 28px;
  219. color: #919193;
  220. background-color: transparent;
  221. cursor: pointer;
  222. &.self {
  223. cursor: default;
  224. img {
  225. width: 36px;
  226. height: 36px;
  227. border-radius: 3px;
  228. }
  229. }
  230. &.active {
  231. color: #ffffff;
  232. background-color: rgba(255, 255, 255, 0.06);
  233. }
  234. &:hover {
  235. > i {
  236. transform: scale(1.1);
  237. }
  238. }
  239. > i {
  240. transition: all 0.2s;
  241. }
  242. .chat-num {
  243. position: absolute;
  244. top: 50%;
  245. left: 50%;
  246. height: auto;
  247. line-height: normal;
  248. color: #ffffff;
  249. background-color: #ff0000;
  250. text-align: center;
  251. border-radius: 10px;
  252. padding: 1px 5px;
  253. font-size: 12px;
  254. transform: scale(0.9) translate(5px, -20px);
  255. }
  256. }
  257. }
  258. .chat-user {
  259. display: flex;
  260. flex-direction: column;
  261. width: 248px;
  262. height: 100%;
  263. background-color: #ffffff;
  264. border-right: 1px solid #ededed;
  265. > li {
  266. position: relative;
  267. &.sreach {
  268. display: flex;
  269. flex-direction: row;
  270. align-items: center;
  271. height: 62px;
  272. margin: 0;
  273. padding: 0 12px;
  274. position: relative;
  275. cursor: pointer;
  276. &:before {
  277. content: "";
  278. position: absolute;
  279. left: 0;
  280. right: 0;
  281. bottom: 0;
  282. height: 1px;
  283. background-color: rgba(0, 0, 0, 0.06);
  284. }
  285. }
  286. &.lists {
  287. flex: 1;
  288. overflow: auto;
  289. transform: translateZ(0);
  290. > ul {
  291. > li {
  292. display: flex;
  293. flex-direction: row;
  294. align-items: center;
  295. height: 70px;
  296. padding: 0 12px;
  297. position: relative;
  298. cursor: pointer;
  299. &:before {
  300. content: "";
  301. position: absolute;
  302. left: 0;
  303. right: 0;
  304. bottom: 0;
  305. height: 1px;
  306. background-color: rgba(0, 0, 0, 0.06);
  307. }
  308. &.active {
  309. &:before {
  310. top: 0;
  311. height: 100%;
  312. }
  313. }
  314. img {
  315. width: 42px;
  316. height: 42px;
  317. border-radius: 4px;
  318. }
  319. .user-msg-box {
  320. flex: 1;
  321. display: flex;
  322. flex-direction: column;
  323. padding-left: 12px;
  324. .user-msg-title {
  325. display: flex;
  326. flex-direction: row;
  327. align-items: center;
  328. justify-content: space-between;
  329. line-height: 24px;
  330. span {
  331. flex: 1;
  332. max-width: 130px;
  333. color: #333333;
  334. font-size: 14px;
  335. white-space: nowrap;
  336. overflow: hidden;
  337. text-overflow: ellipsis;
  338. }
  339. em {
  340. color: #999999;
  341. font-size: 12px;
  342. }
  343. }
  344. .user-msg-text {
  345. max-width: 170px;
  346. color: #999999;
  347. font-size: 12px;
  348. line-height: 24px;
  349. white-space: nowrap;
  350. overflow: hidden;
  351. text-overflow: ellipsis;
  352. }
  353. }
  354. }
  355. }
  356. }
  357. .user-msg-num {
  358. position: absolute;
  359. top: 6px;
  360. left: 44px;
  361. height: auto;
  362. line-height: normal;
  363. color: #ffffff;
  364. background-color: #ff0000;
  365. text-align: center;
  366. border-radius: 10px;
  367. padding: 1px 5px;
  368. font-size: 12px;
  369. transform: scale(0.9);
  370. border: 1px solid #ffffff;
  371. }
  372. }
  373. }
  374. .chat-team {
  375. display: flex;
  376. flex-direction: column;
  377. width: 248px;
  378. height: 100%;
  379. background-color: #ffffff;
  380. border-right: 1px solid #ededed;
  381. > li {
  382. position: relative;
  383. &.sreach {
  384. display: flex;
  385. flex-direction: row;
  386. align-items: center;
  387. height: 62px;
  388. margin: 0;
  389. padding: 0 12px;
  390. position: relative;
  391. cursor: pointer;
  392. &:before {
  393. content: "";
  394. position: absolute;
  395. left: 0;
  396. right: 0;
  397. bottom: 0;
  398. height: 1px;
  399. background-color: rgba(0, 0, 0, 0.06);
  400. }
  401. }
  402. &.lists {
  403. flex: 1;
  404. overflow: auto;
  405. transform: translateZ(0);
  406. > ul {
  407. > li {
  408. margin-left: 24px;
  409. position: relative;
  410. .team-label {
  411. padding-left: 4px;
  412. margin-top: 6px;
  413. margin-bottom: 6px;
  414. height: 34px;
  415. line-height: 34px;
  416. border-bottom: 1px solid #efefef;
  417. }
  418. > ul {
  419. > li {
  420. display: flex;
  421. flex-direction: row;
  422. align-items: center;
  423. height: 52px;
  424. cursor: pointer;
  425. img {
  426. width: 30px;
  427. height: 30px;
  428. border-radius: 3px;
  429. }
  430. .team-username {
  431. padding: 0 12px;
  432. font-size: 14px;
  433. white-space: nowrap;
  434. overflow: hidden;
  435. text-overflow: ellipsis;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. }
  443. }
  444. .chat-message {
  445. flex: 1;
  446. height: 100%;
  447. background-color: #F3F3F3;
  448. position: relative;
  449. .manage-title {
  450. position: absolute;
  451. top: 0;
  452. left: 0;
  453. z-index: 3;
  454. width: 100%;
  455. height: 62px;
  456. padding: 0 20px;
  457. line-height: 62px;
  458. font-size: 16px;
  459. font-weight: 500;
  460. text-align: left;
  461. background: #ffffff;
  462. border-bottom: 1px solid #ededed;
  463. .manage-title-right {
  464. position: absolute;
  465. top: 0;
  466. right: 0;
  467. z-index: 9;
  468. width: 62px;
  469. height: 62px;
  470. line-height: 62px;
  471. text-align: center;
  472. font-size: 22px;
  473. color: #242424;
  474. }
  475. }
  476. .manage-lists {
  477. position: absolute;
  478. left: 0;
  479. top: 62px;
  480. z-index: 1;
  481. bottom: 120px;
  482. width: 100%;
  483. overflow: auto;
  484. padding: 8px 0;
  485. background-color: #E8EBF2;
  486. .manage-more {
  487. color: #666666;
  488. padding: 8px 0;
  489. text-align: center;
  490. cursor: pointer;
  491. &:hover {
  492. color: #444444;
  493. }
  494. }
  495. .manage-lists-message-new {
  496. position: fixed;
  497. bottom: 130px;
  498. right: 20px;
  499. color: #ffffff;
  500. background-color: rgba(0, 0, 0, 0.6);
  501. padding: 6px 12px;
  502. border-radius: 16px;
  503. font-size: 12px;
  504. cursor: pointer;
  505. }
  506. }
  507. .manage-send {
  508. position: absolute;
  509. left: 0;
  510. bottom: 0;
  511. z-index: 2;
  512. display: flex;
  513. width: 100%;
  514. height: 120px;
  515. background-color: #ffffff;
  516. border-top: 1px solid #e4e4e4;
  517. .manage-input,.manage-input:focus {
  518. flex: 1;
  519. -webkit-appearance: none;
  520. font-size: 14px;
  521. box-sizing: border-box;
  522. padding: 0;
  523. margin: 38px 10px 6px;
  524. border: 0;
  525. line-height: 20px;
  526. box-shadow: none;
  527. resize:none;
  528. outline: 0;
  529. }
  530. .manage-join,
  531. .manage-spin {
  532. position: absolute;
  533. top: 0;
  534. left: 0;
  535. right: 0;
  536. bottom: 0;
  537. background: #ffffff;
  538. display: flex;
  539. align-items: center;
  540. justify-content: center;
  541. }
  542. }
  543. .manage-quick {
  544. position: absolute;
  545. z-index: 2;
  546. left: 0;
  547. right: 0;
  548. bottom: 79px;
  549. padding: 8px 0;
  550. display: flex;
  551. align-items: center;
  552. .quick-item {
  553. color: #444444;
  554. font-size: 24px;
  555. margin: 0 7px;
  556. &.voicecam {
  557. font-size: 26px;
  558. height: 24px;
  559. line-height: 24px;
  560. }
  561. &.videocam {
  562. color: #666666;
  563. font-size: 30px;
  564. height: 24px;
  565. line-height: 24px;
  566. }
  567. }
  568. .emoji-box {
  569. position: absolute;
  570. left: 0;
  571. bottom: 40px;
  572. max-height: 320px;
  573. width: 100%;
  574. overflow: auto;
  575. background-color: #ffffff;
  576. padding: 12px;
  577. border-bottom: 1px solid #efefef;
  578. .emoji-input {
  579. margin: 6px 0;
  580. }
  581. h5 {
  582. padding: 0;
  583. margin: 8px 0 0 0;
  584. color: #b1b1b1;
  585. text-transform: uppercase;
  586. font-size: 14px;
  587. cursor: default;
  588. font-weight: normal;
  589. }
  590. .emojis {
  591. display: flex;
  592. flex-wrap: wrap;
  593. justify-content: space-between;
  594. &:after {
  595. content: "";
  596. flex: auto;
  597. }
  598. span {
  599. padding: 2px 4px;
  600. cursor: pointer;
  601. font-size: 22px;
  602. &:hover {
  603. background: #ececec;
  604. cursor: pointer;
  605. }
  606. }
  607. }
  608. }
  609. .message-upload {
  610. display: none;
  611. width: 0;
  612. height: 0;
  613. overflow: hidden;
  614. }
  615. }
  616. @media screen and (max-width: 768px) {
  617. .manage-lists {
  618. bottom: 96px;
  619. .manage-lists-message-new {
  620. bottom: 106px;
  621. }
  622. }
  623. .manage-send {
  624. height: 96px;
  625. }
  626. .manage-quick {
  627. bottom: 54px;
  628. .quick-item {
  629. font-size: 24px;
  630. margin-right: 8px;
  631. }
  632. }
  633. }
  634. }
  635. .chat-video {
  636. position: fixed;
  637. top: 0;
  638. left: 0;
  639. width: 100%;
  640. height: 100%;
  641. background-color: #000000;
  642. background-size: cover;
  643. background-position: center center;
  644. background-repeat: no-repeat;
  645. z-index: 9;
  646. &:before {
  647. content: "";
  648. position: absolute;
  649. left: -10%;
  650. right: -10%;
  651. top: -10%;
  652. bottom: -10%;
  653. background: inherit;
  654. filter: blur(25px);
  655. z-index: 1;
  656. }
  657. &:after {
  658. content: "";
  659. position: absolute;
  660. left: -10%;
  661. right: -10%;
  662. top: -10%;
  663. bottom: -10%;
  664. background: rgba(0, 0, 0, 0.82);
  665. z-index: 2;
  666. }
  667. .video-opacity {
  668. position: absolute;
  669. top: 50%;
  670. left: 50%;
  671. transform: translate(-50%, -50%);
  672. font-size: 26px;
  673. color: #aaaaaa;
  674. padding: 24px;
  675. z-index: 3;
  676. animation:opacity 2s infinite alternate ;
  677. @keyframes opacity {
  678. 0% {
  679. opacity: 0.1;
  680. }
  681. 100% {
  682. opacity: 1;
  683. }
  684. }
  685. }
  686. .video-mini,
  687. .video-active {
  688. position: absolute;
  689. max-width: 640px;
  690. max-height: 100%;
  691. object-fit: cover;
  692. transition: opacity 1s;
  693. }
  694. .video-active {
  695. top: 0;
  696. left: 50%;
  697. width: 100%;
  698. height: 100%;
  699. transform: rotateY(180deg) translateX(50%);
  700. z-index: 4;
  701. }
  702. .video-mini {
  703. top: 0;
  704. right: 0;
  705. width: 260px;
  706. height: 180px;
  707. transform: scale(-1, 1);
  708. z-index: 5;
  709. }
  710. .video-close {
  711. position: absolute;
  712. max-width: 720px;
  713. bottom: 18px;
  714. left: 50%;
  715. width: 100%;
  716. transform: translateX(-50%);
  717. display: flex;
  718. align-items: center;
  719. justify-content: center;
  720. z-index: 6;
  721. > i {
  722. font-weight: 600;
  723. font-size: 46px;
  724. color: #ffffff;
  725. cursor: pointer;
  726. &:hover {
  727. color: #ff0000;
  728. }
  729. }
  730. }
  731. }
  732. .chat-audio {
  733. width: 0;
  734. height: 0;
  735. display: none;
  736. }
  737. }
  738. </style>
  739. <script>
  740. import EmojiPicker from 'vue-emoji-picker'
  741. import DrawerTabsContainer from "../DrawerTabsContainer";
  742. import ScrollerY from "../../../_components/ScrollerY";
  743. import ChatMessage from "./message";
  744. import ImgUpload from "../ImgUpload";
  745. export default {
  746. name: 'ChatIndex',
  747. components: {ImgUpload, ChatMessage, EmojiPicker, ScrollerY, DrawerTabsContainer},
  748. props: {
  749. value: {
  750. default: 0
  751. },
  752. openWindow: {
  753. type: Boolean,
  754. default: false
  755. },
  756. },
  757. data () {
  758. return {
  759. loadIng: 0,
  760. openAlready: false,
  761. userInfo: {},
  762. chatTap: 'dialog',
  763. messageAudio: window.location.origin + '/audio/',
  764. dialogSearch: '',
  765. dialogTarget: {},
  766. dialogLists: [],
  767. dialogNoDataText: '',
  768. teamSearch: '',
  769. teamReady: false,
  770. teamLists: {},
  771. teamNoDataText: '',
  772. teamCurrentPage: 1,
  773. teamHasMorePages: false,
  774. autoBottom: true,
  775. messageNew: 0,
  776. messageText: '',
  777. messageLists: [],
  778. messageNoDataText: '',
  779. messageEmojiSearch: '',
  780. messageCurrentPage: 1,
  781. messageHasMorePages: false,
  782. unreadTotal: 0,
  783. videoUserName: '', //视频对话用户名
  784. videoUserImg: '', //视频对话用户头像
  785. videoStartTime: 0, //视频开始时间
  786. videoInitiator: false, //是否发起人
  787. videoChat: false, //是否视频通话(否则音频通话)
  788. videoRtc: null, //视频Rtc
  789. videoLocalStream: null, //视频流
  790. systemConfig: $A.jsonParse($A.storage("systemSetting"), {
  791. callav: '',
  792. }),
  793. }
  794. },
  795. created() {
  796. this.dialogNoDataText = this.$L("数据加载中.....");
  797. this.teamNoDataText = this.$L("数据加载中.....");
  798. this.messageNoDataText = this.$L("数据加载中.....");
  799. },
  800. mounted() {
  801. let resCall = () => {
  802. if ($A.getToken() === false) {
  803. return;
  804. }
  805. $A.WSOB.sendTo('unread', (res) => {
  806. if (res.status === 1) {
  807. this.unreadTotal = $A.runNum(res.message);
  808. } else {
  809. this.unreadTotal = 0;
  810. }
  811. });
  812. this.getDialogLists();
  813. this.messageBottomAuto();
  814. };
  815. this.userInfo = $A.getUserInfo((res, isLogin) => {
  816. if (this.userInfo.id != res.id) {
  817. this.userInfo = res;
  818. resCall();
  819. } else {
  820. this.userInfo = res;
  821. }
  822. }, false);
  823. resCall();
  824. this.getSetting();
  825. //
  826. window.onChatOpenUserName = (username) => {
  827. this.$emit("on-open-notice", username);
  828. this.clickDialog(username, true);
  829. }
  830. //
  831. if (this.openWindow) {
  832. $A.WSOB.connection();
  833. if (!this.openAlready) {
  834. this.openAlready = true;
  835. this.getDialogLists();
  836. }
  837. }
  838. //
  839. $A.WSOB.setOnMsgListener("chat/index", (msgDetail) => {
  840. if (msgDetail.username == $A.getUserName()) {
  841. return;
  842. }
  843. switch (msgDetail.messageType) {
  844. case 'open':
  845. if (this.openWindow) {
  846. this.getDialogLists();
  847. this.getDialogMessage();
  848. } else {
  849. this.openAlready = false;
  850. this.dialogTarget = {};
  851. }
  852. break;
  853. case 'info':
  854. if (msgDetail.body.type == 'video') {
  855. this.videoMessage(msgDetail)
  856. }
  857. break;
  858. case 'user':
  859. let body = msgDetail.body;
  860. if (['taskA'].indexOf(body.type) !== -1) {
  861. return;
  862. }
  863. let lasttext = $A.WSOB.getMsgDesc(body);
  864. this.unreadTotal += 1;
  865. this.addDialog({
  866. username: body.username,
  867. userimg: body.userimg,
  868. lasttext: lasttext,
  869. lastdate: body.indate,
  870. unread: body.unread
  871. });
  872. if (msgDetail.username == this.dialogTarget.username) {
  873. this.addMessageData(body, true);
  874. }
  875. if (!this.openWindow) {
  876. this.$Notice.close('chat-notice');
  877. this.$Notice.open({
  878. name: 'chat-notice',
  879. duration: 0,
  880. render: h => {
  881. return h('div', {
  882. class: 'chat-notice-box',
  883. on: {
  884. click: () => {
  885. this.$Notice.close('chat-notice');
  886. this.$emit("on-open-notice", body.username);
  887. this.clickDialog(body.username);
  888. }
  889. }
  890. }, [
  891. h('img', {class: 'chat-notice-userimg', attrs: {src: body.userimg}}),
  892. h('div', {class: 'ivu-notice-with-desc'}, [
  893. h('div', {class: 'ivu-notice-title'}, [
  894. h('UserView', {props: {username: body.username}})
  895. ]),
  896. h('div', {class: 'ivu-notice-desc'}, lasttext)
  897. ])
  898. ])
  899. }
  900. });
  901. }
  902. try {
  903. this.$refs.messageAudio.play();
  904. } catch (e) {
  905. }
  906. break;
  907. }
  908. });
  909. $A.WSOB.setOnSpecialListener("chat/index", (simpleMsg) => {
  910. this.addDialog({
  911. username: simpleMsg.target,
  912. lasttext: $A.WSOB.getMsgDesc(simpleMsg.body),
  913. lastdate: simpleMsg.body.indate
  914. });
  915. if (simpleMsg.target == this.dialogTarget.username) {
  916. this.addMessageData(simpleMsg.body, true);
  917. }
  918. });
  919. },
  920. watch: {
  921. chatTap(val) {
  922. if (val === 'team' && this.teamReady == false) {
  923. this.teamReady = true;
  924. this.getTeamLists();
  925. } else if (val === 'dialog') {
  926. this.autoBottom = true;
  927. this.$nextTick(() => {
  928. this.messageBottomGo();
  929. });
  930. }
  931. },
  932. openWindow(val) {
  933. if (val) {
  934. $A.WSOB.connection();
  935. if (!this.openAlready) {
  936. this.openAlready = true;
  937. this.getDialogLists();
  938. }
  939. }
  940. //
  941. let tmpRand = $A.randomString(8);
  942. this.__openWindowRand = tmpRand;
  943. setTimeout(() => {
  944. if (this.__openWindowRand !== tmpRand) {
  945. return;
  946. }
  947. $A.WSOB.sendTo('unread', (res) => {
  948. if (res.status === 1) {
  949. this.unreadTotal = $A.runNum(res.message);
  950. } else {
  951. this.unreadTotal = 0;
  952. }
  953. });
  954. }, 500);
  955. },
  956. unreadTotal(val) {
  957. if (val < 0) {
  958. this.unreadTotal = 0;
  959. return;
  960. }
  961. this.$emit('input', val);
  962. },
  963. dialogTarget: {
  964. handler: function () {
  965. let username = this.dialogTarget.username;
  966. if (username === this.__dialogTargetUsername) {
  967. return;
  968. }
  969. this.__dialogTargetUsername = username;
  970. this.getDialogMessage();
  971. },
  972. deep: true
  973. }
  974. },
  975. computed: {
  976. dialogListsS() {
  977. return this.dialogLists.filter(item => {
  978. return (item.username + "").indexOf(this.dialogSearch) > -1 || (item.lasttext + "").indexOf(this.dialogSearch) > -1 || (item.nickname + "").indexOf(this.dialogSearch) > -1
  979. });
  980. },
  981. teamListsS() {
  982. return function (lists) {
  983. return lists.filter(item => {
  984. return (item.username + "").indexOf(this.teamSearch) > -1 || (item.nickname + "").indexOf(this.teamSearch) > -1
  985. });
  986. }
  987. }
  988. },
  989. methods: {
  990. getSetting() {
  991. $A.apiAjax({
  992. url: 'system/setting',
  993. error: () => {
  994. $A.storage("systemSetting", {});
  995. },
  996. success: (res) => {
  997. if (res.ret === 1) {
  998. this.systemConfig = res.data;
  999. this.systemConfig.callav = this.systemConfig.callav || 'open';
  1000. $A.storage("systemSetting", this.systemConfig);
  1001. } else {
  1002. $A.storage("systemSetting", {});
  1003. }
  1004. }
  1005. });
  1006. },
  1007. formatCDate(v) {
  1008. let string = '';
  1009. if ($A.runNum(v) > 0) {
  1010. if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
  1011. string = $A.formatDate('H:i', v)
  1012. } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
  1013. string = $A.formatDate('m-d', v)
  1014. } else {
  1015. string = $A.formatDate('Y-m-d', v)
  1016. }
  1017. }
  1018. return string || '';
  1019. },
  1020. getDialogLists() {
  1021. if (!this.openAlready) {
  1022. return;
  1023. }
  1024. this.loadIng++;
  1025. this.dialogNoDataText = this.$L("数据加载中.....");
  1026. $A.apiAjax({
  1027. url: 'chat/dialog/lists',
  1028. complete: () => {
  1029. this.loadIng--;
  1030. },
  1031. error: () => {
  1032. this.dialogNoDataText = this.$L("数据加载失败!");
  1033. },
  1034. success: (res) => {
  1035. if (res.ret === 1) {
  1036. this.dialogLists = res.data;
  1037. this.dialogNoDataText = this.$L("没有相关的数据");
  1038. } else {
  1039. this.dialogLists = [];
  1040. this.dialogNoDataText = res.msg
  1041. }
  1042. }
  1043. });
  1044. },
  1045. getDialogMessage(isNextPage = false) {
  1046. let username = this.dialogTarget.username;
  1047. if (!username) {
  1048. return;
  1049. }
  1050. //
  1051. if (isNextPage === true) {
  1052. if (!this.messageHasMorePages) {
  1053. return;
  1054. }
  1055. this.messageCurrentPage+= 1;
  1056. } else {
  1057. this.messageCurrentPage = 1;
  1058. this.autoBottom = true;
  1059. this.messageNew = 0;
  1060. this.messageLists = [];
  1061. }
  1062. this.messageHasMorePages = false;
  1063. //
  1064. this.loadIng++;
  1065. this.messageNoDataText = this.$L("数据加载中.....");
  1066. $A.apiAjax({
  1067. url: 'chat/message/lists',
  1068. data: {
  1069. username: username,
  1070. page: this.messageCurrentPage,
  1071. pagesize: 30
  1072. },
  1073. complete: () => {
  1074. this.loadIng--;
  1075. },
  1076. error: () => {
  1077. this.messageNoDataText = this.$L("数据加载失败!");
  1078. },
  1079. success: (res) => {
  1080. if (username != this.dialogTarget.username) {
  1081. return;
  1082. }
  1083. if (res.ret === 1) {
  1084. let tempId = "notice_" + $A.randomString(6);
  1085. let tempLists = res.data.lists;
  1086. if (isNextPage) {
  1087. this.addMessageData({
  1088. id: tempId,
  1089. type: 'notice',
  1090. notice: this.$L('历史消息'),
  1091. }, false, isNextPage);
  1092. } else {
  1093. tempLists = tempLists.reverse();
  1094. }
  1095. tempLists.forEach((item) => {
  1096. this.addMessageData(Object.assign(item.message, {
  1097. id: item.id,
  1098. username: item.username,
  1099. userimg: item.userimg,
  1100. indate: item.indate,
  1101. }), false, isNextPage);
  1102. });
  1103. if (isNextPage) {
  1104. this.$nextTick(() => {
  1105. let tempObj = $A('div[data-id="' + tempId + '"]');
  1106. if (tempObj.length > 0) {
  1107. this.$refs.manageLists.scrollTo(tempObj.offset().top - tempObj.height() - 24, false);
  1108. }
  1109. });
  1110. }
  1111. this.messageNoDataText = '';
  1112. this.messageHasMorePages = res.data.hasMorePages;
  1113. } else {
  1114. this.messageNoDataText = res.msg
  1115. this.messageHasMorePages = false;
  1116. }
  1117. }
  1118. });
  1119. },
  1120. getTeamLists(isNextPage = false) {
  1121. if (isNextPage === true) {
  1122. if (!this.teamHasMorePages) {
  1123. return;
  1124. }
  1125. this.teamCurrentPage+= 1;
  1126. } else {
  1127. this.teamCurrentPage = 1;
  1128. }
  1129. this.teamHasMorePages = false;
  1130. //
  1131. this.loadIng++;
  1132. this.teamNoDataText = this.$L("数据加载中.....");
  1133. $A.apiAjax({
  1134. url: 'users/team/lists',
  1135. data: {
  1136. sorts: {
  1137. key: 'lists',
  1138. order: 'asc'
  1139. },
  1140. firstchart: 1,
  1141. page: this.teamCurrentPage,
  1142. pagesize: 100,
  1143. },
  1144. complete: () => {
  1145. this.loadIng--;
  1146. },
  1147. error: () => {
  1148. this.teamNoDataText = this.$L("数据加载失败!");
  1149. },
  1150. success: (res) => {
  1151. if (res.ret === 1) {
  1152. res.data.lists.forEach((item) => {
  1153. if (typeof this.teamLists[item.firstchart] === "undefined") {
  1154. this.$set(this.teamLists, item.firstchart, []);
  1155. }
  1156. this.teamLists[item.firstchart].push(item);
  1157. });
  1158. this.teamNoDataText = this.$L("没有相关的数据");
  1159. this.teamHasMorePages = res.data.hasMorePages;
  1160. //
  1161. if (this.teamHasMorePages && res.data.currentPage < 5) {
  1162. this.getTeamLists(true);
  1163. }
  1164. } else {
  1165. this.teamLists = {};
  1166. this.teamNoDataText = res.msg
  1167. this.teamHasMorePages = false;
  1168. }
  1169. }
  1170. });
  1171. },
  1172. addDialog(data) {
  1173. if (!data.username) {
  1174. return;
  1175. }
  1176. let lists = this.dialogLists.filter((item) => {return item.username == data.username});
  1177. let unread = 0;
  1178. if (lists.length > 0) {
  1179. if (typeof data.userimg === "undefined") {
  1180. data.userimg = lists[0].userimg;
  1181. }
  1182. unread = $A.runNum(lists[0].unread);
  1183. this.dialogLists = this.dialogLists.filter((item) => {return item.username != data.username});
  1184. }
  1185. if (typeof data.unread === "undefined") {
  1186. data.unread = unread;
  1187. }
  1188. this.dialogLists.unshift(data);
  1189. },
  1190. openDialog(user, autoAddDialog = false) {
  1191. if (autoAddDialog === true) {
  1192. let lists = this.dialogLists.filter((item) => {return item.username == user.username});
  1193. if (lists.length === 0) {
  1194. this.addDialog(user);
  1195. }
  1196. }
  1197. this.chatTap = 'dialog';
  1198. this.dialogTarget = user;
  1199. if (typeof user.unread === "number" && user.unread > 0) {
  1200. this.unreadTotal -= user.unread;
  1201. this.$set(user, 'unread', 0);
  1202. $A.WSOB.sendTo('read', user.username);
  1203. }
  1204. if (autoAddDialog === true) {
  1205. //自动滚到焦点
  1206. this.$nextTick(() => {
  1207. let dialogObj = $A(this.$refs.dialogLists);
  1208. let activeObj = dialogObj.find("li.active");
  1209. if (activeObj.length > 0) {
  1210. let offsetTop = activeObj.offset().top;
  1211. if (offsetTop < 0) {
  1212. dialogObj.stop().scrollTop(activeObj[0].offsetTop)
  1213. } else if (offsetTop > dialogObj.height()) {
  1214. dialogObj.stop().scrollTop(activeObj[0].offsetTop + activeObj.height() - dialogObj.height())
  1215. }
  1216. }
  1217. });
  1218. }
  1219. },
  1220. clickDialog(username, autoPush = false) {
  1221. let lists = this.dialogLists.filter((item) => {return item.username == username});
  1222. if (lists.length > 0) {
  1223. this.openDialog(lists[0]);
  1224. } else if (autoPush === true) {
  1225. $A.apiAjax({
  1226. url: 'users/team/lists',
  1227. data: {
  1228. username: username,
  1229. },
  1230. success: (res) => {
  1231. if (res.ret === 1 && $A.isPlainObject(res.data)) {
  1232. this.$nextTick(() => {
  1233. typeof this.dialogTarget.username === "undefined" && this.openDialog(res.data, true)
  1234. });
  1235. }
  1236. }
  1237. });
  1238. }
  1239. },
  1240. dialogDropdown(type) {
  1241. switch (type) {
  1242. case 'clear':
  1243. case 'delete':
  1244. this.$Modal.confirm({
  1245. title: this.$L('确认操作'),
  1246. content: type === 'delete' ? this.$L('你确定要删除此对话吗?') : this.$L('你确定要清除聊天记录吗?'),
  1247. loading: true,
  1248. onOk: () => {
  1249. let username = this.dialogTarget.username;
  1250. $A.apiAjax({
  1251. url: 'chat/dialog/clear',
  1252. data: {
  1253. username: username,
  1254. delete: type === 'delete' ? 1 : 0
  1255. },
  1256. error: () => {
  1257. this.$Modal.remove();
  1258. alert(this.$L('网络繁忙,请稍后再试!'));
  1259. },
  1260. success: (res) => {
  1261. this.$Modal.remove();
  1262. if (res.ret === 1) {
  1263. if (type === 'delete') {
  1264. this.dialogLists = this.dialogLists.filter((item) => {return item.username != username});
  1265. this.dialogTarget = {};
  1266. } else {
  1267. this.$set(this.dialogTarget, 'lasttext', '');
  1268. this.getDialogMessage();
  1269. }
  1270. }
  1271. setTimeout(() => {
  1272. if (res.ret === 1) {
  1273. this.$Message.success(res.msg);
  1274. } else {
  1275. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  1276. }
  1277. }, 350);
  1278. }
  1279. });
  1280. }
  1281. });
  1282. break;
  1283. }
  1284. },
  1285. messageListsScroll(res) {
  1286. if (res.directionreal === 'up') {
  1287. if (res.scrollE < 10) {
  1288. this.autoBottom = true;
  1289. }
  1290. } else if (res.directionreal === 'down') {
  1291. this.autoBottom = false;
  1292. }
  1293. },
  1294. messageBottomAuto() {
  1295. let randString = $A.randomString(8);
  1296. window.__messageBottomAuto = randString;
  1297. setTimeout(() => {
  1298. if (randString === window.__messageBottomAuto) {
  1299. window.__messageBottomAuto = null;
  1300. if (this.autoBottom) {
  1301. this.messageBottomGo();
  1302. }
  1303. this.messageBottomAuto();
  1304. }
  1305. }, 1000);
  1306. },
  1307. messageBottomGo(animation = false) {
  1308. this.$nextTick(() => {
  1309. this.messageNew = 0;
  1310. if (typeof this.$refs.manageLists !== "undefined") {
  1311. this.$refs.manageLists.scrollTo(this.$refs.manageBody.clientHeight, animation);
  1312. this.autoBottom = true;
  1313. }
  1314. });
  1315. },
  1316. messageInsertText(emoji) {
  1317. this.messageText+= emoji;
  1318. },
  1319. messageInsertImage(lists) {
  1320. for (let i = 0; i < lists.length; i++) {
  1321. let item = lists[i];
  1322. if (typeof item === 'object' && typeof item.url === "string") {
  1323. let data = {
  1324. type: 'image',
  1325. username: this.userInfo.username,
  1326. userimg: this.userInfo.userimg,
  1327. indate: Math.round(new Date().getTime() / 1000),
  1328. url: item.url
  1329. };
  1330. $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
  1331. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1332. });
  1333. //
  1334. this.addDialog(Object.assign(this.dialogTarget, {
  1335. lasttext: this.$L('[图片]'),
  1336. lastdate: data.indate
  1337. }));
  1338. this.openDialog(this.dialogTarget);
  1339. this.addMessageData(data, true);
  1340. }
  1341. }
  1342. },
  1343. addMessageData(data, animation = false, isUnshift = false) {
  1344. data.self = data.username === this.userInfo.username;
  1345. let sikp = false;
  1346. if (data.id) {
  1347. this.messageLists.some((item, index) => {
  1348. if (item.id == data.id) {
  1349. this.messageLists.splice(index, 1, data);
  1350. return sikp = true;
  1351. }
  1352. });
  1353. if (sikp) {
  1354. return;
  1355. }
  1356. }
  1357. if (isUnshift) {
  1358. this.messageLists.unshift(data);
  1359. } else {
  1360. this.messageLists.push(data);
  1361. if (this.autoBottom) {
  1362. this.messageBottomGo(animation);
  1363. } else {
  1364. this.messageNew++;
  1365. }
  1366. }
  1367. },
  1368. messageSend(e) {
  1369. if (e.keyCode == 13) {
  1370. if (e.shiftKey) {
  1371. return;
  1372. }
  1373. e.preventDefault();
  1374. this.messageSubmit();
  1375. }
  1376. },
  1377. messageSubmit() {
  1378. let dialogUser = this.dialogLists.filter((item) => { return item.username == this.dialogTarget.username });
  1379. if (dialogUser.length > 0) {
  1380. let user = dialogUser[0];
  1381. if (typeof user.unread === "number" && user.unread > 0) {
  1382. this.unreadTotal -= user.unread;
  1383. this.$set(user, 'unread', 0);
  1384. $A.WSOB.sendTo('read', user.username);
  1385. }
  1386. }
  1387. //
  1388. this.autoBottom = true;
  1389. let text = this.messageText.trim();
  1390. if ($A.count(text) > 0) {
  1391. let data = {
  1392. type: 'text',
  1393. username: this.userInfo.username,
  1394. userimg: this.userInfo.userimg,
  1395. indate: Math.round(new Date().getTime() / 1000),
  1396. text: text
  1397. };
  1398. $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
  1399. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1400. });
  1401. //
  1402. this.addDialog(Object.assign(this.dialogTarget, {
  1403. lasttext: text,
  1404. lastdate: data.indate
  1405. }));
  1406. this.openDialog(this.dialogTarget);
  1407. this.addMessageData(data, true);
  1408. }
  1409. this.$nextTick(() => {
  1410. this.messageText = "";
  1411. });
  1412. },
  1413. userViewResult(user, data) {
  1414. this.$set(user, 'nickname', data.nickname);
  1415. this.$set(user, 'userimg', data.userimg);
  1416. },
  1417. videoConnect(username, videoChat) {
  1418. this.videoChat = videoChat;
  1419. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  1420. try {
  1421. navigator.mediaDevices.getUserMedia({
  1422. audio: true,
  1423. video: this.videoChat
  1424. }).then((stream) => {
  1425. this.videoLocalStream = stream;
  1426. this.$refs.localVideo.srcObject = stream;
  1427. this.$refs.localVideo.removeEventListener('loadedmetadata', this.videoListener);
  1428. //
  1429. if (username === null) {
  1430. // 发起者
  1431. this.videoUserName = this.dialogTarget.username;
  1432. this.videoUserImg = this.dialogTarget.userimg;
  1433. this.videoStartTime = 0;
  1434. this.videoInitiator = true;
  1435. this.$refs.localVideo.addEventListener('loadedmetadata', this.videoListener);
  1436. } else {
  1437. // 接受者
  1438. this.videoIcecandidate(this.videoLocalStream, username);
  1439. this.videoRtc.createOffer({
  1440. offerToReceiveAudio: true,
  1441. offerToReceiveVideo: this.videoChat
  1442. }).then((desc) => {
  1443. this.videoRtc.setLocalDescription(desc).then(() => {
  1444. $A.WSOB.sendTo('info', username, {
  1445. 'type': 'video',
  1446. 'subtype': 'offer',
  1447. 'data': this.videoRtc.localDescription
  1448. });
  1449. }).catch((e) => {
  1450. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1451. this.videoClose(username, this.$L('对方:') + e);
  1452. });
  1453. }).catch((e) => {
  1454. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1455. this.videoClose(username, this.$L('对方:') + e);
  1456. });
  1457. }
  1458. }).catch((e) => {
  1459. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1460. username && this.videoClose(username, this.$L('对方:') + e);
  1461. });
  1462. } catch (e) {
  1463. this.$Modal.warning({title: this.$L('温馨提示'), content: this.$L('当前浏览器不支持音视频通话!')});
  1464. username && this.videoClose(username, this.$L('对方:') + this.$L('浏览器不支持音视频通话!'));
  1465. }
  1466. },
  1467. videoListener() {
  1468. $A.WSOB.sendTo('info', this.videoUserName, {
  1469. 'type': 'video',
  1470. 'subtype': 'call',
  1471. 'username': this.userInfo.username,
  1472. 'userimg': this.userInfo.userimg,
  1473. 'video': this.videoChat,
  1474. }, (res) => {
  1475. if (res.status !== 1) {
  1476. this.videoClose(this.videoUserName, this.$L('呼叫失败!'));
  1477. }
  1478. });
  1479. },
  1480. videoIcecandidate(localStream, username) {
  1481. this.videoRtc = new RTCPeerConnection({"iceServers":[{"urls":["turn:business.swoole.com:3478?transport=udp","turn:business.swoole.com:3478?transport=tcp"],"username":"ceshi","credential":"ceshi"}]});
  1482. this.videoRtc.onicecandidate = (event) => {
  1483. if (event.candidate) {
  1484. $A.WSOB.sendTo('info', username, {
  1485. 'type': 'video',
  1486. 'subtype': 'candidate',
  1487. 'data': event.candidate
  1488. });
  1489. }
  1490. };
  1491. try {
  1492. this.videoRtc.addStream(localStream);
  1493. } catch (e) {
  1494. let tracks = localStream.getTracks();
  1495. for (let i = 0; i < tracks.length; i++) {
  1496. this.videoRtc.addTrack(tracks[i], localStream);
  1497. }
  1498. }
  1499. this.videoRtc.onaddstream = (e) => {
  1500. this.$refs.remoteVideo.srcObject = e.stream;
  1501. };
  1502. },
  1503. videoClose(username, reason) {
  1504. if (username && reason !== false) {
  1505. $A.WSOB.sendTo('info', username, {
  1506. 'type': 'video',
  1507. 'subtype': 'close',
  1508. 'reason': reason,
  1509. });
  1510. }
  1511. if (this.videoInitiator) {
  1512. this.videoInitiator = false;
  1513. if (this.videoStartTime > 0) {
  1514. let second = Math.round(new Date().getTime() / 1000) - this.videoStartTime;
  1515. if (second >= 2) {
  1516. $A.WSOB.sendTo('user', this.videoUserName, {
  1517. type: this.videoChat ? 'video' : 'voice',
  1518. username: this.userInfo.username,
  1519. userimg: this.userInfo.userimg,
  1520. indate: Math.round(new Date().getTime() / 1000),
  1521. text: this.videoChat ? '视频通话' : '语音通话',
  1522. other: {
  1523. second: second
  1524. }
  1525. }, 'special');
  1526. }
  1527. }
  1528. }
  1529. if (username == this.videoUserName) {
  1530. this.videoUserName = '';
  1531. this.videoUserImg = '';
  1532. this.videoStartTime = 0;
  1533. if (this.videoLocalStream !== null) {
  1534. this.videoLocalStream.getTracks().forEach((track) => {
  1535. track.stop();
  1536. });
  1537. this.videoLocalStream = null;
  1538. }
  1539. this.$refs.localVideo.srcObject = null;
  1540. this.$refs.remoteVideo.srcObject = null;
  1541. }
  1542. },
  1543. videoMessage(msgDetail) {
  1544. let body = msgDetail.body;
  1545. let username = msgDetail.username;
  1546. if (['offer', 'candidate', 'answer'].indexOf(body.subtype) !== -1) {
  1547. if (!this.videoLocalStream) {
  1548. this.videoClose(username);
  1549. return;
  1550. }
  1551. }
  1552. //
  1553. switch (body.subtype) {
  1554. case 'call':
  1555. let callIng = true;
  1556. let callAudio = this.$refs.callAudio;
  1557. if (callAudio.getAttribute("data-listener") !== 'yes') {
  1558. callAudio.setAttribute("data-listener", "yes");
  1559. callAudio.addEventListener('ended', () => {
  1560. if (callIng) {
  1561. $A.WSOB.sendTo('info', username, {
  1562. 'type': 'video',
  1563. 'subtype': 'judge',
  1564. });
  1565. callAudio.play();
  1566. }
  1567. }, false);
  1568. }
  1569. callAudio.currentTime = 0;
  1570. callAudio.play();
  1571. //
  1572. this.$Notice.close('chat-call');
  1573. this.$Notice.open({
  1574. name: 'chat-call',
  1575. duration: 0,
  1576. onClose: () => {
  1577. callIng = false;
  1578. callAudio.pause();
  1579. this.videoClose(username, this.$L('对方:拒绝接听'));
  1580. },
  1581. render: h => {
  1582. return h('div', {
  1583. class: 'chat-notice-box',
  1584. }, [
  1585. h('img', {class: 'chat-notice-userimg', attrs: {src: body.userimg}}),
  1586. h('div', {class: 'ivu-notice-with-desc'}, [
  1587. h('div', {class: 'ivu-notice-title'}, [
  1588. h('UserView', {props: {username: username}})
  1589. ]),
  1590. h('div', {class: 'ivu-notice-desc'}, this.$L(body.video ? "邀请视频通话..." : "邀请语音通话...")),
  1591. h('div', {class: 'chat-notice-btn-box'}, [
  1592. h('Button', {
  1593. props: {type: 'success', size: 'small'},
  1594. on: {
  1595. click: () => {
  1596. callIng = false;
  1597. callAudio.pause();
  1598. this.$Notice.close('chat-call');
  1599. this.$emit("on-open-notice", username);
  1600. this.clickDialog(username);
  1601. this.videoConnect(username, body.video);
  1602. this.videoUserName = username;
  1603. this.videoUserImg = body.userimg;
  1604. this.videoStartTime = 0;
  1605. this.videoInitiator = false;
  1606. }
  1607. }
  1608. }, this.$L("接受")),
  1609. h('Button', {
  1610. props: {type: 'error', size: 'small'},
  1611. on: {
  1612. click: () => {
  1613. callIng = false;
  1614. callAudio.pause();
  1615. this.$Notice.close('chat-call');
  1616. this.videoClose(username, this.$L('对方:拒绝接听'));
  1617. }
  1618. }
  1619. }, this.$L("拒绝")),
  1620. ])
  1621. ])
  1622. ])
  1623. }
  1624. });
  1625. break;
  1626. case 'judge':
  1627. if (username != this.videoUserName) {
  1628. $A.WSOB.sendTo('info', username, {
  1629. 'type': 'video',
  1630. 'subtype': 'close',
  1631. });
  1632. }
  1633. break;
  1634. case 'close':
  1635. this.$refs.callAudio.pause();
  1636. this.$Notice.close('chat-call');
  1637. this.videoClose(username, false);
  1638. body.reason && this.$Message.warning(body.reason);
  1639. break;
  1640. case 'offer':
  1641. this.videoIcecandidate(this.videoLocalStream, username);
  1642. this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
  1643. if (this.videoStartTime === 0) {
  1644. this.videoRtc.createAnswer().then((desc) => {
  1645. this.videoRtc.setLocalDescription(desc).then(() => {
  1646. $A.WSOB.sendTo('info', username, {
  1647. 'type': 'video',
  1648. 'subtype': 'answer',
  1649. 'data': this.videoRtc.localDescription
  1650. });
  1651. }).catch((e) => {
  1652. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1653. });
  1654. }).catch((e) => {
  1655. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1656. });
  1657. this.videoStartTime = Math.round(new Date().getTime() / 1000);
  1658. }
  1659. }).catch((e) => {
  1660. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1661. });
  1662. break;
  1663. case 'answer':
  1664. if (this.videoRtc) {
  1665. this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
  1666. }).catch((e) => {
  1667. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1668. });
  1669. }
  1670. break;
  1671. case 'candidate':
  1672. if (this.videoRtc) {
  1673. this.videoRtc.addIceCandidate(new RTCIceCandidate(body.data)).then(() => {
  1674. }).catch((e) => {
  1675. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1676. });
  1677. }
  1678. break;
  1679. }
  1680. }
  1681. }
  1682. }
  1683. </script>