Index.vue 78 KB

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