hader.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <template>
  2. <div>
  3. <div class="header row allAlignment">
  4. <div class="row item-center box_div" style="color:#666;font-size:14px;font-weight:bold;">
  5. <img style="width:38px;height:38px;margin: 0 10px;" :src="img_http + user_info.user_avatar">
  6. 你好,<span>{{user_info.user_name}}--{{user_info.group}}</span>
  7. </div>
  8. <div class="row item-center rightAlignment msg box_div" style="padding: 0 30px;font-size:12px;color:#999">
  9. <div>
  10. <el-dropdown @command="handleCommand">
  11. <span class="el-span-1" v-if="value == '在线'" style="color: #00eb00">
  12. <i class="el-icon-user"></i>
  13. {{value}}
  14. </span>
  15. <span class="el-span-1" v-if="value == '隐身'" style="color: gray">
  16. <i class="el-icon-user"></i>
  17. {{value}}
  18. </span>
  19. <span class="el-span-1" v-if="value == '休息'" style="color: #f4f400">
  20. <i class="el-icon-user"></i>
  21. {{value}}
  22. </span>
  23. <el-dropdown-menu slot="dropdown">
  24. <el-dropdown-item command=0>在线</el-dropdown-item>
  25. <el-dropdown-item command=1>隐身</el-dropdown-item>
  26. <el-dropdown-item command=2>休息</el-dropdown-item>
  27. </el-dropdown-menu>
  28. </el-dropdown>
  29. </div>
  30. <!-- 会话总览 -->
  31. <el-badge class="item">
  32. <!-- el-icon-menu -->
  33. <el-button @click="getInnerDrawer()">
  34. <i style="font-size:14px; color:#5aa0fbbd ;" class="el-icon-menu"> </i>会话总览
  35. </el-button>
  36. <el-drawer
  37. id="huihua"
  38. title="会话总览"
  39. :modal="false"
  40. :show-close="true"
  41. size="90%"
  42. style="margin-top: 7vh"
  43. :before-close="handleClose"
  44. :visible.sync="innerDrawer">
  45. <div class="session_overview">
  46. <!-- 会话列表 -->
  47. <el-col :span="6">
  48. <el-tree class="session_list"
  49. :data="dataTree"
  50. :props="defaultProps"
  51. default-expand-all
  52. @node-click="handleNodeClick">
  53. </el-tree>
  54. </el-col>
  55. <!-- 会话消息 -->
  56. <el-col class="session_box" :span="12">
  57. <div class="session_box_title">{{session_litle ? session_litle :'未选择会话'}}</div>
  58. <div class="session_box_content">
  59. <!-- <div class="chatWindow" > -->
  60. <div v-for="(item,index) in dataList " :key="index">
  61. <!-- 模拟用户 -->
  62. <div v-if="item.to_id.startsWith('KF')" style="padding-top:10px;">
  63. <div class="title_time">
  64. <span>{{item.time_line}}</span>
  65. </div>
  66. <div v-if="item.content.text" class=" row wrap" >
  67. <div class="left_session item-center" v-html="item.content.text"></div>
  68. </div>
  69. <div v-if="item.content.img" class="row " >
  70. <div class="left_session item-center " >
  71. <el-image
  72. :src="img_http+item.content.img"
  73. @click="handlePictureCardPreview(img_http+item.content.img)">
  74. </el-image>
  75. </div>
  76. </div>
  77. </div>
  78. <!-- 模拟客户 -->
  79. <div v-else style="padding-top:10px;">
  80. <div class="row rightAlignment title_time" style="width: 100%;">
  81. <span>{{item.time_line}}</span>
  82. </div>
  83. <div v-if="item.content.text" class="row rightAlignment">
  84. <div class="right_session item-center wrap" v-html="item.content.text"></div>
  85. </div>
  86. <div v-if="item.content.img" class="row rightAlignment" >
  87. <div class="right_session item-center ">
  88. <el-image
  89. :src="img_http+item.content.img"
  90. @click="handlePictureCardPreview(img_http+item.content.img)">
  91. </el-image>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. </el-col>
  98. <!-- 用户信息 -->
  99. <el-col class="user_info" :span="6">
  100. <!-- 用户信息展示框 -->
  101. <div>
  102. <ul style="padding-inline-start:0px; margin-block-start:0; margin-top:30px;">
  103. <li style="font-weight:bold;font-weight:bold; color:#666666;">访问信息</li>
  104. <li>IP地址:{{visitorsInfo.user_ip}}</li>
  105. <li>来源终端:{{visitorsInfo.system}}-{{visitorsInfo.browse}}</li>
  106. </ul>
  107. <ul style="padding-inline-start:0px; margin-block-start: 0; margin-top:30px;">
  108. <li style="font-weight:bold;font-weight:bold; color:#666666;">用户信息</li>
  109. <li>账号:{{visitorsInfo.account_name}}</li>
  110. <li>标签:{{visitorsInfo.label}}</li>
  111. <li>昵称:{{visitorsInfo.nick_name}}</li>
  112. <li>手机:{{visitorsInfo.visitorsInfo_phone}}</li>
  113. <li>邮箱:{{visitorsInfo.visitorsInfo_email}}</li>
  114. <li>地址:{{visitorsInfo.address}}</li>
  115. <li>备注:{{visitorsInfo.remark}}</li>
  116. </ul>
  117. </div>
  118. </el-col>
  119. </div>
  120. </el-drawer>
  121. </el-badge>
  122. <!-- 点击图片放大 -->
  123. <el-dialog :visible.sync="dialogVisible">
  124. <img width="100%" :src="dialogImageUrl" alt="">
  125. </el-dialog>
  126. <!-- 消息中心 -->
  127. <el-badge :value="unreadNum" class="item">
  128. <el-button @click="openDrawer">
  129. <i style="font-size:14px; color:#5399F5;" class="el-icon-chat-dot-square"> </i>消息中心
  130. </el-button>
  131. </el-badge>
  132. <span @click="isExit()" class="el-span-1"><i style="font-size:13px; margin-right: 3px; color:#5399F5;" class="el-icon-switch-button"></i>退出</span>
  133. </div>
  134. </div>
  135. </div>
  136. </template>
  137. <script>
  138. import Vue from 'vue';
  139. import '@/css/index.css'
  140. import { Loading } from 'element-ui';
  141. export default {
  142. name: 'hader',
  143. data() {
  144. return {
  145. state: true,//在线状态
  146. announcement: true,//公告
  147. network: true,
  148. HeadPortrait: '',
  149. loginTo: false,//登录状态
  150. options: ['在线', '隐身', '休息'],
  151. value: '在线',
  152. user_info: '',//
  153. userID:null,
  154. unreadNum:null, // 未读数量
  155. img_http:window.url_https_ajax,//图片路径域
  156. innerDrawer:false,//会话总览抽屉开关
  157. dataTree: [],
  158. defaultProps: {
  159. children: 'children',
  160. label: 'label',
  161. },
  162. interval:'',//列表循环定时器
  163. ession_int:'',//会话信息循环定时器
  164. visitorsInfo:{},//访客信息
  165. dataList:[],//会话信息列表
  166. servicelog:'',//当前会话工单信息
  167. session_litle:'',//会话标题
  168. newTime:'',//本次最新时间
  169. isGetList:false,//点击获取会话信息
  170. dialogVisible: false, //图片放大
  171. dialogImageUrl: '', // 放大的图片
  172. serverList:[],
  173. get_num:'',
  174. loadingobj:{},//
  175. }
  176. },
  177. mounted() {
  178. // this.img_http = window.url_https_ajax;
  179. if (this.$store.getters.get_stateValue) {
  180. this.value = this.$store.getters.get_stateValue;
  181. }
  182. if(typeof this.$store.getters.get_user_info != 'string'){
  183. this.user_info = this.$store.getters.get_user_info
  184. }else if(this.$store.getters.get_user_info!= ""){
  185. this.user_info = JSON.parse(this.$store.getters.get_user_info)
  186. }
  187. this.userID = this.user_info.id;
  188. // console.log(this.userID);
  189. this.unreadnotice();
  190. let _this = this;
  191. this.get_num = setInterval(function(){
  192. _this.unreadnotice();
  193. },1000*30)
  194. },
  195. beforeDestroy() {
  196. clearInterval(this.get_num);
  197. },
  198. computed: {
  199. get_drawer() {
  200. return this.$store.getters.get_drawer;
  201. },
  202. },
  203. watch: {
  204. get_drawer(data) {
  205. this.unreadnotice();
  206. },
  207. },
  208. methods: {
  209. /***************图片放大*************** */
  210. handlePictureCardPreview(url) {
  211. this.dialogImageUrl = url;
  212. this.dialogVisible = true;
  213. },
  214. openDrawer() {
  215. this.$store.dispatch("SET_DRAWER", true);
  216. },
  217. /**********************************************/
  218. //切换用户状态
  219. handleCommand(e) {
  220. console.log(e,"切换用户状态");
  221. this.websocketsend(JSON.stringify({
  222. type: 'kfOnline',
  223. data: {
  224. uid: 'KF' + this.user_info.id,
  225. status: e * 1 + 1,
  226. }
  227. }));
  228. //Vue.prototype.$stateValue = this.options[e];
  229. this.$store.dispatch("SET_STATEVALUE", this.options[e]);
  230. this.value = this.options[e];
  231. },
  232. /************************************************/
  233. //退出系统
  234. isExit() {
  235. this.$store.dispatch("SET_STATEVALUE", '在线');
  236. this.$store.dispatch("SET_SESSION",[]);//会话列表
  237. this.$store.dispatch("SET_USER",'');//用户退出
  238. this.$store.dispatch("SET_OFFLINE",[]);//离线列表
  239. this.$store.dispatch("SET_TYPE",1);//选择类型(会话/离线)
  240. this.$store.dispatch("SET_NUM",0);//列表下标
  241. this.$store.dispatch("SET_CURRENT",[]);//当前会话数据
  242. this.$store.dispatch("SET_SESSION_NAME",'');//当前会话对象名
  243. this.$store.dispatch("SET_SESSION_MESSAGE",{});
  244. this.$store.dispatch("SET_SOCKET_OPEN",false);//列表下标
  245. this.$store.dispatch("SET_NAVSTATE", 'TheCurrentSession');
  246. this.websocketsend(JSON.stringify({
  247. type:'kfzdclose',
  248. data: {
  249. uid: 'KF' + this.user_info.id,
  250. }
  251. }));
  252. this.$websocket.close();
  253. this.$token = '';
  254. this.$router.push({path:'/login',query: { pid:escape("这就是一个编码没有什么用啊") }})
  255. },
  256. /**************************************/
  257. //数据发送
  258. websocketsend(Data) {
  259. this.$websocket.send(Data);
  260. },
  261. /****************未读信息**************/
  262. unreadnotice(){
  263. let str = "unreadnotice" + "customer-service" + "index" + "service";
  264. let obj = {
  265. headers: {
  266. "Content-Type": "application/x-www-form-urlencoded",
  267. apiToken: this.$md5(str),
  268. userToken: this.user_info.token
  269. },
  270. };
  271. this.$http.post(this.$ports.center.unreadnotice,{
  272. user_id: this.userID
  273. },obj).then(res => {
  274. if(res.data.code === 1){
  275. // console.log(res.data.data)
  276. this.unreadNum = res.data.data.length;
  277. }
  278. });
  279. },
  280. /************获取客服和用户会话信息************/
  281. handleNodeClick(data,i,j){
  282. if(!data.children){
  283. if(this.isGetList) return false
  284. clearInterval(this.ession_int);
  285. this.servicelog = data;
  286. // console.log(this.servicelog)
  287. this.init();
  288. this.get_session_lise();
  289. this.loadingobj = this.$loading({
  290. lock: true,
  291. text: '拼命加载中...',
  292. spinner: 'el-icon-loading',
  293. });
  294. this.ession_int = setInterval(()=>{
  295. this.get_session_lise(this.newTime,10000);
  296. },1000*5)
  297. }
  298. },
  299. /***************会话总览关闭前回掉处理************/
  300. handleClose(){
  301. this.innerDrawer = false;
  302. //清除列表定时请求
  303. clearInterval(this.interval);
  304. //
  305. clearInterval(this.ession_int);
  306. this.init();
  307. },
  308. /*************获取会话总览数据************/
  309. getInnerDrawer(){
  310. if(this.innerDrawer) return false;
  311. this.innerDrawer = true;
  312. setTimeout(()=>{
  313. // Loading.service({text:'拼命加载中',background:'rgba(0, 0, 0, 0.8)'});
  314. this.loadingobj = this.$loading({
  315. lock: true,
  316. text: '拼命加载中...',
  317. spinner: 'el-icon-loading',
  318. });
  319. let obj = {
  320. headers: {
  321. apiToken: this.$md5("allconversation" + "customer-service" + "history" + "service"),
  322. userToken: this.user_info.token
  323. }
  324. };
  325. this.$http.post(this.$ports.overview.allConversation,'',obj).then(res => {
  326. this.loadingobj.close()
  327. if(res.data.code === 1){
  328. // console.log('会话',res.data)
  329. this.dataTree = res.data.data;
  330. this.interval = setInterval(()=>{
  331. this.$http.post(this.$ports.overview.allConversation,'',obj).then(res => {
  332. if(res.data.code === 1){
  333. this.serverList = res.data.serverList;
  334. this.dataTree = res.data.data;
  335. //this.unreadNum = res.data.data.length;
  336. let step;
  337. for (let i = 0; i < this.serverList.length; i++) {
  338. if (this.servicelog.servicelog_id == this.serverList) {
  339. step = false;
  340. break;
  341. } else {
  342. step = true;
  343. }
  344. }
  345. if (step == true) {
  346. this.init();
  347. }
  348. }
  349. });
  350. },1000*60);
  351. }
  352. });
  353. },200)
  354. },
  355. /******************会话详情列表******************/
  356. get_session_lise(time,type){
  357. // if() return false
  358. let str ="chatbytime" + "customer-service" + "history" + "service";
  359. this.$http.get(this.$ports.overview.chatByTime,{
  360. params:{
  361. servicelog_id:this.servicelog.servicelog_id,
  362. lastTime:time,
  363. },
  364. headers:{
  365. 'apiToken': this.$md5(str),
  366. 'userToken': this.user_info.token
  367. }
  368. }).then(res => {
  369. if(res.data.code == 1){
  370. res.data.data.list = res.data.data.list.reverse();
  371. // console.log(res.data.data.list,'详情列表')
  372. this.isGetList = false;
  373. //本次最新时间
  374. // console.log(res.data.data.list.length, res.data.data.list)
  375. if(res.data.data.list.length > 0){
  376. this.newTime = res.data.data.list[res.data.data.list.length -1].time_line;
  377. }
  378. this.alarm = res.data.data.alarm;
  379. //访客信息
  380. this.visitorsInfo = res.data.data.account;
  381. let name = this.visitorsInfo.nick_name ? this.visitorsInfo.nick_name : this.visitorsInfo.account_name
  382. this.session_litle = '(组)'+res.data.data.groupName +'->(客服)'+ res.data.data.serverName +'->(会话)'+name
  383. res.data.data.list.forEach(e => {
  384. //时间戳转时间
  385. e.time_line = this.$public.customFormatDateTime(e.time_line);
  386. //字符串转换成对象
  387. e.content =JSON.parse(e.content);
  388. //文字转表情符号
  389. e.content.text = this.$public.turnFace(e.content.text,this.$frce);
  390. this.dataList.push(e)
  391. });
  392. }
  393. this.loadingobj.close()
  394. });
  395. },
  396. /*******************会话总览数据初始化****************/
  397. init(){
  398. this.visitorsInfo = {};//访客信息
  399. this.dataList = [];//会话信息列表
  400. this.servicelog_id = '';//会话工单号
  401. this.session_litle = '';//会话标题
  402. this.newTime = '';
  403. }
  404. }
  405. }
  406. </script>
  407. <style scoped>
  408. .header {
  409. width: 90vw;
  410. height: 7vh;
  411. border-bottom: 1px solid #D5E5FF;
  412. }
  413. .box_div {
  414. width: 50%;
  415. height: 100%;
  416. background: #ECF4FF;
  417. }
  418. .msg p {
  419. margin-left: 30px;
  420. display: flex;
  421. align-items: center;
  422. }
  423. .msg p img {
  424. margin-right: 6px;
  425. }
  426. .el-span-1 {
  427. margin-left: 14px;
  428. margin-right: 14px;
  429. font-size: 14px;
  430. color: #666;
  431. }
  432. .el-span-1:hover {
  433. color: #5399f5;
  434. cursor: pointer;
  435. font-weight: 400;
  436. }
  437. button {
  438. outline: none;
  439. /* border: 1px solid #ECF4FF; */
  440. }
  441. .el-button {
  442. background: #ECF4FF;
  443. font-size: 14px;
  444. color: #666;
  445. }
  446. .el-button:hover {
  447. color: #5399f5;
  448. }
  449. .msg_left {
  450. width: 360px;
  451. height: 400px !important
  452. }
  453. .msg_right {
  454. width: 440px;
  455. }
  456. .el-popover {
  457. height: 700px !important;
  458. }
  459. /* 会话总览 */
  460. .session_overview{
  461. /* padding:0 20px; */
  462. border: 1px solid #d5e5ff !important;
  463. /* border-top:1px solid #d5e5ff; */
  464. height: 92vh;
  465. }
  466. .session_list{
  467. /* margin-top: 10px; */
  468. padding: 10px 20px;
  469. height: 92vh;
  470. }
  471. .session_box{
  472. border-left: 1px solid #d5e5ff !important;
  473. border-right: 1px solid #d5e5ff !important;
  474. height: 92vh;
  475. padding:10px 0;
  476. }
  477. .session_box_title{
  478. padding: 0 20px;
  479. padding-bottom:10px;
  480. border-bottom: 1px solid #d5e5ff !important;
  481. font-size: 14px;
  482. font-weight:400;
  483. color:rgba(102,102,102,1);
  484. }
  485. .session_box_content{
  486. padding: 10px 20px;
  487. height: 70vh;
  488. border-bottom: 1px solid #d5e5ff !important;
  489. font-size: 14px;
  490. font-weight:400;
  491. color:rgba(102,102,102,1);
  492. overflow:auto
  493. }
  494. .user_info{
  495. padding:10px 20px;
  496. height: 92vh;
  497. font-size:14px;
  498. color:rgba(153,153,153,1);
  499. font-weight:400;
  500. }
  501. .user_info li{
  502. margin: 5px 0;
  503. }
  504. .title_time{
  505. font-size:12px;
  506. font-weight:400;
  507. color:rgba(187,187,187,1);
  508. }
  509. .left_session{
  510. border:1px solid rgba(221,221,221,1);
  511. margin-right: 50px;
  512. max-width: 100%;
  513. min-height: 20px;
  514. padding: 6px;
  515. background:rgba(245,245,245,1);
  516. border-radius:0px 10px 10px 10px;
  517. margin-top:6px;
  518. word-wrap: break-word;
  519. }
  520. .right_session{
  521. margin-top:6px;
  522. border:1px solid rgba(221,221,221,1);
  523. margin-left: 50px;
  524. max-width: 100%;
  525. min-height: 20px;
  526. padding: 6px;
  527. background:rgba(223,240,255,1);
  528. justify-content: flex-end;
  529. border-radius:10px 0px 10px 10px;
  530. word-wrap: break-word;
  531. }
  532. </style>
  533. <style>
  534. .el-badge__content.is-fixed {
  535. top: 8px !important;
  536. right: 20px !important;
  537. }
  538. </style>