Index.vue 74 KB

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