index.vue 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002
  1. <template>
  2. <div>
  3. <!-- 聊天 -->
  4. <div class="service" v-if="!knowledge">
  5. <!-- 头部信息 -->
  6. <div class="header row allAlignment item-center">
  7. <div class="row item-center" v-if="!link_success">
  8. <img class="icon" style="margin-right:.2rem;" src="@/assets/Service1.png" @click="leftShow = true">
  9. <img class="logo" :src="img_http + logo" alt="">
  10. <p>{{service_info.name}}</p>
  11. <span style="margin-left: 5px;"><img src="@/assets/on_icon.png" alt=""></span>
  12. </div>
  13. <div class="row item-center" v-else>
  14. <img class="icon" style="margin-right:.2rem;" src="@/assets/Service1.png" @click="leftShow = true">
  15. <img class="logo" :src="img_http + logo" alt="">
  16. <p>{{service_info.name}}</p>
  17. <span v-if="service_on" style="margin-left: 5px;"><img src="@/assets/on_icon.png" alt=""></span>
  18. <span v-if="!service_on" style="margin-left: 5px;"><img src="@/assets/off_icon.png" alt=""></span>
  19. </div>
  20. <div class="row">
  21. <yd-button v-if="isExit" color="#fff" bgcolor="#1d57dd" class="exit" size="mini" type="primary"
  22. @click.native="is_exit()">退出聊天
  23. </yd-button>
  24. <img class="icon-msg" v-show=" (chat.length -1) > chatNum " @click="is_show_evaluate()" src="@/assets/Service2.png">
  25. <!--<img class="icon-msg" @click="is_show_evaluate()" src="@/assets/Service2.png">-->
  26. <img class="icon-msg" @click="knowledge = true,flag = false" src="@/assets/leaveSwitch.png" v-if="!isExit">
  27. </div>
  28. </div>
  29. <div class="main" id="main">
  30. <!-- ********************************************************** -->
  31. <!-- 机器人聊天板块 -->
  32. <div v-if="!link_success">
  33. <!-- 系统欢迎语 -->
  34. <div v-if="welcome.length > 0" v-for="(item,i) in welcome" :key="'w'+i">
  35. <div class="row allAlignment" style="margin-top:.3rem;">
  36. <div class="HeadPortrait row center">
  37. <img :src="require('@/assets/headAdvent.png')">
  38. </div>
  39. <div class="messageWindow dialogueA col-w">
  40. <div class="customerService left" v-html="item"></div>
  41. </div>
  42. </div>
  43. </div>
  44. <!-- 系统消息下拉选择 -->
  45. <div class="artificial" v-if="problem.length > 0 && welcome.length > 0">
  46. <div class="row item-center allAlignment" style="height:.75rem;border-bottom:.01rem solid #EEE;"
  47. v-for="(item,index) in problem" :key="index" @click="pushMessage(item.robot_content)">
  48. <span>{{item.robot_name}}</span>
  49. <img style="width:.3rem;height:.3rem;" src="@/assets/addright.png">
  50. </div>
  51. <div class="row item-center" style="height:.72rem;">
  52. <p>以上问题都不是</p>
  53. <div style="color:#5EA0F7;padding-left:.1rem;" @click="connectionService">转人工客服</div>
  54. </div>
  55. </div>
  56. <!-- 和机器人会话 -->
  57. <div v-for="(item,i) in robot" :key="'r'+i">
  58. <!-- 和机器人会话互动 -->
  59. <div v-if="item.type == 'error'" class="row allAlignment"
  60. style="margin-top:.3rem;">
  61. <div class="HeadPortrait row center">
  62. <img v-if="item.type == 'error'" :src="require('@/assets/headAdvent.png')">
  63. </div>
  64. <div class="messageWindow dialogueA col-w">
  65. <!-- <div v-if="item.type == '1001'" class="customerService left"
  66. v-html="item.content.text"></div> -->
  67. <!-- <div v-if="item.type == 'user'" class="user right imgSrc">
  68. <yd-lightbox v-if="item.content.img" style="display:inline-block"
  69. class="row rightAlignment box-img">
  70. <yd-lightbox-img :src=" img_http + item.content.img"></yd-lightbox-img>
  71. </yd-lightbox> -->
  72. <div v-if="item.type == 'error'" class="customerService left">{{item.content.text}}
  73. <div style="color:#5EA0F7;padding-left:.1rem;cursor:pointer;" @click="connectionService">转人工客服</div>
  74. </div>
  75. <!-- </div> -->
  76. </div>
  77. <div class="HeadPortrait row center">
  78. <img v-if="item.type == 'user'"
  79. :src="require('@/assets/timg.jpg') ">
  80. </div>
  81. </div>
  82. <!-- 和机器人会话互动 -->
  83. <div v-if="item.type == 'service' || item.type == 'user'" class="row allAlignment"
  84. style="margin-top:.3rem;">
  85. <div class="HeadPortrait row center">
  86. <img v-if="item.type == 'service'" :src="require('@/assets/headAdvent.png')">
  87. </div>
  88. <div class="messageWindow dialogueA col-w"
  89. :style="item.type == 'user'?'text-align: right;':''">
  90. <div v-if="item.type == 'service'" class="customerService left"
  91. v-html="item.content.text"></div>
  92. <div v-if="item.type == 'user'" class="user right imgSrc">
  93. <yd-lightbox v-if="item.content.img" style="display:inline-block"
  94. class="row rightAlignment box-img">
  95. <yd-lightbox-img :src=" img_http + item.content.img"></yd-lightbox-img>
  96. </yd-lightbox>
  97. <div v-else v-html="item.content"></div>
  98. </div>
  99. </div>
  100. <div class="HeadPortrait row center">
  101. <img v-if="item.type == 'user'"
  102. :src="require('@/assets/timg.jpg') ">
  103. </div>
  104. </div>
  105. <!-- 转人工分组 -->
  106. <div class="artificial" v-if="item.type == 'artificial_service' ">
  107. <div @click="turnArtificial(items.id)" v-for="(items,indexs) in item.content"
  108. :key="'r'+indexs" class="row item-center allAlignment"
  109. style="height:.75rem;border-bottom:.01rem solid #EEE;">
  110. <p>
  111. 人工客服:
  112. <span style="color:#5EA0F7;padding-left:.1rem;">{{items.name}}</span>
  113. </p>
  114. <img style="width:.3rem;height:.3rem;" src="@/assets/addright.png">
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. <!-- ********************************************************** -->
  120. <!-- 人工会话模版 -->
  121. <div v-if="link_success">
  122. <!--历史消息-->
  123. <div v-if="showHistory" v-for="item in hisSviceChat">
  124. <!-- 客服信息 -->
  125. <div v-if="item.from_id.startsWith('KF')">
  126. <div style="width: 100%;text-align: center;">
  127. <span v-if="item.time_line">{{item.time_line}}</span>
  128. </div>
  129. <div class="row allAlignment" style="margin-top:.3rem;margin-top: 0.3rem;">
  130. <div class="HeadPortrait row center">
  131. <img v-if="service_info.avatar == '' " :src="avatar_imgs">
  132. <img v-if="service_info.avatar != ''"
  133. :src="img_http + service_info.avatar ? img_http + service_info.avatar : require('@/assets/user2.png')">
  134. </div>
  135. <div class="messageWindow dialogueA col-w">
  136. <div class="customerService left imgSrc">
  137. <yd-lightbox v-if="item.content.img" style="display:inline-block"
  138. class="row rightAlignment">
  139. <yd-lightbox-img :src=" img_http + item.content.img"></yd-lightbox-img>
  140. </yd-lightbox>
  141. <div v-html="item.content.text" v-else></div>
  142. </div>
  143. </div>
  144. <div class="HeadPortrait row center">
  145. </div>
  146. </div>
  147. </div>
  148. <!-- 用户信息 -->
  149. <div v-else>
  150. <div style="width: 100%;text-align: center;margin-top: 0.3rem;">
  151. <span v-if="item.time_line">{{item.time_line}}</span>
  152. </div>
  153. <div class="row allAlignment" style="margin-top:.3rem;">
  154. <div class="HeadPortrait row center">
  155. </div>
  156. <div class="messageWindow dialogueA col-w" style="text-align: right;">
  157. <div class="user right imgSrc">
  158. <yd-lightbox v-if="item.content.img" style="display:inline-block" class="row rightAlignment">
  159. <yd-lightbox-img :src="img_http+item.content.img"></yd-lightbox-img>
  160. </yd-lightbox>
  161. <span v-html="item.content.text" v-else></span>
  162. </div>
  163. </div>
  164. <div class="HeadPortrait row center">
  165. <img :src="require('@/assets/timg.jpg') ">
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. <div v-for="(item,index) in chat" :key="index">
  171. <!-- 历史消息 -->
  172. <div class="promptBox" v-if="item.type == 'historyMsg'">
  173. <div class="prompt help">
  174. <span>{{historyMsgtext}}</span>
  175. </div>
  176. </div>
  177. <!-- 客服会话 -->
  178. <div v-if="item.type == 'service'">
  179. <div style="width: 100%;text-align: center;margin-top: 0.3rem;">
  180. <span v-if="item.time ">{{item.time}}</span>
  181. </div>
  182. <div class="row allAlignment" style="margin-top:.3rem;">
  183. <div class="HeadPortrait row center">
  184. <img id="123" v-if="service_info.avatar == '' " :src="avatar_imgs">
  185. <img id="321" v-if="service_info.avatar != '' "
  186. :src="img_http + service_info.avatar ? img_http + service_info.avatar : img_http + service_info.avatar">
  187. </div>
  188. <div class="messageWindow dialogueA col-w">
  189. <div class="customerService left imgSrc">
  190. <yd-lightbox v-if="item.content.img" style="display:inline-block"
  191. class="row rightAlignment">
  192. <yd-lightbox-img :src="img_http + item.content.img"></yd-lightbox-img>
  193. </yd-lightbox>
  194. <div v-html="item.content.text" v-else></div>
  195. </div>
  196. </div>
  197. <div class="HeadPortrait row center">
  198. </div>
  199. </div>
  200. </div>
  201. <!-- 用户会话 -->
  202. <div v-if="item.type == 'user'">
  203. <div style="width: 100%;text-align: center;margin-top: 0.3rem;">
  204. <span v-if="item.time">{{item.time}}</span>
  205. </div>
  206. <div class="row allAlignment" style="margin-top:.3rem;">
  207. <div class="HeadPortrait row center">
  208. </div>
  209. <div class="messageWindow dialogueA col-w" style="text-align: right;">
  210. <div class="user right imgSrc">
  211. <yd-lightbox v-if="item.content.img" style="display:inline-block"
  212. class="row rightAlignment">
  213. <yd-lightbox-img :src="img_http+item.content.img"></yd-lightbox-img>
  214. </yd-lightbox>
  215. <span v-html="item.content.text" v-else>{{item.content.text}}</span>
  216. </div>
  217. </div>
  218. <div class="HeadPortrait row center">
  219. <img v-if="item.type == 'user'"
  220. :src="require('@/assets/timg.jpg') ">
  221. </div>
  222. </div>
  223. </div>
  224. <!-- 常规系统消息评价 -->
  225. <div class="row center " v-if="item.type== 'system' ">
  226. <div class="column item-center "
  227. style="margin: 0.3rem 0; background: #fff; width:100% ;padding: 0.1rem 0;"
  228. v-if="item.content.state =='getEvaluate' && !haveEvaluation ">
  229. <p class="row center wrap">{{item.content.text}}</p>
  230. <button class="evaluateBtn" style="margin-top:.2rem;" @click="is_show_evaluate()">评价
  231. </button>
  232. </div>
  233. <div class="column item-center"
  234. style="margin: 0.3rem 0; background: #fff; width:100% ;padding: 0.1rem 0.5rem;"
  235. v-if="item.content.state == 'closeInform' ">
  236. <p class="row center wrap">{{item.content.text}}</p>
  237. </div>
  238. </div>
  239. </div>
  240. </div>
  241. <div v-if="box_height" style="height:65px">
  242. </div>
  243. </div>
  244. <!-- 中间弹窗登录 -->
  245. <!-- <yd-popup
  246. v-model="centerShow"
  247. position="center"
  248. width="6.9rem"
  249. height="8rem"
  250. :masker-opacity=".2"
  251. >
  252. <div class="row rightAlignment" style="padding-top:.2rem;padding-right:.2rem;">
  253. <img
  254. @click="centerShow = false"
  255. style="width: 0.32rem;height: 0.32rem;"
  256. src="@/assets/Service5.png"
  257. >
  258. </div>
  259. <div class="row center" style="font-size:.56rem;">
  260. <p style="color:#F04992;">HX</p>
  261. <span style="color:#5EA0F7;">669</span>
  262. </div>
  263. <input class="loginInput" type="text" placeholder="姓名">
  264. <input class="loginInput" type="text" placeholder="手机号">
  265. <input class="loginInput" type="email" placeholder="邮箱地址">
  266. <div class="row" style="margin:0 .2rem;">
  267. <input class="loginInput" placeholder="输入验证码" type="text" style="margin:.5rem 0 0 0;">
  268. <p
  269. @click="initialLoginCode"
  270. class="row center"
  271. style="width:100%;height:.8rem;margin-top:.5rem;background:#F1E1E0;border-radius: .1rem;margin-left:.2rem;font-size:.3rem;color:#666;"
  272. >{{loginCode}}</p>
  273. </div>
  274. <div class="row center sub" style="margin:.5rem .2rem .2rem .2rem;">登录</div>
  275. </yd-popup> -->
  276. <!-- 底部弹窗评价 -->
  277. <yd-popup v-model="bottomShow" position="bottom" height="6.5rem" :masker-opacity=".2">
  278. <div class="row rightAlignment" style="padding-top:.2rem;padding-right:.2rem;">
  279. <img @click.stop="bottomShow = false, evaluateState = 100" style="width: 0.32rem;height: 0.32rem;"
  280. src="@/assets/Service5.png">
  281. </div>
  282. <div style="color:#666;text-align: center;font-size:.28rem;">感谢您的咨询,请对我们的服务做出评价</div>
  283. <div style="height:2.3rem;" class="row allAlignment evaluatebtn">
  284. <div style="width:33%;height:100%;">
  285. <div class="row wrap center" @click="evaluateClick(1)">
  286. <img style="width:.66rem;height:.66rem;"
  287. :src="evaluateState =='1'?require('@/assets/evaluate1a.png'):require('@/assets/evaluate1.png')">
  288. <p>满意</p>
  289. </div>
  290. </div>
  291. <div style="width:33%;height:100%;" @click="evaluateClick(2)">
  292. <div class="row wrap center">
  293. <img style="width:.66rem;height:.66rem;"
  294. :src="evaluateState =='2'?require('@/assets/evaluate2a.png'):require('@/assets/evaluate2.png')">
  295. <p>一般</p>
  296. </div>
  297. </div>
  298. <div style="width:33%;height:100%;" @click="evaluateClick(3)">
  299. <div class="row wrap center">
  300. <img style="width:.66rem;height:.66rem;"
  301. :src="evaluateState =='3'?require('@/assets/evaluate3a.png'):require('@/assets/evaluate3.png')">
  302. <p>不满意</p>
  303. </div>
  304. </div>
  305. </div>
  306. <!-- <div class="evaluateBox">
  307. <textarea placeholder="评价备注" v-model="evalArea"></textarea>
  308. </div> -->
  309. <div class="row center sub" @click="evaluateEsc">确定</div>
  310. </yd-popup>
  311. <!-- 左侧弹窗客服信息 -->
  312. <yd-popup v-model="leftShow" position="left" width="4.8rem" :masker-opacity=".2">
  313. <div class="leftHader row item-center">
  314. <img @click="leftShow = false" class="icon" src="@/assets/Service4.png">
  315. <img class="logo" :src="img_http + logo" alt="">
  316. <p style="color:#FFF;font-size:.34rem;">{{service_info.name}}</p>
  317. </div>
  318. <div>
  319. <div class="leftMain-top row">
  320. <div>
  321. <p>
  322. <!-- 客服名字 -->
  323. <span>姓名:</span>
  324. {{service_info.name}}
  325. </p>
  326. <p>
  327. <!-- 客服工号 -->
  328. <span>工号:</span>
  329. {{service_info.job_name}}
  330. </p>
  331. <p>
  332. <!-- 客服性别 -->
  333. <span>性别:</span>
  334. 保密
  335. </p>
  336. <p>
  337. <!-- 客服职务 -->
  338. <span>职务:</span>
  339. 咨询服务
  340. </p>
  341. </div>
  342. <div class="row center">
  343. <img style="width:1.8rem;height:1.8rem;" v-if="service_info.avatar == ''" :src="avatar_imgs">
  344. <img style="width:1.8rem;height:1.8rem;" v-if="service_info.avatar != ''"
  345. :src="img_http + service_info.avatar">
  346. </div>
  347. </div>
  348. <div class="leftMain-chenter"
  349. style="padding:0 .3rem;margin-top:.3rem;padding-bottom:.6rem;border-bottom:.01rem solid #ddd;"
  350. >
  351. <!-- 客服个性签名 -->
  352. <span>个性签名:</span>
  353. {{service_info.signature}}
  354. </div>
  355. <!-- 广告图 -->
  356. <div class="leftMain-bottom row center" style="padding:0 .3rem;margin-top:.6rem;">
  357. <a :href="'http://'+advertisement.advertisement_url" target="_blank" rel="noopener noreferrer">
  358. <img style="width:4.2rem;height:7rem;" :src="img_http+advertisement.advertisement_img">
  359. </a>
  360. </div>
  361. </div>
  362. </yd-popup>
  363. <!-- 底部输入框 -->
  364. <div class="footer row wrap" id='input_box'>
  365. <!-- @keydown="inputNumFun()" -->
  366. <textarea
  367. id="textarea"
  368. v-model.trim="text_info"
  369. placeholder="请输入你的问题:"
  370. maxlength="100"
  371. >
  372. </textarea>
  373. <div class="send row item-center" style="border-bottom:.01rem solid #ddd">
  374. <img
  375. :src="meme?require('@/assets/faceActive.png'):require('@/assets/face.png')"
  376. @click="faceClick"
  377. style="width:.48rem;height:.48rem"
  378. >
  379. <input type="file" id="file" @change="uploadIMG" accept="image/jpeg,image/jpg,image/png,image/svg"
  380. style="display:none">
  381. <label for="file">
  382. <img src="@/assets/imge.png" style="width:.46rem;height:.42rem">
  383. </label>
  384. <div
  385. @click="send()"
  386. style="color:#ccc;border:.02rem solid #ddd;width:1rem;height:.66rem;border-radius:.1rem;"
  387. :style="text_info.length>0?'background:#5EA0F7;color:#fff;':''"
  388. class="row center"
  389. >发送
  390. </div>
  391. </div>
  392. <!-- 表情包 -->
  393. <div v-show="meme" class="memeBox">
  394. <yd-slider autoplay="0" :loop="false">
  395. <yd-slider-item>
  396. <div>
  397. <ul style="width:100%;padding-bottom:.3rem;" class="row average wrap">
  398. <li v-for="(item,index) in frceArr" :key="index" v-show="index<15">
  399. <img
  400. class="memeImg"
  401. :src="require(`@/assets/${index}.gif`)"
  402. @click="memeImg(index)"
  403. >
  404. </li>
  405. </ul>
  406. </div>
  407. </yd-slider-item>
  408. <yd-slider-item>
  409. <div>
  410. <ul style="width:100%;padding-bottom:.3rem;" class="row average wrap">
  411. <li v-for="(item,index) in frceArr" :key="index" v-show="index>15&&index<=30">
  412. <img
  413. class="memeImg"
  414. :src="require(`@/assets/${index}.gif`)"
  415. @click="memeImg(index)"
  416. >
  417. </li>
  418. </ul>
  419. </div>
  420. </yd-slider-item>
  421. <yd-slider-item>
  422. <div>
  423. <ul style="width:100%;padding-bottom:.3rem;" class="row average wrap">
  424. <li v-for="(item,index) in frceArr" :key="index" v-show="index>30&&index<=45">
  425. <img
  426. class="memeImg"
  427. :src="require(`@/assets/${index}.gif`)"
  428. @click="memeImg(index)"
  429. >
  430. </li>
  431. </ul>
  432. </div>
  433. </yd-slider-item>
  434. <yd-slider-item>
  435. <div>
  436. <ul style="width:100%;padding-bottom:.3rem;" class="row average wrap">
  437. <li v-for="(item,index) in frceArr" :key="index" v-show="index>45&&index<=60">
  438. <img
  439. class="memeImg"
  440. :src="require(`@/assets/${index}.gif`)"
  441. @click="memeImg(index)"
  442. >
  443. </li>
  444. </ul>
  445. </div>
  446. </yd-slider-item>
  447. <yd-slider-item>
  448. <div>
  449. <ul style="width:100%;padding-bottom:.3rem;" class="row average wrap">
  450. <li v-for="(item,index) in frceArr" :key="index" v-show="index>60">
  451. <img
  452. class="memeImg"
  453. :src="require(`@/assets/${index}.gif`)"
  454. @click="memeImg(index)"
  455. >
  456. </li>
  457. </ul>
  458. </div>
  459. </yd-slider-item>
  460. </yd-slider>
  461. </div>
  462. </div>
  463. </div>
  464. <!-- 留言知识库 -->
  465. <div v-if="knowledge">
  466. <!-- 接收返回消息 -->
  467. <knowledgeLibrary @returnIndex="returnIndex" :currentTime="currentTime"/>
  468. </div>
  469. <!-- 发送消息音频提示 -->
  470. <audio id="send" src="../../static/send.wav"></audio>
  471. <!-- 接收消息音频提示 -->
  472. <audio id="receive" src="../../static/receive.wav"></audio>
  473. </div>
  474. </template>
  475. <script>
  476. import "../css/index.css";
  477. import knowledgeLibrary from './knowledgeLibrary'
  478. import frce from "./frce.js";
  479. import avatarImgs from "./../assets/user.png"
  480. import defaultImgs from "./../assets/timg.jpg"
  481. export default {
  482. name: "service",
  483. // 模板注册
  484. components: {
  485. knowledgeLibrary
  486. },
  487. data() {
  488. return {
  489. /*-----------------------------------------------*/
  490. text_info: "", //输入框内容
  491. knowledge: false,//留言知识库开关
  492. leftShow: false, //左侧详细开关
  493. evaluateOnOff: false, //人工客服评价通知
  494. bottomShow: false, //底部评价弹窗开关
  495. meme: false, // 表情包开关
  496. frceArr: [], //表情包代码
  497. evaluateState: 100,//评价状态
  498. websock: null,//创建websock
  499. user_info: '',//用户信息
  500. apiToken: '',//通话调用凭证
  501. currentTime: '',//接口调用服务器时间
  502. problem: [],//机器人问题
  503. welcome: [],//欢迎语
  504. advertisement: '', //广告
  505. img_http: 'http://103.108.43.176:8080',//图片路径域
  506. //img_http:'http://192.168.2.186:8090',//图片路径域
  507. robot: [],//和机器人聊天临时数据
  508. chat: [],//人工会话
  509. error_num: 1001,//机器人回答超出能力之外编号
  510. isConnection: true,//人工分组列表开关
  511. //客服信息
  512. service_info: {
  513. avatar: '/static/customer/images/robot.png',
  514. job_name: '001',
  515. name: '智能客服',
  516. signature: ""
  517. },
  518. link_success: false,//人工链接成功
  519. service_on: true,
  520. closeByServer: false, //客服关闭会话
  521. serverNotOnlin: false, //客服掉线
  522. willOverTime: false, //超时关闭会话
  523. overTimeMsg: '', // 超时提示内容
  524. conversationId: '',//会话工单
  525. chatNum: 0,//触发评价按钮条件
  526. haveEvaluation: false,//是否已评价
  527. evalArea: '', //评价备注
  528. source: {},//来源信息
  529. initData: 1,//
  530. isTurnArtifcial: true,
  531. box_height: false,//苹果浏览器增加会话框高度
  532. logo: '',
  533. isExit: false,
  534. historyMsg: false, // 是否展示历史信息
  535. historyMsgtext: "", // 历史信息内容提示
  536. hisSviceChat: [],
  537. showHistory: true,
  538. avatar_imgs: avatarImgs,
  539. webTime: '',//人工会话上一次发送消息时间
  540. chatIndex: '',//人工会话上一次下标
  541. /*****************websockt心跳变量*******************/
  542. reconnectData: null,
  543. lockReconnect: false, //避免重复连接,因为onerror之后会立即触发 onclose
  544. timeout: 5000, //5s一次心跳检测
  545. timeoutObj: null,
  546. serverTimeoutObj: null,
  547. waitingMsg: false, // 是否显示等待排队
  548. serviceNotOnlineText: '',
  549. };
  550. },
  551. // 方法
  552. methods: {
  553. // 退出聊天
  554. is_exit() {
  555. this.socket_send(JSON.stringify({
  556. type: 'kfCloseUser',
  557. data: {
  558. to_id: this.user_info.id,
  559. kf_id: this.service_info.id,
  560. group_id: this.service_info.group,
  561. conversationId: this.conversationId,
  562. type: 6,
  563. }
  564. }));
  565. // this.websock.close()
  566. // this.setInit();
  567. // this.initWebsocket()
  568. },
  569. /*******************************************/
  570. //设置token加密
  571. setApiToken(name, controller, time, modules) {
  572. //let txetVal = name + 'customer-service' + controller + time + modules;
  573. let txetVal = name + 'customer-service' + controller + modules;
  574. let sssd = txetVal.toLowerCase();
  575. return this.$md5(txetVal.toLowerCase());
  576. },
  577. /*******************************************/
  578. //初始化Websocket链接
  579. initWebSocket(apiToken) {
  580. let sock_ip = ''; // 线上
  581. // let sock_ip = 'ws://192.168.2.187:9101'; // 本地
  582. this.websock = new WebSocket("ws://103.108.43.176:9101?apiToken=" + apiToken);
  583. //数据返回
  584. this.websock.onmessage = this.socket_message;
  585. //数据发送
  586. this.websock.onopen = this.socket_open;
  587. //重新链接
  588. this.websock.onerror = this.socket_error;
  589. //关闭链接
  590. this.websock.onclose = this.socket_close;
  591. },
  592. /*******************************************/
  593. //连接建立之后执行send方法发送数据
  594. socket_open() {
  595. console.log('我链接了');
  596. },
  597. /*******************************************/
  598. //连接建立失败重连
  599. socket_error() {
  600. console.log('连接建立失败重连');
  601. // this.initWebSocket();
  602. // this.setInit();
  603. // this.reconnect();
  604. },
  605. /*******************************************/
  606. //数据接收
  607. socket_message(e) {
  608. if (!e.data) return;
  609. const redata = JSON.parse(e.data);
  610. console.log(redata);
  611. //心跳检测
  612. this.heatBeat();
  613. //欢迎语
  614. if (redata.message_type == 'helloMessage') {
  615. this.isTurnArtifcial = true;
  616. if (this.initData == 1) {
  617. this.welcome.push(redata.data.content);
  618. //this.welcome.push('请点击您想咨询的问题,若都不是,请在输入框直接输入');
  619. }
  620. }
  621. //广告语
  622. if (redata.message_type == 'advertisement') {
  623. this.advertisement = redata.data[0]
  624. }
  625. //机器人回复
  626. if (redata.message_type == "robotMessage") {
  627. // console.log(redata);
  628. if (redata.data.content == "error") {
  629. this.robot.push({
  630. type: 'error',
  631. content: {text: "您的问题暂无法处理"}
  632. })
  633. // this.error_num++;
  634. } else {
  635. this.robot.push({
  636. type: 'service',
  637. content: {text: redata.data.content}
  638. })
  639. }
  640. console.log(this.robot);
  641. // this.automaticRolling();
  642. //data
  643. //this.robot =
  644. }
  645. //人工链接
  646. if (redata.message_type == 'connect') {
  647. this.chat.splice(-1)
  648. let server = {};
  649. if (redata.data) {
  650. server = redata.data
  651. } else {
  652. server = {
  653. conversationId: redata.data.conversationId,
  654. kf_id: redata.data.kf_id,
  655. kf_name: "",
  656. serverInfo: {
  657. avatar: avatarImgs,
  658. client_id: "",
  659. group: "",
  660. id: "",
  661. intime: "",
  662. job_name: "",
  663. name: "tank",
  664. signature: "",
  665. status: 0,
  666. task: 0,
  667. }
  668. }
  669. }
  670. this.service_on = true;
  671. this.isExit = true;
  672. this.link_success = true;
  673. this.$dialog.loading.close();
  674. this.service_info = server.serverInfo;
  675. this.conversationId = server.conversationId;
  676. }
  677. // 客服掉线.
  678. if (redata.message_type == 'serviceoffline') {
  679. this.chat.push({
  680. type: 'system',
  681. content: {
  682. text: redata.msg,
  683. state: 'closeInform',
  684. }
  685. })
  686. this.automaticRolling();
  687. this.service_on = false;
  688. // let that = this;
  689. // setTimeout(function () {
  690. // that.link_success = false;
  691. // that.serverNotOnlin = true;
  692. // that.closeByServer = true;
  693. // that.chat.splice(-1)
  694. // },3000)
  695. }
  696. // 客服不在线请稍后再试
  697. if (redata.message_type == 'kfNotOnlin') {
  698. this.service_on = false;
  699. }
  700. // 客服会话超时
  701. if (redata.message_type == 'overtime') {
  702. this.willOverTime = true;
  703. this.automaticRolling();
  704. // this.goBack();
  705. this.overTimeMsg = redata.data.content;
  706. }
  707. // 客服等待排队
  708. if (redata.message_type == "inqueue") {
  709. this.waitingMsg = true;
  710. this.automaticRolling();
  711. this.waitingText = redata.content;
  712. }
  713. //人工会话回复
  714. if (redata.message_type == "chatMessage") {
  715. // 转接的时候清除历史信息
  716. // this.hisSviceChat = [];
  717. // this.getHistory = false;
  718. // 接收提示音
  719. this.receiveAudio();
  720. this.$dialog.loading.close();
  721. let obj = {};
  722. let isSession = false;
  723. if (this.$public.isJSON(redata.data.content)) {
  724. obj = JSON.parse(redata.data.content);
  725. obj.text = this.turnFace(obj.text);
  726. isSession = true;
  727. } else {
  728. obj.text = redata.data.content;
  729. }
  730. let thisTime = '';
  731. let newTime = redata.data.time.split(':');
  732. if (this.webTime) {
  733. let lastTime = this.webTime.split(":");
  734. if (newTime[0] == lastTime[0] && newTime[1] < (lastTime[1] + 2)) {
  735. thisTime = ''
  736. } else {
  737. thisTime = redata.data.time;
  738. }
  739. } else {
  740. if (isSession) {
  741. thisTime = redata.data.time;
  742. }
  743. }
  744. if (isSession) {
  745. this.webTime = redata.data.time;
  746. }
  747. this.chat.push({
  748. type: 'service',
  749. time: thisTime ? thisTime : '',
  750. content: obj
  751. })
  752. // this.setNum++;
  753. }
  754. //系统消息通知客户结束通话
  755. if (redata.message_type == 'closeBysever') {
  756. this.setInit();
  757. this.showHistory = false;
  758. this.link_success = false;
  759. this.isTurnArtifcial = true;
  760. }
  761. if (redata.message_type == "changeKeFuSuccess") {
  762. this.$dialog.alert({
  763. mes: redata.data.content
  764. });
  765. }
  766. //系统消息通转人工
  767. if (redata.message_type == 'notice') {
  768. this.$dialog.loading.close();
  769. this.isTurnArtifcial = true;
  770. let _this = this;
  771. this.$dialog.alert({
  772. mes: redata.content, callback: () => {
  773. this.initData = 100;
  774. // _this.$dialog.loading.open('数据加载中...');
  775. // setTimeout(() => {
  776. // _this.$dialog.loading.close();
  777. // // _this.registered();
  778. // }, 2000);
  779. }
  780. });
  781. }
  782. //系统消息评价
  783. if (redata.message_type == "getEvaluate") {
  784. // this.evaluateOnOff = true;
  785. // console.log( this.chat)
  786. this.chat.push({
  787. type: 'system',
  788. content: {
  789. text: redata.data.content,
  790. state: 'getEvaluate',
  791. }
  792. })
  793. }
  794. //会话关闭前通知用户
  795. if (redata.message_type == 'overtime') {
  796. this.chat.push({
  797. type: 'system',
  798. content: {
  799. text: redata.data.content,
  800. state: 'closeInform',
  801. }
  802. })
  803. }
  804. // 历史信息
  805. if (redata.message_type == 'toOld') {
  806. // console.log(redata, '历史信息')
  807. this.hisSviceChat = [];
  808. let obj = redata;
  809. this.historyMsgtext = obj.data.content;
  810. this.chat.push({
  811. type: 'historyMsg',
  812. content: {
  813. text: this.historyMsgtext,
  814. }
  815. })
  816. let historyTime = '';
  817. obj.data.chatLog.forEach(res => {
  818. // console.log(res,'历史信息');
  819. res.content = JSON.parse(res.content);
  820. let time_line = this.$public.customFormatDateTime(res.time_line, '', 3);
  821. // res.time_line =
  822. if (!historyTime) {
  823. res.time_line = time_line
  824. } else {
  825. let newTime = time_line.split(':');
  826. let lastTime = historyTime.split(':');
  827. if (newTime[0] == lastTime[0] && newTime[1] < (lastTime[1] + 2)) {
  828. res.time_line = '';
  829. } else {
  830. res.time_line = time_line
  831. }
  832. }
  833. historyTime = time_line;
  834. this.hisSviceChat.push(res);
  835. })
  836. }
  837. //获取发送时间
  838. if (redata.message_type == "webTime") {
  839. if (this.webTime) {
  840. let newTime = redata.data.webTime.split(':');
  841. let time = this.webTime.split(':');
  842. if (newTime[0] * 1 > time[0] * 1) {
  843. // console.log('newTime[0]')
  844. this.$set(this.chat[this.chatIndex], 'time', redata.data.webTime);
  845. } else if (newTime[0] * 1 == time[0] * 1 && (newTime[1] * 1 - time[1] * 1) > 2) {
  846. this.$set(this.chat[this.chatIndex], 'time', redata.data.webTime);
  847. // console.log('newTime[1]')
  848. }
  849. } else {
  850. this.chat[this.chatIndex].time = redata.data.webTime;
  851. // this.$set(this.chat[this.chatIndex],'time',redata.data.webTime);
  852. }
  853. this.webTime = redata.data.webTime
  854. }
  855. //屏幕滚动
  856. this.automaticRolling();
  857. },
  858. /*******************************************/
  859. //数据发送
  860. socket_send(Data) {
  861. this.websock.send(Data);
  862. },
  863. /*******************************************/
  864. //关闭
  865. socket_close(e) {
  866. console.log('断开连接', e);
  867. this.initData = 100;
  868. this.link_success = false;
  869. this.setInit();
  870. this.reconnect();
  871. // this.registered();
  872. // this.websock.close()
  873. },
  874. /***************************************/
  875. //socket重连
  876. reconnect() {
  877. if (this.lockReconnect) { //这里很关键,因为连接失败之后之后会相继触发 连接关闭,不然会连接上两个 WebSocket
  878. return
  879. }
  880. this.lockReconnect = true;
  881. this.reconnectData && clearTimeout(this.reconnectData);
  882. this.reconnectData = setTimeout(() => {
  883. this.initWebSocket(this.apiToken);
  884. //this.registered()
  885. console.log('-----lail-----');
  886. this.lockReconnect = false;
  887. }, 2000)
  888. },
  889. /*************************************/
  890. //心跳检测
  891. heatBeat() {
  892. this.timeoutObj && clearTimeout(this.timeoutObj);
  893. this.serverTimeoutObj && clearTimeout(this.serverTimeoutObj);
  894. this.timeoutObj = setTimeout(() => {
  895. // console.log('发送', {type: 'ping'});
  896. this.socket_send(JSON.stringify({type: 'ping'})) //根据后台要求发送
  897. this.serverTimeoutObj = setTimeout(() => {
  898. // console.log('------close-------')
  899. this.websock.close(); //如果 4秒之后我们没有收到 后台返回的心跳检测数据 断开socket,断开后会启动重连机制
  900. }, 4000);
  901. }, this.timeout)
  902. },
  903. /*****************************************/
  904. //用户匿名注册
  905. registered() {
  906. let token = localStorage.getItem('token');
  907. let appuid = this.$public.getQueryString('appuid');
  908. let tutype = this.$public.getQueryString('tutype');
  909. if (appuid && tutype >= 1) {
  910. token = localStorage.getItem('token');
  911. } else if (!appuid && tutype < 1) {
  912. token = localStorage.getItem('token');
  913. } else {
  914. token = '';
  915. }
  916. let data = {
  917. token: token != null ? token : '',
  918. appid: this.$public.getQueryString('appid'),
  919. appuid: this.$public.getQueryString('appuid'),
  920. }
  921. let obj = {
  922. headers: {
  923. "apiToken": this.setApiToken('autoReg', 'register', this.currentTime[0], 'index')
  924. }
  925. }
  926. this.post('api/index/register/autoReg', data, obj).then(res => {
  927. if (res.data.code == 0) {
  928. this.$dialog.alert({
  929. mes: res.data.msg
  930. });
  931. } else if (res.data.code == 1) {
  932. this.user_info = res.data.data;
  933. // console.log(this.user_info)
  934. // 游客 token
  935. localStorage.setItem("token", res.data.data.token);
  936. localStorage.setItem("tutype", res.data.tutype);
  937. //Websocket链接
  938. setTimeout(() => {
  939. this.$dialog.loading.close();
  940. this.initWebSocket(this.apiToken);
  941. }, 2000)
  942. //console.log(res.data.data)
  943. }
  944. })
  945. },
  946. /******************************************/
  947. //获取热门问题
  948. getProblem() {
  949. let obj = {
  950. headers: {
  951. // 'Content-Type': 'application/x-www-form-urlencoded',
  952. "apiToken": this.setApiToken('index', 'robot', this.currentTime[0], 'index')
  953. }
  954. }
  955. this.post('api/index/robot/index', {groups_id: 1, robotgroups_id: 1}, obj).then(res => {
  956. //console.log(res.data.data);
  957. this.problem = res.data.data;
  958. })
  959. },
  960. /*******************************************/
  961. //推送机器人消息
  962. pushMessage(e) {
  963. this.robot.push({
  964. type: 'service',
  965. content: {text: e}
  966. });
  967. this.automaticRolling();
  968. },
  969. /*******************************************/
  970. //转人工
  971. turnArtificial(id) {
  972. this.group = id;
  973. this.$dialog.loading.open('转接中...')
  974. if (this.isTurnArtifcial) {
  975. let data = {
  976. 'type': 'userInit',
  977. data: {
  978. 'uid': this.user_info.id,
  979. 'name': this.user_info.name,
  980. 'avatar': this.user_info.avatar,
  981. 'group': this.group
  982. }
  983. }
  984. this.socket_send(JSON.stringify(data));
  985. this.isTurnArtifcial = false
  986. }
  987. },
  988. /******************************************/
  989. // 消息发送
  990. send() {
  991. if (this.text_info == '') return;
  992. let str = this.text_info;
  993. let formatStr = str.replace(/\n|\r\n/g, "<br>");
  994. let type = 'toRobot';
  995. let data = {};
  996. let obj = {
  997. text: formatStr,
  998. img: '',
  999. type: ''
  1000. }
  1001. this.meme = false;
  1002. // console.log(JSON.stringify(obj))
  1003. //和人工发送消息
  1004. if (this.link_success) {
  1005. // if(this.getHistory){
  1006. // this.getHistory = false;
  1007. // }
  1008. data = {
  1009. from_name: this.user_info.name,
  1010. content: JSON.stringify(obj),
  1011. from_id: this.user_info.id,
  1012. avatar: '',
  1013. to_id: this.service_info.id,
  1014. to_name: this.service_info.name,
  1015. conversationId: this.conversationId,
  1016. }
  1017. type = 'chatMessage';
  1018. this.chatIndex = this.chat.length;
  1019. this.chat.push({
  1020. type: 'user',
  1021. time: '',
  1022. content: {text: this.turnFace(obj.text)}
  1023. })
  1024. } else {//和机器人聊天
  1025. data = {
  1026. groups_id: '1',
  1027. robot_name: formatStr,
  1028. robotgroups_id: '1',
  1029. }
  1030. // console.log(this.turnFace(formatStr));
  1031. type = 'toRobot';
  1032. //本地存放数据
  1033. this.robot.push({
  1034. type: 'user',
  1035. content: this.turnFace(formatStr) //obj
  1036. })
  1037. }
  1038. this.socket_send(JSON.stringify({type, data}))
  1039. this.text_info = '';
  1040. this.automaticRolling();
  1041. // console.log(data)
  1042. this.sendAudio();
  1043. },
  1044. // 消息发送
  1045. sendAudio() {
  1046. console.log(1)
  1047. let send = document.getElementById('send')
  1048. send.play()
  1049. },
  1050. // 消息接收
  1051. receiveAudio() {
  1052. let receive = document.getElementById('receive')
  1053. receive.play();
  1054. },
  1055. /*******************************************/
  1056. //获取转接人工客服列表
  1057. connectionService() {
  1058. // if (!this.isConnection) return
  1059. let obj = {
  1060. headers: {
  1061. "apiToken": this.setApiToken('index', 'groups', this.currentTime[0], 'index')
  1062. }
  1063. }
  1064. // this.isConnection = false;
  1065. //api
  1066. this.get('api/index/groups/index', obj).then(res => {
  1067. if (res.data.code == 1) {
  1068. this.robot.push({
  1069. type: 'artificial_service',
  1070. content: res.data.data
  1071. });
  1072. this.automaticRolling();
  1073. }
  1074. })
  1075. //this.hintSwitch.connection = true; //系统提示开关激活
  1076. // 此处为请求
  1077. },
  1078. /*******************************************/
  1079. //发送消息后自动滚动高度
  1080. automaticRolling() {
  1081. this.$nextTick(() => {
  1082. let msg = document.getElementById('main') // 获取对象
  1083. // let input_box = document.getElementById('input_box') // 获取对象
  1084. //判断是否是苹果手机自代浏览器
  1085. if (/Safari/.test(navigator.userAgent) && /Chrome/.test(navigator.userAgent)) {
  1086. this.box_height = true; //input_box+'px';
  1087. }
  1088. msg.scrollTop = msg.scrollHeight // 滚动高度
  1089. })
  1090. },
  1091. /*******************************************/
  1092. //图片发送
  1093. uploadIMG(e) {
  1094. //console.log(e);
  1095. let self = this;
  1096. let files = e.target.files || e.dataTransfer.files;
  1097. if (!files.length) return;
  1098. let picavalue = files[0];
  1099. const isJPG = file.type == 'image/jpeg' || 'image/jpg' || 'image/png' || 'image/svg';
  1100. const isLt2M = picavalue.size / 1000 / 1000 > 2;
  1101. if (isLt2M) {
  1102. this.$dialog.notify({
  1103. mes: '图片过大不支持上传哦!',
  1104. timeout: 2000,
  1105. });
  1106. } else if (!isJPG) {
  1107. this.$dialog.notify({
  1108. mes: '只能上传图片哦!',
  1109. timeout: 2000,
  1110. });
  1111. } else {
  1112. this.$public.imgPreview(picavalue, function (imgSrc, formData) {
  1113. // let img = imgSrc;
  1114. // 数据结构请求
  1115. self.post('api/index/upload/uploadImg', formData).then(res => {
  1116. // console.log(res.data.code)
  1117. if (res.data.code == 1) {
  1118. let type = 'toRobot';
  1119. let data = {};
  1120. let obj = {
  1121. text: '',
  1122. img: res.data.data.src,
  1123. type: ''
  1124. }
  1125. if (self.link_success) {
  1126. //和人工聊天发送图片
  1127. data = {
  1128. from_name: self.user_info.name,
  1129. content: JSON.stringify(obj),
  1130. from_id: self.user_info.id,
  1131. avatar: '',
  1132. to_id: self.service_info.id,
  1133. to_name: self.service_info.name,
  1134. conversationId: self.conversationId,
  1135. }
  1136. type = 'chatMessage';
  1137. //本地储存
  1138. self.chat.push({
  1139. type: 'user',
  1140. content: {img: res.data.data.src}
  1141. });
  1142. } else {
  1143. //和机器发送图片
  1144. data = {
  1145. groups_id: '1',
  1146. robot_name: res.data.data.src,
  1147. robotgroups_id: '1',
  1148. }
  1149. type = 'toRobot';
  1150. //本地储存
  1151. self.robot.push({
  1152. type: 'user',
  1153. content: {img: res.data.data.src}
  1154. });
  1155. }
  1156. self.socket_send(JSON.stringify({type, data}))
  1157. self.automaticRolling();
  1158. }
  1159. })
  1160. });
  1161. }
  1162. },
  1163. /*******************************************/
  1164. //手机弹窗处理
  1165. inputShow(e) {
  1166. //console.log('a')
  1167. let ua = navigator.userAgent.toLowerCase();
  1168. if (ua.match(/iPhone\sOS/i) == "iphone os") {
  1169. var nowClientHeight = document.documentElement.clientHeight || document.body.clientHeight;
  1170. setTimeout(() => {
  1171. document.body.scrollTop = document.body.scrollHeight - (nowClientHeight / 2)
  1172. }, 200);
  1173. } else {
  1174. setTimeout(function () {
  1175. e.target.scrollIntoView({behavior: "smooth", block: "end"});
  1176. }, 100);
  1177. }
  1178. },
  1179. /******************文字信息转表情******************/
  1180. turnFace(data) {
  1181. let str = data.match(/\#\[.*?\]\//g);
  1182. let arr = Array.from(new Set(str));
  1183. arr.forEach(e => {
  1184. let imgsrc = '';
  1185. for (let i = 0; i < this.frceArr.length; i++) {
  1186. let expText = e.slice(1, e.length - 1);
  1187. if (expText == this.frceArr[i]) {
  1188. imgsrc = '<img class="hover" src="' + require(`@/assets/${i}.gif`) + '"/>'
  1189. break;
  1190. }
  1191. }
  1192. data = data.replace(new RegExp(`\\#\\[${e.substring(2, e.length - 2)}\\]\\/`, 'g'), imgsrc);
  1193. })
  1194. return data;
  1195. },
  1196. /*******************************************/
  1197. // 表情包开关
  1198. faceClick() {
  1199. this.meme = !this.meme;
  1200. },
  1201. /*******************************************/
  1202. //当表情被点击
  1203. memeImg(i) {
  1204. this.text_info = this.text_info + "#" + this.frceArr[i] + "/";
  1205. //this.text_info = this.text_info + '<img :src="' + require(`@/assets/${i}.gif`) +'"/>';
  1206. // console.log( this.text_info);
  1207. },
  1208. // /*******************************************/
  1209. // //验证码
  1210. // initialLoginCode() {
  1211. // this.loginCode = "";
  1212. // for (let i = 1; i <= 4; i++) {
  1213. // this.loginCode =
  1214. // this.loginCode + frce.arr[Math.floor(Math.random() * 32)];
  1215. // }
  1216. // },
  1217. /********************************************/
  1218. //显示隐藏评价
  1219. is_show_evaluate() {
  1220. if (this.evaluateState == 100) {
  1221. this.bottomShow = true;
  1222. } else {
  1223. if (!this.haveEvaluation) {
  1224. this.bottomShow = false;
  1225. } else {
  1226. this.$dialog.notify({
  1227. mes: '亲,您已经评价了...',
  1228. timeout: 5000,
  1229. callback: () => {
  1230. //console.log('我走咯!');
  1231. }
  1232. });
  1233. }
  1234. }
  1235. },
  1236. /*******************************************/
  1237. //切换评价状态
  1238. evaluateClick(type) {
  1239. // console.log(type);
  1240. this.evaluateState = type;
  1241. },
  1242. /*******************************************/
  1243. //提交评价信息
  1244. evaluateEsc() {
  1245. console.log();
  1246. if (this.evaluateState != 100) {
  1247. this.bottomShow = false;
  1248. this.haveEvaluation = true; // 标识已评价
  1249. this.socket_send(JSON.stringify({
  1250. type: 'evaluate', data: {
  1251. evaluate_id: this.evaluateState,
  1252. conversationId: this.conversationId,
  1253. // evaluate_content:''
  1254. }
  1255. }))
  1256. this.$dialog.notify({
  1257. mes: '感谢你的评价!',
  1258. timeout: 2000,
  1259. callback: () => {
  1260. //console.log('我走咯!');
  1261. }
  1262. });
  1263. } else {
  1264. this.$dialog.notify({
  1265. mes: '亲,请选择评价类型...',
  1266. timeout: 2000,
  1267. callback: () => {
  1268. //console.log('我走咯!');
  1269. }
  1270. });
  1271. }
  1272. },
  1273. /************************************************/
  1274. //人工聊天初始化
  1275. setInit() {
  1276. this.haveEvaluation = false;
  1277. this.chat = [];
  1278. this.evaluateState = 100;
  1279. this.hisSviceChat = [];
  1280. this.meme = false
  1281. // this.frceArr = [];//表情包代码
  1282. this.isConnection = true;
  1283. this.isExit = false;
  1284. this.service_info = {
  1285. avatar: '/static/customer/images/robot.png',
  1286. job_name: '001',
  1287. name: '智能客服',
  1288. signature: " "
  1289. }
  1290. },
  1291. /* ****************获取聊天次数****************** */
  1292. getChatNum() {
  1293. this.get('/api/index/evaluate/minRound', {
  1294. headers: {
  1295. 'Content-Type': 'application/x-www-form-urlencoded',
  1296. 'apiToken': this.setApiToken('minround', 'evaluate', this.currentTime[0], 'index')
  1297. }
  1298. }).then(res => {
  1299. if (res.data.code == 1) {
  1300. this.chatNum = res.data.data.systemconfig_data
  1301. }
  1302. })
  1303. },
  1304. // 留言知识库返回到主页
  1305. returnIndex(data) {
  1306. console.log(data)
  1307. this.knowledge = data
  1308. }
  1309. },
  1310. /**
  1311. * 视图挂载前
  1312. */
  1313. mounted() {
  1314. this.source.appuid = this.$public.getQueryString('appuid');//用户标识
  1315. this.source.appid = this.$public.getQueryString('appid');//用户来源
  1316. this.frceArr = frce.frce;
  1317. //console.log(this.source);
  1318. //页面初始化获取系统时间第一步
  1319. //console.log(this.$md5('userwordscustomer-servicewords1562169600service'));
  1320. this.$dialog.loading.open('网络连接中...')
  1321. this.$axios.get('api/index/index/systime?t=' + 100).then(res => {
  1322. if (res.data.code == 1) {
  1323. this.logo = res.data.data.logo;
  1324. this.currentTime = res.data.data.time.split(' ')
  1325. this.currentTime[0] = (new Date(this.currentTime[0].replace(/-/g, '/')).getTime()) / 1000;
  1326. // console.log( this.currentTime[0] );
  1327. this.apiToken = this.$md5('customer-service' + window.location.origin);
  1328. //匿名注册
  1329. this.registered();
  1330. //获取机器人热门问题
  1331. this.getProblem();
  1332. //获取配置信息
  1333. this.getChatNum();
  1334. }
  1335. })
  1336. },
  1337. destroyed() {
  1338. this.setInit();
  1339. this.websock.close() //离开路由之后断开websocket连接
  1340. this.lockReconnect = true;
  1341. clearTimeout(this.reconnectData); //离开清除 timeout
  1342. clearTimeout(this.timeoutObj); //离开清除 timeout
  1343. clearTimeout(this.serverTimeoutObj); //离开清除 timeout
  1344. },
  1345. // 计算
  1346. computed: {
  1347. inputmsg() {
  1348. return this.text_info;
  1349. }
  1350. },
  1351. // 监听
  1352. watch: {},
  1353. // 组件生命周期结束销毁阶段
  1354. beforeDestroy() {
  1355. this.timers = false;
  1356. }
  1357. };
  1358. </script>
  1359. <style scoped>
  1360. #textarea {
  1361. margin: 15px;
  1362. width: 50%;
  1363. border: none;
  1364. }
  1365. .logo {
  1366. margin: 0 0.1rem;
  1367. width: 0.4rem;
  1368. height: 0.4rem;
  1369. }
  1370. /* 聊天 */
  1371. .memeImg {
  1372. width: 0.6rem;
  1373. height: 0.6rem;
  1374. margin: 0.15rem 0.4rem;
  1375. }
  1376. .dialogueA {
  1377. padding-left: 0.3rem;
  1378. padding-right: 0.3rem;
  1379. }
  1380. .dialogueB {
  1381. padding-right: 0.3rem;
  1382. padding-left: 0.3rem;
  1383. }
  1384. .left {
  1385. position: relative;
  1386. z-index: 99;
  1387. background: #fff;
  1388. }
  1389. .left::after {
  1390. position: absolute;
  1391. content: "";
  1392. display: inline-block;
  1393. left: -0.08rem;
  1394. top: 0.2rem;
  1395. width: 0.125rem;
  1396. height: 0.2rem;
  1397. background: #fff;
  1398. transform: skewX(30deg);
  1399. z-index: -1;
  1400. border-left: 0.02rem solid #dfdfdf;
  1401. border-top: 0.02rem solid #dfdfdf;
  1402. }
  1403. .right {
  1404. position: relative;
  1405. z-index: 99;
  1406. background: #5ea0f7;
  1407. border: 0.02rem solid #5ea0f7;
  1408. }
  1409. .right::after {
  1410. position: absolute;
  1411. content: "";
  1412. display: inline-block;
  1413. right: -0.07rem;
  1414. top: 0.2rem;
  1415. width: 0.125rem;
  1416. height: 0.2rem;
  1417. background: #5ea0f7;
  1418. transform: skewX(-30deg);
  1419. z-index: -1;
  1420. border-left: 0.02rem solid #5ea0f7;
  1421. border-top: 0.02rem solid #5ea0f7;
  1422. }
  1423. .service {
  1424. width: 100%;
  1425. color: #555;
  1426. font-size: 0.28rem;
  1427. padding-top: 1rem;
  1428. background: #f5f5f5;
  1429. }
  1430. .header {
  1431. position: fixed;
  1432. left: 0;
  1433. top: 0;
  1434. width: 100%;
  1435. z-index: 999;
  1436. height: 1rem;
  1437. background: linear-gradient(
  1438. 90deg,
  1439. rgba(22, 84, 209, 1) 0%,
  1440. rgba(9, 52, 173, 1) 100%
  1441. );
  1442. box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.2);
  1443. font-size: 0.34rem;
  1444. color: #fff;
  1445. padding: 0 0.3rem;
  1446. }
  1447. .main {
  1448. height: 83vh;
  1449. overflow-x: hidden;
  1450. overflow-y: auto;
  1451. padding: 0 0.3rem;
  1452. }
  1453. .btn {
  1454. display: inline-block;
  1455. padding: 0 0.36rem;
  1456. text-align: center;
  1457. line-height: 0.4rem;
  1458. background: rgba(221, 221, 221, 1);
  1459. border-radius: 0.3rem;
  1460. color: #fff;
  1461. font-size: 0.24rem;
  1462. max-width: 6rem;
  1463. margin: 0 auto;
  1464. margin-top: 0.3rem;
  1465. }
  1466. .btn .click {
  1467. color: #5ea0f7;
  1468. }
  1469. .btnRouter {
  1470. color: #5ea0f7;
  1471. }
  1472. .systemDialogue {
  1473. min-height: 0.8rem;
  1474. width: 100%;
  1475. }
  1476. .manUserDialogue {
  1477. min-height: 1rem;
  1478. }
  1479. .manPlatformDialogue {
  1480. min-height: 1rem;
  1481. }
  1482. .user {
  1483. padding: 0.2rem;
  1484. display: inline-block;
  1485. border-radius: 0.1rem;
  1486. font-size: 0.28rem;
  1487. color: #fff;
  1488. }
  1489. .HeadPortrait {
  1490. width: 1rem;
  1491. height: 1rem;
  1492. /* background: #ddd; */
  1493. border-radius: 0.1rem;
  1494. }
  1495. .HeadPortrait img {
  1496. width: 100%;
  1497. height: 100%;
  1498. }
  1499. .icon {
  1500. width: 0.32rem;
  1501. height: 0.32rem;
  1502. }
  1503. .icon-msg {
  1504. width: 0.32rem;
  1505. height: 0.32rem;
  1506. margin: 0 0.1rem;
  1507. }
  1508. .customerService {
  1509. background: #ffffff;
  1510. padding: 0.2rem;
  1511. display: inline-block;
  1512. border-radius: 0.1rem;
  1513. font-size: 0.28rem;
  1514. border: 1px solid rgba(223, 223, 223, 1);
  1515. }
  1516. .customerService {
  1517. /* min-height: 1rem; */
  1518. }
  1519. .system {
  1520. width: 100%;
  1521. border: 0.01rem solid rgba(223, 223, 223, 1);
  1522. border-radius: 0.1rem;
  1523. }
  1524. div /deep/ .yd-accordion-head {
  1525. /* border-radius: 0.1rem; */
  1526. border-bottom: 0.01rem solid rgb(238, 238, 238);
  1527. padding: 0 0.2rem;
  1528. }
  1529. div /deep/ .yd-accordion-title, div /deep/ .yd-accordion-head-arrow {
  1530. min-height: 0.8rem !important;
  1531. }
  1532. div /deep/ .yd-textarea textarea {
  1533. -webkit-user-select: auto;
  1534. }
  1535. .footer {
  1536. min-height: 1.2rem;
  1537. box-shadow: 0px -5px 5px rgba(0, 0, 0, 0.05);
  1538. background: #fff;
  1539. width: 100%;
  1540. position: fixed;
  1541. bottom: 0;
  1542. left: 0;
  1543. z-index: 1000;
  1544. }
  1545. .input {
  1546. width: 60%;
  1547. min-height: 1.2rem;
  1548. padding-top: 0.4rem;
  1549. padding-bottom: 0.4rem;
  1550. border: none;
  1551. padding-right: 0.3rem;
  1552. padding-left: 0.3rem;
  1553. font-size: 0.28rem;
  1554. }
  1555. .send {
  1556. width: 40%;
  1557. position: absolute;
  1558. right: 0;
  1559. top: 0;
  1560. background: #fff;
  1561. height: 1.2rem;
  1562. }
  1563. .memeBox {
  1564. height: 3rem;
  1565. width: 100%;
  1566. }
  1567. .send img {
  1568. vertical-align: middle;
  1569. margin-right: 0.4rem;
  1570. }
  1571. .artificial {
  1572. margin-top: 0.3rem;
  1573. border: 0.01rem solid #dfdfdf;
  1574. background: #fff;
  1575. border-radius: 0.1rem;
  1576. padding: 0 0.2rem;
  1577. }
  1578. div /deep/ .yd-accordion-head-arrow:after {
  1579. border: none;
  1580. width: 0.3rem;
  1581. height: 0.3rem;
  1582. background: url("../assets/addright.png") no-repeat;
  1583. background-size: 100% 100%;
  1584. transform: rotate(0deg);
  1585. }
  1586. div /deep/ .yd-accordion-head-arrow.yd-accordion-rotated:after {
  1587. transform: rotate(-270deg);
  1588. }
  1589. div /deep/ .yd-accordion {
  1590. border-radius: 0.1rem;
  1591. }
  1592. div /deep/ .yd-accordion-content {
  1593. border-radius: 0.1rem;
  1594. }
  1595. .imgSrc img {
  1596. width: 1.2rem;
  1597. }
  1598. .leftHader {
  1599. height: 1rem;
  1600. background: linear-gradient(
  1601. 90deg,
  1602. rgba(22, 84, 209, 1) 0%,
  1603. rgba(9, 52, 173, 1) 100%
  1604. );
  1605. box-shadow: 0 0.03rem 0.03rem rgba(0, 0, 0, 0.2);
  1606. padding: 0 0.3rem;
  1607. }
  1608. .leftMain-top {
  1609. margin-top: 0.4rem;
  1610. font-size: 0.28rem;
  1611. line-height: 0.45rem;
  1612. padding: 0 0.3rem;
  1613. color: #666;
  1614. }
  1615. .leftMain-top span {
  1616. color: #999;
  1617. }
  1618. .leftMain-top > div {
  1619. width: 50%;
  1620. }
  1621. .leftMain-center {
  1622. margin-top: 0.3rem;
  1623. color: #666;
  1624. line-height: 0.5rem;
  1625. }
  1626. .leftMain-chenter span {
  1627. color: #999;
  1628. font-size: 0.28rem;
  1629. }
  1630. .evaluate {
  1631. height: 1.7rem;
  1632. background: #fff;
  1633. border: 0.01rem solid #ddd;
  1634. border-radius: 0.1rem;
  1635. color: #666;
  1636. margin-top: 0.3rem;
  1637. }
  1638. .evaluateBtn {
  1639. width: 1.4rem;
  1640. height: 0.6rem;
  1641. border: none;
  1642. background: #f04992;
  1643. color: #fff;
  1644. border-radius: 0.1rem;
  1645. }
  1646. div /deep/ .yd-popup {
  1647. border-radius: 0.2rem 0.2rem 0 0;
  1648. }
  1649. div /deep/ .yd-popup-content {
  1650. }
  1651. .evaluatebtn > div p {
  1652. height: 50%;
  1653. width: 100%;
  1654. text-align: center;
  1655. margin-top: 0.14rem;
  1656. }
  1657. .evaluatebtn > div {
  1658. display: flex;
  1659. align-items: center;
  1660. justify-content: center;
  1661. }
  1662. .evaluateBox {
  1663. margin: 0 0.2rem;
  1664. height: 1.5rem;
  1665. border: 0.01rem solid #ddd;
  1666. border-radius: 0.1rem;
  1667. background: #f5f5f5;
  1668. }
  1669. .evaluateBox textarea {
  1670. width: 100%;
  1671. height: 100%;
  1672. background: #f5f5f5;
  1673. border: none;
  1674. border-radius: 0.1rem;
  1675. padding: 0.2rem;
  1676. color: #999;
  1677. font-size: 0.28rem;
  1678. }
  1679. .sub {
  1680. margin: 0 0.2rem;
  1681. background: linear-gradient(
  1682. 90deg,
  1683. rgba(22, 84, 209, 1) 0%,
  1684. rgba(9, 52, 173, 1) 100%
  1685. );
  1686. box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.2);
  1687. height: 1rem;
  1688. font-size: 0.34rem;
  1689. color: #fff;
  1690. border-radius: 0.1rem;
  1691. margin-top: 0.4rem;
  1692. }
  1693. div /deep/ .yd-popup-content {
  1694. background: #fff;
  1695. border-radius: 0.1rem;
  1696. }
  1697. .loginInput {
  1698. height: 0.8rem;
  1699. border: 0.01rem solid #ddd;
  1700. background: #f5f5f5;
  1701. border-radius: 0.1rem;
  1702. margin-top: 0.5rem;
  1703. padding: 0.2rem;
  1704. font-size: 0.28rem;
  1705. margin: 0.2rem;
  1706. margin-top: 0.5rem;
  1707. width: 94%;
  1708. color: #999;
  1709. }
  1710. /* 留言 */
  1711. .leave-header {
  1712. height: 1rem;
  1713. background: linear-gradient(
  1714. 90deg,
  1715. rgba(22, 84, 209, 1) 0%,
  1716. rgba(9, 52, 173, 1) 100%
  1717. );
  1718. box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.2);
  1719. color: #fff;
  1720. font-size: 0.34rem;
  1721. padding: 0 0.3rem;
  1722. }
  1723. .leave-main {
  1724. height: 10rem;
  1725. background: #f5f5f5;
  1726. font-size: 0.28rem;
  1727. padding: 0.3rem 0.3rem 0.2rem 0.3rem;
  1728. }
  1729. .leave-main > div {
  1730. height: 1.3rem;
  1731. margin-bottom: 0.2rem;
  1732. }
  1733. .leave-main > div input {
  1734. height: 0.8rem;
  1735. border: 0.01rem solid #ddd;
  1736. border-radius: 0.1rem;
  1737. background: #fff;
  1738. padding: 0.2rem;
  1739. width: 100%;
  1740. margin-top: 0.1rem;
  1741. }
  1742. .leave-main-txt {
  1743. background: #fff;
  1744. padding: 0.2rem;
  1745. border: 0.01rem solid #ddd;
  1746. border-radius: 0.1rem;
  1747. }
  1748. .imgMsg {
  1749. height: 1.5rem;
  1750. padding: 0 0.2rem;
  1751. margin-top: 0.1rem;
  1752. font-size: 0.24rem;
  1753. background: #fff;
  1754. border: 0.01rem solid #ddd;
  1755. border-radius: 0.1rem;
  1756. }
  1757. .yd-cell-box {
  1758. width: 60%;
  1759. min-height: 1.2rem;
  1760. border: none;
  1761. padding-right: 0.3rem;
  1762. padding-left: 0.3rem;
  1763. border-bottom: 0.01rem solid rgb(221, 221, 221);
  1764. }
  1765. div /deep/ .yd-textarea > textarea {
  1766. height: 1.2rem;
  1767. font-size: 0.28rem;
  1768. padding-top: 0.2rem;
  1769. }
  1770. .yd-textarea {
  1771. padding: 0;
  1772. }
  1773. .yd-cell-box {
  1774. margin: 0;
  1775. }
  1776. .yd-cell-item {
  1777. padding: 0;
  1778. }
  1779. div /deep/ .yd-cell:after {
  1780. height: 0;
  1781. }
  1782. div /deep/ .yd-textarea-counter {
  1783. display: none;
  1784. }
  1785. .promptBox {
  1786. display: flex;
  1787. justify-content: center;
  1788. height: 26px;
  1789. margin: 10px 0 10px;
  1790. /* line-height: 26px; */
  1791. }
  1792. .promptBoxH {
  1793. display: flex;
  1794. justify-content: center;
  1795. height: 50px;
  1796. margin: 10px 0 10px;
  1797. /* line-height: 26px; */
  1798. }
  1799. .prompt {
  1800. line-height: 25px;
  1801. text-align: center;
  1802. background: #DDDDDD;
  1803. border-radius: 30px;
  1804. width: 140px;
  1805. color: #FFFFFF;
  1806. font-size: 12px;
  1807. }
  1808. .help {
  1809. width: 80%;
  1810. }
  1811. .help .prompt {
  1812. width: 100%;
  1813. }
  1814. /*
  1815. *留言知识库
  1816. */
  1817. </style>