index.vue 54 KB

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