Index.vue 77 KB

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