1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804 |
- <template>
- <div class="chat-index">
- <!--左边选项-->
- <ul class="chat-menu">
- <li class="self">
- <UserImg :info="userInfo" class="avatar"/>
- </li>
- <li :class="{active:chatTap=='dialog'}" @click="[chatTap='dialog',chatTam='dialog']">
- <Icon type="md-text" />
- <em v-if="unreadTotal > 0" class="chat-num">{{unreadTotal > 99 ? '99+' : unreadTotal}}</em>
- </li>
- <li :class="{active:chatTap=='team'}" @click="[chatTap='team',chatTam='team']">
- <Icon type="md-person" />
- </li>
- </ul>
- <!--对话列表-->
- <ul class="chat-user" :class="{'chat-flex':chatTap=='dialog','chat-tam':chatTam=='dialog'}">
- <li class="sreach">
- <Input :placeholder="$L('搜索')" prefix="ios-search" v-model="dialogSearch"/>
- </li>
- <li ref="dialogLists" class="lists">
- <ul>
- <li v-for="(dialog, index) in dialogListsS"
- :key="index"
- :class="{active:dialog.username==dialogTarget.username}"
- :data-id="dialog.id"
- @click="openDialog(dialog)">
- <UserImg :info="dialog" class="avatar"/>
- <div class="user-msg-box">
- <div class="user-msg-title">
- <span><user-view :username="dialog.username" placement="right" @on-result="userViewResult(dialog, $event)"/></span>
- <em>{{formatCDate(dialog.lastdate)}}</em>
- </div>
- <div class="user-msg-text">{{dialog.lasttext}}</div>
- </div>
- <em v-if="dialog.unread > 0" class="user-msg-num">{{dialog.unread}}</em>
- </li>
- <li v-if="dialogNoDataText==$L('数据加载中.....')" class="chat-none"><w-loading/></li>
- <li v-else-if="dialogLists.length == 0" class="chat-none">{{dialogNoDataText}}</li>
- </ul>
- </li>
- </ul>
- <!--联系人列表-->
- <ul class="chat-team" :class="{'chat-flex':chatTap=='team','chat-tam':chatTam=='team'}">
- <li class="sreach">
- <Input :placeholder="$L('搜索')" prefix="ios-search" v-model="teamSearch"/>
- </li>
- <li class="lists">
- <ul>
- <li v-for="(lists, key) in teamLists">
- <div class="team-label">{{key}}</div>
- <ul>
- <li v-for="(item, index) in teamListsS(lists)" :key="index" @click="openDialog(item, true)">
- <UserImg :info="item" class="avatar"/>
- <div class="team-username">{{item.nickname||item.username}}</div>
- </li>
- </ul>
- </li>
- <li v-if="teamNoDataText==$L('数据加载中.....')" class="chat-none"><w-loading/></li>
- <li v-else-if="Object.keys(teamLists).length == 0" class="chat-none">{{teamNoDataText}}</li>
- <li v-if="teamHasMorePages" class="chat-more" @click="getTeamLists(true)">{{$L('加载更多...')}}</li>
- </ul>
- </li>
- </ul>
- <!--对话窗口-->
- <div class="chat-message" :style="{display:(chatTap=='dialog'&&dialogTarget.username)?'block':'none'}">
- <div class="manage-title">
- <user-view :username="dialogTarget.username"/>
- <Dropdown class="manage-title-right" placement="bottom-end" trigger="click" @on-click="dialogDropdown" transfer>
- <Icon type="ios-more"/>
- <DropdownMenu slot="list">
- <DropdownItem name="delete">{{$L('删除对话')}}</DropdownItem>
- <DropdownItem name="clear">{{$L('清除聊天记录')}}</DropdownItem>
- </DropdownMenu>
- </Dropdown>
- </div>
- <ScrollerY ref="manageLists" class="manage-lists" @on-scroll="messageListsScroll">
- <div ref="manageBody" class="manage-body">
- <div v-if="messageHasMorePages" class="manage-more" @click="getDialogMessage(true)">{{$L('加载更多...')}}</div>
- <div v-if="messageNoDataText==$L('数据加载中.....')" class="manage-more"><w-loading/></div>
- <div v-else-if="messageNoDataText" class="manage-more">{{messageNoDataText}}</div>
- <chat-message v-for="(info, index) in messageLists" :key="index" :info="info"></chat-message>
- </div>
- <div class="manage-lists-message-new" v-if="messageNew > 0" @click="messageBottomGo(true)">{{$L('有%条新消息', messageNew)}}</div>
- </ScrollerY>
- <div class="manage-send" @click="clickDialog(dialogTarget.username)">
- <textarea ref="textarea" class="manage-input" maxlength="20000" v-model="messageText" :placeholder="$L('请输入要发送的消息')" @keydown="messageSend($event)"></textarea>
- </div>
- <div class="manage-quick">
- <emoji-picker @emoji="messageInsertText" :search="messageEmojiSearch">
- <div slot="emoji-invoker" slot-scope="{ events: { click: clickEvent } }" @click.stop="clickEvent">
- <Tooltip :content="$L('表情')" placement="top">
- <Icon class="quick-item" type="ios-happy-outline" />
- </Tooltip>
- </div>
- <div slot="emoji-picker" slot-scope="{ emojis, insert, display }">
- <div class="emoji-box">
- <Input class="emoji-input" :placeholder="$L('搜索')" v-model="messageEmojiSearch" prefix="ios-search"/>
- <div>
- <div v-for="(emojiGroup, category) in emojis" :key="category">
- <h5>{{ category }}</h5>
- <div class="emojis">
- <span v-for="(emoji, emojiName) in emojiGroup" :key="emojiName" @click="insert(emoji)" :title="emojiName">{{ emoji }}</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </emoji-picker>
- <Tooltip :content="$L('图片')" placement="top">
- <Icon class="quick-item" type="ios-photos-outline" @click="$refs.messageUpload.handleClick()"/>
- <img-upload ref="messageUpload" class="message-upload" type="callback" @on-callback="messageInsertImage" num="3" :otherParams="{from:'chat'}"></img-upload>
- </Tooltip>
- <template v-if="systemConfig.callav=='open'">
- <Tooltip :content="$L('语音聊天')" placement="top">
- <Icon class="quick-item voicecam" type="ios-call-outline" @click="videoConnect(null, false)"/>
- </Tooltip>
- <Tooltip :content="$L('视频聊天')" placement="top">
- <Icon class="quick-item videocam" type="ios-videocam-outline" @click="videoConnect(null, true)"/>
- </Tooltip>
- </template>
- </div>
- </div>
- <!--语音、视频通话-->
- <div class="chat-video" :style="{display:(videoUserName)?'block':'none',backgroundImage:'url(' + videoUserImg +')'}">
- <div v-if="videoChat" class="video-opacity">{{$L('正在视频通话...')}}</div>
- <div v-else class="video-opacity">{{$L('正在语音通话...')}}</div>
- <video ref="remoteVideo" class="video-active" autoplay></video>
- <video ref="localVideo" class="video-mini" autoplay muted="true"></video>
- <div class="video-close"><Icon type="ios-close-circle-outline" @click="videoClose(videoUserName)"/></div>
- </div>
- <!--提示音-->
- <audio class="chat-audio" ref="messageAudio" preload="none">
- <source :src="messageAudio + 'message.mp3'" type="audio/mpeg">
- <source :src="messageAudio + 'message.wav'" type="audio/wav">
- </audio>
- <audio class="chat-audio" ref="callAudio" preload="none">
- <source :src="messageAudio + 'call.mp3'" type="audio/mpeg">
- <source :src="messageAudio + 'call.wav'" type="audio/wav">
- </audio>
- </div>
- </template>
- <style lang="scss">
- .chat-notice-box {
- display: flex;
- align-items: flex-start;
- cursor: pointer;
- .chat-notice-userimg {
- width: 42px;
- height: 42px;
- font-size: 20px;
- line-height: 42px;
- border-radius: 4px;
- }
- .ivu-notice-with-desc {
- flex: 1;
- padding: 0 12px;
- }
- .chat-notice-btn-box {
- margin-top: 8px;
- margin-bottom: -4px;
- .ivu-btn {
- margin-right: 12px;
- font-size: 12px;
- min-width: 42px;
- }
- }
- .ivu-notice-desc {
- font-size: 13px;
- word-break: break-all;
- line-height: 1.3;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- overflow: hidden;
- -webkit-box-orient: vertical;
- }
- }
- </style>
- <style lang="scss" scoped>
- .chat-index {
- display: flex;
- flex-direction: row;
- align-items: flex-start;
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .chat-none {
- height: auto;
- color: #666666;
- padding: 22px 8px;
- text-align: center;
- justify-content: center;
- margin: 0 !important;
- &:before {
- display: none;
- }
- }
- .chat-more {
- color: #666666;
- padding: 18px 0;
- text-align: center;
- cursor: pointer;
- margin: 0 !important;
- &:hover {
- color: #444444;
- }
- }
- .chat-menu {
- background-color: rgba(28, 29, 31, 0.92);
- width: 68px;
- height: 100%;
- padding-top: 20px;
- li {
- position: relative;
- padding: 12px 0;
- text-align: center;
- font-size: 28px;
- color: #919193;
- background-color: transparent;
- cursor: pointer;
- &.self {
- cursor: default;
- .avatar {
- width: 36px;
- height: 36px;
- font-size: 20px;
- border-radius: 3px;
- }
- }
- &.active {
- color: #ffffff;
- background-color: rgba(255, 255, 255, 0.06);
- }
- &:hover {
- > i {
- transform: scale(1.1);
- }
- }
- > i {
- transition: all 0.2s;
- }
- .chat-num {
- position: absolute;
- top: 50%;
- left: 50%;
- height: auto;
- line-height: normal;
- color: #ffffff;
- background-color: #ff0000;
- text-align: center;
- border-radius: 10px;
- padding: 1px 5px;
- font-size: 12px;
- transform: scale(0.9) translate(5px, -20px);
- }
- }
- }
- .chat-user {
- display: none;
- flex-direction: column;
- width: 248px;
- height: 100%;
- background-color: #ffffff;
- border-right: 1px solid #ededed;
- > li {
- position: relative;
- &.sreach {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 62px;
- margin: 0;
- padding: 0 12px;
- position: relative;
- cursor: pointer;
- &:before {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- height: 1px;
- background-color: rgba(0, 0, 0, 0.06);
- }
- }
- &.lists {
- flex: 1;
- overflow: auto;
- transform: translateZ(0);
- > ul {
- > li {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 70px;
- padding: 0 12px;
- position: relative;
- cursor: pointer;
- &:before {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- height: 1px;
- background-color: rgba(0, 0, 0, 0.06);
- }
- &.active {
- &:before {
- top: 0;
- height: 100%;
- }
- }
- .avatar {
- width: 42px;
- height: 42px;
- font-size: 20px;
- border-radius: 4px;
- }
- .user-msg-box {
- flex: 1;
- display: flex;
- flex-direction: column;
- padding-left: 12px;
- .user-msg-title {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- line-height: 24px;
- span {
- flex: 1;
- max-width: 130px;
- color: #333333;
- font-size: 14px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- em {
- color: #999999;
- font-size: 12px;
- }
- }
- .user-msg-text {
- max-width: 170px;
- color: #999999;
- font-size: 12px;
- line-height: 24px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- }
- }
- }
- }
- .user-msg-num {
- position: absolute;
- top: 6px;
- left: 44px;
- height: auto;
- line-height: normal;
- color: #ffffff;
- background-color: #ff0000;
- text-align: center;
- border-radius: 10px;
- padding: 1px 5px;
- font-size: 12px;
- transform: scale(0.9);
- border: 1px solid #ffffff;
- }
- }
- }
- .chat-team {
- display: none;
- flex-direction: column;
- width: 248px;
- height: 100%;
- background-color: #ffffff;
- border-right: 1px solid #ededed;
- > li {
- position: relative;
- &.sreach {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 62px;
- margin: 0;
- padding: 0 12px;
- position: relative;
- cursor: pointer;
- &:before {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- height: 1px;
- background-color: rgba(0, 0, 0, 0.06);
- }
- }
- &.lists {
- flex: 1;
- overflow: auto;
- transform: translateZ(0);
- > ul {
- > li {
- margin-left: 24px;
- position: relative;
- .team-label {
- padding-left: 4px;
- margin-top: 6px;
- margin-bottom: 6px;
- height: 34px;
- line-height: 34px;
- border-bottom: 1px solid #efefef;
- }
- > ul {
- > li {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 52px;
- cursor: pointer;
- .avatar {
- width: 30px;
- height: 30px;
- font-size: 16px;
- border-radius: 3px;
- }
- .team-username {
- padding: 0 12px;
- font-size: 14px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- }
- }
- }
- }
- }
- }
- }
- .chat-message {
- flex: 1;
- height: 100%;
- background-color: #F3F3F3;
- position: relative;
- .manage-title {
- position: absolute;
- top: 0;
- left: 0;
- z-index: 3;
- width: 100%;
- height: 62px;
- padding: 0 20px;
- line-height: 62px;
- font-size: 16px;
- font-weight: 500;
- text-align: left;
- background: #ffffff;
- border-bottom: 1px solid #ededed;
- .manage-title-right {
- position: absolute;
- top: 0;
- right: 0;
- z-index: 9;
- width: 62px;
- height: 62px;
- line-height: 62px;
- text-align: center;
- font-size: 22px;
- color: #242424;
- }
- }
- .manage-lists {
- position: absolute;
- left: 0;
- top: 62px;
- z-index: 1;
- bottom: 120px;
- width: 100%;
- overflow: auto;
- padding: 8px 0;
- background-color: #E8EBF2;
- .manage-more {
- color: #666666;
- padding: 8px 0;
- text-align: center;
- cursor: pointer;
- &:hover {
- color: #444444;
- }
- }
- .manage-lists-message-new {
- position: fixed;
- bottom: 130px;
- right: 20px;
- color: #ffffff;
- background-color: rgba(0, 0, 0, 0.6);
- padding: 6px 12px;
- border-radius: 16px;
- font-size: 12px;
- cursor: pointer;
- }
- }
- .manage-send {
- position: absolute;
- left: 0;
- bottom: 0;
- z-index: 2;
- display: flex;
- width: 100%;
- height: 120px;
- background-color: #ffffff;
- border-top: 1px solid #e4e4e4;
- .manage-input,.manage-input:focus {
- flex: 1;
- -webkit-appearance: none;
- font-size: 14px;
- box-sizing: border-box;
- padding: 0;
- margin: 38px 10px 6px;
- border: 0;
- line-height: 20px;
- box-shadow: none;
- resize:none;
- outline: 0;
- }
- .manage-join,
- .manage-spin {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: #ffffff;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- }
- .manage-quick {
- position: absolute;
- z-index: 2;
- left: 0;
- right: 0;
- bottom: 79px;
- padding: 8px 0;
- display: flex;
- align-items: center;
- .quick-item {
- color: #444444;
- font-size: 24px;
- margin: 0 7px;
- &.voicecam {
- font-size: 26px;
- height: 24px;
- line-height: 24px;
- }
- &.videocam {
- color: #666666;
- font-size: 30px;
- height: 24px;
- line-height: 24px;
- }
- }
- .emoji-box {
- position: absolute;
- left: 0;
- bottom: 40px;
- max-height: 320px;
- width: 100%;
- overflow: auto;
- background-color: #ffffff;
- padding: 12px;
- border-bottom: 1px solid #efefef;
- .emoji-input {
- margin: 6px 0;
- }
- h5 {
- padding: 0;
- margin: 8px 0 0 0;
- color: #b1b1b1;
- text-transform: uppercase;
- font-size: 14px;
- cursor: default;
- font-weight: normal;
- }
- .emojis {
- display: flex;
- flex-wrap: wrap;
- justify-content: space-between;
- &:after {
- content: "";
- flex: auto;
- }
- span {
- padding: 2px 4px;
- cursor: pointer;
- font-size: 22px;
- &:hover {
- background: #ececec;
- cursor: pointer;
- }
- }
- }
- }
- .message-upload {
- display: none;
- width: 0;
- height: 0;
- overflow: hidden;
- }
- }
- @media screen and (max-width: 768px) {
- .manage-lists {
- bottom: 96px;
- .manage-lists-message-new {
- bottom: 106px;
- }
- }
- .manage-send {
- height: 96px;
- }
- .manage-quick {
- bottom: 54px;
- .quick-item {
- font-size: 24px;
- margin-right: 8px;
- }
- }
- }
- }
- .chat-video {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background-color: #000000;
- background-size: cover;
- background-position: center center;
- background-repeat: no-repeat;
- z-index: 9;
- &:before {
- content: "";
- position: absolute;
- left: -10%;
- right: -10%;
- top: -10%;
- bottom: -10%;
- background: inherit;
- filter: blur(25px);
- z-index: 1;
- }
- &:after {
- content: "";
- position: absolute;
- left: -10%;
- right: -10%;
- top: -10%;
- bottom: -10%;
- background: rgba(0, 0, 0, 0.82);
- z-index: 2;
- }
- .video-opacity {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- font-size: 26px;
- color: #aaaaaa;
- padding: 24px;
- z-index: 3;
- animation:opacity 2s infinite alternate ;
- @keyframes opacity {
- 0% {
- opacity: 0.1;
- }
- 100% {
- opacity: 1;
- }
- }
- }
- .video-mini,
- .video-active {
- position: absolute;
- max-width: 640px;
- max-height: 100%;
- object-fit: cover;
- transition: opacity 1s;
- }
- .video-active {
- top: 0;
- left: 50%;
- width: 100%;
- height: 100%;
- transform: rotateY(180deg) translateX(50%);
- z-index: 4;
- }
- .video-mini {
- top: 0;
- right: 0;
- width: 260px;
- height: 180px;
- transform: scale(-1, 1);
- z-index: 5;
- }
- .video-close {
- position: absolute;
- max-width: 720px;
- bottom: 18px;
- left: 50%;
- width: 100%;
- transform: translateX(-50%);
- display: flex;
- align-items: center;
- justify-content: center;
- z-index: 6;
- > i {
- font-weight: 600;
- font-size: 46px;
- color: #ffffff;
- cursor: pointer;
- &:hover {
- color: #ff0000;
- }
- }
- }
- }
- .chat-audio {
- width: 0;
- height: 0;
- display: none;
- }
- .chat-flex {
- display: flex;
- }
- @media (max-width: 768px) {
- .chat-menu {
- width: 50px;
- li {
- padding: 6px 0;
- margin: 6px 0;
- font-size: 24px;
- &.self {
- .avatar {
- width: 32px;
- height: 32px;
- font-size: 18px;
- }
- }
- }
- }
- .chat-user,
- .chat-team {
- display: none;
- position: absolute;
- left: 50px;
- right: 0;
- z-index: 2;
- width: auto;
- > li {
- &.sreach {
- height: 54px;
- }
- }
- &.chat-tam {
- display: flex;
- }
- }
- .chat-message {
- .manage-title {
- height: 54px;
- line-height: 54px;
- .manage-title-right {
- width: 54px;
- height: 54px;
- line-height: 54px;
- }
- }
- .manage-lists {
- top: 54px;
- }
- }
- }
- }
- </style>
- <script>
- import EmojiPicker from 'vue-emoji-picker'
- import DrawerTabsContainer from "../DrawerTabsContainer";
- import ScrollerY from "../../../_components/ScrollerY";
- import ChatMessage from "./message";
- import ImgUpload from "../ImgUpload";
- export default {
- name: 'ChatIndex',
- components: {ImgUpload, ChatMessage, EmojiPicker, ScrollerY, DrawerTabsContainer},
- props: {
- value: {
- default: 0
- },
- openWindow: {
- type: Boolean,
- default: false
- },
- },
- data () {
- return {
- loadIng: 0,
- openAlready: false,
- userInfo: {},
- chatTap: 'dialog',
- chatTam: 'dialog',
- messageAudio: window.location.origin + '/audio/',
- dialogSearch: '',
- dialogTarget: {},
- dialogLists: [],
- dialogNoDataText: '',
- teamSearch: '',
- teamReady: false,
- teamLists: {},
- teamNoDataText: '',
- teamCurrentPage: 1,
- teamHasMorePages: false,
- autoBottom: true,
- messageNew: 0,
- messageText: '',
- messageLists: [],
- messageNoDataText: '',
- messageEmojiSearch: '',
- messageCurrentPage: 1,
- messageHasMorePages: false,
- unreadTotal: 0,
- videoUserName: '', //视频对话用户名
- videoUserImg: '', //视频对话用户头像
- videoStartTime: 0, //视频开始时间
- videoInitiator: false, //是否发起人
- videoChat: false, //是否视频通话(否则音频通话)
- videoRtc: null, //视频Rtc
- videoLocalStream: null, //视频流
- systemConfig: $A.jsonParse($A.storage("systemSetting"), {
- callav: '',
- }),
- }
- },
- created() {
- this.dialogNoDataText = this.$L("数据加载中.....");
- this.teamNoDataText = this.$L("数据加载中.....");
- this.messageNoDataText = this.$L("数据加载中.....");
- },
- mounted() {
- let resCall = () => {
- if ($A.getToken() === false) {
- return;
- }
- $A.WSOB.sendTo('unread', (res) => {
- if (res.status === 1) {
- this.unreadTotal = $A.runNum(res.message);
- } else {
- this.unreadTotal = 0;
- }
- });
- this.getDialogLists();
- this.messageBottomAuto();
- };
- this.userInfo = $A.getUserInfo((res, isLogin) => {
- if (this.userInfo.id != res.id) {
- this.userInfo = res;
- resCall();
- } else {
- this.userInfo = res;
- }
- }, false);
- resCall();
- this.getSetting();
- //
- window.onChatOpenUserName = (username) => {
- this.$emit("on-open-notice", username);
- this.clickDialog(username, true);
- }
- //
- if (this.openWindow) {
- $A.WSOB.connection();
- if (!this.openAlready) {
- this.openAlready = true;
- this.getDialogLists();
- }
- }
- //
- $A.WSOB.setOnMsgListener("chat/index", (msgDetail) => {
- if (msgDetail.username == $A.getUserName()) {
- return;
- }
- switch (msgDetail.messageType) {
- case 'open':
- if (this.openWindow) {
- this.getDialogLists();
- this.getDialogMessage();
- } else {
- this.openAlready = false;
- this.dialogTarget = {};
- }
- break;
- case 'info':
- if (msgDetail.body.type == 'video') {
- this.videoMessage(msgDetail)
- }
- break;
- case 'user':
- let body = msgDetail.body;
- if (['taskA'].indexOf(body.type) !== -1) {
- return;
- }
- let lasttext = $A.WSOB.getMsgDesc(body);
- this.unreadTotal += 1;
- this.addDialog({
- username: body.username,
- userimg: body.userimg,
- lasttext: lasttext,
- lastdate: body.indate,
- unread: body.unread
- });
- if (msgDetail.username == this.dialogTarget.username) {
- this.addMessageData(body, true);
- }
- if (!this.openWindow) {
- this.$Notice.close('chat-notice');
- this.$Notice.open({
- name: 'chat-notice',
- duration: 0,
- render: h => {
- return h('div', {
- class: 'chat-notice-box',
- on: {
- click: () => {
- this.$Notice.close('chat-notice');
- this.$emit("on-open-notice", body.username);
- this.clickDialog(body.username);
- }
- }
- }, [
- h('UserImg', {class: 'chat-notice-userimg', props: {info: body}}),
- h('div', {class: 'ivu-notice-with-desc'}, [
- h('div', {class: 'ivu-notice-title'}, [
- h('UserView', {props: {username: body.username}})
- ]),
- h('div', {class: 'ivu-notice-desc'}, lasttext)
- ])
- ])
- }
- });
- }
- try {
- this.$refs.messageAudio.play();
- } catch (e) {
- }
- break;
- }
- });
- $A.WSOB.setOnSpecialListener("chat/index", (simpleMsg) => {
- this.addDialog({
- username: simpleMsg.target,
- lasttext: $A.WSOB.getMsgDesc(simpleMsg.body),
- lastdate: simpleMsg.body.indate
- });
- if (simpleMsg.target == this.dialogTarget.username) {
- this.addMessageData(simpleMsg.body, true);
- }
- });
- },
- watch: {
- chatTap(val) {
- if (val === 'team' && this.teamReady == false) {
- this.teamReady = true;
- this.getTeamLists();
- } else if (val === 'dialog') {
- this.autoBottom = true;
- this.$nextTick(() => {
- this.messageBottomGo();
- });
- }
- },
- openWindow(val) {
- if (val) {
- $A.WSOB.connection();
- if (!this.openAlready) {
- this.openAlready = true;
- this.getDialogLists();
- }
- }
- //
- let tmpRand = $A.randomString(8);
- this.__openWindowRand = tmpRand;
- setTimeout(() => {
- if (this.__openWindowRand !== tmpRand) {
- return;
- }
- $A.WSOB.sendTo('unread', (res) => {
- if (res.status === 1) {
- this.unreadTotal = $A.runNum(res.message);
- } else {
- this.unreadTotal = 0;
- }
- });
- }, 500);
- },
- unreadTotal(val) {
- if (val < 0) {
- this.unreadTotal = 0;
- return;
- }
- this.$emit('input', val);
- },
- dialogTarget: {
- handler: function () {
- let username = this.dialogTarget.username;
- if (username === this.__dialogTargetUsername) {
- return;
- }
- this.__dialogTargetUsername = username;
- this.getDialogMessage();
- },
- deep: true
- }
- },
- computed: {
- dialogListsS() {
- return this.dialogLists.filter(item => {
- return (item.username + "").indexOf(this.dialogSearch) > -1 || (item.lasttext + "").indexOf(this.dialogSearch) > -1 || (item.nickname + "").indexOf(this.dialogSearch) > -1
- });
- },
- teamListsS() {
- return function (lists) {
- return lists.filter(item => {
- return (item.username + "").indexOf(this.teamSearch) > -1 || (item.nickname + "").indexOf(this.teamSearch) > -1
- });
- }
- }
- },
- methods: {
- getSetting() {
- $A.apiAjax({
- url: 'system/setting',
- error: () => {
- $A.storage("systemSetting", {});
- },
- success: (res) => {
- if (res.ret === 1) {
- this.systemConfig = res.data;
- this.systemConfig.callav = this.systemConfig.callav || 'open';
- $A.storage("systemSetting", this.systemConfig);
- } else {
- $A.storage("systemSetting", {});
- }
- }
- });
- },
- formatCDate(v) {
- let string = '';
- if ($A.runNum(v) > 0) {
- if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
- string = $A.formatDate('H:i', v)
- } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
- string = $A.formatDate('m-d', v)
- } else {
- string = $A.formatDate('Y-m-d', v)
- }
- }
- return string || '';
- },
- getDialogLists() {
- if (!this.openAlready) {
- return;
- }
- this.loadIng++;
- this.dialogNoDataText = this.$L("数据加载中.....");
- $A.apiAjax({
- url: 'chat/dialog/lists',
- complete: () => {
- this.loadIng--;
- },
- error: () => {
- this.dialogNoDataText = this.$L("数据加载失败!");
- },
- success: (res) => {
- if (res.ret === 1) {
- this.dialogLists = res.data;
- this.dialogNoDataText = this.$L("没有相关的数据");
- } else {
- this.dialogLists = [];
- this.dialogNoDataText = res.msg
- }
- }
- });
- },
- getDialogMessage(isNextPage = false) {
- let username = this.dialogTarget.username;
- if (!username) {
- return;
- }
- //
- if (isNextPage === true) {
- if (!this.messageHasMorePages) {
- return;
- }
- this.messageCurrentPage+= 1;
- } else {
- this.messageCurrentPage = 1;
- this.autoBottom = true;
- this.messageNew = 0;
- this.messageLists = [];
- }
- this.messageHasMorePages = false;
- //
- this.loadIng++;
- this.messageNoDataText = this.$L("数据加载中.....");
- $A.apiAjax({
- url: 'chat/message/lists',
- data: {
- username: username,
- page: this.messageCurrentPage,
- pagesize: 30
- },
- complete: () => {
- this.loadIng--;
- },
- error: () => {
- this.messageNoDataText = this.$L("数据加载失败!");
- },
- success: (res) => {
- if (username != this.dialogTarget.username) {
- return;
- }
- if (res.ret === 1) {
- let tempId = "notice_" + $A.randomString(6);
- let tempLists = res.data.lists;
- if (isNextPage) {
- this.addMessageData({
- id: tempId,
- type: 'notice',
- notice: this.$L('历史消息'),
- }, false, isNextPage);
- } else {
- tempLists = tempLists.reverse();
- }
- tempLists.forEach((item) => {
- this.addMessageData(Object.assign(item.message, {
- id: item.id,
- username: item.username,
- userimg: item.userimg,
- indate: item.indate,
- }), false, isNextPage);
- });
- if (isNextPage) {
- this.$nextTick(() => {
- let tempObj = $A('div[data-id="' + tempId + '"]');
- if (tempObj.length > 0) {
- this.$refs.manageLists.scrollTo(tempObj.offset().top - tempObj.height() - 24, false);
- }
- });
- }
- this.messageNoDataText = '';
- this.messageHasMorePages = res.data.hasMorePages;
- } else {
- this.messageNoDataText = res.msg
- this.messageHasMorePages = false;
- }
- }
- });
- },
- getTeamLists(isNextPage = false) {
- if (isNextPage === true) {
- if (!this.teamHasMorePages) {
- return;
- }
- this.teamCurrentPage+= 1;
- } else {
- this.teamCurrentPage = 1;
- }
- this.teamHasMorePages = false;
- //
- this.loadIng++;
- this.teamNoDataText = this.$L("数据加载中.....");
- $A.apiAjax({
- url: 'users/team/lists',
- data: {
- sorts: {
- key: 'lists',
- order: 'asc'
- },
- firstchart: 1,
- page: this.teamCurrentPage,
- pagesize: 100,
- },
- complete: () => {
- this.loadIng--;
- },
- error: () => {
- this.teamNoDataText = this.$L("数据加载失败!");
- },
- success: (res) => {
- if (res.ret === 1) {
- res.data.lists.forEach((item) => {
- if (typeof this.teamLists[item.firstchart] === "undefined") {
- this.$set(this.teamLists, item.firstchart, []);
- }
- this.teamLists[item.firstchart].push(item);
- });
- this.teamNoDataText = this.$L("没有相关的数据");
- this.teamHasMorePages = res.data.hasMorePages;
- //
- if (this.teamHasMorePages && res.data.currentPage < 5) {
- this.getTeamLists(true);
- }
- } else {
- this.teamLists = {};
- this.teamNoDataText = res.msg
- this.teamHasMorePages = false;
- }
- }
- });
- },
- addDialog(data) {
- if (!data.username) {
- return;
- }
- let lists = this.dialogLists.filter((item) => {return item.username == data.username});
- let unread = 0;
- if (lists.length > 0) {
- if (typeof data.userimg === "undefined") {
- data.userimg = lists[0].userimg;
- }
- unread = $A.runNum(lists[0].unread);
- this.dialogLists = this.dialogLists.filter((item) => {return item.username != data.username});
- }
- if (typeof data.unread === "undefined") {
- data.unread = unread;
- }
- this.dialogLists.unshift(data);
- },
- openDialog(user, autoAddDialog = false) {
- if (autoAddDialog === true) {
- let lists = this.dialogLists.filter((item) => {return item.username == user.username});
- if (lists.length === 0) {
- this.addDialog(user);
- }
- }
- this.chatTap = 'dialog';
- this.chatTam = '';
- this.dialogTarget = user;
- if (typeof user.unread === "number" && user.unread > 0) {
- this.unreadTotal -= user.unread;
- this.$set(user, 'unread', 0);
- $A.WSOB.sendTo('read', user.username);
- }
- if (autoAddDialog === true) {
- //自动滚到焦点
- this.$nextTick(() => {
- let dialogObj = $A(this.$refs.dialogLists);
- let activeObj = dialogObj.find("li.active");
- if (activeObj.length > 0) {
- let offsetTop = activeObj.offset().top;
- if (offsetTop < 0) {
- dialogObj.stop().scrollTop(activeObj[0].offsetTop)
- } else if (offsetTop > dialogObj.height()) {
- dialogObj.stop().scrollTop(activeObj[0].offsetTop + activeObj.height() - dialogObj.height())
- }
- }
- });
- }
- },
- clickDialog(username, autoPush = false) {
- let lists = this.dialogLists.filter((item) => {return item.username == username});
- if (lists.length > 0) {
- this.openDialog(lists[0]);
- } else if (autoPush === true) {
- $A.apiAjax({
- url: 'users/team/lists',
- data: {
- username: username,
- },
- success: (res) => {
- if (res.ret === 1 && $A.isPlainObject(res.data)) {
- this.$nextTick(() => {
- typeof this.dialogTarget.username === "undefined" && this.openDialog(res.data, true)
- });
- }
- }
- });
- }
- },
- dialogDropdown(type) {
- switch (type) {
- case 'clear':
- case 'delete':
- this.$Modal.confirm({
- title: this.$L('确认操作'),
- content: type === 'delete' ? this.$L('你确定要删除此对话吗?') : this.$L('你确定要清除聊天记录吗?'),
- loading: true,
- onOk: () => {
- let username = this.dialogTarget.username;
- $A.apiAjax({
- url: 'chat/dialog/clear',
- data: {
- username: username,
- delete: type === 'delete' ? 1 : 0
- },
- error: () => {
- this.$Modal.remove();
- alert(this.$L('网络繁忙,请稍后再试!'));
- },
- success: (res) => {
- this.$Modal.remove();
- if (res.ret === 1) {
- if (type === 'delete') {
- this.dialogLists = this.dialogLists.filter((item) => {return item.username != username});
- this.dialogTarget = {};
- } else {
- this.$set(this.dialogTarget, 'lasttext', '');
- this.getDialogMessage();
- }
- }
- setTimeout(() => {
- if (res.ret === 1) {
- this.$Message.success(res.msg);
- } else {
- this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
- }
- }, 350);
- }
- });
- }
- });
- break;
- }
- },
- messageListsScroll(res) {
- if (res.directionreal === 'up') {
- if (res.scrollE < 10) {
- this.autoBottom = true;
- }
- } else if (res.directionreal === 'down') {
- this.autoBottom = false;
- }
- },
- messageBottomAuto() {
- let randString = $A.randomString(8);
- window.__messageBottomAuto = randString;
- setTimeout(() => {
- if (randString === window.__messageBottomAuto) {
- window.__messageBottomAuto = null;
- if (this.autoBottom) {
- this.messageBottomGo();
- }
- this.messageBottomAuto();
- }
- }, 1000);
- },
- messageBottomGo(animation = false) {
- this.$nextTick(() => {
- this.messageNew = 0;
- if (typeof this.$refs.manageLists !== "undefined") {
- this.$refs.manageLists.scrollTo(this.$refs.manageBody.clientHeight, animation);
- this.autoBottom = true;
- }
- });
- },
- messageInsertText(emoji) {
- this.messageText+= emoji;
- },
- messageInsertImage(lists) {
- for (let i = 0; i < lists.length; i++) {
- let item = lists[i];
- if (typeof item === 'object' && typeof item.url === "string") {
- let data = {
- type: 'image',
- username: this.userInfo.username,
- userimg: this.userInfo.userimg,
- indate: Math.round(new Date().getTime() / 1000),
- url: item.url,
- width: $A.getObject(item, 'response.data.width'),
- height: $A.getObject(item, 'response.data.height'),
- };
- $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
- this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
- });
- //
- this.addDialog(Object.assign(this.dialogTarget, {
- lasttext: this.$L('[图片]'),
- lastdate: data.indate
- }));
- this.openDialog(this.dialogTarget);
- this.addMessageData(data, true);
- }
- }
- },
- addMessageData(data, animation = false, isUnshift = false) {
- data.self = data.username === this.userInfo.username;
- let sikp = false;
- if (data.id) {
- this.messageLists.some((item, index) => {
- if (item.id == data.id) {
- this.messageLists.splice(index, 1, data);
- return sikp = true;
- }
- });
- if (sikp) {
- return;
- }
- }
- if (isUnshift) {
- this.messageLists.unshift(data);
- } else {
- this.messageLists.push(data);
- if (this.autoBottom) {
- this.messageBottomGo(animation);
- } else {
- this.messageNew++;
- }
- }
- },
- messageSend(e) {
- if (e.keyCode == 13) {
- if (e.shiftKey) {
- return;
- }
- e.preventDefault();
- this.messageSubmit();
- }
- },
- messageSubmit() {
- let dialogUser = this.dialogLists.filter((item) => { return item.username == this.dialogTarget.username });
- if (dialogUser.length > 0) {
- let user = dialogUser[0];
- if (typeof user.unread === "number" && user.unread > 0) {
- this.unreadTotal -= user.unread;
- this.$set(user, 'unread', 0);
- $A.WSOB.sendTo('read', user.username);
- }
- }
- //
- this.autoBottom = true;
- let text = this.messageText.trim();
- if ($A.count(text) > 0) {
- let data = {
- type: 'text',
- username: this.userInfo.username,
- userimg: this.userInfo.userimg,
- indate: Math.round(new Date().getTime() / 1000),
- text: text
- };
- $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
- this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
- });
- //
- this.addDialog(Object.assign(this.dialogTarget, {
- lasttext: text,
- lastdate: data.indate
- }));
- this.openDialog(this.dialogTarget);
- this.addMessageData(data, true);
- }
- this.$nextTick(() => {
- this.messageText = "";
- });
- },
- userViewResult(user, data) {
- this.$set(user, 'nickname', data.nickname);
- this.$set(user, 'userimg', data.userimg);
- },
- videoConnect(username, videoChat) {
- if (!$A.leftExists(window.location.protocol, "https")) {
- this.$Modal.warning({title: this.$L('温馨提示'), content: this.$L('浏览器阻止音视频访问不是https的网站,所以尝试安装SSL!')});
- return;
- }
- this.videoChat = videoChat;
- navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
- try {
- navigator.mediaDevices.getUserMedia({
- audio: true,
- video: this.videoChat
- }).then((stream) => {
- this.videoLocalStream = stream;
- this.$refs.localVideo.srcObject = stream;
- this.$refs.localVideo.removeEventListener('loadedmetadata', this.videoListener);
- //
- if (username === null) {
- // 发起者
- this.videoUserName = this.dialogTarget.username;
- this.videoUserImg = this.dialogTarget.userimg;
- this.videoStartTime = 0;
- this.videoInitiator = true;
- this.$refs.localVideo.addEventListener('loadedmetadata', this.videoListener);
- } else {
- // 接受者
- this.videoIcecandidate(this.videoLocalStream, username);
- this.videoRtc.createOffer({
- offerToReceiveAudio: true,
- offerToReceiveVideo: this.videoChat
- }).then((desc) => {
- this.videoRtc.setLocalDescription(desc).then(() => {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'offer',
- 'data': this.videoRtc.localDescription
- });
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- this.videoClose(username, this.$L('对方:') + e);
- });
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- this.videoClose(username, this.$L('对方:') + e);
- });
- }
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- username && this.videoClose(username, this.$L('对方:') + e);
- });
- } catch (e) {
- this.$Modal.warning({title: this.$L('温馨提示'), content: this.$L('当前浏览器不支持音视频通话!')});
- username && this.videoClose(username, this.$L('对方:') + this.$L('浏览器不支持音视频通话!'));
- }
- },
- videoListener() {
- $A.WSOB.sendTo('info', this.videoUserName, {
- 'type': 'video',
- 'subtype': 'call',
- 'username': this.userInfo.username,
- 'userimg': this.userInfo.userimg,
- 'video': this.videoChat,
- }, (res) => {
- if (res.status !== 1) {
- this.videoClose(this.videoUserName, this.$L('呼叫失败!'));
- }
- });
- },
- videoIcecandidate(localStream, username) {
- this.videoRtc = new RTCPeerConnection({"iceServers":[{"urls":["turn:business.swoole.com:3478?transport=udp","turn:business.swoole.com:3478?transport=tcp"],"username":"ceshi","credential":"ceshi"}]});
- this.videoRtc.onicecandidate = (event) => {
- if (event.candidate) {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'candidate',
- 'data': event.candidate
- });
- }
- };
- try {
- this.videoRtc.addStream(localStream);
- } catch (e) {
- let tracks = localStream.getTracks();
- for (let i = 0; i < tracks.length; i++) {
- this.videoRtc.addTrack(tracks[i], localStream);
- }
- }
- this.videoRtc.onaddstream = (e) => {
- this.$refs.remoteVideo.srcObject = e.stream;
- };
- },
- videoClose(username, reason) {
- if (username && reason !== false) {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'close',
- 'reason': reason,
- });
- }
- if (this.videoInitiator) {
- this.videoInitiator = false;
- if (this.videoStartTime > 0) {
- let second = Math.round(new Date().getTime() / 1000) - this.videoStartTime;
- if (second >= 2) {
- $A.WSOB.sendTo('user', this.videoUserName, {
- type: this.videoChat ? 'video' : 'voice',
- username: this.userInfo.username,
- userimg: this.userInfo.userimg,
- indate: Math.round(new Date().getTime() / 1000),
- text: this.videoChat ? '视频通话' : '语音通话',
- other: {
- second: second
- }
- }, 'special');
- }
- }
- }
- if (username == this.videoUserName) {
- this.videoUserName = '';
- this.videoUserImg = '';
- this.videoStartTime = 0;
- if (this.videoLocalStream !== null) {
- this.videoLocalStream.getTracks().forEach((track) => {
- track.stop();
- });
- this.videoLocalStream = null;
- }
- this.$refs.localVideo.srcObject = null;
- this.$refs.remoteVideo.srcObject = null;
- }
- },
- videoMessage(msgDetail) {
- let body = msgDetail.body;
- let username = msgDetail.username;
- if (['offer', 'candidate', 'answer'].indexOf(body.subtype) !== -1) {
- if (!this.videoLocalStream) {
- this.videoClose(username);
- return;
- }
- }
- //
- switch (body.subtype) {
- case 'call':
- let callIng = true;
- let callAudio = this.$refs.callAudio;
- if (callAudio.getAttribute("data-listener") !== 'yes') {
- callAudio.setAttribute("data-listener", "yes");
- callAudio.addEventListener('ended', () => {
- if (callIng) {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'judge',
- });
- callAudio.play();
- }
- }, false);
- }
- callAudio.currentTime = 0;
- callAudio.play();
- //
- this.$Notice.close('chat-call');
- this.$Notice.open({
- name: 'chat-call',
- duration: 0,
- onClose: () => {
- callIng = false;
- callAudio.pause();
- this.videoClose(username, this.$L('对方:拒绝接听'));
- },
- render: h => {
- return h('div', {
- class: 'chat-notice-box',
- }, [
- h('UserImg', {class: 'chat-notice-userimg', props: {info: body}}),
- h('div', {class: 'ivu-notice-with-desc'}, [
- h('div', {class: 'ivu-notice-title'}, [
- h('UserView', {props: {username: username}})
- ]),
- h('div', {class: 'ivu-notice-desc'}, this.$L(body.video ? "邀请视频通话..." : "邀请语音通话...")),
- h('div', {class: 'chat-notice-btn-box'}, [
- h('Button', {
- props: {type: 'success', size: 'small'},
- on: {
- click: () => {
- callIng = false;
- callAudio.pause();
- this.$Notice.close('chat-call');
- this.$emit("on-open-notice", username);
- this.clickDialog(username);
- this.videoConnect(username, body.video);
- this.videoUserName = username;
- this.videoUserImg = body.userimg;
- this.videoStartTime = 0;
- this.videoInitiator = false;
- }
- }
- }, this.$L("接受")),
- h('Button', {
- props: {type: 'error', size: 'small'},
- on: {
- click: () => {
- callIng = false;
- callAudio.pause();
- this.$Notice.close('chat-call');
- this.videoClose(username, this.$L('对方:拒绝接听'));
- }
- }
- }, this.$L("拒绝")),
- ])
- ])
- ])
- }
- });
- break;
- case 'judge':
- if (username != this.videoUserName) {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'close',
- });
- }
- break;
- case 'close':
- this.$refs.callAudio.pause();
- this.$Notice.close('chat-call');
- this.videoClose(username, false);
- body.reason && this.$Message.warning(body.reason);
- break;
- case 'offer':
- this.videoIcecandidate(this.videoLocalStream, username);
- this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
- if (this.videoStartTime === 0) {
- this.videoRtc.createAnswer().then((desc) => {
- this.videoRtc.setLocalDescription(desc).then(() => {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'answer',
- 'data': this.videoRtc.localDescription
- });
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- });
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- });
- this.videoStartTime = Math.round(new Date().getTime() / 1000);
- }
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- });
- break;
- case 'answer':
- if (this.videoRtc) {
- this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- });
- }
- break;
- case 'candidate':
- if (this.videoRtc) {
- this.videoRtc.addIceCandidate(new RTCIceCandidate(body.data)).then(() => {
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- });
- }
- break;
- }
- }
- }
- }
- </script>
|