index.vue 54 KB

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