Index.vue 78 KB

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