chat.vue 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096
  1. <template>
  2. <div v-loading="allLoading" element-loading-text="拼命连接中">
  3. <div class="chatBox">
  4. <!-- ************************* 头部消息 ************************* -->
  5. <el-header height='80px'>
  6. <el-row type="flex" justify='space-between' align='middle' style="height:100%;">
  7. <el-col class="tit nopd" v-if="machineAndAtl == 10">
  8. <img id="logo" :src="url + logo" alt="">
  9. <span>智能客服</span>
  10. <span style="margin-left: 5px;"><img src="./../assets/st-img/on_icon.png" alt=""></span>
  11. </el-col>
  12. <el-col class="tit nopd" v-else-if="machineAndAtl == 100">
  13. <img id="logo" :src="url + logo" alt="">
  14. <span v-if="service">{{service.serverInfo.name}}</span>
  15. <span v-if="service_on" style="margin-left: 5px;"><img src="./../assets/st-img/on_icon.png" alt=""></span>
  16. <span v-if="!service_on" style="margin-left: 5px;"><img src="./../assets/st-img/off_icon.png" alt=""></span>
  17. </el-col>
  18. <el-col>
  19. <div class="imgBox">
  20. <i v-if="(selNum + tokNum) > 2" @click="ejectEvl(10)" class="sc pointer" :class="selType?'scActy':''">
  21. </i>
  22. <div v-if="showleaveIcon" style="float: right" class="pointer" @click="leaveMsg()">
  23. <span style="font-size: 25px; color: #b3c1e7; margin-top: 13px;" @click="back()"
  24. class="el-icon-chat-line-round"></span>
  25. </div>
  26. <div v-if="!showleaveIcon" style="float: right; cursor: not-allowed">
  27. <span style="font-size: 25px; color: #d6d1c4; margin-top: 13px;"
  28. class="el-icon-chat-line-round"></span>
  29. </div>
  30. </div>
  31. </el-col>
  32. </el-row>
  33. </el-header>
  34. <div class="cationer">
  35. <!--****************************** 聊天会话框模块 *****************************-->
  36. <el-main>
  37. <!-- 广告展示隐藏按钮 -->
  38. <div class="retract pointer" @click="retract()">
  39. <img src="./../assets/st-img/retract.png" alt="" v-if="retractShow">
  40. <img src="./../assets/st-img/retract2.png" alt="" v-else>
  41. </div>
  42. <el-row class="pd informationBox scroll" id="main">
  43. <!-------------------机器人聊天板块 ----------------------->
  44. <div v-if="machineAndAtl == 10">
  45. <!--··············· 欢迎语 ············-->
  46. <div class="conversationBox">
  47. <div class="row" v-for="(item,index) in machine" :key="index">
  48. <div class="conversation row">
  49. <div class="headImg">
  50. <img src="./../assets/st-img/headAdvent.png" alt="">
  51. </div>
  52. <div class="cont left">
  53. <div v-html="item"></div>
  54. </div>
  55. </div>
  56. <div style="width:66px;"></div>
  57. </div>
  58. </div>
  59. <!--··········· 快捷问题回答模块 ············-->
  60. <div class="questionList" v-if="questionShow">
  61. <section v-for="(item,idx) in problem" :key="item.id">
  62. <div @click="answers(idx)">
  63. <span class="pointer gl">{{item.robot_name}}</span>
  64. </div>
  65. </section>
  66. <section>
  67. <div>
  68. <span class="col6">上面问题都不是</span>
  69. <span class="pointer ly" @click="changeService()">转人工客服</span>
  70. </div>
  71. </section>
  72. </div>
  73. <!--················ 和机器人会话发送消息 ·············-->
  74. <div v-for="item in chatCont" :key="item.id">
  75. <!-- 用户发文本信息 -->
  76. <div class="conversationBox" v-if="item.type =='user'">
  77. <div class="timer">{{item.time}}</div>
  78. <div class="customer row allAlignment">
  79. <div style="width:66px;"></div>
  80. <div class="row">
  81. <!-- 显示内容 -->
  82. <div v-if="item.chat" class="cont right">
  83. <div v-html="item.chat"></div>
  84. </div>
  85. <div v-else class=" right noafter" style="width:200px;margin-right:10px; ">
  86. <div slot="file">
  87. <img class="el-upload-list__item-thumbnail"
  88. @click="handlePictureCardPreview(url+item.imgUrl)"
  89. style="width:100%;height:auto;border-radius: 10px;"
  90. :src="url+item.imgUrl" alt="">
  91. </div>
  92. </div>
  93. <!-- 图片放大 -->
  94. <el-dialog :visible.sync="dialogVisible">
  95. <img width="100%" :src="dialogImageUrl" alt="">
  96. </el-dialog>
  97. <!-- 头像 -->
  98. <div class="headImg">
  99. <img :src="user_info.avatar" alt="">
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. <!-- 机器人无法回答转人工 -->
  105. <div class="conversationBox" v-if="item.type == 1001">
  106. <div class=" row">
  107. <div class="conversation row">
  108. <div class="headImg">
  109. <img src="./../assets/st-img/headAdvent.png" alt="">
  110. </div>
  111. <div class="cont left">
  112. <div>您的问题暂时无法处理</div>
  113. <div>
  114. <span class="col">问题没有解决?</span>
  115. <span class="change pointer ly"
  116. @click="changeService()">转人工客服</span>
  117. </div>
  118. </div>
  119. </div>
  120. <div style="width:66px;"></div>
  121. </div>
  122. </div>
  123. <!-- 机器人回答 -->
  124. <div class="conversationBox" v-else-if='item.type == "service"'>
  125. <div class=" row">
  126. <div class="conversation row">
  127. <div class="headImg">
  128. <img src="./../assets/st-img/headAdvent.png" alt="">
  129. </div>
  130. <div class="cont left">
  131. <div>{{item.cont}}</div>
  132. </div>
  133. </div>
  134. <div style="width:66px;"></div>
  135. </div>
  136. </div>
  137. <!-- 快捷问题回答 -->
  138. <div class="conversationBox" v-else-if="item.type == 'machine'">
  139. <div class="timer">
  140. {{item.robot_addTime}}
  141. </div>
  142. <div class=" row">
  143. <div class="conversation row">
  144. <div class="headImg">
  145. <img src="./../assets/st-img/headAdvent.png" alt="">
  146. </div>
  147. <div class="cont left">
  148. <div>{{item.robot_content}}</div>
  149. <div>
  150. <span class="col">问题没有解决</span>
  151. <span class="change pointer ly"
  152. @click="changeService()">转人工客服</span>
  153. </div>
  154. </div>
  155. </div>
  156. <div style="width:66px;"></div>
  157. </div>
  158. </div>
  159. <!-- 转接客服列表 -->
  160. <div class="changeService" v-else-if="item.type == 'artService'">
  161. <div v-for="(itemList,idx) in serviceList" :key="idx">
  162. <span class="col6">人工客服:</span>
  163. <span class="colE5 pointer gl" @click="jumpService(itemList.id, itemList.name)">{{itemList.name}}</span>
  164. </div>
  165. </div>
  166. </div>
  167. <!--············· 各种消息提示框 ··············-->
  168. <!-- 客服不在线帮助提示框 -->
  169. <div class="promptBox" v-if="artAndLeave == 100">
  170. <div class="prompt help">
  171. <span>{{jumpName + Onlinemsg}}</span>
  172. <span class="colE5 ly pointer" @click="leaveMsg()">留言</span>
  173. </div>
  174. </div>
  175. <!-- 排队等待 -->
  176. <div class="evaluate" v-if="waitingMsg">
  177. <span>{{waitingText}}</span>
  178. <el-button type="primary" style="margin: 10px auto; display: block;"
  179. @click="closedWating">退出排队
  180. </el-button>
  181. </div>
  182. </div>
  183. <!--············ 和人工会话聊天模块 ··············-->
  184. <div v-if="machineAndAtl == 100">
  185. <!-- 人工客服回复消息 -->
  186. <div v-for="item in customerSviceChat" :key="item.id">
  187. <!-- tem.cont != '' -->
  188. <div class="conversationBox" v-if="item.type == 'service' ">
  189. <div class="timer" v-html="item.time"></div>
  190. <div class="row">
  191. <div class="conversation row">
  192. <div class="headImg">
  193. <img :src="serviceImg?url+serviceImg:require('@/assets/st-img/kf.png')"
  194. alt="">
  195. </div>
  196. <div class="cont left">
  197. <div v-if="item.content != ''" v-html="item.content"></div>
  198. <div v-else slot="file">
  199. <img class="el-upload-list__item-thumbnail"
  200. @click="handlePictureCardPreview(url+item.imgUrl)"
  201. style="width:100%;height:auto;border-radius: 10px;"
  202. :src="url+item.imgUrl" alt="">
  203. </div>
  204. </div>
  205. </div>
  206. <div style="width:66px;"></div>
  207. </div>
  208. </div>
  209. <!-- 用户发送文本消息 -->
  210. <div class="conversationBox" v-if="item.type == 'user' ">
  211. <div>
  212. <div class="timer">{{item.time}}</div>
  213. <div class="customer row allAlignment">
  214. <div style="width:66px;"></div>
  215. <div class="row">
  216. <div class="cont right">
  217. <div v-if="item.content != ''" v-html="item.content"></div>
  218. <div v-else slot="file">
  219. <img class="el-upload-list__item-thumbnail"
  220. @click="handlePictureCardPreview(url+item.imgUrl)"
  221. style="width:100%;height:auto;border-radius: 10px;"
  222. :src="url+item.imgUrl" alt="">
  223. </div>
  224. </div>
  225. <div class="headImg">
  226. <img :src="user_info.avatar" alt="">
  227. </div>
  228. </div>
  229. </div>
  230. </div>
  231. </div>
  232. <div v-if="item.type == 'system' ">
  233. <!-- 客服会话转接 -->
  234. <div class="promptBox" v-if="item.str == 'changeKeFu'">
  235. <div class="prompt help">
  236. <span>会话转接成功</span>
  237. </div>
  238. </div>
  239. </div>
  240. <!-- 点击图片放大 -->
  241. <el-dialog :visible.sync="dialogVisible">
  242. <img width="100%" :src="dialogImageUrl" alt="">
  243. </el-dialog>
  244. </div>
  245. <!-- 评价 -->
  246. <div class="evaluate" @click="ejectEvl(10)" v-if="consult">
  247. <span>欢迎你的咨询,请对我们的服务做出评价</span>
  248. <span class="btn seek">评价</span>
  249. </div>
  250. <div class="promptBox " v-if="comtSuccess">
  251. <div class="prompt help">
  252. <span>您对我们的服务评价为: {{comtCount}}。非常感谢!</span>
  253. </div>
  254. </div>
  255. <!-- 客服会话超时 -->
  256. <div class="promptBox" v-if="willOverTime">
  257. <div class="prompt help">
  258. <span>{{overTimeMsg}}</span>
  259. </div>
  260. </div>
  261. </div>
  262. <!-- 发送消息音频提示 -->
  263. <audio id="send" src="../../static/send.wav"></audio>
  264. <!-- 接收消息音频提示 -->
  265. <audio id="receive" src="../../static/receive.wav"></audio>
  266. </el-row>
  267. <!--·········· 文本编辑框 ···········-->
  268. <el-row class="chatting">
  269. <el-col>
  270. <!-- 发送图和表情按钮 -->
  271. <div style="height:18px; display:flex;">
  272. <el-popover placement="top-start" width="200" trigger="hover"
  273. style="margin-top: -2px;">
  274. <ul>
  275. <li class="emoticon" v-for="(item,index) in frceArr" :key="item.id">
  276. <img class="pointer" :src="require(`@/assets/st-img/${index}.gif`)"
  277. @click="memeImg(index)" alt="">
  278. </li>
  279. </ul>
  280. <el-button class="expression" slot="reference"></el-button>
  281. </el-popover>
  282. <el-upload class="avatar-uploader" action="/api/index/upload/uploadImg"
  283. :on-success="handleAvatarSuccess"
  284. :before-upload="beforeAvatarUpload"
  285. :on-error='handError'
  286. list-type='no' accept="image/jpeg,image/jpg,image/png,image/svg">
  287. <!-- <img v-if="imageUrl" :src="imageUrl" class="avatar"> -->
  288. <i slot="default" class=" photo"></i>
  289. </el-upload>
  290. </div>
  291. <div class="row center allAlignment chattingBox">
  292. <div style="height:44px;width:300px;">
  293. <textarea name=""
  294. id="information"
  295. v-model.trim="information"
  296. cols="30"
  297. rows="1"
  298. autofocus
  299. placeholder="请输入你的问题:"
  300. @keyup.enter="listenEnter($event)"
  301. >
  302. </textarea>
  303. </div>
  304. <div>
  305. <!-- 准备修改 -->
  306. <div @click="sendCol?(!closeByServer||artAndLeave==0||artAndLeave==100?sendInfo():''):''"
  307. class="sendOut pointer"
  308. :class="sendCol?(!closeByServer||artAndLeave==0||artAndLeave==100?'sendCol':'netSendCol'):'netSendCol'">
  309. <span class="">发送</span>
  310. </div>
  311. </div>
  312. </div>
  313. </el-col>
  314. </el-row>
  315. </el-main>
  316. <el-aside width='255px' v-if="retractShow">
  317. <el-row class="rt">
  318. <div v-if="machineAndAtl == 10">
  319. <el-col :span='24' class="artificial pd20">
  320. <div class="infor">
  321. <div>
  322. <span>姓名:</span>
  323. <span>智能客服</span>
  324. </div>
  325. <div>
  326. <span>工号:</span>
  327. <span>001</span>
  328. </div>
  329. <div>
  330. <span>性别:</span>
  331. <span>保密</span>
  332. </div>
  333. <div>
  334. <span>职务:</span>
  335. <span>咨询客服</span>
  336. </div>
  337. </div>
  338. <div class="headPortrait">
  339. <img :src="require('@/assets/st-img/kf.png')" alt="">
  340. </div>
  341. </el-col>
  342. <el-col class="autograph pd20">
  343. <div>
  344. <span>个性签名:</span>
  345. <span></span>
  346. </div>
  347. </el-col>
  348. </div>
  349. <div v-if="machineAndAtl == 100">
  350. <el-col :span='24' class="artificial pd20">
  351. <div class="infor">
  352. <div>
  353. <span>姓名:</span>
  354. <span v-if="service">{{ service.serverInfo.name ? service.serverInfo.name : '001客服' }}</span>
  355. </div>
  356. <div>
  357. <span>工号:</span>
  358. <span>{{service.serverInfo ? service.serverInfo.job_name : '001'}}</span>
  359. </div>
  360. <div>
  361. <span>性别:</span>
  362. <span>保密</span>
  363. </div>
  364. <div>
  365. <span>职务:</span>
  366. <span>咨询客服</span>
  367. </div>
  368. </div>
  369. <div class="headPortrait">
  370. <img :src="service.serverInfo ? service.serverInfo.avatar ? (url+service.serverInfo.avatar) :require('@/assets/st-img/kf.png') : require('@/assets/st-img/kf.png')"
  371. alt="">
  372. </div>
  373. </el-col>
  374. <el-col class="autograph pd20">
  375. <div>
  376. <span>个性签名:</span>
  377. <span>{{service.serverInfo ? service.serverInfo.signature :'' }}</span>
  378. </div>
  379. </el-col>
  380. </div>
  381. <el-col class="advent" v-for="imgs in advert" :key="imgs.id">
  382. <a :href="'http://'+imgs.advertisement_url" target="_blank" rel="noopener noreferrer">
  383. <img :src="url + imgs.advertisement_img" alt="">
  384. </a>
  385. </el-col>
  386. </el-row>
  387. </el-aside>
  388. </div>
  389. <!-- 评价框 -->
  390. <el-card class="box-card" v-if="evlShow">
  391. <div class="close"><i @click="closeEvl()"></i></div>
  392. <div class="tit">
  393. <span>感谢您的咨询,请对我们的服务做出评价</span>
  394. </div>
  395. <div class="selIcon row allAlignment">
  396. <div @click="chage(1)">
  397. <i :class="changeIcon == 10? '':'sfd'"></i>
  398. <span>满意</span>
  399. </div>
  400. <div @click="chage(2)">
  401. <i class="comm" :class="changeIcon == 100?'comm2':''"></i>
  402. <span>一般</span>
  403. </div>
  404. <div @click="chage(3)">
  405. <i class="notSfd" :class="changeIcon == 1000?'notSfd2':''"></i>
  406. <span>不满意</span>
  407. </div>
  408. </div>
  409. <div class="sure" @click="evaluateSure()">
  410. <span>确定</span>
  411. </div>
  412. </el-card>
  413. <div class="zzBox" v-if="zzShow"></div>
  414. </div>
  415. </div>
  416. </template>
  417. <script>
  418. import '../css/index.css';
  419. import frce from '../assets/frce.js';
  420. export default {
  421. data() {
  422. return {
  423. textarea: '',//备注
  424. evlShow: false, // 评价框显示
  425. zzShow: false, // 遮罩层显示
  426. vertion: '',//图形验证码
  427. provShow: true, // 验证框显示
  428. changeIcon: 10,
  429. name: '', // 验证框姓名model
  430. phone: '',// 验证框电话model
  431. email: '',// 验证框邮箱model
  432. frceArr: [], //表情包代码
  433. information: '',//发送的文本信息
  434. sendCol: false, // 发送按钮切换样式
  435. selType: false, //图标选中样式 true为选中,false为未选中
  436. selNum: 0, // 服务端消息数量
  437. tokNum: 0, // 用户端消息数量
  438. // syType : false,
  439. // sqType : false,
  440. error: false,
  441. emlError: false,
  442. artAndLeave: 0, // 默认为100,转人工为10,人工不在转留言为100
  443. chatCont: [], // 客户会话数据
  444. imageUrl: [],//上传图片
  445. img: '', //上传的单个图片路径
  446. dialogVisible: false, //图片放大
  447. dialogImageUrl: '', // 放大的图片
  448. dialogUrl: false,
  449. serviceInfor: '', //客服信息
  450. websock: null, //会话初始值
  451. currTime: "", //获取系统时间
  452. apiToken: '',//系统Token
  453. machine: [], //机器会话信息
  454. advert: '', // 广告语
  455. problem: '', //机器智能问题
  456. macNotPro: false, //机器人问题无法解决显示
  457. answer: [], //解答问题的答案
  458. questionShow: true, // 问题显示
  459. consult: false, //评价模块显示
  460. type: 1001, //自增
  461. jumpArtl: false, // 跳转人工客服状态
  462. group: '', //客服组
  463. userConversation: {}, //用户当前会话
  464. machineAndAtl: 10, //默认为机器人,100为人工
  465. satisfaction: 1, //评价满意度,1为满意,2为一般,3为不满意
  466. url: 'http://kfadmin.bocai186.com', // 域名地址
  467. // url: 'http://192.168.2.187:8090', // 域名地址
  468. user_info: '', // 用户信息
  469. // 人工客服信息
  470. service: '',
  471. serviceList: [], //后台推送的人工客服列表
  472. customerWelCome: '', // 客服欢迎语
  473. customerSviceChat: [], // 客服会话信息
  474. serviceImg: '',
  475. timerVote: '', //存储上一次时间
  476. curtTimer: '',//当前时间
  477. returnTimer: '',//返回当前时间
  478. // isConnection:true,//人工分组列表开关
  479. chatNum: '', // 会话数量
  480. comtSuccess: false, // 评论发送成功显示
  481. comtCount: '', // 评论成功返回的满意度
  482. retractShow: true, // 展开侧边栏
  483. sensitive: [], //敏感词1
  484. senType: false,//敏感词状态
  485. sensitiveNumber: 0,//敏感词次数
  486. doubSensitive: [],//重复的敏感词
  487. senInfo: '', //敏感词数据
  488. // sensitiveWordsNumber:0,
  489. hourse: '', //返回时间,小时
  490. closeByServer: false, //客服关闭会话
  491. serverNotOnlin: false, //客服掉线
  492. willOverTime: false, //超时关闭会话
  493. overTimeMsg: '', // 超时提示内容
  494. allLoading: true, //整个页面加载中
  495. webTime: '',//网络时间
  496. changeKeFu: false, //客服转接
  497. /*****************websockt心跳变量*******************/
  498. reconnectData: null,
  499. lockReconnect: false, //避免重复连接,因为onerror之后会立即触发 onclose
  500. timeout: 10000, //10s一次心跳检测
  501. timeoutObj: null,
  502. serverTimeoutObj: null,
  503. logo: '', // logo 图片
  504. Onlinemsg: "", // 系统留言信息
  505. showleaveIcon: true, // 留言按钮触发条件
  506. jumpName: '', // 根据类型提示售后服务名称
  507. waitingMsg: false, // 是否显示等待排队
  508. waitingText: "", // 等待内容
  509. service_on:true, // 现在状态
  510. }
  511. },
  512. methods: {
  513. // 关闭评价框按钮
  514. closeEvl(){
  515. this.evlShow = false;
  516. this.zzShow = false;
  517. },
  518. // 消息发送
  519. sendAudio() {
  520. let send = document.getElementById('send')
  521. send.play()
  522. },
  523. // 消息接收
  524. receiveAudio() {
  525. let receive = document.getElementById('receive')
  526. receive.play();
  527. },
  528. // 回车提交
  529. listenEnter(event) {
  530. let text = document.getElementById('information');
  531. if (event.keyCode == 13 && event.ctrlKey == true) {
  532. text.value = text.value + '\n'
  533. } else if (event.keyCode == 13) {
  534. if (this.information == "") {
  535. text.value = '';
  536. return false
  537. } else {
  538. this.sendInfo();
  539. event.preventDefault()
  540. }
  541. }
  542. },
  543. // 切换留言板返回
  544. back() {
  545. this.$emit('value', 100)
  546. },
  547. /******************文字信息转表情******************/
  548. turnFace(data) {
  549. let str = data.match(/\#\[.*?\]\//g);
  550. let arr = Array.from(new Set(str));
  551. arr.forEach(e => {
  552. let imgsrc = '';
  553. for (let i = 0; i < this.frceArr.length; i++) {
  554. let expText = e.slice(1, e.length - 1);
  555. if (expText == this.frceArr[i]) {
  556. imgsrc = '<img class="hover" src="' + require(`@/assets/st-img/${i}.gif`) + '"/>'
  557. break;
  558. }
  559. }
  560. data = data.replace(new RegExp(`\\#\\[${e.substring(2, e.length - 2)}\\]\\/`, 'g'), imgsrc);
  561. })
  562. return data;
  563. },
  564. // 关闭加载中
  565. allLoadingClose() {
  566. this.allLoading = false;
  567. },
  568. /**************切换显示客服信息**************** */
  569. retract() {
  570. this.retractShow = !this.retractShow;
  571. },
  572. /***************发送图片***************/
  573. beforeAvatarUpload(file) {
  574. let self = this
  575. const isJPG = file.type == 'image/jpeg' || 'image/jpg' || 'image/png' || 'image/svg';
  576. const isLt2M = file.size / 1024 / 1024 < 2;
  577. if (!isJPG) {
  578. this.$message.error('上传只能是图片格式!');
  579. }
  580. if (!isLt2M) {
  581. this.$message.error('上传图片大小不能超过 2MB!');
  582. }
  583. //对图片进行压缩
  584. const imgSize = file.size / 1024 / 1024;
  585. if (imgSize > 0.5) {
  586. const _this = this
  587. return new Promise(resolve => {
  588. const reader = new FileReader()
  589. const image = new Image()
  590. image.onload = (imageEvent) => {
  591. const canvas = document.createElement('canvas');
  592. const context = canvas.getContext('2d');
  593. const width = image.width * 0.4;
  594. const height = image.height * 0.4;
  595. canvas.width = width;
  596. canvas.height = height;
  597. context.clearRect(0, 0, width, height);
  598. context.drawImage(image, 0, 0, width, height);
  599. const dataUrl = canvas.toDataURL(file.type);
  600. const blobData = _this.dataURItoBlob(dataUrl, file.type);
  601. resolve(blobData)
  602. }
  603. reader.onload = (e => {
  604. image.src = e.target.result;
  605. });
  606. reader.readAsDataURL(file);
  607. })
  608. }
  609. },
  610. dataURItoBlob(dataURI, type) {
  611. var binary = atob(dataURI.split(',')[1]);
  612. var array = [];
  613. for (var i = 0; i < binary.length; i++) {
  614. array.push(binary.charCodeAt(i));
  615. }
  616. return new Blob([new Uint8Array(array)], {type: type});
  617. },
  618. handError(err, file, fileList) {
  619. // 获取当前发送时间
  620. console.log(err, '上传图片报错!')
  621. },
  622. /***************传输成功之后返回图片*************** */
  623. handleAvatarSuccess(res, file) {
  624. // console.log(res)
  625. this.dialogUrl = true;
  626. this.img = res.data.src;
  627. this.sendMessage();
  628. },
  629. /***************图片放大*************** */
  630. handlePictureCardPreview(url) {
  631. this.dialogImageUrl = url;
  632. this.dialogVisible = true;
  633. },
  634. /***************弹出评价框*************** */
  635. ejectEvl(type) {
  636. if (this.comtSuccess) return;
  637. this.changeIcon = 10;
  638. if (type == 10) {
  639. this.evlShow = true
  640. }
  641. this.zzShow = true;
  642. },
  643. /***************传入父组件进行组件切换*************** */
  644. leaveMsg() {
  645. this.$emit('value', 100)
  646. },
  647. //回到初始页面
  648. goBack(type) {
  649. if (type === 1) {
  650. this.artAndLeave = 0;
  651. this.chatCont = [];
  652. } else {
  653. this.machineAndAtl = 10;
  654. this.macNotPro = false;
  655. this.jumpArtl = false;
  656. this.willOverTime = false;
  657. this.waitingMsg = false;
  658. this.time = '';
  659. this.returnTimer = '';
  660. // this.automaticRolling();
  661. this.customerSviceChat = [];
  662. this.reconnect();
  663. }
  664. },
  665. /*******发送消息按钮*******/
  666. sendInfo() {
  667. this.closeByServer = false;
  668. this.artAndLeave = 0;
  669. this.jumpArtl = false;
  670. this.dialogUrl = false;
  671. this.sendMessage();
  672. this.sendAudio();
  673. },
  674. /***************改变评价框的满意度*************** */
  675. chage(type) {
  676. this.satisfaction = type;
  677. if (type == 1) {
  678. this.comtCount = '满意'
  679. this.changeIcon = 10;
  680. } else if (type == 2) {
  681. this.comtCount = '一般'
  682. this.changeIcon = 100;
  683. } else {
  684. this.comtCount = '不满意'
  685. this.changeIcon = 1000;
  686. }
  687. },
  688. /***************图标样式切换*************** */
  689. select(type) {
  690. if (type == 1) {
  691. this.selType = !this.selType;
  692. } else if (type == 2) {
  693. this.syType = !this.syType;
  694. } else {
  695. this.sqType = !this.sqType;
  696. }
  697. },
  698. /***************评价确认*************** */
  699. evaluateSure() {
  700. this.websocketsend(JSON.stringify({
  701. type: 'evaluate',
  702. data: {
  703. evaluate_id: this.satisfaction,
  704. conversationId: this.service.conversationId,
  705. evaluate_content: this.textarea
  706. }
  707. }))
  708. this.evlShow = false;
  709. this.zzShow = false;
  710. this.textarea = '';
  711. this.consult = false;
  712. if (this.changeIcon == 10) {
  713. this.comtCount = '满意'
  714. }
  715. },
  716. /***************验证框确认*************** */
  717. yySure() {
  718. this.provShow = false;
  719. this.zzShow = false;
  720. },
  721. /***************转人工客服列表*************** */
  722. changeService() {
  723. // if(!this.isConnection) return
  724. this.$axios.post('/api/index/groups/index', {}, {
  725. headers: {
  726. 'Content-Type': 'application/x-www-form-urlencoded',
  727. 'apiToken': this.setApiToken('index', 'groups', this.currTime, 'index')
  728. }
  729. }).then(res => {
  730. if (res.data.code == 1) {
  731. this.serviceList = res.data.data;
  732. this.chatCont.push({
  733. 'type': 'artService'
  734. })
  735. this.automaticRolling();
  736. }
  737. })
  738. // this.isConnection = false;
  739. },
  740. /***************表情点击*************** */
  741. memeImg(i) {
  742. //当表情被点击
  743. this.information = this.information + "#" + this.frceArr[i] + "/";
  744. },
  745. /***************失去焦点做正则验证*************** */
  746. sureInfor(type) {
  747. if (type == 1) {
  748. if (!/^1[34578]\d{9}$/.test(this.phone)) {
  749. this.error = true;
  750. this.phone = '';
  751. } else {
  752. this.error = false;
  753. }
  754. } else if (type == 10) {
  755. if (!/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(this.email)) {
  756. this.emlError = true;
  757. this.email = '';
  758. } else {
  759. this.emlError = false;
  760. }
  761. }
  762. },
  763. /***************获取热点智能问题*************** */
  764. getProblem() {
  765. this.$axios.post('/api/index/robot/index', {groups_id: 1, robotgroups_id: 1}, {
  766. headers: {
  767. 'Content-Type': 'application/x-www-form-urlencoded',
  768. 'apiToken': this.setApiToken('index', 'robot', this.currTime, 'index')
  769. }
  770. }).then(res => {
  771. if (res.data.code == 1) {
  772. this.problem = res.data.data;
  773. }
  774. })
  775. },
  776. /*****************获取聊天次数*******************/
  777. getChatNum() {
  778. this.$axios.post('/api/index/evaluate/minRound', '', {
  779. headers: {
  780. 'Content-Type': 'application/x-www-form-urlencoded',
  781. 'apiToken': this.setApiToken('minround', 'evaluate', this.currTime, 'index')
  782. }
  783. }).then(res => {
  784. if (res.data.code == 1) {
  785. this.chatNum = res.data.data.systemconfig_data
  786. }
  787. })
  788. },
  789. /*****************屏蔽关键字******************/
  790. shieldingKeyword(data) {
  791. //将敏感词组用|转换字符串
  792. let snstive = this.sensitive.join('|');
  793. //console.log(snstive);
  794. this.sensitiveNumber = 0;
  795. //匹配出会话中的敏感词
  796. return data.replace(eval('/' + snstive + '/g'), (res) => {
  797. var str = '';
  798. for (var i = 0; i < res.length; i++) {
  799. str += '*';
  800. }
  801. this.sensitiveNumber++;
  802. return str;
  803. })
  804. },
  805. /*---------------------------------------------------------------------------------*/
  806. /**************初始化WebSocket****************/
  807. initWebSocket() {
  808. let _this = this;
  809. let apiToken = this.$md5.hex_md5('customer-service' + this.currTime + window.location.origin);
  810. this.websock = new WebSocket('ws://103.108.43.176:9101?apiToken=' + apiToken);
  811. // this.websock = new WebSocket('ws://192.168.2.187:9101?apiToken=' + apiToken);
  812. this.websock.debug = true;
  813. // 数据接收
  814. this.websock.onmessage = this.websocketonmessage;
  815. // 连接建立之后
  816. this.websock.onopen = this.websocketonopen;
  817. // 连接建立失败重连
  818. this.websock.onerror = this.websocketonerror;
  819. // 关闭会话
  820. this.websock.onclose = this.websocketclose;
  821. },
  822. /****************连接建立成功***************/
  823. websocketonopen() {
  824. console.log('链接成功');
  825. // 如果有传 group_id 直接跳转人工客服
  826. let group_id = this.$public.getQueryString("group_id");
  827. if (group_id) {
  828. this.jumpService(group_id);
  829. }
  830. //心跳检测
  831. this.heatBeat()
  832. },
  833. /*************连接建立失败重连***************** */
  834. websocketonerror(e) {
  835. console.log('连接建立失败重连:', e)
  836. this.goBack(1);
  837. },
  838. /**************数据接收***************** */
  839. websocketonmessage(e) {
  840. let redata = e
  841. if (e.data) {
  842. redata = JSON.parse(e.data);
  843. }
  844. //心跳检测
  845. this.heatBeat();
  846. if (redata.type != 'pong') {
  847. console.log(redata)
  848. }
  849. // 欢迎语
  850. if (redata.message_type == 'helloMessage') {
  851. this.machine.push(redata.data.content)
  852. }
  853. // 广告语
  854. if (redata.message_type == 'advertisement') {
  855. this.advert = redata.data;
  856. }
  857. // 评价
  858. if (redata.message_type == 'getEvaluate') {
  859. this.consult = true;
  860. }
  861. //返回的会话时间
  862. if (redata.message_type == 'webTime') {
  863. //处理会话时间大于两分钟显示会话时间并且储存本次会话时间
  864. if (this.machineAndAtl == 100) {
  865. let num = this.customerSviceChat.length - 1;
  866. if (this.customerSviceChat[num].type == "user") {
  867. if (redata.data.webTime.split(":")[1] - this.webTime.split(":")[1] > 2) {
  868. this.$set(this.customerSviceChat[num], 'time', redata.data.webTime);
  869. this.webTime = redata.data.webTime;
  870. } else {
  871. this.$set(this.customerSviceChat[num], 'time', '');
  872. }
  873. }
  874. }
  875. }
  876. //会话超时提示
  877. if (redata.message_type == 'overtime') {
  878. console.log('接收会话超时');
  879. }
  880. // 链接客服信息
  881. if (redata.message_type == 'connect') {
  882. this.artAndLeave = 10;
  883. this.machineAndAtl = 100;
  884. this.service = redata.data;
  885. // console.log(this.service, '============客服信息')
  886. this.serviceImg = redata.data.serverInfo.avatar;
  887. this.consult = false;
  888. this.evlShow = false;
  889. this.comtSuccess = false;
  890. this.showleaveIcon = false;
  891. this.waitingMsg = false;
  892. }
  893. // 暂无客服
  894. if (redata.message_type == 'wait') {
  895. let content = JSON.parse(redata.data.content)
  896. this.artAndLeave = 100;
  897. }
  898. //接收客服会话
  899. if (redata.message_type == 'chatMessage') {
  900. // 接收提示音
  901. this.receiveAudio();
  902. //存储会话超时间
  903. this.webTime = redata.data.time;
  904. //会话大于两分钟显示
  905. let timer = ''
  906. if (this.returnTimer == '') {
  907. timer = redata.data.time;
  908. this.returnTimer = redata.data.time
  909. } else {
  910. let timeStamp = this.returnTimer.split(":");
  911. let rdtime = redata.data.time.split(":");
  912. if (timeStamp[0] == rdtime[0]) {
  913. if ((rdtime[1] - timeStamp[1]) < 2) {
  914. timer = ''
  915. } else {
  916. timer = redata.data.time;
  917. }
  918. }
  919. }
  920. let contType = this.isJSON(redata.data.content);
  921. let content = {};
  922. if (contType == false) {
  923. content.text = redata.data.content
  924. } else {
  925. content = JSON.parse(redata.data.content)
  926. }
  927. let obj = {
  928. time: timer,
  929. content: content.text ? this.turnFace(content.text) : '',
  930. imgUrl: content.img ? content.img : '',
  931. type: 'service'
  932. }
  933. this.customerSviceChat.push(obj);
  934. // console.log(this.customerSviceChat);
  935. this.selNum++;
  936. this.automaticRolling();
  937. }
  938. //接收机器会话
  939. if (redata.message_type == 'robotMessage') {
  940. if (redata.data.content == 'error') {
  941. let _this = this;
  942. this.chatCont.push({type: 1001})
  943. this.automaticRolling();
  944. } else {
  945. this.chatCont.push({
  946. 'robot_content': redata.data.content,
  947. 'type': 'machine'
  948. })
  949. this.automaticRolling();
  950. }
  951. let num = this.chatCont.length - 2;
  952. if (this.webTime) {
  953. if (redata.data.time.split(":")[1] - this.webTime.split(":")[1] > 2) {
  954. this.$set(this.chatCont[num], 'time', redata.data.time);
  955. this.webTime = redata.data.time;
  956. } else {
  957. this.$set(this.chatCont[num], 'time', '');
  958. }
  959. } else {
  960. this.webTime = redata.data.time;
  961. this.$set(this.chatCont[num], 'time', redata.data.time);
  962. }
  963. }
  964. // 没有客服上线.
  965. if (redata.message_type == 'notice') {
  966. this.artAndLeave = 100;
  967. this.automaticRolling();
  968. this.machineAndAtl = 10;
  969. this.jumpArtl = false;
  970. // console.log(redata.content);
  971. this.Onlinemsg = redata.content;
  972. }
  973. // 客服关闭会话.
  974. if (redata.message_type == 'closeBysever') {
  975. this.goBack(1);
  976. this.machineAndAtl = 10;
  977. this.selNum = 0;
  978. }
  979. // 客服掉线.
  980. if (redata.message_type == 'serviceoffline') {
  981. this.serverNotOnlin = true;
  982. this.closeByServer = true;
  983. this.automaticRolling();
  984. }
  985. // 客服转接
  986. if (redata.message_type == 'changeKeFuSuccess') {
  987. this.changeKeFu = true;
  988. // this.goBack();
  989. this.customerSviceChat.push({type: 'system', str: 'changeKeFu'})
  990. this.consult = false;
  991. }
  992. // 客服会话超时
  993. if (redata.message_type == 'overtime') {
  994. this.willOverTime = true;
  995. this.automaticRolling();
  996. // this.goBack();
  997. this.overTimeMsg = redata.data.content;
  998. }
  999. // 客服等待排队
  1000. if (redata.message_type == "inqueue") {
  1001. this.waitingMsg = true;
  1002. this.automaticRolling();
  1003. this.waitingText = redata.content;
  1004. }
  1005. // 掉线
  1006. if (redata.message_type == 'kfNotOnlin'){
  1007. console.log(redata);
  1008. this.service_on = false;
  1009. }
  1010. // 评价返回
  1011. if(redata.message_type == "evaluate"){
  1012. console.log(redata,"评价返回");
  1013. if(redata.data.status == 1){
  1014. this.comtSuccess = true;
  1015. }
  1016. }
  1017. },
  1018. closedWating() {
  1019. this.waitingMsg = false;
  1020. this.goBack();
  1021. },
  1022. /************关闭会话*******************/
  1023. websocketclose(e) {
  1024. console.log('websocket 断开: ' + e.code + ' ' + e.reason + ' ', e)
  1025. this.goBack();
  1026. },
  1027. /*************数据发送***************** */
  1028. websocketsend(data) {
  1029. this.websock.send(data);
  1030. },
  1031. /***************************************/
  1032. //socket重连
  1033. reconnect() {
  1034. if (this.lockReconnect) { //这里很关键,因为连接失败之后之后会相继触发 连接关闭,不然会连接上两个 WebSocket
  1035. return
  1036. }
  1037. this.lockReconnect = true;
  1038. this.reconnectData && clearTimeout(this.reconnectData);
  1039. this.reconnectData = setTimeout(() => {
  1040. this.initWebSocket();
  1041. console.log('-----lail-----');
  1042. this.lockReconnect = false;
  1043. }, 5000)
  1044. },
  1045. /*************************************/
  1046. //心跳检测
  1047. heatBeat() {
  1048. this.timeoutObj && clearTimeout(this.timeoutObj);
  1049. this.serverTimeoutObj && clearTimeout(this.serverTimeoutObj);
  1050. this.timeoutObj = setTimeout(() => {
  1051. // console.log('发送', {type: 'ping'});
  1052. this.websocketsend(JSON.stringify({type: 'ping'})) //根据后台要求发送
  1053. this.serverTimeoutObj = setTimeout(() => {
  1054. console.log('------close-------')
  1055. this.websock.close(); //如果 5秒之后我们没有收到 后台返回的心跳检测数据 断开socket,断开后会启动重连机制
  1056. }, 5000);
  1057. }, this.timeout)
  1058. },
  1059. /******************消息发送数据处理********************/
  1060. sendMessage() {
  1061. let str = this.information;
  1062. let formatStr = str.replace(/\n/g, '<br/>');
  1063. // 给机器人发送文本消息
  1064. if (this.machineAndAtl == 10) {
  1065. //给机器人发送文本消息-本地储存
  1066. let datas = {
  1067. time: '',
  1068. chat: this.turnFace(this.shieldingKeyword(formatStr)),
  1069. imgUrl: this.img,
  1070. type: 'user'
  1071. }
  1072. this.chatCont.push(datas)
  1073. //消息发送-机器人
  1074. this.websocketsend(JSON.stringify({
  1075. type: 'toRobot',
  1076. data: {
  1077. groups_id: '1',
  1078. robot_name: this.shieldingKeyword(formatStr),
  1079. webTime: this.webTime,
  1080. robotgroups_id: '1',
  1081. }
  1082. }))
  1083. } else if (this.machineAndAtl == 100) { //人工聊天
  1084. // 人工聊天超时隐藏
  1085. this.willOverTime = false;
  1086. //发送给客服消息-本地储存
  1087. this.customerSviceChat.push({
  1088. time: '',
  1089. content: this.turnFace(this.shieldingKeyword(formatStr)),
  1090. imgUrl: this.img,
  1091. type: 'user',
  1092. });
  1093. //消息发送-客服
  1094. this.websocketsend(JSON.stringify({
  1095. type: 'chatMessage',
  1096. data: {
  1097. from_name: this.user_info.name,
  1098. from_avatar: this.user_info.avatar,
  1099. from_id: this.user_info.id,
  1100. content: JSON.stringify({
  1101. text: formatStr,
  1102. img: this.img,
  1103. type: 'user'
  1104. }),
  1105. webTime: this.webTime,
  1106. to_id: this.service.kf_id,
  1107. to_name: this.service.kf_name,
  1108. sensitiveNumber: this.sensitiveNumber,
  1109. conversationId: this.service.conversationId
  1110. }
  1111. }))
  1112. this.tokNum++;
  1113. console.log(this.tokNum,"我发的消息");
  1114. }
  1115. // 发送之后清空发送数据
  1116. this.img = '';
  1117. this.information = '';
  1118. //高度自动向上滑动
  1119. this.automaticRolling();
  1120. },
  1121. /*************设置token加密***************** */
  1122. setApiToken(name, controller, time, modules) {
  1123. return this.$md5.hex_md5(name + 'customer-service' + controller + time + modules)
  1124. },
  1125. /*************跳转人工客服***************** */
  1126. jumpService(id, name) {
  1127. this.jumpArtl = true;
  1128. this.closeByServer = false;
  1129. this.group = id;
  1130. //人工会话登陆
  1131. let data = {
  1132. 'type': 'userInit',
  1133. data: {
  1134. 'uid': this.user_info.id,
  1135. 'name': this.user_info.name,
  1136. 'avatar': this.user_info.avatar,
  1137. 'group': this.group
  1138. }
  1139. }
  1140. this.websock.send(JSON.stringify(data));
  1141. // 客服类型名称
  1142. this.jumpName = name;
  1143. },
  1144. /*************机器智能回答问题***************** */
  1145. answers(idx) {
  1146. let obj = {
  1147. 'robot_addTime': this.problem[idx].robot_addTime,
  1148. 'robot_content': this.problem[idx].robot_content,
  1149. 'type': 'machine'
  1150. }
  1151. this.information = this.problem[idx].robot_name
  1152. this.sendMessage();
  1153. this.automaticRolling();
  1154. },
  1155. /**************匿名注册**************** */
  1156. registered() {
  1157. let token = localStorage.getItem('token');
  1158. let data = {
  1159. token: token != null ? token : '',//
  1160. appid: this.$public.getQueryString('appid'),//
  1161. appuid: this.$public.getQueryString('appuid'),//
  1162. }
  1163. let obj = {
  1164. headers: {
  1165. "apiToken": this.setApiToken('autoreg', 'register', this.currTime, 'index')
  1166. }
  1167. }
  1168. this.$axios.post('/api/index/register/autoReg', data, obj).then(res => {
  1169. if (res.data.code == 1) {
  1170. this.user_info = res.data.data;
  1171. localStorage.setItem("token", res.data.data.token);
  1172. setTimeout(() => {
  1173. //关闭加载条
  1174. this.allLoadingClose();
  1175. // 初始化websocket
  1176. this.initWebSocket();
  1177. }, 2000);
  1178. }
  1179. });
  1180. },
  1181. /***********聊天滑动的时候滑动滚动条到底部******************* */
  1182. automaticRolling() {
  1183. this.$nextTick(() => {
  1184. let msg = document.getElementById('main') // 获取对象
  1185. msg.scrollTop = msg.scrollHeight // 滚动高度
  1186. })
  1187. },
  1188. /**************获取敏感词**************** */
  1189. getSensitive() {
  1190. let obj = {
  1191. headers: {
  1192. 'Content-Type': 'application/x-www-form-urlencoded',
  1193. "apiToken": this.setApiToken('sensitivewords', 'index', this.currTime, 'index')
  1194. }
  1195. };
  1196. let data = {
  1197. userToken: ''
  1198. }
  1199. this.$axios.post('/api/index/index/sensitiveWords', '', obj).then(res => {
  1200. if (res.data.code == 1) {
  1201. console.log(res.data.data);
  1202. res.data.data.userSensitive.forEach(res => {
  1203. this.sensitive.push(res.sensitivewords_word)
  1204. })
  1205. }
  1206. })
  1207. },
  1208. /**********判定是否是JSON格式*********** */
  1209. isJSON(str) {
  1210. if (typeof str == 'string') {
  1211. try {
  1212. JSON.parse(str);
  1213. return true;
  1214. } catch (e) {
  1215. //console.log(e);
  1216. return false;
  1217. }
  1218. }
  1219. },
  1220. },
  1221. /**************页面加载中挂载**************** */
  1222. mounted() {
  1223. let self = this;
  1224. this.frceArr = frce.frce;
  1225. this.$axios.get('api/index/index/systime?t=' + new Date()).then(res => {
  1226. if (res.data.code == 1) {
  1227. // 获取系统时间
  1228. let date = res.data.data.time.split(" ");
  1229. date[0] = (new Date(date[0].replace(/-/g, '/')).getTime()) / 1000;
  1230. this.currTime = date[0];
  1231. this.hourse = date[1];
  1232. this.logo = res.data.data.logo;
  1233. // 获取机器智能问题
  1234. this.getProblem();
  1235. // 匿名注册
  1236. this.registered();
  1237. // 获取聊天次数
  1238. this.getChatNum();
  1239. // 获取敏感词
  1240. this.getSensitive();
  1241. }
  1242. })
  1243. },
  1244. // 组件挂载阶段
  1245. destroyed() {
  1246. this.websock.close() //离开路由之后断开websocket连接
  1247. this.lockReconnect = true;
  1248. clearTimeout(this.reconnectData); //离开清除 timeout
  1249. clearTimeout(this.timeoutObj); //离开清除 timeout
  1250. clearTimeout(this.serverTimeoutObj); //离开清除 timeout
  1251. },
  1252. computed: {
  1253. inforLeng() {
  1254. return this.information.length;
  1255. }
  1256. },
  1257. watch: {
  1258. inforLeng(val) {
  1259. if (val > 0) {
  1260. this.sendCol = true;
  1261. } else {
  1262. this.sendCol = false;
  1263. }
  1264. }
  1265. }
  1266. }
  1267. </script>
  1268. <style scoped>
  1269. .chatBox {
  1270. width: 700px;
  1271. position: relative;
  1272. }
  1273. .el-header {
  1274. background: linear-gradient(90deg, rgba(22, 84, 209, 1) 0%, rgba(9, 52, 173, 1) 100%);
  1275. box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.2);
  1276. }
  1277. .tit {
  1278. height: 100%;
  1279. line-height: 80px;
  1280. text-align: left;
  1281. padding-left: 20px;
  1282. }
  1283. .el-col span {
  1284. font-size: 18px;
  1285. color: #FFFFFF;
  1286. }
  1287. .imgBox {
  1288. text-align: right;
  1289. }
  1290. .imgBox img {
  1291. margin-right: 20px;
  1292. }
  1293. .imgBox img:nth-last-child(1) {
  1294. margin-right: 0
  1295. }
  1296. .el-main {
  1297. background: #fff;
  1298. width: 63%;
  1299. padding: 0;
  1300. }
  1301. .el-aside {
  1302. background: #F5F5F5;
  1303. width: 37%;
  1304. }
  1305. .cationer, .artificial {
  1306. display: flex;
  1307. justify-content: space-between;
  1308. /* align-items: center; */
  1309. }
  1310. .rt {
  1311. width: 100%;
  1312. box-sizing: inherit;
  1313. }
  1314. .artificial {
  1315. /* width: 150px; */
  1316. /* padding:0 20px; */
  1317. margin-top: 23px;
  1318. margin-bottom: 9px;
  1319. vertical-align: middle;
  1320. /* flex-direction: column;*/
  1321. }
  1322. .infor div {
  1323. margin-bottom: 3px;
  1324. }
  1325. .infor div span, .autograph span {
  1326. color: #999999;
  1327. font-size: 14px;
  1328. font-weight: 400;
  1329. }
  1330. .infor div span:nth-child(2), .autograph span:nth-child(2) {
  1331. color: #666666;
  1332. margin-left: 4px;
  1333. }
  1334. .headPortrait {
  1335. width: 46%;
  1336. height: 100px;
  1337. }
  1338. .headPortrait img {
  1339. width: 100%;
  1340. height: 100%;
  1341. }
  1342. .autograph {
  1343. margin-bottom: 11px;
  1344. }
  1345. .advent {
  1346. border-top: 1px solid #DDDDDD;
  1347. padding: 20px;
  1348. }
  1349. .advent img {
  1350. margin-top: 25px;
  1351. width: 100%;
  1352. }
  1353. .pd {
  1354. padding: 20px;
  1355. }
  1356. .pd20 {
  1357. padding: 0 20px;
  1358. }
  1359. /* 会话 */
  1360. .conversationBox {
  1361. margin-top: 13px;
  1362. margin-bottom: 13px;
  1363. }
  1364. .timer {
  1365. text-align: center;
  1366. margin: 10px 0;
  1367. color: #999999;
  1368. font-size: 12px;
  1369. }
  1370. .headImg {
  1371. width: 40px;
  1372. height: 40px;
  1373. margin-right: 13px;
  1374. }
  1375. .headImg img {
  1376. display: inline-block;
  1377. width: 40px;
  1378. height: 40px;
  1379. }
  1380. .conversation .cont, .customer .cont {
  1381. background: #ffffff;
  1382. padding: 9px 8px 12px 10px;
  1383. display: inline-block;
  1384. border: 1px solid rgba(223, 223, 223, 1);
  1385. border-radius: 5px;
  1386. position: relative;
  1387. max-width: 270px;
  1388. }
  1389. .left::after {
  1390. position: absolute;
  1391. content: "";
  1392. display: inline-block;
  1393. left: -4px;
  1394. top: 5px;
  1395. width: 5px;
  1396. height: 9px;
  1397. background: #fff;
  1398. -webkit-transform: skewX(30deg);
  1399. transform: skewX(30deg);
  1400. /* z-index: -1; */
  1401. border-left: 1px solid #dfdfdf;
  1402. border-top: 1px solid #dfdfdf;
  1403. }
  1404. div.noafter::after {
  1405. content: '';
  1406. width: 0;
  1407. height: 0;;
  1408. display: inline;
  1409. position: relative;
  1410. border: 0;
  1411. }
  1412. .conversation .cont div, .customer .cont div {
  1413. color: #666666;
  1414. font-size: 16px;
  1415. }
  1416. .customer {
  1417. justify-content: space-between;
  1418. }
  1419. .customer .cont {
  1420. margin-right: 13px;
  1421. border: 0;
  1422. background: #5EA0F7;
  1423. max-width: 260px;
  1424. word-wrap: break-word;
  1425. word-break: normal;
  1426. }
  1427. .customer .cont div {
  1428. color: #FFFFFF;
  1429. }
  1430. .right::after {
  1431. position: absolute;
  1432. content: "";
  1433. display: inline-block;
  1434. right: -2px;
  1435. top: 6px;
  1436. width: 5px;
  1437. height: 9px;
  1438. background: #5ea0f7;
  1439. -webkit-transform: skewX(-30deg);
  1440. transform: skewX(-30deg);
  1441. border-left: 1px solid #5ea0f7;
  1442. border-top: 1px solid #5ea0f7;
  1443. }
  1444. .col {
  1445. color: #999999;
  1446. }
  1447. .change {
  1448. color: #5ea0f7;
  1449. }
  1450. .questionList, .changeService {
  1451. margin: 10px;
  1452. border: 1px solid rgba(223, 223, 223, 1);
  1453. border-radius: 5px;
  1454. }
  1455. .questionList div, .changeService div {
  1456. height: 40px;
  1457. line-height: 40px;
  1458. padding-left: 15px;
  1459. }
  1460. .questionList div span {
  1461. color: #5EA0F7;
  1462. font-size: 14px;
  1463. }
  1464. .questionList section:nth-child(odd), .changeService div:nth-child(odd) {
  1465. background: #F6F6F6;
  1466. }
  1467. .changeService div span {
  1468. font-size: 14px;
  1469. }
  1470. .changeService div span:nth-child(1) {
  1471. margin-right: 5px;
  1472. }
  1473. .col6 {
  1474. color: #666666 !important;
  1475. }
  1476. .colE5 {
  1477. color: #5EA0F7;
  1478. }
  1479. .promptBox {
  1480. display: flex;
  1481. justify-content: center;
  1482. height: 26px;
  1483. margin: 10px 0 10px;
  1484. /* line-height: 26px; */
  1485. }
  1486. .promptBoxH {
  1487. display: flex;
  1488. justify-content: center;
  1489. height: 50px;
  1490. margin: 10px 0 10px;
  1491. /* line-height: 26px; */
  1492. }
  1493. .prompt {
  1494. line-height: 25px;
  1495. text-align: center;
  1496. background: #DDDDDD;
  1497. border-radius: 30px;
  1498. width: 140px;
  1499. color: #FFFFFF;
  1500. font-size: 12px;
  1501. }
  1502. .help {
  1503. width: 80%;
  1504. }
  1505. .help .prompt {
  1506. width: 100%;
  1507. }
  1508. /* 评论 */
  1509. .evaluate {
  1510. height: 101px;
  1511. padding: 19px 0 16px;
  1512. background: rgba(255, 255, 255, 1);
  1513. border: 1px solid rgba(223, 223, 223, 1);
  1514. border-radius: 10px;
  1515. margin-top: 15px;
  1516. text-align: center;
  1517. position: relative;
  1518. box-sizing: border-box;
  1519. }
  1520. .evaluate span {
  1521. font-size: 14px;
  1522. color: #666666;
  1523. }
  1524. .nopd {
  1525. padding: 0;
  1526. }
  1527. .nopd i{
  1528. margin-left: 10px;
  1529. width: 8px;
  1530. height: 8px;
  1531. background: #cdcdcd;
  1532. background: #81d981;
  1533. display: inline-block;
  1534. border-radius: 50%;
  1535. }
  1536. .evaluate .btn {
  1537. display: block;
  1538. background: #F04992;
  1539. border-radius: 10px;
  1540. margin-top: 10px;
  1541. color: #FFFFFF;
  1542. height: 36px;
  1543. line-height: 36px;
  1544. width: 100px;
  1545. position: absolute;
  1546. bottom: 16px;
  1547. left: 35%;
  1548. cursor: pointer;
  1549. }
  1550. /* 聊天框 */
  1551. .chatting {
  1552. width: 100%;
  1553. background: rgba(255, 255, 255, 1);
  1554. box-shadow: 0px -5px 5px rgba(0, 0, 0, 0.05);
  1555. height: 100px;
  1556. padding: 10px 20px;
  1557. }
  1558. .informationBox {
  1559. height: 500px;
  1560. overflow: auto;
  1561. }
  1562. .expression, .photo {
  1563. display: inline-block;
  1564. width: 18px;
  1565. height: 18px;
  1566. background: url("./../assets/st-img/expression.png") no-repeat;
  1567. background-size: 100% 100%;
  1568. cursor: pointer;
  1569. margin-right: 18px;
  1570. }
  1571. .expression:hover {
  1572. background: url("./../assets/st-img/expressionHover.png") no-repeat;
  1573. background-size: 100% 100%;
  1574. }
  1575. .photo {
  1576. background: url("./../assets/st-img/photo.png") no-repeat;
  1577. background-size: 100% 100%;
  1578. }
  1579. .photo:hover {
  1580. background: url("./../assets/st-img/photoHover.png") no-repeat;
  1581. background-size: 100% 100%;
  1582. }
  1583. textarea {
  1584. height: 30px;
  1585. width: 300px;
  1586. border: 0;
  1587. -webkit-user-select: auto;
  1588. user-select: auto;
  1589. -o-user-select: auto;
  1590. -ms-user-select: auto;
  1591. resize: none;
  1592. outline: none;
  1593. padding-top: 10px;
  1594. overflow: hidden;
  1595. }
  1596. .sendOut {
  1597. width: 80px;
  1598. height: 44px;
  1599. line-height: 40px;
  1600. border: 1px solid rgba(221, 221, 221, 1);
  1601. border-radius: 5px;
  1602. text-align: center;
  1603. margin-left: 20px;
  1604. }
  1605. .sendOut span {
  1606. color: #CCCCCC;
  1607. font-size: 16px;
  1608. }
  1609. .chattingBox {
  1610. margin-top: 12px;
  1611. }
  1612. /* 评论弹框 */
  1613. .zzBox {
  1614. position: absolute;
  1615. width: 100%;
  1616. height: 100%;
  1617. background: rgba(0, 0, 0, 0.3);
  1618. top: 0;
  1619. left: 0;
  1620. }
  1621. .box-card, .proving {
  1622. width: 494px;
  1623. height: 300px;
  1624. position: absolute;
  1625. left: 50%;
  1626. top: 50%;
  1627. transform: translate(-50%, -50%);
  1628. z-index: 999;
  1629. border-radius: 10px;
  1630. padding: 20px 20px 30px 50px;
  1631. box-sizing: border-box;
  1632. }
  1633. .proving {
  1634. padding: 20px 20px 30px 47px;
  1635. }
  1636. .close{
  1637. text-align: right;
  1638. cursor: pointer;
  1639. }
  1640. .close i{
  1641. display: inline-block;
  1642. width: 18px;
  1643. height: 18px;
  1644. background: url("./../assets/st-img/close.png") no-repeat;
  1645. background-size: 100% 100%;
  1646. }
  1647. .box-card .tit {
  1648. text-align: center;
  1649. padding-right: 65px;
  1650. margin-bottom: 40px;
  1651. }
  1652. .box-card .tit span {
  1653. font-size: 18px;
  1654. color: #666666;
  1655. }
  1656. .selIcon {
  1657. padding-right: 30px;
  1658. margin-bottom: 30px;
  1659. }
  1660. .selIcon div {
  1661. text-align: center;
  1662. cursor: pointer;
  1663. }
  1664. .selIcon div i {
  1665. display: block;
  1666. width: 44px;
  1667. height: 44px;
  1668. background: url("./../assets/st-img/satisfied.png") no-repeat;
  1669. background-size: 100% 100%;
  1670. margin-bottom: 10px;
  1671. }
  1672. .selIcon div span {
  1673. /* display: block; */
  1674. }
  1675. .selIcon div .comm {
  1676. background: url("./../assets/st-img/comm2.png") no-repeat;
  1677. }
  1678. .selIcon div .sfd {
  1679. background: url("./../assets/st-img/Satisfied2.png") no-repeat;
  1680. }
  1681. .selIcon div .comm2 {
  1682. background: url("./../assets/st-img/comm.png") no-repeat;
  1683. }
  1684. .selIcon div .notSfd {
  1685. background: url("./../assets/st-img/notSatisfied2.png")
  1686. }
  1687. .selIcon div .notSfd2 {
  1688. background: url("./../assets/st-img/notSatisfied.png")
  1689. }
  1690. .levMsg {
  1691. padding-right: 30px;
  1692. margin-bottom: 20px;
  1693. }
  1694. .sure {
  1695. text-align: center;
  1696. background: linear-gradient(90deg, rgba(22, 84, 209, 1) 0%, rgba(9, 52, 173, 1) 100%);
  1697. box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.2);
  1698. border-radius: 10px;
  1699. width: 100px;
  1700. height: 48px;
  1701. line-height: 48px;
  1702. color: #fff;
  1703. position: absolute;
  1704. bottom: 30px;
  1705. left: 37%;
  1706. cursor: pointer;
  1707. }
  1708. /* 验证框 */
  1709. .logo {
  1710. text-align: center;
  1711. margin-bottom: 20px;
  1712. }
  1713. .logo span {
  1714. font-size: 38px;
  1715. font-weight: bold;
  1716. color: #5EA0F7;
  1717. font-family: Microsoft YaHei;
  1718. }
  1719. .logo span:nth-child(1) {
  1720. color: #F04992;
  1721. }
  1722. .formBox {
  1723. padding: 0 27px 0 0;
  1724. }
  1725. .formBox .el-input {
  1726. margin-bottom: 21px;
  1727. }
  1728. .formBox .phone .el-input, .formBox .email .el-input {
  1729. margin-bottom: 0;
  1730. }
  1731. .formBox .phone, .formBox .email {
  1732. margin-bottom: 10px;
  1733. }
  1734. .vertion {
  1735. vertical-align: middle;
  1736. /* margin-bottom: 28px; */
  1737. }
  1738. .vertion .el-input {
  1739. width: 250px;
  1740. margin-right: 15px;
  1741. display: inline-block;
  1742. }
  1743. .vertion span {
  1744. display: inline-block;
  1745. width: 128px;
  1746. height: 40px;;
  1747. vertical-align: middle;
  1748. background: rgba(241, 225, 224, 1);
  1749. }
  1750. .formBox .sure {
  1751. bottom: 21px;
  1752. }
  1753. .el-card__body .tit {
  1754. line-height: 25px;
  1755. }
  1756. .chatting .el-button {
  1757. border: none;
  1758. padding: 0;
  1759. border-radius: 0
  1760. }
  1761. .emoticon {
  1762. width: 30px;
  1763. height: 30px;
  1764. display: inline-block;
  1765. }
  1766. .pointer {
  1767. cursor: pointer;
  1768. }
  1769. .ly:hover {
  1770. border-bottom: 1px solid #5EA0F7;
  1771. /* 高亮效果 */
  1772. filter: brightness(0.9);
  1773. }
  1774. .gl:hover {
  1775. filter: brightness(0.9);
  1776. }
  1777. .seek:hover {
  1778. background: #860c60
  1779. }
  1780. .sendCol {
  1781. background: linear-gradient(90deg, rgba(22, 84, 209, 1) 0%, rgba(9, 52, 173, 1) 100%);
  1782. }
  1783. .netSendCol {
  1784. cursor: not-allowed;
  1785. }
  1786. /* 修改滚动条 */
  1787. ::-webkit-scrollbar-button {
  1788. background: transparent;
  1789. border: 0;
  1790. }
  1791. /* 顶部三个图标 */
  1792. .imgBox i {
  1793. display: inline-block;
  1794. width: 25px;
  1795. height: 25px;
  1796. margin-right: 20px;
  1797. background: url("./../assets/st-img/pj.png") no-repeat;
  1798. background-size: 100% 100%;
  1799. vertical-align: middle;
  1800. }
  1801. .imgBox .sy {
  1802. background: url("./../assets/st-img/sy.png") no-repeat;
  1803. }
  1804. .imgBox .sq {
  1805. background: url("./../assets/st-img/sq.png") no-repeat;
  1806. }
  1807. /* .sc:hover{
  1808. background: url("./../assets/st-img/pjhover.png") no-repeat;
  1809. }
  1810. .sy:hover{
  1811. background: url("./../assets/st-img/sy2.png")no-repeat;
  1812. }
  1813. .sq:hover{
  1814. background: url("./../assets/st-img/sq2.png") no-repeat;
  1815. } */
  1816. i.scActy {
  1817. background: #1654D1 url("./../assets/st-img/pjhover.png") no-repeat;
  1818. width: 33px;
  1819. height: 33px;
  1820. background-position: 5px;
  1821. }
  1822. /* .imgBox .syActy{
  1823. background:#1654D1 url("./../assets/st-img/jzsy.png") no-repeat;
  1824. width: 33px;
  1825. height: 33px;
  1826. background-position: 5px;
  1827. }
  1828. .imgBox .sqActy{
  1829. background: #1654D1 url("./../assets/st-img/sq2.png") no-repeat;
  1830. width: 33px;
  1831. height: 33px;
  1832. transform: rotate(180deg);
  1833. background-position: 5px;
  1834. } */
  1835. .tips {
  1836. font-size: 12px;
  1837. color: #F04992;
  1838. }
  1839. #main {
  1840. position: relative;
  1841. }
  1842. .retract {
  1843. position: absolute;
  1844. right: 0;
  1845. top: 290px;
  1846. z-index: 999;
  1847. }
  1848. /* 滚动条样式 */
  1849. .scroll::-webkit-scrollbar {
  1850. border: 5px solid #fff;
  1851. }
  1852. .scroll::-webkit-scrollbar {
  1853. width: 5px;
  1854. height: 20px;
  1855. }
  1856. .scroll::-webkit-scrollbar-button {
  1857. width: 0px;
  1858. height: 0px;
  1859. }
  1860. .scroll::-webkit-scrollbar-thumb {
  1861. border-radius: 5px;
  1862. box-shadow: inset 0 0 0 5px #aaa;
  1863. border: .02rem solid transparent;
  1864. }
  1865. .scroll::-webkit-scrollbar-track {
  1866. display: block;
  1867. background: rgba(0, 0, 0, 0.1);
  1868. }
  1869. #logo {
  1870. margin-right: 10px;
  1871. width: 40px;
  1872. height: 40px;
  1873. line-height: 40px;
  1874. display: inline-block;
  1875. border-radius: 50%;
  1876. vertical-align: sub;
  1877. position: relative;
  1878. top: 10px;
  1879. }
  1880. </style>