Index.vue 78 KB

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