Index.vue 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  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. }
  820. }, false);
  821. resCall();
  822. this.getSetting();
  823. //
  824. window.onChatOpenUserName = (username) => {
  825. this.$emit("on-open-notice", username);
  826. this.clickDialog(username, true);
  827. }
  828. //
  829. if (this.openWindow) {
  830. $A.WSOB.connection();
  831. if (!this.openAlready) {
  832. this.openAlready = true;
  833. this.getDialogLists();
  834. }
  835. }
  836. //
  837. $A.WSOB.setOnMsgListener("chat/index", (msgDetail) => {
  838. if (msgDetail.username == $A.getUserName()) {
  839. return;
  840. }
  841. switch (msgDetail.messageType) {
  842. case 'open':
  843. if (this.openWindow) {
  844. this.getDialogLists();
  845. this.getDialogMessage();
  846. } else {
  847. this.openAlready = false;
  848. this.dialogTarget = {};
  849. }
  850. break;
  851. case 'info':
  852. if (msgDetail.body.type == 'video') {
  853. this.videoMessage(msgDetail)
  854. }
  855. break;
  856. case 'user':
  857. let body = msgDetail.body;
  858. if (['taskA'].indexOf(body.type) !== -1) {
  859. return;
  860. }
  861. let lasttext = $A.WSOB.getMsgDesc(body);
  862. this.unreadTotal += 1;
  863. this.addDialog({
  864. username: body.username,
  865. userimg: body.userimg,
  866. lasttext: lasttext,
  867. lastdate: body.indate,
  868. unread: body.unread
  869. });
  870. if (msgDetail.username == this.dialogTarget.username) {
  871. this.addMessageData(body, true);
  872. }
  873. if (!this.openWindow) {
  874. this.$Notice.close('chat-notice');
  875. this.$Notice.open({
  876. name: 'chat-notice',
  877. duration: 0,
  878. render: h => {
  879. return h('div', {
  880. class: 'chat-notice-box',
  881. on: {
  882. click: () => {
  883. this.$Notice.close('chat-notice');
  884. this.$emit("on-open-notice", body.username);
  885. this.clickDialog(body.username);
  886. }
  887. }
  888. }, [
  889. h('img', {class: 'chat-notice-userimg', attrs: {src: body.userimg}}),
  890. h('div', {class: 'ivu-notice-with-desc'}, [
  891. h('div', {class: 'ivu-notice-title'}, [
  892. h('UserView', {props: {username: body.username}})
  893. ]),
  894. h('div', {class: 'ivu-notice-desc'}, lasttext)
  895. ])
  896. ])
  897. }
  898. });
  899. }
  900. try {
  901. this.$refs.messageAudio.play();
  902. } catch (e) {
  903. }
  904. break;
  905. }
  906. });
  907. $A.WSOB.setOnSpecialListener("chat/index", (simpleMsg) => {
  908. this.addDialog({
  909. username: simpleMsg.target,
  910. lasttext: $A.WSOB.getMsgDesc(simpleMsg.body),
  911. lastdate: simpleMsg.body.indate
  912. });
  913. if (simpleMsg.target == this.dialogTarget.username) {
  914. this.addMessageData(simpleMsg.body, true);
  915. }
  916. });
  917. },
  918. watch: {
  919. chatTap(val) {
  920. if (val === 'team' && this.teamReady == false) {
  921. this.teamReady = true;
  922. this.getTeamLists();
  923. } else if (val === 'dialog') {
  924. this.autoBottom = true;
  925. this.$nextTick(() => {
  926. this.messageBottomGo();
  927. });
  928. }
  929. },
  930. openWindow(val) {
  931. if (val) {
  932. $A.WSOB.connection();
  933. if (!this.openAlready) {
  934. this.openAlready = true;
  935. this.getDialogLists();
  936. }
  937. }
  938. //
  939. let tmpRand = $A.randomString(8);
  940. this.__openWindowRand = tmpRand;
  941. setTimeout(() => {
  942. if (this.__openWindowRand !== tmpRand) {
  943. return;
  944. }
  945. $A.WSOB.sendTo('unread', (res) => {
  946. if (res.status === 1) {
  947. this.unreadTotal = $A.runNum(res.message);
  948. } else {
  949. this.unreadTotal = 0;
  950. }
  951. });
  952. }, 500);
  953. },
  954. unreadTotal(val) {
  955. if (val < 0) {
  956. this.unreadTotal = 0;
  957. return;
  958. }
  959. this.$emit('input', val);
  960. },
  961. dialogTarget: {
  962. handler: function () {
  963. let username = this.dialogTarget.username;
  964. if (username === this.__dialogTargetUsername) {
  965. return;
  966. }
  967. this.__dialogTargetUsername = username;
  968. this.getDialogMessage();
  969. },
  970. deep: true
  971. }
  972. },
  973. computed: {
  974. dialogListsS() {
  975. return this.dialogLists.filter(item => {
  976. return (item.username + "").indexOf(this.dialogSearch) > -1 || (item.lasttext + "").indexOf(this.dialogSearch) > -1 || (item.nickname + "").indexOf(this.dialogSearch) > -1
  977. });
  978. },
  979. teamListsS() {
  980. return function (lists) {
  981. return lists.filter(item => {
  982. return (item.username + "").indexOf(this.teamSearch) > -1 || (item.nickname + "").indexOf(this.teamSearch) > -1
  983. });
  984. }
  985. }
  986. },
  987. methods: {
  988. getSetting() {
  989. $A.apiAjax({
  990. url: 'system/setting',
  991. error: () => {
  992. $A.storage("systemSetting", {});
  993. },
  994. success: (res) => {
  995. if (res.ret === 1) {
  996. this.systemConfig = res.data;
  997. this.systemConfig.callav = this.systemConfig.callav || 'open';
  998. $A.storage("systemSetting", this.systemConfig);
  999. } else {
  1000. $A.storage("systemSetting", {});
  1001. }
  1002. }
  1003. });
  1004. },
  1005. formatCDate(v) {
  1006. let string = '';
  1007. if ($A.runNum(v) > 0) {
  1008. if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
  1009. string = $A.formatDate('H:i', v)
  1010. } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
  1011. string = $A.formatDate('m-d', v)
  1012. } else {
  1013. string = $A.formatDate('Y-m-d', v)
  1014. }
  1015. }
  1016. return string || '';
  1017. },
  1018. getDialogLists() {
  1019. if (!this.openAlready) {
  1020. return;
  1021. }
  1022. this.loadIng++;
  1023. this.dialogNoDataText = this.$L("数据加载中.....");
  1024. $A.apiAjax({
  1025. url: 'chat/dialog/lists',
  1026. complete: () => {
  1027. this.loadIng--;
  1028. },
  1029. error: () => {
  1030. this.dialogNoDataText = this.$L("数据加载失败!");
  1031. },
  1032. success: (res) => {
  1033. if (res.ret === 1) {
  1034. this.dialogLists = res.data;
  1035. this.dialogNoDataText = this.$L("没有相关的数据");
  1036. } else {
  1037. this.dialogLists = [];
  1038. this.dialogNoDataText = res.msg
  1039. }
  1040. }
  1041. });
  1042. },
  1043. getDialogMessage(isNextPage = false) {
  1044. let username = this.dialogTarget.username;
  1045. if (!username) {
  1046. return;
  1047. }
  1048. //
  1049. if (isNextPage === true) {
  1050. if (!this.messageHasMorePages) {
  1051. return;
  1052. }
  1053. this.messageCurrentPage+= 1;
  1054. } else {
  1055. this.messageCurrentPage = 1;
  1056. this.autoBottom = true;
  1057. this.messageNew = 0;
  1058. this.messageLists = [];
  1059. }
  1060. this.messageHasMorePages = false;
  1061. //
  1062. this.loadIng++;
  1063. this.messageNoDataText = this.$L("数据加载中.....");
  1064. $A.apiAjax({
  1065. url: 'chat/message/lists',
  1066. data: {
  1067. username: username,
  1068. page: this.messageCurrentPage,
  1069. pagesize: 30
  1070. },
  1071. complete: () => {
  1072. this.loadIng--;
  1073. },
  1074. error: () => {
  1075. this.messageNoDataText = this.$L("数据加载失败!");
  1076. },
  1077. success: (res) => {
  1078. if (username != this.dialogTarget.username) {
  1079. return;
  1080. }
  1081. if (res.ret === 1) {
  1082. let tempId = "notice_" + $A.randomString(6);
  1083. let tempLists = res.data.lists;
  1084. if (isNextPage) {
  1085. this.addMessageData({
  1086. id: tempId,
  1087. type: 'notice',
  1088. notice: this.$L('历史消息'),
  1089. }, false, isNextPage);
  1090. } else {
  1091. tempLists = tempLists.reverse();
  1092. }
  1093. tempLists.forEach((item) => {
  1094. this.addMessageData(Object.assign(item.message, {
  1095. id: item.id,
  1096. username: item.username,
  1097. userimg: item.userimg,
  1098. indate: item.indate,
  1099. }), false, isNextPage);
  1100. });
  1101. if (isNextPage) {
  1102. this.$nextTick(() => {
  1103. let tempObj = $A('div[data-id="' + tempId + '"]');
  1104. if (tempObj.length > 0) {
  1105. this.$refs.manageLists.scrollTo(tempObj.offset().top - tempObj.height() - 24, false);
  1106. }
  1107. });
  1108. }
  1109. this.messageNoDataText = '';
  1110. this.messageHasMorePages = res.data.hasMorePages;
  1111. } else {
  1112. this.messageNoDataText = res.msg
  1113. this.messageHasMorePages = false;
  1114. }
  1115. }
  1116. });
  1117. },
  1118. getTeamLists(isNextPage = false) {
  1119. if (isNextPage === true) {
  1120. if (!this.teamHasMorePages) {
  1121. return;
  1122. }
  1123. this.teamCurrentPage+= 1;
  1124. } else {
  1125. this.teamCurrentPage = 1;
  1126. }
  1127. this.teamHasMorePages = false;
  1128. //
  1129. this.loadIng++;
  1130. this.teamNoDataText = this.$L("数据加载中.....");
  1131. $A.apiAjax({
  1132. url: 'users/team/lists',
  1133. data: {
  1134. sorts: {
  1135. key: 'lists',
  1136. order: 'asc'
  1137. },
  1138. firstchart: 1,
  1139. page: this.teamCurrentPage,
  1140. pagesize: 100,
  1141. },
  1142. complete: () => {
  1143. this.loadIng--;
  1144. },
  1145. error: () => {
  1146. this.teamNoDataText = this.$L("数据加载失败!");
  1147. },
  1148. success: (res) => {
  1149. if (res.ret === 1) {
  1150. res.data.lists.forEach((item) => {
  1151. if (typeof this.teamLists[item.firstchart] === "undefined") {
  1152. this.$set(this.teamLists, item.firstchart, []);
  1153. }
  1154. this.teamLists[item.firstchart].push(item);
  1155. });
  1156. this.teamNoDataText = this.$L("没有相关的数据");
  1157. this.teamHasMorePages = res.data.hasMorePages;
  1158. //
  1159. if (this.teamHasMorePages && res.data.currentPage < 5) {
  1160. this.getTeamLists(true);
  1161. }
  1162. } else {
  1163. this.teamLists = {};
  1164. this.teamNoDataText = res.msg
  1165. this.teamHasMorePages = false;
  1166. }
  1167. }
  1168. });
  1169. },
  1170. addDialog(data) {
  1171. if (!data.username) {
  1172. return;
  1173. }
  1174. let lists = this.dialogLists.filter((item) => {return item.username == data.username});
  1175. let unread = 0;
  1176. if (lists.length > 0) {
  1177. if (typeof data.userimg === "undefined") {
  1178. data.userimg = lists[0].userimg;
  1179. }
  1180. unread = $A.runNum(lists[0].unread);
  1181. this.dialogLists = this.dialogLists.filter((item) => {return item.username != data.username});
  1182. }
  1183. if (typeof data.unread === "undefined") {
  1184. data.unread = unread;
  1185. }
  1186. this.dialogLists.unshift(data);
  1187. },
  1188. openDialog(user, autoAddDialog = false) {
  1189. if (autoAddDialog === true) {
  1190. let lists = this.dialogLists.filter((item) => {return item.username == user.username});
  1191. if (lists.length === 0) {
  1192. this.addDialog(user);
  1193. }
  1194. }
  1195. this.chatTap = 'dialog';
  1196. this.dialogTarget = user;
  1197. if (typeof user.unread === "number" && user.unread > 0) {
  1198. this.unreadTotal -= user.unread;
  1199. this.$set(user, 'unread', 0);
  1200. $A.WSOB.sendTo('read', user.username);
  1201. }
  1202. if (autoAddDialog === true) {
  1203. //自动滚到焦点
  1204. this.$nextTick(() => {
  1205. let dialogObj = $A(this.$refs.dialogLists);
  1206. let activeObj = dialogObj.find("li.active");
  1207. if (activeObj.length > 0) {
  1208. let offsetTop = activeObj.offset().top;
  1209. if (offsetTop < 0) {
  1210. dialogObj.stop().scrollTop(activeObj[0].offsetTop)
  1211. } else if (offsetTop > dialogObj.height()) {
  1212. dialogObj.stop().scrollTop(activeObj[0].offsetTop + activeObj.height() - dialogObj.height())
  1213. }
  1214. }
  1215. });
  1216. }
  1217. },
  1218. clickDialog(username, autoPush = false) {
  1219. let lists = this.dialogLists.filter((item) => {return item.username == username});
  1220. if (lists.length > 0) {
  1221. this.openDialog(lists[0]);
  1222. } else if (autoPush === true) {
  1223. $A.apiAjax({
  1224. url: 'users/team/lists',
  1225. data: {
  1226. username: username,
  1227. },
  1228. success: (res) => {
  1229. if (res.ret === 1 && $A.isPlainObject(res.data)) {
  1230. this.$nextTick(() => {
  1231. typeof this.dialogTarget.username === "undefined" && this.openDialog(res.data, true)
  1232. });
  1233. }
  1234. }
  1235. });
  1236. }
  1237. },
  1238. dialogDropdown(type) {
  1239. switch (type) {
  1240. case 'clear':
  1241. case 'delete':
  1242. this.$Modal.confirm({
  1243. title: this.$L('确认操作'),
  1244. content: type === 'delete' ? this.$L('你确定要删除此对话吗?') : this.$L('你确定要清除聊天记录吗?'),
  1245. loading: true,
  1246. onOk: () => {
  1247. let username = this.dialogTarget.username;
  1248. $A.apiAjax({
  1249. url: 'chat/dialog/clear',
  1250. data: {
  1251. username: username,
  1252. delete: type === 'delete' ? 1 : 0
  1253. },
  1254. error: () => {
  1255. this.$Modal.remove();
  1256. alert(this.$L('网络繁忙,请稍后再试!'));
  1257. },
  1258. success: (res) => {
  1259. this.$Modal.remove();
  1260. if (res.ret === 1) {
  1261. if (type === 'delete') {
  1262. this.dialogLists = this.dialogLists.filter((item) => {return item.username != username});
  1263. this.dialogTarget = {};
  1264. } else {
  1265. this.$set(this.dialogTarget, 'lasttext', '');
  1266. this.getDialogMessage();
  1267. }
  1268. }
  1269. setTimeout(() => {
  1270. if (res.ret === 1) {
  1271. this.$Message.success(res.msg);
  1272. } else {
  1273. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  1274. }
  1275. }, 350);
  1276. }
  1277. });
  1278. }
  1279. });
  1280. break;
  1281. }
  1282. },
  1283. messageListsScroll(res) {
  1284. if (res.directionreal === 'up') {
  1285. if (res.scrollE < 10) {
  1286. this.autoBottom = true;
  1287. }
  1288. } else if (res.directionreal === 'down') {
  1289. this.autoBottom = false;
  1290. }
  1291. },
  1292. messageBottomAuto() {
  1293. let randString = $A.randomString(8);
  1294. window.__messageBottomAuto = randString;
  1295. setTimeout(() => {
  1296. if (randString === window.__messageBottomAuto) {
  1297. window.__messageBottomAuto = null;
  1298. if (this.autoBottom) {
  1299. this.messageBottomGo();
  1300. }
  1301. this.messageBottomAuto();
  1302. }
  1303. }, 1000);
  1304. },
  1305. messageBottomGo(animation = false) {
  1306. this.$nextTick(() => {
  1307. this.messageNew = 0;
  1308. if (typeof this.$refs.manageLists !== "undefined") {
  1309. this.$refs.manageLists.scrollTo(this.$refs.manageBody.clientHeight, animation);
  1310. this.autoBottom = true;
  1311. }
  1312. });
  1313. },
  1314. messageInsertText(emoji) {
  1315. this.messageText+= emoji;
  1316. },
  1317. messageInsertImage(lists) {
  1318. for (let i = 0; i < lists.length; i++) {
  1319. let item = lists[i];
  1320. if (typeof item === 'object' && typeof item.url === "string") {
  1321. let data = {
  1322. type: 'image',
  1323. username: this.userInfo.username,
  1324. userimg: this.userInfo.userimg,
  1325. indate: Math.round(new Date().getTime() / 1000),
  1326. url: item.url
  1327. };
  1328. $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
  1329. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1330. });
  1331. //
  1332. this.addDialog(Object.assign(this.dialogTarget, {
  1333. lasttext: this.$L('[图片]'),
  1334. lastdate: data.indate
  1335. }));
  1336. this.openDialog(this.dialogTarget);
  1337. this.addMessageData(data, true);
  1338. }
  1339. }
  1340. },
  1341. addMessageData(data, animation = false, isUnshift = false) {
  1342. data.self = data.username === this.userInfo.username;
  1343. let sikp = false;
  1344. if (data.id) {
  1345. this.messageLists.some((item, index) => {
  1346. if (item.id == data.id) {
  1347. this.messageLists.splice(index, 1, data);
  1348. return sikp = true;
  1349. }
  1350. });
  1351. if (sikp) {
  1352. return;
  1353. }
  1354. }
  1355. if (isUnshift) {
  1356. this.messageLists.unshift(data);
  1357. } else {
  1358. this.messageLists.push(data);
  1359. if (this.autoBottom) {
  1360. this.messageBottomGo(animation);
  1361. } else {
  1362. this.messageNew++;
  1363. }
  1364. }
  1365. },
  1366. messageSend(e) {
  1367. if (e.keyCode == 13) {
  1368. if (e.shiftKey) {
  1369. return;
  1370. }
  1371. e.preventDefault();
  1372. this.messageSubmit();
  1373. }
  1374. },
  1375. messageSubmit() {
  1376. let dialogUser = this.dialogLists.filter((item) => { return item.username == this.dialogTarget.username });
  1377. if (dialogUser.length > 0) {
  1378. let user = dialogUser[0];
  1379. if (typeof user.unread === "number" && user.unread > 0) {
  1380. this.unreadTotal -= user.unread;
  1381. this.$set(user, 'unread', 0);
  1382. $A.WSOB.sendTo('read', user.username);
  1383. }
  1384. }
  1385. //
  1386. this.autoBottom = true;
  1387. let text = this.messageText.trim();
  1388. if ($A.count(text) > 0) {
  1389. let data = {
  1390. type: 'text',
  1391. username: this.userInfo.username,
  1392. userimg: this.userInfo.userimg,
  1393. indate: Math.round(new Date().getTime() / 1000),
  1394. text: text
  1395. };
  1396. $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
  1397. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1398. });
  1399. //
  1400. this.addDialog(Object.assign(this.dialogTarget, {
  1401. lasttext: text,
  1402. lastdate: data.indate
  1403. }));
  1404. this.openDialog(this.dialogTarget);
  1405. this.addMessageData(data, true);
  1406. }
  1407. this.$nextTick(() => {
  1408. this.messageText = "";
  1409. });
  1410. },
  1411. userViewResult(user, data) {
  1412. this.$set(user, 'nickname', data.nickname);
  1413. this.$set(user, 'userimg', data.userimg);
  1414. },
  1415. videoConnect(username, videoChat) {
  1416. this.videoChat = videoChat;
  1417. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  1418. try {
  1419. navigator.mediaDevices.getUserMedia({
  1420. audio: true,
  1421. video: this.videoChat
  1422. }).then((stream) => {
  1423. this.videoLocalStream = stream;
  1424. this.$refs.localVideo.srcObject = stream;
  1425. this.$refs.localVideo.removeEventListener('loadedmetadata', this.videoListener);
  1426. //
  1427. if (username === null) {
  1428. // 发起者
  1429. this.videoUserName = this.dialogTarget.username;
  1430. this.videoUserImg = this.dialogTarget.userimg;
  1431. this.videoStartTime = 0;
  1432. this.videoInitiator = true;
  1433. this.$refs.localVideo.addEventListener('loadedmetadata', this.videoListener);
  1434. } else {
  1435. // 接受者
  1436. this.videoIcecandidate(this.videoLocalStream, username);
  1437. this.videoRtc.createOffer({
  1438. offerToReceiveAudio: true,
  1439. offerToReceiveVideo: this.videoChat
  1440. }).then((desc) => {
  1441. this.videoRtc.setLocalDescription(desc).then(() => {
  1442. $A.WSOB.sendTo('info', username, {
  1443. 'type': 'video',
  1444. 'subtype': 'offer',
  1445. 'data': this.videoRtc.localDescription
  1446. });
  1447. }).catch((e) => {
  1448. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1449. this.videoClose(username, this.$L('对方:') + e);
  1450. });
  1451. }).catch((e) => {
  1452. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1453. this.videoClose(username, this.$L('对方:') + e);
  1454. });
  1455. }
  1456. }).catch((e) => {
  1457. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1458. username && this.videoClose(username, this.$L('对方:') + e);
  1459. });
  1460. } catch (e) {
  1461. this.$Modal.warning({title: this.$L('温馨提示'), content: this.$L('当前浏览器不支持音视频通话!')});
  1462. username && this.videoClose(username, this.$L('对方:') + this.$L('浏览器不支持音视频通话!'));
  1463. }
  1464. },
  1465. videoListener() {
  1466. $A.WSOB.sendTo('info', this.videoUserName, {
  1467. 'type': 'video',
  1468. 'subtype': 'call',
  1469. 'username': this.userInfo.username,
  1470. 'userimg': this.userInfo.userimg,
  1471. 'video': this.videoChat,
  1472. }, (res) => {
  1473. if (res.status !== 1) {
  1474. this.videoClose(this.videoUserName, this.$L('呼叫失败!'));
  1475. }
  1476. });
  1477. },
  1478. videoIcecandidate(localStream, username) {
  1479. this.videoRtc = new RTCPeerConnection({"iceServers":[{"urls":["turn:business.swoole.com:3478?transport=udp","turn:business.swoole.com:3478?transport=tcp"],"username":"ceshi","credential":"ceshi"}]});
  1480. this.videoRtc.onicecandidate = (event) => {
  1481. if (event.candidate) {
  1482. $A.WSOB.sendTo('info', username, {
  1483. 'type': 'video',
  1484. 'subtype': 'candidate',
  1485. 'data': event.candidate
  1486. });
  1487. }
  1488. };
  1489. try {
  1490. this.videoRtc.addStream(localStream);
  1491. } catch (e) {
  1492. let tracks = localStream.getTracks();
  1493. for (let i = 0; i < tracks.length; i++) {
  1494. this.videoRtc.addTrack(tracks[i], localStream);
  1495. }
  1496. }
  1497. this.videoRtc.onaddstream = (e) => {
  1498. this.$refs.remoteVideo.srcObject = e.stream;
  1499. };
  1500. },
  1501. videoClose(username, reason) {
  1502. if (username && reason !== false) {
  1503. $A.WSOB.sendTo('info', username, {
  1504. 'type': 'video',
  1505. 'subtype': 'close',
  1506. 'reason': reason,
  1507. });
  1508. }
  1509. if (this.videoInitiator) {
  1510. this.videoInitiator = false;
  1511. if (this.videoStartTime > 0) {
  1512. let second = Math.round(new Date().getTime() / 1000) - this.videoStartTime;
  1513. if (second >= 2) {
  1514. $A.WSOB.sendTo('user', this.videoUserName, {
  1515. type: this.videoChat ? 'video' : 'voice',
  1516. username: this.userInfo.username,
  1517. userimg: this.userInfo.userimg,
  1518. indate: Math.round(new Date().getTime() / 1000),
  1519. text: this.videoChat ? '视频通话' : '语音通话',
  1520. other: {
  1521. second: second
  1522. }
  1523. }, 'special');
  1524. }
  1525. }
  1526. }
  1527. if (username == this.videoUserName) {
  1528. this.videoUserName = '';
  1529. this.videoUserImg = '';
  1530. this.videoStartTime = 0;
  1531. if (this.videoLocalStream !== null) {
  1532. this.videoLocalStream.getTracks().forEach((track) => {
  1533. track.stop();
  1534. });
  1535. this.videoLocalStream = null;
  1536. }
  1537. this.$refs.localVideo.srcObject = null;
  1538. this.$refs.remoteVideo.srcObject = null;
  1539. }
  1540. },
  1541. videoMessage(msgDetail) {
  1542. let body = msgDetail.body;
  1543. let username = msgDetail.username;
  1544. if (['offer', 'candidate', 'answer'].indexOf(body.subtype) !== -1) {
  1545. if (!this.videoLocalStream) {
  1546. this.videoClose(username);
  1547. return;
  1548. }
  1549. }
  1550. //
  1551. switch (body.subtype) {
  1552. case 'call':
  1553. let callIng = true;
  1554. let callAudio = this.$refs.callAudio;
  1555. if (callAudio.getAttribute("data-listener") !== 'yes') {
  1556. callAudio.setAttribute("data-listener", "yes");
  1557. callAudio.addEventListener('ended', () => {
  1558. if (callIng) {
  1559. $A.WSOB.sendTo('info', username, {
  1560. 'type': 'video',
  1561. 'subtype': 'judge',
  1562. });
  1563. callAudio.play();
  1564. }
  1565. }, false);
  1566. }
  1567. callAudio.currentTime = 0;
  1568. callAudio.play();
  1569. //
  1570. this.$Notice.close('chat-call');
  1571. this.$Notice.open({
  1572. name: 'chat-call',
  1573. duration: 0,
  1574. onClose: () => {
  1575. callIng = false;
  1576. callAudio.pause();
  1577. this.videoClose(username, this.$L('对方:拒绝接听'));
  1578. },
  1579. render: h => {
  1580. return h('div', {
  1581. class: 'chat-notice-box',
  1582. }, [
  1583. h('img', {class: 'chat-notice-userimg', attrs: {src: body.userimg}}),
  1584. h('div', {class: 'ivu-notice-with-desc'}, [
  1585. h('div', {class: 'ivu-notice-title'}, [
  1586. h('UserView', {props: {username: username}})
  1587. ]),
  1588. h('div', {class: 'ivu-notice-desc'}, this.$L(body.video ? "邀请视频通话..." : "邀请语音通话...")),
  1589. h('div', {class: 'chat-notice-btn-box'}, [
  1590. h('Button', {
  1591. props: {type: 'success', size: 'small'},
  1592. on: {
  1593. click: () => {
  1594. callIng = false;
  1595. callAudio.pause();
  1596. this.$Notice.close('chat-call');
  1597. this.$emit("on-open-notice", username);
  1598. this.clickDialog(username);
  1599. this.videoConnect(username, body.video);
  1600. this.videoUserName = username;
  1601. this.videoUserImg = body.userimg;
  1602. this.videoStartTime = 0;
  1603. this.videoInitiator = false;
  1604. }
  1605. }
  1606. }, this.$L("接受")),
  1607. h('Button', {
  1608. props: {type: 'error', size: 'small'},
  1609. on: {
  1610. click: () => {
  1611. callIng = false;
  1612. callAudio.pause();
  1613. this.$Notice.close('chat-call');
  1614. this.videoClose(username, this.$L('对方:拒绝接听'));
  1615. }
  1616. }
  1617. }, this.$L("拒绝")),
  1618. ])
  1619. ])
  1620. ])
  1621. }
  1622. });
  1623. break;
  1624. case 'judge':
  1625. if (username != this.videoUserName) {
  1626. $A.WSOB.sendTo('info', username, {
  1627. 'type': 'video',
  1628. 'subtype': 'close',
  1629. });
  1630. }
  1631. break;
  1632. case 'close':
  1633. this.$refs.callAudio.pause();
  1634. this.$Notice.close('chat-call');
  1635. this.videoClose(username, false);
  1636. body.reason && this.$Message.warning(body.reason);
  1637. break;
  1638. case 'offer':
  1639. this.videoIcecandidate(this.videoLocalStream, username);
  1640. this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
  1641. if (this.videoStartTime === 0) {
  1642. this.videoRtc.createAnswer().then((desc) => {
  1643. this.videoRtc.setLocalDescription(desc).then(() => {
  1644. $A.WSOB.sendTo('info', username, {
  1645. 'type': 'video',
  1646. 'subtype': 'answer',
  1647. 'data': this.videoRtc.localDescription
  1648. });
  1649. }).catch((e) => {
  1650. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1651. });
  1652. }).catch((e) => {
  1653. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1654. });
  1655. this.videoStartTime = Math.round(new Date().getTime() / 1000);
  1656. }
  1657. }).catch((e) => {
  1658. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1659. });
  1660. break;
  1661. case 'answer':
  1662. if (this.videoRtc) {
  1663. this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
  1664. }).catch((e) => {
  1665. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1666. });
  1667. }
  1668. break;
  1669. case 'candidate':
  1670. if (this.videoRtc) {
  1671. this.videoRtc.addIceCandidate(new RTCIceCandidate(body.data)).then(() => {
  1672. }).catch((e) => {
  1673. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1674. });
  1675. }
  1676. break;
  1677. }
  1678. }
  1679. }
  1680. }
  1681. </script>