| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488 |
- <template>
- <div v-loading="allLoading" element-loading-text="拼命连接中">
- <div class="chatBox">
- <!-- ************************* 头部消息 ************************* -->
- <el-header height='80px'>
- <el-row type="flex" justify='space-between' align='middle' style="height:100%;">
- <el-col class="tit nopd" v-if="machineAndAtl == 10">
- <img id="logo" :src="url + logo" alt="">
- <span>智能客服</span>
- <span style="margin-left: 5px;"><img src="./../assets/st-img/on_icon.png" alt=""></span>
- </el-col>
- <el-col class="tit nopd" v-else-if="machineAndAtl == 100">
- <img id="logo" :src="url + logo" alt="">
- <span v-if="service">{{service.serverInfo.name}}</span>
- <span v-if="service_on" style="margin-left: 5px;"><img src="./../assets/st-img/on_icon.png" alt=""></span>
- <span v-if="!service_on" style="margin-left: 5px;"><img src="./../assets/st-img/off_icon.png" alt=""></span>
- </el-col>
- <el-col>
- <div class="imgBox">
- <!-- <el-button v-if="!service_on" size="mini" type="primary" @click="exit" style="margin-right: 10px;">退出聊天</el-button>-->
- <el-button v-if="machineAndAtl == 100" size="mini" type="primary" @click="exit" style="margin-right: 10px;">退出聊天</el-button>
- <i v-if="(selNum + tokNum) >= 4" @click="ejectEvl(10)" class="sc pointer" :class="selType?'scActy':''"></i>
- <div v-if="showleaveIcon" style="float: right" class="pointer" @click="leaveMsg()">
- <span style="font-size: 25px; color: #b3c1e7; vertical-align: middle;" @click="back()"
- class="el-icon-chat-line-round"></span>
- </div>
- <div v-if="!showleaveIcon" style="float: right; cursor: not-allowed">
- <span style="font-size: 25px; color: #d6d1c4; vertical-align: middle;"
- class="el-icon-chat-line-round"></span>
- </div>
- </div>
- </el-col>
- </el-row>
- </el-header>
- <div class="cationer">
- <!--****************************** 聊天会话框模块 *****************************-->
- <el-main>
- <!-- 广告展示隐藏按钮 -->
- <div class="retract pointer" @click="retract()">
- <img src="./../assets/st-img/retract.png" alt="" v-if="retractShow">
- <img src="./../assets/st-img/retract2.png" alt="" v-else>
- </div>
- <el-row class="pd informationBox scroll" id="main">
- <!-------------------机器人聊天板块 ----------------------->
- <div v-if="machineAndAtl == 10">
- <!--··············· 欢迎语 ············-->
- <div class="conversationBox">
- <div class="row" v-for="(item,index) in machine" :key="index">
- <div class="conversation row">
- <div class="headImg">
- <img src="./../assets/st-img/headAdvent.png" alt="">
- </div>
- <div class="cont left">
- <div v-html="item"></div>
- </div>
- </div>
- <div style="width:66px;"></div>
- </div>
- </div>
- <!--··········· 快捷问题回答模块 ············-->
- <div class="questionList" v-if="questionShow">
- <section v-for="(item,idx) in problem" :key="item.id">
- <div @click="answers(idx)">
- <span class="pointer gl">{{item.robot_name}}</span>
- </div>
- </section>
- <section>
- <div>
- <span class="col6">上面问题都不是</span>
- <span class="pointer ly" @click="changeService()">转人工客服</span>
- </div>
- </section>
- </div>
- <!--················ 和机器人会话发送消息 ·············-->
- <div v-for="item in chatCont" :key="item.id">
- <!-- 用户发文本信息 -->
- <div class="conversationBox" v-if="item.type =='user'">
- <div class="timer">{{item.time}}</div>
- <div class="customer row allAlignment">
- <div style="width:66px;"></div>
- <div class="row">
- <!-- 显示内容 -->
- <div v-if="item.chat" class="cont right">
- <div v-html="item.chat"></div>
- </div>
- <div v-else class=" right noafter" style="width:200px;margin-right:10px; ">
- <div slot="file">
- <img class="el-upload-list__item-thumbnail"
- @click="handlePictureCardPreview(url+item.imgUrl)"
- style="width:100%;height:auto;border-radius: 10px;"
- :src="url+item.imgUrl" alt="">
- </div>
- </div>
- <!-- 图片放大 -->
- <el-dialog :visible.sync="dialogVisible">
- <img width="100%" :src="dialogImageUrl" alt="">
- </el-dialog>
- <!-- 头像 -->
- <div class="headImg">
- <img :src="require('@/assets/st-img/timg.jpg') " alt="">
- </div>
- </div>
- </div>
- </div>
- <!-- 机器人无法回答转人工 -->
- <div class="conversationBox" v-if="item.type == 1001">
- <div class=" row">
- <div class="conversation row">
- <div class="headImg">
- <img src="./../assets/st-img/headAdvent.png" alt="">
- </div>
- <div class="cont left">
- <div>您的问题暂时无法处理</div>
- <div>
- <span class="col">问题没有解决?</span>
- <span class="change pointer ly"
- @click="changeService()">转人工客服</span>
- </div>
- </div>
- </div>
- <div style="width:66px;"></div>
- </div>
- </div>
- <!-- 机器人回答 -->
- <div class="conversationBox" v-else-if='item.type == "service"'>
- <div class="row">
- <div class="conversation row">
- <div class="headImg">
- <img src="./../assets/st-img/headAdvent.png" alt="">
- </div>
- <div class="cont left">
- <div>{{item.cont}}</div>
- </div>
- </div>
- <div style="width:66px;"></div>
- </div>
- </div>
- <!-- 快捷问题回答 -->
- <div class="conversationBox" v-else-if="item.type == 'machine'">
- <div class="timer">
- {{item.robot_addTime}}
- </div>
- <div class=" row">
- <div class="conversation row">
- <div class="headImg">
- <img src="./../assets/st-img/headAdvent.png" alt="">
- </div>
- <div class="cont left">
- <div>{{item.robot_content}}</div>
- <div>
- <span class="col">问题没有解决</span>
- <span class="change pointer ly"
- @click="changeService()">转人工客服</span>
- </div>
- </div>
- </div>
- <div style="width:66px;"></div>
- </div>
- </div>
- <!-- 转接客服列表 -->
- <div class="changeService" v-else-if="item.type == 'artService'">
- <div v-for="(itemList,idx) in serviceList" :key="idx">
- <span class="col6">人工客服:</span>
- <span class="colE5 pointer gl" @click="jumpService(itemList.id, itemList.name)">{{itemList.name}}</span>
- </div>
- </div>
- </div>
- <!--············· 各种消息提示框 ··············-->
- <!-- 客服不在线帮助提示框 -->
- <div class="promptBox" v-if="artAndLeave == 100">
- <div class="prompt help">
- <span>{{jumpName + Onlinemsg}}</span>
- <span class="colE5 ly pointer" @click="leaveMsg()">留言</span>
- </div>
- </div>
- <!-- 客服会话超时 -->
- <div class="promptBox" v-if="resigtermsg">
- <div class="prompt help">
- <span>客服已经关闭会话,如需继续咨询请重新连接客服</span>
- </div>
- </div>
- <div class="promptBox " v-if="serverNotOnlin">
- <div class="prompt help">
- <span>{{serviceNotOnlineText}}</span>
- </div>
- </div>
- <!-- 排队等待 -->
- <div class="evaluate" v-if="waitingMsg">
- <span>{{waitingText}}</span>
- <el-button type="primary" style="margin: 10px auto; display: block;"
- @click="closedWating">退出排队
- </el-button>
- </div>
- </div>
- <!--············ 和人工会话聊天模块 ··············-->
- <div v-if="machineAndAtl == 100">
- <!--历史消息-->
- <div v-for="(item,index) in hisSviceChat" :key="index">
- <!-- 客服信息 -->
- <div class="conversationBox" v-if="item.from_id.startsWith('KF')">
- <div class="timer">{{item.time_line | formatDate}}</div>
- <div class="row">
- <div class="conversation row">
- <div class="headImg">
- <img :src="serviceImg?url+serviceImg:require('@/assets/st-img/kf.png')"
- alt="">
- </div>
- <div class="cont left">
- <div v-if="item.content != ''" v-html="item.content.text"></div>
- <div v-if="item.content.img != ''" slot="file">
- <img class="el-upload-list__item-thumbnail"
- @click="handlePictureCardPreview(url+item.content.img)"
- style="width:100%;height:auto;border-radius: 10px;"
- :src="url+item.content.img" alt="">
- </div>
- </div>
- </div>
- <div style="width:66px;"></div>
- </div>
- </div>
- <!-- 用户信息 -->
- <div class="conversationBox" v-else>
- <div>
- <div class="timer">{{item.time_line | formatDate}}</div>
- <div class="customer row allAlignment">
- <div style="width:66px;"></div>
- <div class="row">
- <div class="cont right">
- <div v-if="item.content != ''" v-html="item.content.text"></div>
- <div v-if="item.content.img != ''" slot="file">
- <img class="el-upload-list__item-thumbnail"
- @click="handlePictureCardPreview(url+item.content.img)"
- style="width:100%;height:auto;border-radius: 10px;"
- :src="url+item.content.img" alt="">
- </div>
- </div>
- <div class="headImg">
- <img :src="require('@/assets/st-img/timg.jpg') " alt="">
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- 人工客服回复消息 -->
- <div v-for="item in customerSviceChat" :key="item.id">
- <div class="conversationBox" v-if="item.type == 'service' ">
- <div class="timer" v-html="item.timer"></div>
- <div class="row">
- <div class="conversation row">
- <div class="headImg">
- <img :src="serviceImg?url+serviceImg:require('@/assets/st-img/kf.png')"
- alt="">
- </div>
- <div class="cont left">
- <div v-if="item.content != ''" v-html="item.content"></div>
- <div v-else slot="file">
- <img class="el-upload-list__item-thumbnail"
- @click="handlePictureCardPreview(url+item.imgUrl)"
- style="width:100%;height:auto;border-radius: 10px;"
- :src="url+item.imgUrl" alt="">
- </div>
- </div>
- </div>
- <div style="width:66px;"></div>
- </div>
- </div>
- <!-- 用户发送文本消息 -->
- <div class="conversationBox" v-if="item.type == 'user' ">
- <div>
- <div class="timer">{{webTime}}</div>
- <div class="customer row allAlignment">
- <div style="width:66px;"></div>
- <div class="row">
- <div class="cont right">
- <div v-if="item.content != ''" v-html="item.content"></div>
- <div v-else slot="file">
- <img class="el-upload-list__item-thumbnail"
- @click="handlePictureCardPreview(url+item.imgUrl)"
- style="width:100%;height:auto;border-radius: 10px;"
- :src="url+item.imgUrl" alt="">
- </div>
- </div>
- <div class="headImg">
- <img :src="require('@/assets/st-img/timg.jpg') " alt="">
- </div>
- </div>
- </div>
- </div>
- </div>
- <div v-if="item.type == 'system' ">
- <!-- 客服会话转接 -->
- <div class="promptBox" v-if="item.str == 'changeKeFu'">
- <div class="prompt help">
- <span>会话转接成功</span>
- </div>
- </div>
- <!-- 历史会话 -->
- <div class="promptBox" v-if="item.str == 'historyMsg'">
- <div class="prompt help">
- <span>{{historyMsgtext}}</span>
- </div>
- </div>
- </div>
- <!-- 点击图片放大 -->
- <el-dialog :visible.sync="dialogVisible">
- <img width="100%" :src="dialogImageUrl" alt="">
- </el-dialog>
- </div>
- <!-- 评价 -->
- <div class="evaluate" @click="ejectEvl(10)" v-if="consult">
- <span>欢迎你的咨询,请对我们的服务做出评价</span>
- <span class="btn seek">评价</span>
- </div>
- <div class="promptBox " v-if="comtSuccess">
- <div class="prompt help">
- <span>您对我们的服务评价为: {{comtCount}}。非常感谢!</span>
- </div>
- </div>
- <!-- 客服会话超时 -->
- <div class="promptBox" v-if="willOverTime">
- <div class="prompt help">
- <span>{{overTimeMsg}}</span>
- </div>
- </div>
- </div>
- <!-- 发送消息音频提示 -->
- <audio id="send" src="../../static/send.wav"></audio>
- <!-- 接收消息音频提示 -->
- <audio id="receive" src="../../static/receive.wav"></audio>
- </el-row>
- <!--·········· 文本编辑框 ···········-->
- <el-row class="chatting">
- <el-col>
- <!-- 发送图和表情按钮 -->
- <div style="height:18px; display:flex;">
- <el-popover id="pop" placement="top-start" width="200" trigger="hover">
- <ul>
- <li class="emoticon" v-for="(item,index) in frceArr" :key="item.id">
- <img class="pointer" :src="require(`@/assets/st-img/${index}.gif`)"
- @click="memeImg(index)" alt="">
- </li>
- </ul>
- <el-button class="expression" slot="reference"></el-button>
- </el-popover>
- <el-upload class="avatar-uploader" action="/api/index/upload/uploadImg"
- :on-success="handleAvatarSuccess"
- :before-upload="beforeAvatarUpload"
- :on-error='handError'
- list-type='no' accept="image/jpeg,image/jpg,image/png,image/svg">
- <!-- <img v-if="imageUrl" :src="imageUrl" class="avatar"> -->
- <i slot="default" class=" photo"></i>
- </el-upload>
- </div>
- <div class="row center allAlignment chattingBox">
- <div style="height:44px;width:300px;">
- <textarea name=""
- id="information"
- v-model.trim="information"
- cols="30"
- rows="1"
- autofocus
- placeholder="请输入你的问题:"
- @keyup.enter="listenEnter($event)"
- >
- </textarea>
- </div>
- <div>
- <!-- 准备修改 -->
- <div @click="sendCol?(!closeByServer||artAndLeave==0||artAndLeave==100?sendInfo():''):''"
- class="sendOut pointer"
- :class="sendCol?(!closeByServer||artAndLeave==0||artAndLeave==100?'sendCol':'netSendCol'):'netSendCol'">
- <span class="">发送</span>
- </div>
- </div>
- </div>
- </el-col>
- </el-row>
- </el-main>
- <el-aside width='255px' v-if="retractShow">
- <el-row class="rt">
- <div v-if="machineAndAtl == 10">
- <el-col :span='24' class="artificial pd20">
- <div class="infor">
- <div>
- <span>姓名:</span>
- <span>智能客服</span>
- </div>
- <div>
- <span>工号:</span>
- <span>001</span>
- </div>
- <div>
- <span>性别:</span>
- <span>保密</span>
- </div>
- <div>
- <span>职务:</span>
- <span>咨询客服</span>
- </div>
- </div>
- <div class="headPortrait">
- <img :src="require('@/assets/st-img/headPortrait.png')" alt="">
- </div>
- </el-col>
- <el-col class="autograph pd20">
- <div>
- <span>个性签名:</span>
- <span></span>
- </div>
- </el-col>
- </div>
- <div v-if="machineAndAtl == 100">
- <el-col :span='24' class="artificial pd20">
- <div class="infor">
- <div>
- <span>姓名:</span>
- <span v-if="service.serverInfo">{{ service.serverInfo.name ? service.serverInfo.name : '001客服' }}</span>
- </div>
- <div>
- <span>工号:</span>
- <span>{{service.serverInfo ? service.serverInfo.job_name : '001'}}</span>
- </div>
- <div>
- <span>性别:</span>
- <span>保密</span>
- </div>
- <div>
- <span>职务:</span>
- <span class="duty">{{service.serverInfo ? service.serverInfo.groupname : '咨询客服'}}</span>
- </div>
- </div>
- <div class="headPortrait">
- <img :src="service.serverInfo ? service.serverInfo.avatar ? (url+service.serverInfo.avatar) :require('@/assets/st-img/kf.png') : require('@/assets/st-img/kf.png')"
- alt="">
- </div>
- </el-col>
- <el-col class="autograph pd20">
- <div>
- <span>个性签名:</span>
- <span>{{service.serverInfo ? service.serverInfo.signature :'' }}</span>
- </div>
- </el-col>
- </div>
- <el-col class="advent" v-for="imgs in advert" :key="imgs.id">
- <a :href="'http://'+imgs.advertisement_url" target="_blank" rel="noopener noreferrer">
- <img :src="url + imgs.advertisement_img" alt="">
- </a>
- </el-col>
- </el-row>
- </el-aside>
- </div>
- <!-- 评价框 -->
- <el-card id="box_card" class="box-card" v-if="evlShow">
- <div class="close"><i @click="closeEvl()"></i></div>
- <div class="tit">
- <span>感谢您的咨询,请对我们的服务做出评价</span>
- </div>
- <div class="selIcon row allAlignment">
- <div @click="chage(1)">
- <i :class="changeIcon == 10? '':'sfd'"></i>
- <span>满意</span>
- </div>
- <div @click="chage(2)">
- <i class="comm" :class="changeIcon == 100?'comm2':''"></i>
- <span>一般</span>
- </div>
- <div @click="chage(3)">
- <i class="notSfd" :class="changeIcon == 1000?'notSfd2':''"></i>
- <span>不满意</span>
- </div>
- </div>
- <div class="sure" @click="evaluateSure()">
- <span>确定</span>
- </div>
- </el-card>
- <div class="zzBox" v-if="zzShow"></div>
- <el-dialog
- :close-on-click-modal="true"
- :close-on-press-escape ="true"
- title="是否发送图片"
- :visible.sync="dialogPaste"
- width="35%">
- <el-image :src="pasteUrl" :fit="fit"></el-image>
- <span slot="footer" class="dialog-footer">
- <el-button @click="dialogPaste = false">取 消</el-button>
- <el-button type="primary" style="color: #333" @click="handleClose()">确 定</el-button>
- </span>
- </el-dialog>
- </div>
- </div>
- </template>
- <script>
- import '../css/index.css';
- import frce from '../assets/frce.js';
- import fk from '../assets/st-img/kf.png'
- export default {
- data() {
- return {
- textarea: '',//备注
- evlShow: false, // 评价框显示
- zzShow: false, // 遮罩层显示
- vertion: '',//图形验证码
- provShow: true, // 验证框显示
- changeIcon: 10,
- name: '', // 验证框姓名model
- phone: '',// 验证框电话model
- email: '',// 验证框邮箱model
- frceArr: [], //表情包代码
- information: '',//发送的文本信息
- sendCol: false, // 发送按钮切换样式
- selType: false, //图标选中样式 true为选中,false为未选中
- selNum: 0, // 服务端消息数量
- tokNum: 0, // 用户端消息数量
- // syType : false,
- // sqType : false,
- error: false,
- emlError: false,
- artAndLeave: 0, // 默认为100,转人工为10,人工不在转留言为100
- chatCont: [], // 机器人会话数据
- imageUrl: [],//上传图片
- img: '', //上传的单个图片路径
- dialogVisible: false, //图片放大
- dialogImageUrl: '', // 放大的图片
- dialogUrl: false,
- serviceInfor: '', //客服信息
- websock: null, //会话初始值
- // currTime: "", //获取系统时间
- apiToken: '',//系统Token
- machine: [], //机器会话信息
- advert: '', // 广告语
- problem: '', //机器智能问题
- macNotPro: false, //机器人问题无法解决显示
- answer: [], //解答问题的答案
- questionShow: true, // 问题显示
- consult: false, //评价模块显示
- type: 1001, //自增
- jumpArtl: false, // 跳转人工客服状态
- group: '', //客服组
- userConversation: {}, //用户当前会话
- machineAndAtl: 10, //默认为机器人,100为人工
- satisfaction: 1, //评价满意度,1为满意,2为一般,3为不满意
- url: 'http://kfadmin.bocai186.com', // 域名地址
- // url: 'http://192.168.2.187:8090', // 域名地址
- user_info: '', // 用户信息
- // 人工客服信息
- service: '',
- serviceList: [], //后台推送的人工客服列表
- customerWelCome: '', // 客服欢迎语
- customerSviceChat: [], // 客服会话信息
- hisSviceChat:[],
- serviceImg: '',
- timerVote: '', //存储上一次时间
- curtTimer: '',//当前时间
- returnTimer: '',//返回当前时间
- // isConnection:true,//人工分组列表开关
- chatNum: '', // 会话数量
- comtSuccess: false, // 评论发送成功显示
- comtCount: '', // 评论成功返回的满意度
- retractShow: true, // 展开侧边栏
- sensitive: [], //敏感词1
- senType: false,//敏感词状态
- sensitiveNumber: 0,//敏感词次数
- doubSensitive: [],//重复的敏感词
- senInfo: '', //敏感词数据
- hourse: '', //返回时间,小时
- closeByServer: false, //客服关闭会话
- serverNotOnlin: false, //客服掉线
- willOverTime: false, //超时关闭会话
- overTimeMsg: '', // 超时提示内容
- allLoading: true, //整个页面加载中
- webTime: '',//网络时间
- changeKeFu: false, //客服转接
- historyMsg: false, // 是否展示历史信息
- historyMsgtext:"", // 历史信息内容提示
- /*****************websockt心跳变量*******************/
- reconnectData: null,
- lockReconnect: false, //避免重复连接,因为onerror之后会立即触发 onclose
- timeout: 10000, //10s一次心跳检测
- timeoutObj: null,
- serverTimeoutObj: null,
- logo: '', // logo 图片
- Onlinemsg: "", // 系统留言信息
- showleaveIcon: true, // 留言按钮触发条件
- jumpName: '', // 根据类型提示售后服务名称
- waitingMsg: false, // 是否显示等待排队
- waitingText: "", // 等待内容
- service_on:true, // 现在状态
- avatarImg: fk,
- dialogPaste: false,
- pasteUrl:'',//截屏图片
- fit:'contain', // 图片样式
- resigtermsg:false, //提示重连
- evaluateNum:false,
- }
- },
- filters: {
- /**
- * 时间戳转日期自定义时间格式
- * timeStamp:时间戳
- * custom:转换日期时定义年月日用是什么符号隔开
- * isDtae:0=月份、1=日期、3=时间
- */
- formatDate: function (value, custom='',isDtae=3) {
- let timeStamp =value;
- var date = new Date();
- date.setTime(timeStamp * 1000);
- var y = date.getFullYear();
- var m = date.getMonth() + 1;
- m = m < 10 ? ('0' + m) : m;
- var d = date.getDate();
- d = d < 10 ? ('0' + d) : d;
- var h = date.getHours();
- h = h < 10 ? ('0' + h) : h;
- var minute = date.getMinutes();
- var second = date.getSeconds();
- minute = minute < 10 ? ('0' + minute) : minute;
- second = second < 10 ? ('0' + second) : second;
- if (isDtae == 0){
- return y + custom + m //+'student';
- }else if (isDtae ==1){
- return y + custom + m + custom + d;
- }else if(isDtae == 3){
- return h + ':' + minute;
- }else {
- return y + '-' + m + '-' + d + ' ' + h + ':' + minute //+ ':' + second;
- }
- }
- },
- methods: {
- /******************qq截图粘贴---获取剪切板数据*****************/
- getClipboardData( e ){
- // 添加到事件对象中的访问系统剪贴板的接口
- let clipboardData = e.clipboardData,
- i = 0,
- items, item, types;
- if( clipboardData ){
- items = clipboardData.items;
- if( !items ){
- return;
- }
- item = items[0];
- // 保存在剪贴板中的数据类型
- types = clipboardData.types || [];
- for( ; i < types.length; i++ ){
- if( types[i] === 'Files' ){
- item = items[i];
- break;
- }
- }
- // 判断是否为图片数据
- if( item && item.kind === 'file' && item.type.match(/^image\//i) ){
- this.imgReader( item );
- }
- }
- },
- /**********qq截图粘贴---获取剪切板图片信息进行转换blob***********/
- imgReader( item ){
- let _this = this;
- var blob = item.getAsFile(),reader = new FileReader();
- // 读取文件后将其显示在网页中
- reader.onload = function( e ){
- var img = new Image();
- img.src = e.target.result;
- _this.dialogPaste =true;
- _this.pasteUrl = e.target.result;
- // console.log(img.src)
- //document.body.appendChild( img );
- };
- // 读取文件
- reader.readAsDataURL( blob );
- },
- /***qq截图粘贴************/
- paste(){
- document.getElementById('information').addEventListener('paste',this.getClipboardData)
- },
- /*****发送截图******/
- handleClose(done) {
- this.dialogPaste = false;
- let blob = this.$public.dataURItoBlob(this.pasteUrl)
- let self = this;
- var formData = new FormData();
- formData.append("file", blob);
- self.upImg(formData);
- },
- upImg(formData){
- let self = this;
- // 数据结构请求
- this.$axios.post('/api/index/upload/uploadImg', formData).then(res => {
- // console.log(res.data.data)
- // console.log(res.data.data.src);
- let str = this.information;
- let formatStr = str.replace(/\n/g, '<br/>');
- if (res.data.code == 1) {
- let isFirst = true;
- let str = this.information;
- let formatStr = str.replace(/\n/g, '<br/>');
- // 给机器人发送文本消息
- if (this.machineAndAtl == 10) {
- //给机器人发送文本消息-本地储存
- let datas = {
- time: '',
- chat: this.turnFace(this.shieldingKeyword(formatStr)),
- imgUrl: res.data.data.src,
- type: 'user'
- }
- this.chatCont.push(datas)
- //消息发送-机器人
- this.websocketsend(JSON.stringify({
- type: 'toRobot',
- data: {
- groups_id: '1',
- robot_name: this.shieldingKeyword(formatStr),
- webTime: this.webTime,
- robotgroups_id: '1',
- }
- }))
- } else if (this.machineAndAtl == 100) { //人工聊天
- // 人工聊天超时隐藏
- this.willOverTime = false;
- //发送给客服消息-本地储存
- this.customerSviceChat.push({
- time: '',
- content: this.turnFace(this.shieldingKeyword(formatStr)),
- imgUrl: res.data.data.src,
- type: 'user',
- });
- //消息发送-客服
- this.websocketsend(JSON.stringify({
- type: 'chatMessage',
- data: {
- from_name: this.user_info.name,
- from_avatar: this.user_info.avatar,
- from_id: this.user_info.id,
- content: JSON.stringify({
- text: formatStr,
- img: res.data.data.src,
- type: 'user'
- }),
- webTime: this.webTime,
- to_id: this.service.kf_id,
- to_name: this.service.kf_name,
- sensitiveNumber: this.sensitiveNumber,
- conversationId: this.service.conversationId
- }
- }))
- this.tokNum++;
- }
- // 发送之后清空发送数据
- this.img = '';
- this.information = '';
- //高度自动向上滑动
- this.automaticRolling();
- }
- })
- },
- // 退出聊天
- exit(){
- this.websocketsend(JSON.stringify({
- type: 'kfCloseUser',
- data: {
- to_id: this.service.kf_id,
- kf_id: this.user_info.id,
- group_id: this.service.serverInfo.group,
- conversationId:this.service.conversationId,
- type:6,
- }
- }))
- // this.goBack();
- this.machineAndAtl = 10;
- const loading = this.$loading({
- lock: true,
- text: '加载中',
- spinner: 'el-icon-loading',
- background: 'rgba(0, 0, 0, 0.7)'
- });
- setTimeout(() => {
- loading.close();
- }, 4000);
- },
- // 关闭评价框按钮
- closeEvl(){
- this.evlShow = false;
- this.zzShow = false;
- },
- // 消息发送
- sendAudio() {
- let send = document.getElementById('send')
- send.play()
- },
- // 消息接收
- receiveAudio() {
- let receive = document.getElementById('receive')
- receive.play();
- },
- // 回车提交
- listenEnter(event) {
- let text = document.getElementById('information');
- if (event.keyCode == 13 && event.ctrlKey == true) {
- text.value = text.value + '\n'
- } else if (event.keyCode == 13) {
- if (this.information == "") {
- text.value = '';
- return false
- } else {
- this.sendInfo();
- event.preventDefault()
- }
- }
- },
- // 切换留言板返回
- back() {
- document.getElementById('information').removeEventListener('paste',this.getClipboardData)
- this.$emit('value', 100)
- },
- /******************文字信息转表情******************/
- turnFace(data) {
- let str = data.match(/\#\[.*?\]\//g);
- let arr = Array.from(new Set(str));
- arr.forEach(e => {
- let imgsrc = '';
- for (let i = 0; i < this.frceArr.length; i++) {
- let expText = e.slice(1, e.length - 1);
- if (expText == this.frceArr[i]) {
- imgsrc = '<img class="hover" src="' + require(`@/assets/st-img/${i}.gif`) + '"/>'
- break;
- }
- }
- data = data.replace(new RegExp(`\\#\\[${e.substring(2, e.length - 2)}\\]\\/`, 'g'), imgsrc);
- })
- return data;
- },
- // 关闭加载中
- allLoadingClose() {
- this.allLoading = false;
- },
- /**************切换显示客服信息**************** */
- retract() {
- this.retractShow = !this.retractShow;
- },
- /***************发送图片***************/
- beforeAvatarUpload(file) {
- let self = this
- const isJPG = file.type == 'image/jpeg' || 'image/jpg' || 'image/png' || 'image/svg';
- const isLt2M = file.size / 1024 / 1024 < 2;
- if (!isJPG) {
- this.$message.error('上传只能是图片格式!');
- return false;
- }
- if (!isLt2M) {
- this.$message.error('上传图片大小不能超过 2MB!');
- return false;
- }
- //对图片进行压缩
- const imgSize = file.size / 1024 / 1024;
- if (imgSize > 0.5) {
- const _this = this
- return new Promise(resolve => {
- const reader = new FileReader()
- const image = new Image()
- image.onload = (imageEvent) => {
- const canvas = document.createElement('canvas');
- const context = canvas.getContext('2d');
- const width = image.width * 0.4;
- const height = image.height * 0.4;
- canvas.width = width;
- canvas.height = height;
- context.clearRect(0, 0, width, height);
- context.drawImage(image, 0, 0, width, height);
- const dataUrl = canvas.toDataURL(file.type);
- const blobData = _this.dataURItoBlob(dataUrl, file.type);
- resolve(blobData)
- }
- reader.onload = (e => {
- image.src = e.target.result;
- });
- reader.readAsDataURL(file);
- })
- }
- },
- dataURItoBlob(dataURI, type) {
- var binary = atob(dataURI.split(',')[1]);
- var array = [];
- for (var i = 0; i < binary.length; i++) {
- array.push(binary.charCodeAt(i));
- }
- return new Blob([new Uint8Array(array)], {type: type});
- },
- handError(err, file, fileList) {
- // 获取当前发送时间
- // console.log(err, '上传图片报错!')
- },
- /***************传输成功之后返回图片*************** */
- handleAvatarSuccess(res, file) {
- // console.log(res)
- this.dialogUrl = true;
- this.img = res.data.src;
- this.sendMessage();
- },
- /***************图片放大*************** */
- handlePictureCardPreview(url) {
- this.dialogImageUrl = url;
- this.dialogVisible = true;
- },
- /***************弹出评价框*************** */
- ejectEvl(type) {
- if (this.comtSuccess) return;
- this.changeIcon = 10;
- if (type == 10) {
- this.evlShow = true
- }
- this.zzShow = true;
- },
- /***************传入父组件进行组件切换*************** */
- leaveMsg() {
- this.$emit('value', 100)
- },
- //回到初始页面
- goBack(type) {
- if (type === 1) {
- this.artAndLeave = 0;
- this.chatCont = [];
- } else {
- this.closeByServer = true;
- this.machineAndAtl = 10;
- this.macNotPro = false;
- this.jumpArtl = false;
- this.willOverTime = false;
- this.waitingMsg = false;
- this.time = '';
- this.returnTimer = '';
- this.service_on = true;
- this.historyMsg = false,
- // this.automaticRolling();
- this.customerSviceChat = [];
- this.reconnect();
- this.selNum = 0;
- this.tokNum = 0;
- }
- },
- /*******发送消息按钮*******/
- sendInfo() {
- this.closeByServer = false;
- this.artAndLeave = 0;
- this.jumpArtl = false;
- this.dialogUrl = false;
- this.sendMessage();
- this.sendAudio();
- },
- /***************改变评价框的满意度*************** */
- chage(type) {
- this.satisfaction = type;
- if (type == 1) {
- this.comtCount = '满意'
- this.changeIcon = 10;
- } else if (type == 2) {
- this.comtCount = '一般'
- this.changeIcon = 100;
- } else {
- this.comtCount = '不满意'
- this.changeIcon = 1000;
- }
- },
- /***************图标样式切换*************** */
- select(type) {
- if (type == 1) {
- this.selType = !this.selType;
- } else if (type == 2) {
- this.syType = !this.syType;
- } else {
- this.sqType = !this.sqType;
- }
- },
- /***************评价确认*************** */
- evaluateSure() {
- this.websocketsend(JSON.stringify({
- type: 'evaluate',
- data: {
- evaluate_id: this.satisfaction,
- conversationId: this.service.conversationId,
- evaluate_content: this.textarea
- }
- }))
- this.evlShow = false;
- this.zzShow = false;
- this.textarea = '';
- this.consult = false;
- if (this.changeIcon == 10) {
- this.comtCount = '满意'
- }
- },
- /***************验证框确认*************** */
- yySure() {
- this.provShow = false;
- this.zzShow = false;
- },
- /***************转人工客服列表*************** */
- changeService() {
- // if(!this.isConnection) return
- this.$axios.post('/api/index/groups/index', {}, {
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'apiToken': this.setApiToken('index', 'groups', 'index')
- }
- }).then(res => {
- if (res.data.code == 1) {
- this.serviceList = res.data.data;
- this.chatCont.push({
- 'type': 'artService'
- })
- this.automaticRolling();
- }
- })
- // this.isConnection = false;
- },
- /***************表情点击*************** */
- memeImg(i) {
- //当表情被点击
- this.information = this.information + "#" + this.frceArr[i] + "/";
- },
- /***************失去焦点做正则验证*************** */
- sureInfor(type) {
- if (type == 1) {
- if (!/^1[34578]\d{9}$/.test(this.phone)) {
- this.error = true;
- this.phone = '';
- } else {
- this.error = false;
- }
- } else if (type == 10) {
- if (!/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(this.email)) {
- this.emlError = true;
- this.email = '';
- } else {
- this.emlError = false;
- }
- }
- },
- /***************获取热点智能问题*************** */
- getProblem() {
- this.$axios.post('/api/index/robot/index', {groups_id: 1, robotgroups_id: 1}, {
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'apiToken': this.setApiToken('index', 'robot', 'index')
- }
- }).then(res => {
- if (res.data.code == 1) {
- this.problem = res.data.data;
- }
- })
- },
- /*****************获取聊天次数*******************/
- getChatNum() {
- this.$axios.post('/api/index/evaluate/minRound', '', {
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'apiToken': this.setApiToken('minround', 'evaluate', 'index')
- }
- }).then(res => {
- if (res.data.code == 1) {
- this.chatNum = res.data.data.systemconfig_data
- }
- })
- },
- /*****************屏蔽关键字******************/
- shieldingKeyword(data) {
- //将敏感词组用|转换字符串
- let snstive = this.sensitive.join('|');
- //console.log(snstive);
- this.sensitiveNumber = 0;
- //匹配出会话中的敏感词
- return data.replace(eval('/' + snstive + '/g'), (res) => {
- var str = '';
- for (var i = 0; i < res.length; i++) {
- str += '*';
- }
- this.sensitiveNumber++;
- return str;
- })
- },
- /*---------------------------------------------------------------------------------*/
- /**************初始化WebSocket****************/
- initWebSocket() {
- let _this = this;
- let apiToken = this.$md5.hex_md5('customer-service' + window.location.origin);
- this.websock = new WebSocket('ws://103.108.43.176:9101?apiToken=' + apiToken);
- // this.websock = new WebSocket('ws://192.168.2.187:9101?apiToken=' + apiToken);
- this.websock.debug = true;
- // 数据接收
- this.websock.onmessage = this.websocketonmessage;
- // 连接建立之后
- this.websock.onopen = this.websocketonopen;
- // 连接建立失败重连
- this.websock.onerror = this.websocketonerror;
- // 关闭会话
- this.websock.onclose = this.websocketclose;
- },
- /****************连接建立成功***************/
- websocketonopen() {
- console.log('链接成功');
- // 如果有传 group_id 直接跳转人工客服
- let group_id = this.$public.getQueryString("group_id");
- if (group_id) {
- this.jumpService(group_id);
- }
- //心跳检测
- this.heatBeat()
- },
- /*************连接建立失败重连***************** */
- websocketonerror(e) {
- console.log('连接建立失败重连:', e)
- this.goBack(1);
- },
- /**************数据接收***************** */
- websocketonmessage(e) {
- let redata = e
- if (e.data) {
- redata = JSON.parse(e.data);
- }
- //心跳检测
- this.heatBeat();
- // 心跳检测
- if(redata.message_type == "ping"){
- this.websock.send('{"type":"pong"}')
- return false;
- }
- if (redata.type != 'pong' || redata.message_type != "ping") {
- console.log(redata)
- }
- // 欢迎语
- if (redata.message_type == 'helloMessage') {
- this.machine.push(redata.data.content);
- }
- // 广告语
- if (redata.message_type == 'advertisement') {
- this.advert = redata.data;
- }
- // 评价
- if (redata.message_type == 'getEvaluate') {
- this.consult = true;
- }
- //返回的会话时间
- if (redata.message_type == 'webTime') {
- //处理会话时间大于两分钟显示会话时间并且储存本次会话时间
- if (this.machineAndAtl == 100) {
- let num = this.customerSviceChat.length - 1;
- if (this.customerSviceChat[num].type == "user") {
- if (redata.data.webTime.split(":")[1] - this.webTime.split(":")[1] > 2) {
- this.$set(this.customerSviceChat[num], 'time', redata.data.webTime);
- this.webTime = redata.data.webTime;
- } else {
- this.$set(this.customerSviceChat[num], 'time', '');
- }
- }
- }
- }
- //会话超时提示
- if (redata.message_type == 'overtime') {
- console.log('接收会话超时');
- }
- // 链接客服信息
- if (redata.message_type == 'connect') {
- let server= {};
- if (redata.data) {
- server = redata.data
- } else {
- server = {
- conversationId: redata.data.conversationId,
- kf_id: redata.data.kf_id,
- kf_name: "",
- serverInfo: {
- avatar: this.avatarImg,
- client_id:"",
- group:"",
- id: "",
- intime:"",
- job_name: "",
- name: "tank",
- signature: "",
- status: 0,
- task: 0,
- }
- }
- }
- this.artAndLeave = 10;
- this.machineAndAtl = 100;
- // console.log(server, '============客服信息')
- this.service = server;
- this.serviceImg = server.serverInfo.avatar;
- this.consult = false;
- this.evlShow = false;
- this.comtSuccess = false;
- this.showleaveIcon = false;
- this.waitingMsg = false;
- this.selNum = 0;
- this.tokNum = 0;
- this.service_on = true;
- this.closeByServer = false;
- // console.log(redata.data.evaluate_id,"评价数量")
- if(redata.data.evaluate_id > 0){
- this.evaluateNum = true;
- }
- }
- // 暂无客服
- if (redata.message_type == 'wait') {
- let content = JSON.parse(redata.data.content)
- this.artAndLeave = 100;
- }
- //接收客服会话
- if (redata.message_type == 'chatMessage') {
- // 转接的时候清除历史信息
- this.hisSviceChat = [];
- // 接收提示音
- this.receiveAudio();
- //存储会话超时间
- this.webTime = redata.data.time;
- //会话大于两分钟显示
- let timer = ''
- if (this.returnTimer == '') {
- timer = redata.data.time;
- this.returnTimer = redata.data.time
- } else {
- let timeStamp = this.returnTimer.split(":");
- let rdtime = redata.data.time.split(":");
- if (timeStamp[0] == rdtime[0]) {
- if ((rdtime[1] - timeStamp[1]) < 2) {
- timer = ''
- } else {
- timer = redata.data.time;
- }
- }
- }
- let contType = this.isJSON(redata.data.content);
- let content = {};
- if (contType == false) {
- content.text = redata.data.content
- } else {
- content = JSON.parse(redata.data.content)
- }
- let obj = {
- time: timer,
- content: content.text ? this.turnFace(content.text) : '',
- imgUrl: content.img ? content.img : '',
- type: 'service'
- }
- this.customerSviceChat.push(obj);
- // console.log(this.customerSviceChat);
- this.selNum++;
- this.automaticRolling();
- }
- //接收机器会话
- if (redata.message_type == 'robotMessage') {
- if (redata.data.content == 'error') {
- let _this = this;
- this.chatCont.push({type: 1001})
- this.automaticRolling();
- } else {
- this.chatCont.push({
- 'robot_content': redata.data.content,
- 'type': 'machine'
- })
- this.automaticRolling();
- }
- let num = this.chatCont.length - 2;
- if (this.webTime) {
- if (redata.data.time.split(":")[1] - this.webTime.split(":")[1] > 2) {
- this.$set(this.chatCont[num], 'time', redata.data.time);
- this.webTime = redata.data.time;
- } else {
- this.$set(this.chatCont[num], 'time', '');
- }
- } else {
- this.webTime = redata.data.time;
- this.$set(this.chatCont[num], 'time', redata.data.time);
- }
- }
- // 没有客服上线.
- if (redata.message_type == 'notice') {
- this.artAndLeave = 100;
- this.automaticRolling();
- this.machineAndAtl = 10;
- this.jumpArtl = false;
- // console.log(redata.content);
- this.Onlinemsg = redata.content;
- }
- // 客服关闭会话.
- if (redata.message_type == 'closeBysever') {
- //this.goBack(1);
- this.machineAndAtl = 10;
- this.selNum = 0;
- this.showleaveIcon = true;
- this.resigtermsg = true;
- }
- // 客服掉线.
- if (redata.message_type == 'serviceoffline') {
- this.serviceNotOnlineText = redata.msg;
- this.service_on = false;
- this.serverNotOnlin = true;
- this.closeByServer = true;
- }
- // 客服转接
- if (redata.message_type == 'changeKeFuSuccess') {
- this.changeKeFu = true;
- // this.goBack();
- this.customerSviceChat.push({type: 'system', str: 'changeKeFu'})
- this.consult = false;
- }
- // 客服会话超时
- if (redata.message_type == 'overtime') {
- this.willOverTime = true;
- this.automaticRolling();
- // this.goBack();
- this.overTimeMsg = redata.data.content;
- }
- // 客服等待排队
- if (redata.message_type == "inqueue") {
- this.waitingMsg = true;
- this.automaticRolling();
- this.waitingText = redata.content;
- }
- // 客服不在线请稍后再试
- if (redata.message_type == 'kfNotOnlin'){
- this.service_on = false;
- }
- // 评价返回
- if(redata.message_type == "evaluate"){
- if(redata.data.status == 1){
- this.comtSuccess = true;
- }
- }
- // 历史信息
- if(redata.message_type == 'toOld'){
- let obj = redata;
- this.historyMsgtext = obj.data.content;
- obj.data.chatLog.forEach(res => {
- res.content = JSON.parse(res.content)
- this.hisSviceChat.push(res)
- })
- this.customerSviceChat.push({type: 'system', str: 'historyMsg'})
- // console.log(obj.data.chatLog.length,"历史信息数量");
- if(obj.data.chatLog.length >= 3){
- this.selNum = 3;
- this.tokNum = 3;
- }else {
- this.selNum = 0;
- this.tokNum = 0;
- }
- }
- },
- closedWating() {
- this.waitingMsg = false;
- },
- /************关闭会话*******************/
- websocketclose(e) {
- console.log('websocket 关闭会话: ' + e.code, e)
- this.goBack();
- },
- /*************数据发送***************** */
- websocketsend(data) {
- this.websock.send(data);
- },
- /***************************************/
- //socket重连
- reconnect() {
- if (this.lockReconnect) { //这里很关键,因为连接失败之后之后会相继触发 连接关闭,不然会连接上两个 WebSocket
- return
- }
- this.lockReconnect = true;
- this.reconnectData && clearTimeout(this.reconnectData);
- this.reconnectData = setTimeout(() => {
- this.initWebSocket();
- console.log('-----socket重连-----');
- this.lockReconnect = false;
- }, 3000)
- },
- /*************************************/
- //心跳检测
- heatBeat() {
- this.timeoutObj && clearTimeout(this.timeoutObj);
- this.serverTimeoutObj && clearTimeout(this.serverTimeoutObj);
- this.timeoutObj = setTimeout(() => {
- // console.log('发送', {type: 'ping'});
- this.websocketsend(JSON.stringify({type: 'ping'})) //根据后台要求发送
- this.serverTimeoutObj = setTimeout(() => {
- // console.log('------心跳检测close-------')
- this.websock.close(); //如果 5秒之后我们没有收到 后台返回的心跳检测数据 断开socket,断开后会启动重连机制
- }, 5000);
- }, this.timeout)
- },
- /******************消息发送数据处理********************/
- sendMessage() {
- let str = this.information;
- let formatStr = str.replace(/\n/g, '<br/>');
- // 给机器人发送文本消息
- if (this.machineAndAtl == 10) {
- //给机器人发送文本消息-本地储存
- let datas = {
- time: '',
- chat: this.turnFace(this.shieldingKeyword(formatStr)),
- imgUrl: this.img,
- type: 'user'
- }
- this.chatCont.push(datas)
- //消息发送-机器人
- this.websocketsend(JSON.stringify({
- type: 'toRobot',
- data: {
- groups_id: '1',
- robot_name: this.shieldingKeyword(formatStr),
- webTime: this.webTime,
- robotgroups_id: '1',
- }
- }))
- } else if (this.machineAndAtl == 100) { //人工聊天
- // 人工聊天超时隐藏
- this.willOverTime = false;
- // 发送给客服消息-本地储存
- this.customerSviceChat.push({
- time: '',
- content: this.turnFace(this.shieldingKeyword(formatStr)),
- imgUrl: this.img,
- type: 'user',
- });
- //消息发送-客服
- this.websocketsend(JSON.stringify({
- type: 'chatMessage',
- data: {
- from_name: this.user_info.name,
- from_avatar: this.user_info.avatar,
- from_id: this.user_info.id,
- content: JSON.stringify({
- text: formatStr,
- img: this.img,
- type: 'user'
- }),
- webTime: this.webTime,
- to_id: this.service.kf_id,
- to_name: this.service.kf_name,
- sensitiveNumber: this.sensitiveNumber,
- conversationId: this.service.conversationId
- }
- }))
- this.tokNum++;
- // console.log(this.tokNum,"我发的消息");
- }
- // 发送之后清空发送数据
- this.img = '';
- this.information = '';
- //高度自动向上滑动
- this.automaticRolling();
- },
- /*************设置token加密***************** */
- setApiToken(name, controller,modules) {
- return this.$md5.hex_md5(name + 'customer-service' + controller + modules)
- },
- /*************跳转人工客服***************** */
- jumpService(id, name) {
- this.jumpArtl = true;
- this.closeByServer = false;
- this.group = id;
- //人工会话登陆
- let data = {
- 'type': 'userInit',
- data: {
- 'uid': this.user_info.id,
- 'name': this.user_info.name,
- 'avatar': this.user_info.avatar,
- 'group': this.group
- }
- }
- this.websock.send(JSON.stringify(data));
- // 客服类型名称
- this.jumpName = name;
- },
- /*************机器智能回答问题***************** */
- answers(idx) {
- let obj = {
- 'robot_addTime': this.problem[idx].robot_addTime,
- 'robot_content': this.problem[idx].robot_content,
- 'type': 'machine'
- }
- this.information = this.problem[idx].robot_name
- this.sendMessage();
- this.automaticRolling();
- },
- /**************匿名注册**************** */
- registered() {
- let token = localStorage.getItem('token');
- let appuid = this.$public.getQueryString('appuid');
- let tutype = this.$public.getQueryString('tutype');
- if (appuid && tutype >= 1) {
- token = localStorage.getItem('token');
- } else if (!appuid && tutype < 1) {
- token = localStorage.getItem('token');
- } else {
- token = '';
- }
- let data = {
- token: token != null ? token : '',
- appid: this.$public.getQueryString('appid'),
- appuid: this.$public.getQueryString('appuid'),
- }
- // console.log(data,'参数')
- // let obj = {
- // headers: {
- // 'Content-Type': 'application/x-www-form-urlencoded',
- // "apiToken": this.setApiToken('autoreg', 'register', this.currTime, 'index')
- // }
- // }
- this.$http.post('/index/register/autoReg', data).then(res => {
- if(res.data.code == 0){
- this.$message({
- showClose: true,
- message: res.data.msg,
- type: 'error'
- });
- }
- if (res.data.code == 1) {
- this.user_info = res.data.data;
- // console.log(this.user_info,"用户信息")
- localStorage.setItem('uid', res.data.data.id)
- // 游客 token
- localStorage.setItem("token", res.data.data.token);
- localStorage.setItem("tutype", res.data.tutype);
- setTimeout(() => {
- //关闭加载条
- this.allLoadingClose();
- // 初始化websocket
- this.initWebSocket();
- }, 2000);
- }
- });
- },
- /***********聊天滑动的时候滑动滚动条到底部******************* */
- automaticRolling() {
- this.$nextTick(() => {
- let msg = document.getElementById('main') // 获取对象
- msg.scrollTop = msg.scrollHeight // 滚动高度
- })
- },
- /**************获取敏感词**************** */
- getSensitive() {
- let obj = {
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- "apiToken": this.setApiToken('sensitivewords', 'index','index')
- }
- };
- let data = {
- userToken: ''
- }
- this.$axios.post('/api/index/index/sensitiveWords', '', obj).then(res => {
- if (res.data.code == 1) {
- // console.log(res.data.data);
- res.data.data.userSensitive.forEach(res => {
- this.sensitive.push(res.sensitivewords_word)
- })
- }
- })
- },
- /**********判定是否是JSON格式*********** */
- isJSON(str) {
- if (typeof str == 'string') {
- try {
- JSON.parse(str);
- return true;
- } catch (e) {
- //console.log(e);
- return false;
- }
- }
- },
- },
- /**************页面加载中挂载**************** */
- mounted() {
- let self = this;
- this.frceArr = frce.frce;
- this.$axios.get('api/index/index/systime?t=' + new Date()).then(res => {
- if (res.data.code == 1) {
- // 获取系统时间
- let date = res.data.data.time.split(" ");
- date[0] = (new Date(date[0].replace(/-/g, '/')).getTime()) / 1000;
- // this.currTime = date[0];
- this.hourse = date[1];
- this.logo = res.data.data.logo;
- // 获取机器智能问题
- this.getProblem();
- // 匿名注册
- this.registered();
- // 获取聊天次数
- this.getChatNum();
- // 获取敏感词
- this.getSensitive();
- }
- })
- this.paste();
- },
- beforeDestroy(){
- },
- destroyed() {
- this.websock.close() //离开路由之后断开websocket连接
- this.lockReconnect = true;
- clearTimeout(this.reconnectData); //离开清除 timeout
- clearTimeout(this.timeoutObj); //离开清除 timeout
- clearTimeout(this.serverTimeoutObj); //离开清除 timeout
- },
- computed: {
- inforLeng() {
- return this.information.length;
- }
- },
- watch: {
- inforLeng(val) {
- if (val > 0) {
- this.sendCol = true;
- } else {
- this.sendCol = false;
- }
- }
- }
- }
- </script>
- <style scoped>
- .chatBox {
- width: 700px;
- position: relative;
- }
- .el-header {
- background: linear-gradient(90deg, rgba(22, 84, 209, 1) 0%, rgba(9, 52, 173, 1) 100%);
- box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.2);
- }
- .tit {
- height: 100%;
- line-height: 80px;
- text-align: left;
- padding-left: 20px;
- }
- .el-col span {
- font-size: 18px;
- color: #FFFFFF;
- }
- .imgBox {
- text-align: right;
- }
- .imgBox img {
- margin-right: 20px;
- }
- .imgBox img:nth-last-child(1) {
- margin-right: 0
- }
- .el-main {
- background: #fff;
- width: 63%;
- padding: 0;
- }
- .el-aside {
- background: #F5F5F5;
- width: 37%;
- overflow: hidden;
- }
- .cationer{
- height: 570px;
- }
- .cationer, .artificial {
- display: flex;
- justify-content: space-between;
- /* align-items: center; */
- }
- .rt {
- width: 100%;
- box-sizing: inherit;
- }
- .artificial {
- /* width: 150px; */
- /* padding:0 20px; */
- margin-top: 23px;
- margin-bottom: 9px;
- vertical-align: middle;
- /* flex-direction: column;*/
- }
- .infor div {
- margin-bottom: 3px;
- }
- .infor div span, .autograph span {
- color: #999999;
- font-size: 14px;
- font-weight: 400;
- }
- .infor div span:nth-child(2), .autograph span:nth-child(2) {
- color: #666666;
- margin-left: 4px;
- }
- .headPortrait {
- width: 46%;
- height: 100px;
- }
- .headPortrait img {
- width: 100%;
- height: 100%;
- }
- .autograph {
- margin-bottom: 11px;
- }
- .advent {
- border-top: 1px solid #DDDDDD;
- padding: 20px;
- }
- .advent img {
- margin-top: 25px;
- width: 100%;
- }
- .pd {
- padding: 20px;
- }
- .pd20 {
- padding: 0 20px;
- }
- /* 会话 */
- .conversationBox {
- margin-top: 13px;
- margin-bottom: 13px;
- }
- .timer {
- text-align: center;
- margin: 10px 0;
- color: #999999;
- font-size: 12px;
- }
- .headImg {
- width: 40px;
- height: 40px;
- margin-right: 13px;
- }
- .headImg img {
- display: inline-block;
- width: 40px;
- height: 40px;
- }
- .conversation .cont, .customer .cont {
- background: #ffffff;
- padding: 9px 8px 12px 10px;
- display: inline-block;
- border: 1px solid rgba(223, 223, 223, 1);
- border-radius: 5px;
- position: relative;
- max-width: 270px;
- }
- .left::after {
- position: absolute;
- content: "";
- display: inline-block;
- left: -4px;
- top: 5px;
- width: 5px;
- height: 9px;
- background: #fff;
- -webkit-transform: skewX(30deg);
- transform: skewX(30deg);
- /* z-index: -1; */
- border-left: 1px solid #dfdfdf;
- border-top: 1px solid #dfdfdf;
- }
- div.noafter::after {
- content: '';
- width: 0;
- height: 0;;
- display: inline;
- position: relative;
- border: 0;
- }
- .conversation .cont div, .customer .cont div {
- color: #666666;
- font-size: 16px;
- }
- .customer {
- justify-content: space-between;
- }
- .customer .cont {
- margin-right: 13px;
- border: 0;
- background: #5EA0F7;
- max-width: 260px;
- word-wrap: break-word;
- word-break: normal;
- }
- .customer .cont div {
- color: #FFFFFF;
- }
- .right::after {
- position: absolute;
- content: "";
- display: inline-block;
- right: -2px;
- top: 6px;
- width: 5px;
- height: 9px;
- background: #5ea0f7;
- -webkit-transform: skewX(-30deg);
- transform: skewX(-30deg);
- border-left: 1px solid #5ea0f7;
- border-top: 1px solid #5ea0f7;
- }
- .col {
- color: #999999;
- }
- .change {
- color: #5ea0f7;
- }
- .questionList, .changeService {
- margin: 10px;
- border: 1px solid rgba(223, 223, 223, 1);
- border-radius: 5px;
- }
- .questionList div, .changeService div {
- height: 40px;
- line-height: 40px;
- padding-left: 15px;
- }
- .questionList div span {
- color: #5EA0F7;
- font-size: 14px;
- }
- .questionList section:nth-child(odd), .changeService div:nth-child(odd) {
- background: #F6F6F6;
- }
- .changeService div span {
- font-size: 14px;
- }
- .changeService div span:nth-child(1) {
- margin-right: 5px;
- }
- .col6 {
- color: #666666 !important;
- }
- .colE5 {
- color: #5EA0F7;
- }
- .promptBox {
- display: flex;
- justify-content: center;
- height: 26px;
- margin: 10px 0 10px;
- /* line-height: 26px; */
- }
- .promptBoxH {
- display: flex;
- justify-content: center;
- height: 50px;
- margin: 10px 0 10px;
- /* line-height: 26px; */
- }
- .prompt {
- line-height: 25px;
- text-align: center;
- background: #DDDDDD;
- border-radius: 30px;
- width: 140px;
- color: #FFFFFF;
- font-size: 12px;
- }
- .help {
- width: 90%;
- }
- .help .prompt {
- width: 100%;
- }
- /* 评论 */
- .evaluate {
- height: 101px;
- padding: 19px 0 16px;
- background: rgba(255, 255, 255, 1);
- border: 1px solid rgba(223, 223, 223, 1);
- border-radius: 10px;
- margin-top: 15px;
- text-align: center;
- position: relative;
- box-sizing: border-box;
- }
- .evaluate span {
- font-size: 14px;
- color: #666666;
- }
- .nopd {
- padding: 0;
- }
- .nopd i{
- margin-left: 10px;
- width: 8px;
- height: 8px;
- background: #cdcdcd;
- background: #81d981;
- display: inline-block;
- border-radius: 50%;
- }
- .evaluate .btn {
- display: block;
- background: #F04992;
- border-radius: 10px;
- margin-top: 10px;
- color: #FFFFFF;
- height: 36px;
- line-height: 36px;
- width: 100px;
- position: absolute;
- bottom: 16px;
- left: 35%;
- cursor: pointer;
- }
- /* 聊天框 */
- .chatting {
- width: 100%;
- background: rgba(255, 255, 255, 1);
- box-shadow: 0px -5px 5px rgba(0, 0, 0, 0.05);
- height: 100px;
- padding: 10px 20px;
- }
- .informationBox {
- height: 450px;
- overflow: auto;
- }
- .expression, .photo {
- display: inline-block;
- width: 18px;
- height: 18px;
- background: url("./../assets/st-img/expression.png") no-repeat;
- background-size: 100% 100%;
- cursor: pointer;
- margin-right: 18px;
- }
- .expression:hover {
- background: url("./../assets/st-img/expressionHover.png") no-repeat;
- background-size: 100% 100%;
- }
- .photo {
- background: url("./../assets/st-img/photo.png") no-repeat;
- background-size: 100% 100%;
- }
- .photo:hover {
- background: url("./../assets/st-img/photoHover.png") no-repeat;
- background-size: 100% 100%;
- }
- textarea {
- height: 30px;
- width: 300px;
- border: 0;
- -webkit-user-select: auto;
- user-select: auto;
- -o-user-select: auto;
- -ms-user-select: auto;
- resize: none;
- outline: none;
- padding-top: 10px;
- overflow: hidden;
- }
- .sendOut {
- width: 80px;
- height: 44px;
- line-height: 40px;
- border: 1px solid rgba(221, 221, 221, 1);
- border-radius: 5px;
- text-align: center;
- margin-left: 20px;
- }
- .sendOut span {
- color: #CCCCCC;
- font-size: 16px;
- }
- .chattingBox {
- margin-top: 12px;
- }
- /* 评论弹框 */
- .zzBox {
- position: absolute;
- width: 100%;
- height: 100%;
- background: rgba(0, 0, 0, 0.3);
- top: 0;
- left: 0;
- }
- .box-card, .proving {
- width: 494px;
- height: 300px;
- position: absolute;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- z-index: 999;
- border-radius: 10px;
- padding: 20px 20px 30px 50px;
- box-sizing: border-box;
- }
- .proving {
- padding: 20px 20px 30px 47px;
- }
- .close{
- text-align: right;
- cursor: pointer;
- }
- .close i{
- display: inline-block;
- width: 18px;
- height: 18px;
- background: url("./../assets/st-img/close.png") no-repeat;
- background-size: 100% 100%;
- }
- .box-card .tit {
- text-align: center;
- padding-right: 65px;
- margin-bottom: 40px;
- }
- .box-card .tit span {
- font-size: 18px;
- color: #666666;
- }
- .selIcon {
- padding-right: 30px;
- margin-bottom: 30px;
- }
- .selIcon div {
- text-align: center;
- cursor: pointer;
- }
- .selIcon div i {
- display: block;
- width: 44px;
- height: 44px;
- background: url("./../assets/st-img/satisfied.png") no-repeat;
- background-size: 100% 100%;
- margin-bottom: 10px;
- }
- .selIcon div span {
- /* display: block; */
- }
- .selIcon div .comm {
- background: url("./../assets/st-img/comm2.png") no-repeat;
- }
- .selIcon div .sfd {
- background: url("./../assets/st-img/Satisfied2.png") no-repeat;
- }
- .selIcon div .comm2 {
- background: url("./../assets/st-img/comm.png") no-repeat;
- }
- .selIcon div .notSfd {
- background: url("./../assets/st-img/notSatisfied2.png")
- }
- .selIcon div .notSfd2 {
- background: url("./../assets/st-img/notSatisfied.png")
- }
- .levMsg {
- padding-right: 30px;
- margin-bottom: 20px;
- }
- .sure {
- text-align: center;
- background: linear-gradient(90deg, rgba(22, 84, 209, 1) 0%, rgba(9, 52, 173, 1) 100%);
- box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.2);
- border-radius: 10px;
- width: 100px;
- height: 48px;
- line-height: 48px;
- color: #fff;
- position: absolute;
- bottom: 30px;
- left: 37%;
- cursor: pointer;
- }
- /* 验证框 */
- .logo {
- text-align: center;
- margin-bottom: 20px;
- }
- .logo span {
- font-size: 38px;
- font-weight: bold;
- color: #5EA0F7;
- font-family: Microsoft YaHei;
- }
- .logo span:nth-child(1) {
- color: #F04992;
- }
- .formBox {
- padding: 0 27px 0 0;
- }
- .formBox .el-input {
- margin-bottom: 21px;
- }
- .formBox .phone .el-input, .formBox .email .el-input {
- margin-bottom: 0;
- }
- .formBox .phone, .formBox .email {
- margin-bottom: 10px;
- }
- .vertion {
- vertical-align: middle;
- /* margin-bottom: 28px; */
- }
- .vertion .el-input {
- width: 250px;
- margin-right: 15px;
- display: inline-block;
- }
- .vertion span {
- display: inline-block;
- width: 128px;
- height: 40px;;
- vertical-align: middle;
- background: rgba(241, 225, 224, 1);
- }
- .formBox .sure {
- bottom: 21px;
- }
- .el-card__body .tit {
- line-height: 25px;
- }
- .chatting .el-button {
- border: none;
- padding: 0;
- border-radius: 0
- }
- .emoticon {
- width: 30px;
- height: 30px;
- display: inline-block;
- }
- .pointer {
- cursor: pointer;
- }
- .ly:hover {
- border-bottom: 1px solid #5EA0F7;
- /* 高亮效果 */
- filter: brightness(0.9);
- }
- .gl:hover {
- filter: brightness(0.9);
- }
- .seek:hover {
- background: #860c60
- }
- .sendCol {
- background: linear-gradient(90deg, rgba(22, 84, 209, 1) 0%, rgba(9, 52, 173, 1) 100%);
- }
- .netSendCol {
- cursor: not-allowed;
- }
- /* 修改滚动条 */
- ::-webkit-scrollbar-button {
- background: transparent;
- border: 0;
- }
- /* 顶部三个图标 */
- .imgBox i {
- display: inline-block;
- width: 25px;
- height: 25px;
- margin-right: 20px;
- background: url("./../assets/st-img/pj.png") no-repeat;
- background-size: 100% 100%;
- vertical-align: middle;
- }
- .imgBox .sy {
- background: url("./../assets/st-img/sy.png") no-repeat;
- }
- .imgBox .sq {
- background: url("./../assets/st-img/sq.png") no-repeat;
- }
- /* .sc:hover{
- background: url("./../assets/st-img/pjhover.png") no-repeat;
- }
- .sy:hover{
- background: url("./../assets/st-img/sy2.png")no-repeat;
- }
- .sq:hover{
- background: url("./../assets/st-img/sq2.png") no-repeat;
- } */
- i.scActy {
- background: #1654D1 url("./../assets/st-img/pjhover.png") no-repeat;
- width: 33px;
- height: 33px;
- background-position: 5px;
- }
- /* .imgBox .syActy{
- background:#1654D1 url("./../assets/st-img/jzsy.png") no-repeat;
- width: 33px;
- height: 33px;
- background-position: 5px;
- }
- .imgBox .sqActy{
- background: #1654D1 url("./../assets/st-img/sq2.png") no-repeat;
- width: 33px;
- height: 33px;
- transform: rotate(180deg);
- background-position: 5px;
- } */
- .tips {
- font-size: 12px;
- color: #F04992;
- }
- #main {
- position: relative;
- }
- .retract {
- position: absolute;
- right: 0;
- top: 290px;
- z-index: 999;
- }
- /* 滚动条样式 */
- .scroll::-webkit-scrollbar {
- border: 5px solid #fff;
- }
- .scroll::-webkit-scrollbar {
- width: 5px;
- height: 20px;
- }
- .scroll::-webkit-scrollbar-button {
- width: 0px;
- height: 0px;
- }
- .scroll::-webkit-scrollbar-thumb {
- border-radius: 5px;
- box-shadow: inset 0 0 0 5px #aaa;
- border: .02rem solid transparent;
- }
- .scroll::-webkit-scrollbar-track {
- display: block;
- background: rgba(0, 0, 0, 0.1);
- }
- #logo {
- margin-right: 10px;
- width: 40px;
- height: 40px;
- line-height: 40px;
- display: inline-block;
- border-radius: 50%;
- vertical-align: sub;
- position: relative;
- top: 10px;
- }
- .duty {
- display: inline-block;
- width: 60px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- vertical-align: bottom;
- }
- </style>
|