Index.vue 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  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. width: $A.getObject(item, 'response.data.width'),
  1330. height: $A.getObject(item, 'response.data.height'),
  1331. };
  1332. $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
  1333. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1334. });
  1335. //
  1336. this.addDialog(Object.assign(this.dialogTarget, {
  1337. lasttext: this.$L('[图片]'),
  1338. lastdate: data.indate
  1339. }));
  1340. this.openDialog(this.dialogTarget);
  1341. this.addMessageData(data, true);
  1342. }
  1343. }
  1344. },
  1345. addMessageData(data, animation = false, isUnshift = false) {
  1346. data.self = data.username === this.userInfo.username;
  1347. let sikp = false;
  1348. if (data.id) {
  1349. this.messageLists.some((item, index) => {
  1350. if (item.id == data.id) {
  1351. this.messageLists.splice(index, 1, data);
  1352. return sikp = true;
  1353. }
  1354. });
  1355. if (sikp) {
  1356. return;
  1357. }
  1358. }
  1359. if (isUnshift) {
  1360. this.messageLists.unshift(data);
  1361. } else {
  1362. this.messageLists.push(data);
  1363. if (this.autoBottom) {
  1364. this.messageBottomGo(animation);
  1365. } else {
  1366. this.messageNew++;
  1367. }
  1368. }
  1369. },
  1370. messageSend(e) {
  1371. if (e.keyCode == 13) {
  1372. if (e.shiftKey) {
  1373. return;
  1374. }
  1375. e.preventDefault();
  1376. this.messageSubmit();
  1377. }
  1378. },
  1379. messageSubmit() {
  1380. let dialogUser = this.dialogLists.filter((item) => { return item.username == this.dialogTarget.username });
  1381. if (dialogUser.length > 0) {
  1382. let user = dialogUser[0];
  1383. if (typeof user.unread === "number" && user.unread > 0) {
  1384. this.unreadTotal -= user.unread;
  1385. this.$set(user, 'unread', 0);
  1386. $A.WSOB.sendTo('read', user.username);
  1387. }
  1388. }
  1389. //
  1390. this.autoBottom = true;
  1391. let text = this.messageText.trim();
  1392. if ($A.count(text) > 0) {
  1393. let data = {
  1394. type: 'text',
  1395. username: this.userInfo.username,
  1396. userimg: this.userInfo.userimg,
  1397. indate: Math.round(new Date().getTime() / 1000),
  1398. text: text
  1399. };
  1400. $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
  1401. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1402. });
  1403. //
  1404. this.addDialog(Object.assign(this.dialogTarget, {
  1405. lasttext: text,
  1406. lastdate: data.indate
  1407. }));
  1408. this.openDialog(this.dialogTarget);
  1409. this.addMessageData(data, true);
  1410. }
  1411. this.$nextTick(() => {
  1412. this.messageText = "";
  1413. });
  1414. },
  1415. userViewResult(user, data) {
  1416. this.$set(user, 'nickname', data.nickname);
  1417. this.$set(user, 'userimg', data.userimg);
  1418. },
  1419. videoConnect(username, videoChat) {
  1420. this.videoChat = videoChat;
  1421. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  1422. try {
  1423. navigator.mediaDevices.getUserMedia({
  1424. audio: true,
  1425. video: this.videoChat
  1426. }).then((stream) => {
  1427. this.videoLocalStream = stream;
  1428. this.$refs.localVideo.srcObject = stream;
  1429. this.$refs.localVideo.removeEventListener('loadedmetadata', this.videoListener);
  1430. //
  1431. if (username === null) {
  1432. // 发起者
  1433. this.videoUserName = this.dialogTarget.username;
  1434. this.videoUserImg = this.dialogTarget.userimg;
  1435. this.videoStartTime = 0;
  1436. this.videoInitiator = true;
  1437. this.$refs.localVideo.addEventListener('loadedmetadata', this.videoListener);
  1438. } else {
  1439. // 接受者
  1440. this.videoIcecandidate(this.videoLocalStream, username);
  1441. this.videoRtc.createOffer({
  1442. offerToReceiveAudio: true,
  1443. offerToReceiveVideo: this.videoChat
  1444. }).then((desc) => {
  1445. this.videoRtc.setLocalDescription(desc).then(() => {
  1446. $A.WSOB.sendTo('info', username, {
  1447. 'type': 'video',
  1448. 'subtype': 'offer',
  1449. 'data': this.videoRtc.localDescription
  1450. });
  1451. }).catch((e) => {
  1452. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1453. this.videoClose(username, this.$L('对方:') + e);
  1454. });
  1455. }).catch((e) => {
  1456. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1457. this.videoClose(username, this.$L('对方:') + e);
  1458. });
  1459. }
  1460. }).catch((e) => {
  1461. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1462. username && this.videoClose(username, this.$L('对方:') + e);
  1463. });
  1464. } catch (e) {
  1465. this.$Modal.warning({title: this.$L('温馨提示'), content: this.$L('当前浏览器不支持音视频通话!')});
  1466. username && this.videoClose(username, this.$L('对方:') + this.$L('浏览器不支持音视频通话!'));
  1467. }
  1468. },
  1469. videoListener() {
  1470. $A.WSOB.sendTo('info', this.videoUserName, {
  1471. 'type': 'video',
  1472. 'subtype': 'call',
  1473. 'username': this.userInfo.username,
  1474. 'userimg': this.userInfo.userimg,
  1475. 'video': this.videoChat,
  1476. }, (res) => {
  1477. if (res.status !== 1) {
  1478. this.videoClose(this.videoUserName, this.$L('呼叫失败!'));
  1479. }
  1480. });
  1481. },
  1482. videoIcecandidate(localStream, username) {
  1483. this.videoRtc = new RTCPeerConnection({"iceServers":[{"urls":["turn:business.swoole.com:3478?transport=udp","turn:business.swoole.com:3478?transport=tcp"],"username":"ceshi","credential":"ceshi"}]});
  1484. this.videoRtc.onicecandidate = (event) => {
  1485. if (event.candidate) {
  1486. $A.WSOB.sendTo('info', username, {
  1487. 'type': 'video',
  1488. 'subtype': 'candidate',
  1489. 'data': event.candidate
  1490. });
  1491. }
  1492. };
  1493. try {
  1494. this.videoRtc.addStream(localStream);
  1495. } catch (e) {
  1496. let tracks = localStream.getTracks();
  1497. for (let i = 0; i < tracks.length; i++) {
  1498. this.videoRtc.addTrack(tracks[i], localStream);
  1499. }
  1500. }
  1501. this.videoRtc.onaddstream = (e) => {
  1502. this.$refs.remoteVideo.srcObject = e.stream;
  1503. };
  1504. },
  1505. videoClose(username, reason) {
  1506. if (username && reason !== false) {
  1507. $A.WSOB.sendTo('info', username, {
  1508. 'type': 'video',
  1509. 'subtype': 'close',
  1510. 'reason': reason,
  1511. });
  1512. }
  1513. if (this.videoInitiator) {
  1514. this.videoInitiator = false;
  1515. if (this.videoStartTime > 0) {
  1516. let second = Math.round(new Date().getTime() / 1000) - this.videoStartTime;
  1517. if (second >= 2) {
  1518. $A.WSOB.sendTo('user', this.videoUserName, {
  1519. type: this.videoChat ? 'video' : 'voice',
  1520. username: this.userInfo.username,
  1521. userimg: this.userInfo.userimg,
  1522. indate: Math.round(new Date().getTime() / 1000),
  1523. text: this.videoChat ? '视频通话' : '语音通话',
  1524. other: {
  1525. second: second
  1526. }
  1527. }, 'special');
  1528. }
  1529. }
  1530. }
  1531. if (username == this.videoUserName) {
  1532. this.videoUserName = '';
  1533. this.videoUserImg = '';
  1534. this.videoStartTime = 0;
  1535. if (this.videoLocalStream !== null) {
  1536. this.videoLocalStream.getTracks().forEach((track) => {
  1537. track.stop();
  1538. });
  1539. this.videoLocalStream = null;
  1540. }
  1541. this.$refs.localVideo.srcObject = null;
  1542. this.$refs.remoteVideo.srcObject = null;
  1543. }
  1544. },
  1545. videoMessage(msgDetail) {
  1546. let body = msgDetail.body;
  1547. let username = msgDetail.username;
  1548. if (['offer', 'candidate', 'answer'].indexOf(body.subtype) !== -1) {
  1549. if (!this.videoLocalStream) {
  1550. this.videoClose(username);
  1551. return;
  1552. }
  1553. }
  1554. //
  1555. switch (body.subtype) {
  1556. case 'call':
  1557. let callIng = true;
  1558. let callAudio = this.$refs.callAudio;
  1559. if (callAudio.getAttribute("data-listener") !== 'yes') {
  1560. callAudio.setAttribute("data-listener", "yes");
  1561. callAudio.addEventListener('ended', () => {
  1562. if (callIng) {
  1563. $A.WSOB.sendTo('info', username, {
  1564. 'type': 'video',
  1565. 'subtype': 'judge',
  1566. });
  1567. callAudio.play();
  1568. }
  1569. }, false);
  1570. }
  1571. callAudio.currentTime = 0;
  1572. callAudio.play();
  1573. //
  1574. this.$Notice.close('chat-call');
  1575. this.$Notice.open({
  1576. name: 'chat-call',
  1577. duration: 0,
  1578. onClose: () => {
  1579. callIng = false;
  1580. callAudio.pause();
  1581. this.videoClose(username, this.$L('对方:拒绝接听'));
  1582. },
  1583. render: h => {
  1584. return h('div', {
  1585. class: 'chat-notice-box',
  1586. }, [
  1587. h('img', {class: 'chat-notice-userimg', attrs: {src: body.userimg}}),
  1588. h('div', {class: 'ivu-notice-with-desc'}, [
  1589. h('div', {class: 'ivu-notice-title'}, [
  1590. h('UserView', {props: {username: username}})
  1591. ]),
  1592. h('div', {class: 'ivu-notice-desc'}, this.$L(body.video ? "邀请视频通话..." : "邀请语音通话...")),
  1593. h('div', {class: 'chat-notice-btn-box'}, [
  1594. h('Button', {
  1595. props: {type: 'success', size: 'small'},
  1596. on: {
  1597. click: () => {
  1598. callIng = false;
  1599. callAudio.pause();
  1600. this.$Notice.close('chat-call');
  1601. this.$emit("on-open-notice", username);
  1602. this.clickDialog(username);
  1603. this.videoConnect(username, body.video);
  1604. this.videoUserName = username;
  1605. this.videoUserImg = body.userimg;
  1606. this.videoStartTime = 0;
  1607. this.videoInitiator = false;
  1608. }
  1609. }
  1610. }, this.$L("接受")),
  1611. h('Button', {
  1612. props: {type: 'error', size: 'small'},
  1613. on: {
  1614. click: () => {
  1615. callIng = false;
  1616. callAudio.pause();
  1617. this.$Notice.close('chat-call');
  1618. this.videoClose(username, this.$L('对方:拒绝接听'));
  1619. }
  1620. }
  1621. }, this.$L("拒绝")),
  1622. ])
  1623. ])
  1624. ])
  1625. }
  1626. });
  1627. break;
  1628. case 'judge':
  1629. if (username != this.videoUserName) {
  1630. $A.WSOB.sendTo('info', username, {
  1631. 'type': 'video',
  1632. 'subtype': 'close',
  1633. });
  1634. }
  1635. break;
  1636. case 'close':
  1637. this.$refs.callAudio.pause();
  1638. this.$Notice.close('chat-call');
  1639. this.videoClose(username, false);
  1640. body.reason && this.$Message.warning(body.reason);
  1641. break;
  1642. case 'offer':
  1643. this.videoIcecandidate(this.videoLocalStream, username);
  1644. this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
  1645. if (this.videoStartTime === 0) {
  1646. this.videoRtc.createAnswer().then((desc) => {
  1647. this.videoRtc.setLocalDescription(desc).then(() => {
  1648. $A.WSOB.sendTo('info', username, {
  1649. 'type': 'video',
  1650. 'subtype': 'answer',
  1651. 'data': this.videoRtc.localDescription
  1652. });
  1653. }).catch((e) => {
  1654. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1655. });
  1656. }).catch((e) => {
  1657. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1658. });
  1659. this.videoStartTime = Math.round(new Date().getTime() / 1000);
  1660. }
  1661. }).catch((e) => {
  1662. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1663. });
  1664. break;
  1665. case 'answer':
  1666. if (this.videoRtc) {
  1667. this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
  1668. }).catch((e) => {
  1669. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1670. });
  1671. }
  1672. break;
  1673. case 'candidate':
  1674. if (this.videoRtc) {
  1675. this.videoRtc.addIceCandidate(new RTCIceCandidate(body.data)).then(() => {
  1676. }).catch((e) => {
  1677. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1678. });
  1679. }
  1680. break;
  1681. }
  1682. }
  1683. }
  1684. }
  1685. </script>