index.vue 54 KB

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