Index.vue 71 KB

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