Index.vue 78 KB

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