Index.vue 74 KB

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