Index.vue 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898
  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><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" :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">
  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. <user-view :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. .quick-item {
  571. color: #444444;
  572. font-size: 24px;
  573. margin: 0 7px;
  574. &.voicecam {
  575. font-size: 26px;
  576. height: 24px;
  577. line-height: 24px;
  578. }
  579. &.videocam {
  580. color: #666666;
  581. font-size: 30px;
  582. height: 24px;
  583. line-height: 24px;
  584. }
  585. }
  586. .emoji-box {
  587. position: absolute;
  588. left: 0;
  589. bottom: 40px;
  590. max-height: 320px;
  591. width: 100%;
  592. overflow: auto;
  593. background-color: #ffffff;
  594. padding: 12px;
  595. border-bottom: 1px solid #efefef;
  596. .emoji-input {
  597. margin: 6px 0;
  598. }
  599. h5 {
  600. padding: 0;
  601. margin: 8px 0 0 0;
  602. color: #b1b1b1;
  603. text-transform: uppercase;
  604. font-size: 14px;
  605. cursor: default;
  606. font-weight: normal;
  607. }
  608. .emojis {
  609. display: flex;
  610. flex-wrap: wrap;
  611. justify-content: space-between;
  612. &:after {
  613. content: "";
  614. flex: auto;
  615. }
  616. span {
  617. padding: 2px 4px;
  618. cursor: pointer;
  619. font-size: 22px;
  620. &:hover {
  621. background: #ececec;
  622. cursor: pointer;
  623. }
  624. }
  625. }
  626. }
  627. .message-upload {
  628. display: none;
  629. width: 0;
  630. height: 0;
  631. overflow: hidden;
  632. }
  633. }
  634. .manage-drag-over {
  635. position: absolute;
  636. top: 0;
  637. left: 0;
  638. right: 0;
  639. bottom: 0;
  640. z-index: 3;
  641. background-color: rgba(255, 255, 255, 0.78);
  642. display: flex;
  643. align-items: center;
  644. justify-content: center;
  645. &:before {
  646. content: "";
  647. position: absolute;
  648. top: 16px;
  649. left: 16px;
  650. right: 16px;
  651. bottom: 16px;
  652. border: 2px dashed #7b7b7b;
  653. border-radius: 12px;
  654. }
  655. .manage-drag-text {
  656. padding: 12px;
  657. font-size: 18px;
  658. color: #666666;
  659. }
  660. }
  661. @media screen and (max-width: 768px) {
  662. .manage-lists {
  663. bottom: 96px;
  664. .manage-lists-message-new {
  665. bottom: 106px;
  666. }
  667. }
  668. .manage-send {
  669. height: 96px;
  670. }
  671. .manage-quick {
  672. bottom: 54px;
  673. .quick-item {
  674. font-size: 24px;
  675. margin-right: 8px;
  676. }
  677. }
  678. }
  679. }
  680. .chat-video {
  681. position: fixed;
  682. top: 0;
  683. left: 0;
  684. width: 100%;
  685. height: 100%;
  686. background-color: #000000;
  687. background-size: cover;
  688. background-position: center center;
  689. background-repeat: no-repeat;
  690. z-index: 9;
  691. &:before {
  692. content: "";
  693. position: absolute;
  694. left: -10%;
  695. right: -10%;
  696. top: -10%;
  697. bottom: -10%;
  698. background: inherit;
  699. filter: blur(25px);
  700. z-index: 1;
  701. }
  702. &:after {
  703. content: "";
  704. position: absolute;
  705. left: -10%;
  706. right: -10%;
  707. top: -10%;
  708. bottom: -10%;
  709. background: rgba(0, 0, 0, 0.82);
  710. z-index: 2;
  711. }
  712. .video-opacity {
  713. position: absolute;
  714. top: 50%;
  715. left: 50%;
  716. transform: translate(-50%, -50%);
  717. font-size: 26px;
  718. color: #aaaaaa;
  719. padding: 24px;
  720. z-index: 3;
  721. animation:opacity 2s infinite alternate ;
  722. @keyframes opacity {
  723. 0% {
  724. opacity: 0.1;
  725. }
  726. 100% {
  727. opacity: 1;
  728. }
  729. }
  730. }
  731. .video-mini,
  732. .video-active {
  733. position: absolute;
  734. max-width: 640px;
  735. max-height: 100%;
  736. object-fit: cover;
  737. transition: opacity 1s;
  738. }
  739. .video-active {
  740. top: 0;
  741. left: 50%;
  742. width: 100%;
  743. height: 100%;
  744. transform: rotateY(180deg) translateX(50%);
  745. z-index: 4;
  746. }
  747. .video-mini {
  748. top: 0;
  749. right: 0;
  750. width: 260px;
  751. height: 180px;
  752. transform: scale(-1, 1);
  753. z-index: 5;
  754. }
  755. .video-close {
  756. position: absolute;
  757. max-width: 720px;
  758. bottom: 18px;
  759. left: 50%;
  760. width: 100%;
  761. transform: translateX(-50%);
  762. display: flex;
  763. align-items: center;
  764. justify-content: center;
  765. z-index: 6;
  766. > i {
  767. font-weight: 600;
  768. font-size: 46px;
  769. color: #ffffff;
  770. cursor: pointer;
  771. &:hover {
  772. color: #ff0000;
  773. }
  774. }
  775. }
  776. }
  777. .chat-audio {
  778. width: 0;
  779. height: 0;
  780. display: none;
  781. }
  782. .chat-flex {
  783. display: flex;
  784. }
  785. @media (max-width: 768px) {
  786. .chat-menu {
  787. width: 50px;
  788. li {
  789. padding: 6px 0;
  790. margin: 6px 0;
  791. font-size: 24px;
  792. &.self {
  793. .avatar {
  794. width: 32px;
  795. height: 32px;
  796. font-size: 18px;
  797. }
  798. }
  799. }
  800. }
  801. .chat-user,
  802. .chat-team {
  803. display: none;
  804. position: absolute;
  805. left: 50px;
  806. right: 0;
  807. z-index: 2;
  808. width: auto;
  809. > li {
  810. &.sreach {
  811. height: 54px;
  812. }
  813. }
  814. &.chat-tam {
  815. display: flex;
  816. }
  817. }
  818. .chat-message {
  819. .manage-title {
  820. height: 54px;
  821. line-height: 54px;
  822. .manage-title-right {
  823. width: 54px;
  824. height: 54px;
  825. line-height: 54px;
  826. }
  827. }
  828. .manage-lists {
  829. top: 54px;
  830. }
  831. }
  832. }
  833. }
  834. </style>
  835. <script>
  836. import EmojiPicker from 'vue-emoji-picker'
  837. import DrawerTabsContainer from "../DrawerTabsContainer";
  838. import ScrollerY from "../../../_components/ScrollerY";
  839. import ChatMessage from "./Message";
  840. import ImgUpload from "../ImgUpload";
  841. import ChatLoad from "./Upload";
  842. export default {
  843. name: 'ChatIndex',
  844. components: {ChatLoad, ImgUpload, ChatMessage, EmojiPicker, ScrollerY, DrawerTabsContainer},
  845. props: {
  846. value: {
  847. default: 0
  848. },
  849. openWindow: {
  850. type: Boolean,
  851. default: false
  852. },
  853. },
  854. data () {
  855. return {
  856. loadIng: 0,
  857. openAlready: false,
  858. userInfo: {},
  859. chatTap: 'dialog',
  860. chatTam: 'dialog',
  861. messageAudio: window.location.origin + '/audio/',
  862. dialogSearch: '',
  863. dialogTarget: {},
  864. dialogLists: [],
  865. dialogNoDataText: '',
  866. dialogDragOver: false,
  867. teamSearch: '',
  868. teamReady: false,
  869. teamLists: {},
  870. teamNoDataText: '',
  871. teamCurrentPage: 1,
  872. teamHasMorePages: false,
  873. autoBottom: true,
  874. messageNew: 0,
  875. messageText: '',
  876. messageLists: [],
  877. messageNoDataText: '',
  878. messageEmojiSearch: '',
  879. messageCurrentPage: 1,
  880. messageHasMorePages: false,
  881. unreadTotal: 0,
  882. videoUserName: '', //视频对话用户名
  883. videoUserImg: '', //视频对话用户头像
  884. videoStartTime: 0, //视频开始时间
  885. videoInitiator: false, //是否发起人
  886. videoChat: false, //是否视频通话(否则音频通话)
  887. videoRtc: null, //视频Rtc
  888. videoLocalStream: null, //视频流
  889. systemConfig: $A.jsonParse($A.storage("systemSetting"), {
  890. callav: '',
  891. }),
  892. }
  893. },
  894. created() {
  895. this.dialogNoDataText = this.$L("数据加载中.....");
  896. this.teamNoDataText = this.$L("数据加载中.....");
  897. this.messageNoDataText = this.$L("数据加载中.....");
  898. },
  899. mounted() {
  900. let resCall = () => {
  901. if ($A.getToken() === false) {
  902. return;
  903. }
  904. $A.WSOB.sendTo('unread', (res) => {
  905. if (res.status === 1) {
  906. this.unreadTotal = $A.runNum(res.message);
  907. } else {
  908. this.unreadTotal = 0;
  909. }
  910. });
  911. this.getDialogLists();
  912. this.messageBottomAuto();
  913. };
  914. this.userInfo = $A.getUserInfo((res, isLogin) => {
  915. if (this.userInfo.id != res.id) {
  916. this.userInfo = res;
  917. resCall();
  918. } else {
  919. this.userInfo = res;
  920. }
  921. }, false);
  922. resCall();
  923. this.getSetting();
  924. //
  925. window.onChatOpenUserName = (username) => {
  926. this.$emit("on-open-notice", username);
  927. this.clickDialog(username, true);
  928. }
  929. //
  930. if (this.openWindow) {
  931. $A.WSOB.connection();
  932. if (!this.openAlready) {
  933. this.openAlready = true;
  934. this.getDialogLists();
  935. }
  936. }
  937. //
  938. $A.WSOB.setOnMsgListener("chat/index", (msgDetail) => {
  939. if (msgDetail.username == $A.getUserName()) {
  940. return;
  941. }
  942. switch (msgDetail.messageType) {
  943. case 'open':
  944. if (this.openWindow) {
  945. this.getDialogLists();
  946. this.getDialogMessage();
  947. } else {
  948. this.openAlready = false;
  949. this.dialogTarget = {};
  950. }
  951. break;
  952. case 'info':
  953. if (msgDetail.body.type == 'video') {
  954. this.videoMessage(msgDetail)
  955. }
  956. break;
  957. case 'user':
  958. let body = msgDetail.body;
  959. if (['taskA'].indexOf(body.type) !== -1) {
  960. return;
  961. }
  962. let lasttext = $A.WSOB.getMsgDesc(body);
  963. this.unreadTotal += 1;
  964. this.addDialog({
  965. username: body.username,
  966. userimg: body.userimg,
  967. lasttext: lasttext,
  968. lastdate: body.indate,
  969. unread: body.unread
  970. });
  971. if (msgDetail.username == this.dialogTarget.username) {
  972. this.addMessageData(body, true);
  973. }
  974. if (!this.openWindow) {
  975. this.$Notice.close('chat-notice');
  976. this.$Notice.open({
  977. name: 'chat-notice',
  978. duration: 0,
  979. render: h => {
  980. return h('div', {
  981. class: 'chat-notice-box',
  982. on: {
  983. click: () => {
  984. this.$Notice.close('chat-notice');
  985. this.$emit("on-open-notice", body.username);
  986. this.clickDialog(body.username);
  987. }
  988. }
  989. }, [
  990. h('UserImg', {class: 'chat-notice-userimg', props: {info: body}}),
  991. h('div', {class: 'ivu-notice-with-desc'}, [
  992. h('div', {class: 'ivu-notice-title'}, [
  993. h('UserView', {props: {username: body.username}})
  994. ]),
  995. h('div', {class: 'ivu-notice-desc'}, lasttext)
  996. ])
  997. ])
  998. }
  999. });
  1000. }
  1001. try {
  1002. this.$refs.messageAudio.play();
  1003. } catch (e) {
  1004. }
  1005. break;
  1006. }
  1007. });
  1008. $A.WSOB.setOnSpecialListener("chat/index", (simpleMsg) => {
  1009. this.addDialog({
  1010. username: simpleMsg.target,
  1011. lasttext: $A.WSOB.getMsgDesc(simpleMsg.body),
  1012. lastdate: simpleMsg.body.indate
  1013. });
  1014. if (simpleMsg.target == this.dialogTarget.username) {
  1015. this.addMessageData(simpleMsg.body, true);
  1016. }
  1017. });
  1018. },
  1019. watch: {
  1020. chatTap(val) {
  1021. if (val === 'team' && this.teamReady == false) {
  1022. this.teamReady = true;
  1023. this.getTeamLists();
  1024. } else if (val === 'dialog') {
  1025. this.autoBottom = true;
  1026. this.$nextTick(() => {
  1027. this.messageBottomGo();
  1028. });
  1029. }
  1030. },
  1031. openWindow(val) {
  1032. if (val) {
  1033. $A.WSOB.connection();
  1034. if (!this.openAlready) {
  1035. this.openAlready = true;
  1036. this.getDialogLists();
  1037. }
  1038. }
  1039. //
  1040. let tmpRand = $A.randomString(8);
  1041. this.__openWindowRand = tmpRand;
  1042. setTimeout(() => {
  1043. if (this.__openWindowRand !== tmpRand) {
  1044. return;
  1045. }
  1046. $A.WSOB.sendTo('unread', (res) => {
  1047. if (res.status === 1) {
  1048. this.unreadTotal = $A.runNum(res.message);
  1049. } else {
  1050. this.unreadTotal = 0;
  1051. }
  1052. });
  1053. }, 500);
  1054. },
  1055. unreadTotal(val) {
  1056. if (val < 0) {
  1057. this.unreadTotal = 0;
  1058. return;
  1059. }
  1060. this.$emit('input', val);
  1061. },
  1062. dialogTarget: {
  1063. handler: function () {
  1064. let username = this.dialogTarget.username;
  1065. if (username === this.__dialogTargetUsername) {
  1066. return;
  1067. }
  1068. this.__dialogTargetUsername = username;
  1069. this.getDialogMessage();
  1070. },
  1071. deep: true
  1072. }
  1073. },
  1074. computed: {
  1075. dialogListsS() {
  1076. return this.dialogLists.filter(item => {
  1077. return (item.username + "").indexOf(this.dialogSearch) > -1 || (item.lasttext + "").indexOf(this.dialogSearch) > -1 || (item.nickname + "").indexOf(this.dialogSearch) > -1
  1078. });
  1079. },
  1080. teamListsS() {
  1081. return function (lists) {
  1082. return lists.filter(item => {
  1083. return (item.username + "").indexOf(this.teamSearch) > -1 || (item.nickname + "").indexOf(this.teamSearch) > -1
  1084. });
  1085. }
  1086. }
  1087. },
  1088. methods: {
  1089. getSetting() {
  1090. $A.apiAjax({
  1091. url: 'system/setting',
  1092. error: () => {
  1093. $A.storage("systemSetting", {});
  1094. },
  1095. success: (res) => {
  1096. if (res.ret === 1) {
  1097. this.systemConfig = res.data;
  1098. this.systemConfig.callav = this.systemConfig.callav || 'open';
  1099. $A.storage("systemSetting", this.systemConfig);
  1100. } else {
  1101. $A.storage("systemSetting", {});
  1102. }
  1103. }
  1104. });
  1105. },
  1106. formatCDate(v) {
  1107. let string = '';
  1108. if ($A.runNum(v) > 0) {
  1109. if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
  1110. string = $A.formatDate('H:i', v)
  1111. } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
  1112. string = $A.formatDate('m-d', v)
  1113. } else {
  1114. string = $A.formatDate('Y-m-d', v)
  1115. }
  1116. }
  1117. return string || '';
  1118. },
  1119. getDialogLists() {
  1120. if (!this.openAlready) {
  1121. return;
  1122. }
  1123. this.loadIng++;
  1124. this.dialogNoDataText = this.$L("数据加载中.....");
  1125. $A.apiAjax({
  1126. url: 'chat/dialog/lists',
  1127. complete: () => {
  1128. this.loadIng--;
  1129. },
  1130. error: () => {
  1131. this.dialogNoDataText = this.$L("数据加载失败!");
  1132. },
  1133. success: (res) => {
  1134. if (res.ret === 1) {
  1135. this.dialogLists = res.data;
  1136. this.dialogNoDataText = this.$L("没有相关的数据");
  1137. } else {
  1138. this.dialogLists = [];
  1139. this.dialogNoDataText = res.msg
  1140. }
  1141. }
  1142. });
  1143. },
  1144. getDialogMessage(isNextPage = false) {
  1145. let username = this.dialogTarget.username;
  1146. if (!username) {
  1147. return;
  1148. }
  1149. //
  1150. if (isNextPage === true) {
  1151. if (!this.messageHasMorePages) {
  1152. return;
  1153. }
  1154. this.messageCurrentPage+= 1;
  1155. } else {
  1156. this.messageCurrentPage = 1;
  1157. this.autoBottom = true;
  1158. this.messageNew = 0;
  1159. this.messageLists = [];
  1160. }
  1161. this.messageHasMorePages = false;
  1162. //
  1163. this.loadIng++;
  1164. this.messageNoDataText = this.$L("数据加载中.....");
  1165. $A.apiAjax({
  1166. url: 'chat/message/lists',
  1167. data: {
  1168. username: username,
  1169. page: this.messageCurrentPage,
  1170. pagesize: 30
  1171. },
  1172. complete: () => {
  1173. this.loadIng--;
  1174. },
  1175. error: () => {
  1176. this.messageNoDataText = this.$L("数据加载失败!");
  1177. },
  1178. success: (res) => {
  1179. if (username != this.dialogTarget.username) {
  1180. return;
  1181. }
  1182. if (res.ret === 1) {
  1183. let tempId = "notice_" + $A.randomString(6);
  1184. let tempLists = res.data.lists;
  1185. if (isNextPage) {
  1186. this.addMessageData({
  1187. id: tempId,
  1188. type: 'notice',
  1189. notice: this.$L('历史消息'),
  1190. }, false, isNextPage);
  1191. } else {
  1192. tempLists = tempLists.reverse();
  1193. }
  1194. tempLists.forEach((item) => {
  1195. this.addMessageData(Object.assign(item.message, {
  1196. id: item.id,
  1197. username: item.username,
  1198. userimg: item.userimg,
  1199. indate: item.indate,
  1200. }), false, isNextPage);
  1201. });
  1202. if (isNextPage) {
  1203. this.$nextTick(() => {
  1204. let tempObj = $A('div[data-id="' + tempId + '"]');
  1205. if (tempObj.length > 0) {
  1206. this.$refs.manageLists.scrollTo(tempObj.offset().top - tempObj.height() - 24, false);
  1207. }
  1208. });
  1209. }
  1210. this.messageNoDataText = '';
  1211. this.messageHasMorePages = res.data.hasMorePages;
  1212. } else {
  1213. this.messageNoDataText = res.msg
  1214. this.messageHasMorePages = false;
  1215. }
  1216. }
  1217. });
  1218. },
  1219. getTeamLists(isNextPage = false) {
  1220. if (isNextPage === true) {
  1221. if (!this.teamHasMorePages) {
  1222. return;
  1223. }
  1224. this.teamCurrentPage+= 1;
  1225. } else {
  1226. this.teamCurrentPage = 1;
  1227. }
  1228. this.teamHasMorePages = false;
  1229. //
  1230. this.loadIng++;
  1231. this.teamNoDataText = this.$L("数据加载中.....");
  1232. $A.apiAjax({
  1233. url: 'users/team/lists',
  1234. data: {
  1235. sorts: {
  1236. key: 'az',
  1237. order: 'asc'
  1238. },
  1239. page: this.teamCurrentPage,
  1240. pagesize: 100,
  1241. },
  1242. complete: () => {
  1243. this.loadIng--;
  1244. },
  1245. error: () => {
  1246. this.teamNoDataText = this.$L("数据加载失败!");
  1247. },
  1248. success: (res) => {
  1249. if (res.ret === 1) {
  1250. res.data.lists.forEach((item) => {
  1251. if (typeof this.teamLists[item.az] === "undefined") {
  1252. this.$set(this.teamLists, item.az, []);
  1253. }
  1254. this.teamLists[item.az].push(item);
  1255. });
  1256. this.teamNoDataText = this.$L("没有相关的数据");
  1257. this.teamHasMorePages = res.data.hasMorePages;
  1258. //
  1259. if (this.teamHasMorePages && res.data.currentPage < 5) {
  1260. this.getTeamLists(true);
  1261. }
  1262. } else {
  1263. this.teamLists = {};
  1264. this.teamNoDataText = res.msg
  1265. this.teamHasMorePages = false;
  1266. }
  1267. }
  1268. });
  1269. },
  1270. addDialog(data) {
  1271. if (!data.username) {
  1272. return;
  1273. }
  1274. let lists = this.dialogLists.filter((item) => {return item.username == data.username});
  1275. let unread = 0;
  1276. if (lists.length > 0) {
  1277. if (typeof data.userimg === "undefined") {
  1278. data.userimg = lists[0].userimg;
  1279. }
  1280. unread = $A.runNum(lists[0].unread);
  1281. this.dialogLists = this.dialogLists.filter((item) => {return item.username != data.username});
  1282. }
  1283. if (typeof data.unread === "undefined") {
  1284. data.unread = unread;
  1285. }
  1286. this.dialogLists.unshift(data);
  1287. },
  1288. openDialog(user, autoAddDialog = false) {
  1289. if (autoAddDialog === true) {
  1290. let lists = this.dialogLists.filter((item) => {return item.username == user.username});
  1291. if (lists.length === 0) {
  1292. this.addDialog(user);
  1293. }
  1294. }
  1295. this.chatTap = 'dialog';
  1296. this.chatTam = '';
  1297. this.dialogTarget = user;
  1298. if (typeof user.unread === "number" && user.unread > 0) {
  1299. this.unreadTotal -= user.unread;
  1300. this.$set(user, 'unread', 0);
  1301. $A.WSOB.sendTo('read', user.username);
  1302. }
  1303. if (autoAddDialog === true) {
  1304. //自动滚到焦点
  1305. this.$nextTick(() => {
  1306. let dialogObj = $A(this.$refs.dialogLists);
  1307. let activeObj = dialogObj.find("li.active");
  1308. if (activeObj.length > 0) {
  1309. let offsetTop = activeObj.offset().top;
  1310. if (offsetTop < 0) {
  1311. dialogObj.stop().scrollTop(activeObj[0].offsetTop)
  1312. } else if (offsetTop > dialogObj.height()) {
  1313. dialogObj.stop().scrollTop(activeObj[0].offsetTop + activeObj.height() - dialogObj.height())
  1314. }
  1315. }
  1316. });
  1317. }
  1318. },
  1319. clickDialog(username, autoPush = false) {
  1320. let lists = this.dialogLists.filter((item) => {return item.username == username});
  1321. if (lists.length > 0) {
  1322. this.openDialog(lists[0]);
  1323. } else if (autoPush === true) {
  1324. $A.apiAjax({
  1325. url: 'users/team/lists',
  1326. data: {
  1327. username: username,
  1328. },
  1329. success: (res) => {
  1330. if (res.ret === 1 && $A.isPlainObject(res.data)) {
  1331. this.$nextTick(() => {
  1332. typeof this.dialogTarget.username === "undefined" && this.openDialog(res.data, true)
  1333. });
  1334. }
  1335. }
  1336. });
  1337. }
  1338. },
  1339. dialogDropdown(type) {
  1340. switch (type) {
  1341. case 'clear':
  1342. case 'delete':
  1343. this.$Modal.confirm({
  1344. title: this.$L('确认操作'),
  1345. content: type === 'delete' ? this.$L('你确定要删除此对话吗?') : this.$L('你确定要清除聊天记录吗?'),
  1346. loading: true,
  1347. onOk: () => {
  1348. let username = this.dialogTarget.username;
  1349. $A.apiAjax({
  1350. url: 'chat/dialog/clear',
  1351. data: {
  1352. username: username,
  1353. delete: type === 'delete' ? 1 : 0
  1354. },
  1355. error: () => {
  1356. this.$Modal.remove();
  1357. alert(this.$L('网络繁忙,请稍后再试!'));
  1358. },
  1359. success: (res) => {
  1360. this.$Modal.remove();
  1361. if (res.ret === 1) {
  1362. if (type === 'delete') {
  1363. this.dialogLists = this.dialogLists.filter((item) => {return item.username != username});
  1364. this.dialogTarget = {};
  1365. } else {
  1366. this.$set(this.dialogTarget, 'lasttext', '');
  1367. this.getDialogMessage();
  1368. }
  1369. }
  1370. setTimeout(() => {
  1371. if (res.ret === 1) {
  1372. this.$Message.success(res.msg);
  1373. } else {
  1374. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  1375. }
  1376. }, 350);
  1377. }
  1378. });
  1379. }
  1380. });
  1381. break;
  1382. }
  1383. },
  1384. messageListsScroll(res) {
  1385. if (res.directionreal === 'up') {
  1386. if (res.scrollE < 10) {
  1387. this.autoBottom = true;
  1388. }
  1389. } else if (res.directionreal === 'down') {
  1390. this.autoBottom = false;
  1391. }
  1392. },
  1393. messageBottomAuto() {
  1394. let randString = $A.randomString(8);
  1395. window.__messageBottomAuto = randString;
  1396. setTimeout(() => {
  1397. if (randString === window.__messageBottomAuto) {
  1398. window.__messageBottomAuto = null;
  1399. if (this.autoBottom) {
  1400. this.messageBottomGo();
  1401. }
  1402. this.messageBottomAuto();
  1403. }
  1404. }, 1000);
  1405. },
  1406. messageBottomGo(animation = false) {
  1407. this.$nextTick(() => {
  1408. this.messageNew = 0;
  1409. if (typeof this.$refs.manageLists !== "undefined") {
  1410. this.$refs.manageLists.scrollTo(this.$refs.manageBody.clientHeight, animation);
  1411. this.autoBottom = true;
  1412. }
  1413. });
  1414. },
  1415. messageInsertText(emoji) {
  1416. this.messageText+= emoji;
  1417. },
  1418. messageInsertFile(item) {
  1419. if (typeof item === 'object' && typeof item.url === "string") {
  1420. let data = {
  1421. type: ['jpg', 'jpeg', 'png', 'gif'].indexOf(item.ext) !== -1 ? 'image' : 'file',
  1422. filename: item.name,
  1423. filesize: item.size,
  1424. filethumb: item.thumb,
  1425. username: this.userInfo.username,
  1426. userimg: this.userInfo.userimg,
  1427. indate: Math.round(new Date().getTime() / 1000),
  1428. url: item.url,
  1429. width: $A.getObject(item, 'response.data.width'),
  1430. height: $A.getObject(item, 'response.data.height'),
  1431. replaceId: item.tempId,
  1432. };
  1433. $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
  1434. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1435. });
  1436. //
  1437. this.addDialog(Object.assign(this.dialogTarget, {
  1438. lasttext: this.$L(data.type == 'image' ? '[图片]' : '[文件]'),
  1439. lastdate: data.indate
  1440. }));
  1441. this.openDialog(this.dialogTarget);
  1442. this.addMessageData(data, true);
  1443. }
  1444. },
  1445. addMessageData(data, animation = false, isUnshift = false) {
  1446. data.self = data.username === this.userInfo.username;
  1447. let sikp = false;
  1448. if (data.id || data.replaceId) {
  1449. this.messageLists.some((item, index) => {
  1450. if (item.id == data.id || item.id == data.replaceId) {
  1451. data.nickname = data.nickname || item.nickname;
  1452. this.messageLists.splice(index, 1, data);
  1453. return sikp = true;
  1454. }
  1455. });
  1456. if (sikp) {
  1457. return;
  1458. }
  1459. }
  1460. if (isUnshift) {
  1461. this.messageLists.unshift(data);
  1462. } else {
  1463. this.messageLists.push(data);
  1464. if (this.autoBottom) {
  1465. this.messageBottomGo(animation);
  1466. } else {
  1467. this.messageNew++;
  1468. }
  1469. }
  1470. },
  1471. messageSend(e) {
  1472. if (e.keyCode == 13) {
  1473. if (e.shiftKey) {
  1474. return;
  1475. }
  1476. e.preventDefault();
  1477. this.messageSubmit();
  1478. }
  1479. },
  1480. messageDragOver(show) {
  1481. let random = (this.__dialogDragOver = $A.randomString(8));
  1482. if (!show) {
  1483. setTimeout(() => {
  1484. if (random === this.__dialogDragOver) {
  1485. this.dialogDragOver = show;
  1486. }
  1487. }, 150);
  1488. } else {
  1489. this.dialogDragOver = show;
  1490. }
  1491. },
  1492. messagePasteDrag(e, type) {
  1493. this.dialogDragOver = false;
  1494. const files = type === 'drag' ? e.dataTransfer.files : e.clipboardData.files;
  1495. const postFiles = Array.prototype.slice.call(files);
  1496. if (postFiles.length > 0) {
  1497. e.preventDefault();
  1498. postFiles.forEach((file) => {
  1499. this.$refs.messageUpload.upload(file);
  1500. });
  1501. }
  1502. },
  1503. messageFile(type, file) {
  1504. switch (type) {
  1505. case 'progress':
  1506. this.addMessageData({
  1507. id: file.tempId,
  1508. type: 'image',
  1509. username: this.userInfo.username,
  1510. userimg: this.userInfo.userimg,
  1511. indate: Math.round(new Date().getTime() / 1000),
  1512. url: 'loading',
  1513. }, true);
  1514. break;
  1515. case 'error':
  1516. this.messageLists.some((item, index) => {
  1517. if (item.id == file.tempId) {
  1518. this.messageLists.splice(index, 1);
  1519. return true;
  1520. }
  1521. });
  1522. break;
  1523. case 'success':
  1524. this.messageInsertFile(file);
  1525. break;
  1526. }
  1527. },
  1528. messageSubmit() {
  1529. let dialogUser = this.dialogLists.filter((item) => { return item.username == this.dialogTarget.username });
  1530. if (dialogUser.length > 0) {
  1531. let user = dialogUser[0];
  1532. if (typeof user.unread === "number" && user.unread > 0) {
  1533. this.unreadTotal -= user.unread;
  1534. this.$set(user, 'unread', 0);
  1535. $A.WSOB.sendTo('read', user.username);
  1536. }
  1537. }
  1538. //
  1539. this.autoBottom = true;
  1540. let text = this.messageText.trim();
  1541. if ($A.count(text) > 0) {
  1542. let data = {
  1543. type: 'text',
  1544. username: this.userInfo.username,
  1545. userimg: this.userInfo.userimg,
  1546. indate: Math.round(new Date().getTime() / 1000),
  1547. text: text
  1548. };
  1549. $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
  1550. this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
  1551. });
  1552. //
  1553. this.addDialog(Object.assign(this.dialogTarget, {
  1554. lasttext: text,
  1555. lastdate: data.indate
  1556. }));
  1557. this.openDialog(this.dialogTarget);
  1558. this.addMessageData(data, true);
  1559. }
  1560. this.$nextTick(() => {
  1561. this.messageText = "";
  1562. });
  1563. },
  1564. userViewResult(user, data) {
  1565. this.$set(user, 'nickname', data.nickname);
  1566. this.$set(user, 'userimg', data.userimg);
  1567. },
  1568. videoConnect(username, videoChat) {
  1569. if (!$A.leftExists(window.location.protocol, "https")) {
  1570. this.$Modal.warning({title: this.$L('温馨提示'), content: this.$L('浏览器阻止音视频访问不是https的网站,所以尝试安装SSL!')});
  1571. return;
  1572. }
  1573. this.videoChat = videoChat;
  1574. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  1575. try {
  1576. navigator.mediaDevices.getUserMedia({
  1577. audio: true,
  1578. video: this.videoChat
  1579. }).then((stream) => {
  1580. this.videoLocalStream = stream;
  1581. this.$refs.localVideo.srcObject = stream;
  1582. this.$refs.localVideo.removeEventListener('loadedmetadata', this.videoListener);
  1583. //
  1584. if (username === null) {
  1585. // 发起者
  1586. this.videoUserName = this.dialogTarget.username;
  1587. this.videoUserImg = this.dialogTarget.userimg;
  1588. this.videoStartTime = 0;
  1589. this.videoInitiator = true;
  1590. this.$refs.localVideo.addEventListener('loadedmetadata', this.videoListener);
  1591. } else {
  1592. // 接受者
  1593. this.videoIcecandidate(this.videoLocalStream, username);
  1594. this.videoRtc.createOffer({
  1595. offerToReceiveAudio: true,
  1596. offerToReceiveVideo: this.videoChat
  1597. }).then((desc) => {
  1598. this.videoRtc.setLocalDescription(desc).then(() => {
  1599. $A.WSOB.sendTo('info', username, {
  1600. 'type': 'video',
  1601. 'subtype': 'offer',
  1602. 'data': this.videoRtc.localDescription
  1603. });
  1604. }).catch((e) => {
  1605. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1606. this.videoClose(username, this.$L('对方:') + e);
  1607. });
  1608. }).catch((e) => {
  1609. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1610. this.videoClose(username, this.$L('对方:') + e);
  1611. });
  1612. }
  1613. }).catch((e) => {
  1614. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1615. username && this.videoClose(username, this.$L('对方:') + e);
  1616. });
  1617. } catch (e) {
  1618. this.$Modal.warning({title: this.$L('温馨提示'), content: this.$L('当前浏览器不支持音视频通话!')});
  1619. username && this.videoClose(username, this.$L('对方:') + this.$L('浏览器不支持音视频通话!'));
  1620. }
  1621. },
  1622. videoListener() {
  1623. $A.WSOB.sendTo('info', this.videoUserName, {
  1624. 'type': 'video',
  1625. 'subtype': 'call',
  1626. 'username': this.userInfo.username,
  1627. 'userimg': this.userInfo.userimg,
  1628. 'video': this.videoChat,
  1629. }, (res) => {
  1630. if (res.status !== 1) {
  1631. this.videoClose(this.videoUserName, this.$L('呼叫失败!'));
  1632. }
  1633. });
  1634. },
  1635. videoIcecandidate(localStream, username) {
  1636. this.videoRtc = new RTCPeerConnection({"iceServers":[{"urls":["turn:business.swoole.com:3478?transport=udp","turn:business.swoole.com:3478?transport=tcp"],"username":"ceshi","credential":"ceshi"}]});
  1637. this.videoRtc.onicecandidate = (event) => {
  1638. if (event.candidate) {
  1639. $A.WSOB.sendTo('info', username, {
  1640. 'type': 'video',
  1641. 'subtype': 'candidate',
  1642. 'data': event.candidate
  1643. });
  1644. }
  1645. };
  1646. try {
  1647. this.videoRtc.addStream(localStream);
  1648. } catch (e) {
  1649. let tracks = localStream.getTracks();
  1650. for (let i = 0; i < tracks.length; i++) {
  1651. this.videoRtc.addTrack(tracks[i], localStream);
  1652. }
  1653. }
  1654. this.videoRtc.onaddstream = (e) => {
  1655. this.$refs.remoteVideo.srcObject = e.stream;
  1656. };
  1657. },
  1658. videoClose(username, reason) {
  1659. if (username && reason !== false) {
  1660. $A.WSOB.sendTo('info', username, {
  1661. 'type': 'video',
  1662. 'subtype': 'close',
  1663. 'reason': reason,
  1664. });
  1665. }
  1666. if (this.videoInitiator) {
  1667. this.videoInitiator = false;
  1668. if (this.videoStartTime > 0) {
  1669. let second = Math.round(new Date().getTime() / 1000) - this.videoStartTime;
  1670. if (second >= 2) {
  1671. $A.WSOB.sendTo('user', this.videoUserName, {
  1672. type: this.videoChat ? 'video' : 'voice',
  1673. username: this.userInfo.username,
  1674. userimg: this.userInfo.userimg,
  1675. indate: Math.round(new Date().getTime() / 1000),
  1676. text: this.videoChat ? '视频通话' : '语音通话',
  1677. other: {
  1678. second: second
  1679. }
  1680. }, 'special');
  1681. }
  1682. }
  1683. }
  1684. if (username == this.videoUserName) {
  1685. this.videoUserName = '';
  1686. this.videoUserImg = '';
  1687. this.videoStartTime = 0;
  1688. if (this.videoLocalStream !== null) {
  1689. this.videoLocalStream.getTracks().forEach((track) => {
  1690. track.stop();
  1691. });
  1692. this.videoLocalStream = null;
  1693. }
  1694. this.$refs.localVideo.srcObject = null;
  1695. this.$refs.remoteVideo.srcObject = null;
  1696. }
  1697. },
  1698. videoMessage(msgDetail) {
  1699. let body = msgDetail.body;
  1700. let username = msgDetail.username;
  1701. if (['offer', 'candidate', 'answer'].indexOf(body.subtype) !== -1) {
  1702. if (!this.videoLocalStream) {
  1703. this.videoClose(username);
  1704. return;
  1705. }
  1706. }
  1707. //
  1708. switch (body.subtype) {
  1709. case 'call':
  1710. let callIng = true;
  1711. let callAudio = this.$refs.callAudio;
  1712. if (callAudio.getAttribute("data-listener") !== 'yes') {
  1713. callAudio.setAttribute("data-listener", "yes");
  1714. callAudio.addEventListener('ended', () => {
  1715. if (callIng) {
  1716. $A.WSOB.sendTo('info', username, {
  1717. 'type': 'video',
  1718. 'subtype': 'judge',
  1719. });
  1720. callAudio.play();
  1721. }
  1722. }, false);
  1723. }
  1724. callAudio.currentTime = 0;
  1725. callAudio.play();
  1726. //
  1727. this.$Notice.close('chat-call');
  1728. this.$Notice.open({
  1729. name: 'chat-call',
  1730. duration: 0,
  1731. onClose: () => {
  1732. callIng = false;
  1733. callAudio.pause();
  1734. this.videoClose(username, this.$L('对方:拒绝接听'));
  1735. },
  1736. render: h => {
  1737. return h('div', {
  1738. class: 'chat-notice-box',
  1739. }, [
  1740. h('UserImg', {class: 'chat-notice-userimg', props: {info: body}}),
  1741. h('div', {class: 'ivu-notice-with-desc'}, [
  1742. h('div', {class: 'ivu-notice-title'}, [
  1743. h('UserView', {props: {username: username}})
  1744. ]),
  1745. h('div', {class: 'ivu-notice-desc'}, this.$L(body.video ? "邀请视频通话..." : "邀请语音通话...")),
  1746. h('div', {class: 'chat-notice-btn-box'}, [
  1747. h('Button', {
  1748. props: {type: 'success', size: 'small'},
  1749. on: {
  1750. click: () => {
  1751. callIng = false;
  1752. callAudio.pause();
  1753. this.$Notice.close('chat-call');
  1754. this.$emit("on-open-notice", username);
  1755. this.clickDialog(username);
  1756. this.videoConnect(username, body.video);
  1757. this.videoUserName = username;
  1758. this.videoUserImg = body.userimg;
  1759. this.videoStartTime = 0;
  1760. this.videoInitiator = false;
  1761. }
  1762. }
  1763. }, this.$L("接受")),
  1764. h('Button', {
  1765. props: {type: 'error', size: 'small'},
  1766. on: {
  1767. click: () => {
  1768. callIng = false;
  1769. callAudio.pause();
  1770. this.$Notice.close('chat-call');
  1771. this.videoClose(username, this.$L('对方:拒绝接听'));
  1772. }
  1773. }
  1774. }, this.$L("拒绝")),
  1775. ])
  1776. ])
  1777. ])
  1778. }
  1779. });
  1780. break;
  1781. case 'judge':
  1782. if (username != this.videoUserName) {
  1783. $A.WSOB.sendTo('info', username, {
  1784. 'type': 'video',
  1785. 'subtype': 'close',
  1786. });
  1787. }
  1788. break;
  1789. case 'close':
  1790. this.$refs.callAudio.pause();
  1791. this.$Notice.close('chat-call');
  1792. this.videoClose(username, false);
  1793. body.reason && this.$Message.warning(body.reason);
  1794. break;
  1795. case 'offer':
  1796. this.videoIcecandidate(this.videoLocalStream, username);
  1797. this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
  1798. if (this.videoStartTime === 0) {
  1799. this.videoRtc.createAnswer().then((desc) => {
  1800. this.videoRtc.setLocalDescription(desc).then(() => {
  1801. $A.WSOB.sendTo('info', username, {
  1802. 'type': 'video',
  1803. 'subtype': 'answer',
  1804. 'data': this.videoRtc.localDescription
  1805. });
  1806. }).catch((e) => {
  1807. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1808. });
  1809. }).catch((e) => {
  1810. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1811. });
  1812. this.videoStartTime = Math.round(new Date().getTime() / 1000);
  1813. }
  1814. }).catch((e) => {
  1815. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1816. });
  1817. break;
  1818. case 'answer':
  1819. if (this.videoRtc) {
  1820. this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
  1821. }).catch((e) => {
  1822. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1823. });
  1824. }
  1825. break;
  1826. case 'candidate':
  1827. if (this.videoRtc) {
  1828. this.videoRtc.addIceCandidate(new RTCIceCandidate(body.data)).then(() => {
  1829. }).catch((e) => {
  1830. this.$Modal.warning({title: this.$L('温馨提示'), content: e});
  1831. });
  1832. }
  1833. break;
  1834. }
  1835. }
  1836. }
  1837. }
  1838. </script>