hader.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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. export default {
  141. name: 'hader',
  142. data() {
  143. return {
  144. state: true,//在线状态
  145. announcement: true,//公告
  146. network: true,
  147. HeadPortrait: '',
  148. loginTo: false,//登录状态
  149. options: ['在线', '隐身', '休息'],
  150. value: '在线',
  151. user_info: '',//
  152. userID:null,
  153. unreadNum:null, // 未读数量
  154. img_http:'http://manage.281570.com',//图片路径域
  155. innerDrawer:false,//会话总览抽屉开关
  156. // img_http: 'http://192.168.2.187:8090',//图片路径域
  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. }
  174. },
  175. mounted() {
  176. if (this.$store.getters.get_stateValue) {
  177. this.value = this.$store.getters.get_stateValue;
  178. }
  179. if(typeof this.$store.getters.get_user_info != 'string'){
  180. this.user_info = this.$store.getters.get_user_info
  181. }else if(this.$store.getters.get_user_info!= ""){
  182. this.user_info = JSON.parse(this.$store.getters.get_user_info)
  183. }
  184. this.userID = this.$store.getters.get_user_info.id;
  185. this.unreadnotice();
  186. let _this = this;
  187. let get = setTimeout(function(){
  188. _this.unreadnotice();
  189. },1000)
  190. },
  191. computed: {
  192. get_drawer() {
  193. return this.$store.getters.get_drawer;
  194. },
  195. },
  196. watch: {
  197. get_drawer(data) {
  198. this.unreadnotice();
  199. },
  200. },
  201. methods: {
  202. /***************图片放大*************** */
  203. handlePictureCardPreview(url) {
  204. this.dialogImageUrl = url;
  205. this.dialogVisible = true;
  206. },
  207. openDrawer() {
  208. this.$store.dispatch("SET_DRAWER", true);
  209. },
  210. /**********************************************/
  211. //切换用户状态
  212. handleCommand(e) {
  213. console.log(e,"切换用户状态");
  214. this.websocketsend(JSON.stringify({
  215. type: 'kfOnline',
  216. data: {
  217. uid: 'KF' + this.user_info.id,
  218. status: e * 1 + 1,
  219. }
  220. }));
  221. //Vue.prototype.$stateValue = this.options[e];
  222. this.$store.dispatch("SET_STATEVALUE", this.options[e]);
  223. this.value = this.options[e];
  224. },
  225. /************************************************/
  226. //退出系统
  227. isExit() {
  228. this.$store.dispatch("SET_STATEVALUE", '在线');
  229. this.$store.dispatch("SET_SESSION",[]);//会话列表
  230. this.$store.dispatch("SET_USER",'');//用户退出
  231. this.$store.dispatch("SET_OFFLINE",[]);//离线列表
  232. this.$store.dispatch("SET_TYPE",1);//选择类型(会话/离线)
  233. this.$store.dispatch("SET_NUM",0);//列表下标
  234. this.$store.dispatch("SET_CURRENT",[]);//当前会话数据
  235. this.$store.dispatch("SET_SESSION_NAME",'');//当前会话对象名
  236. this.$store.dispatch("SET_SESSION_MESSAGE",{});
  237. this.$store.dispatch("SET_SOCKET_OPEN",false);//列表下标
  238. this.$store.dispatch("SET_NAVSTATE", 'TheCurrentSession');
  239. this.$websocket.close();
  240. // this.$socket_open = false;
  241. // console.log(this.$socket_open)
  242. this.$token = '';
  243. this.$router.push({path:'/login',query: { pid:escape("这就是一个编码没有什么用啊") }})
  244. },
  245. /**************************************/
  246. //数据发送
  247. websocketsend(Data) {
  248. this.$websocket.send(Data);
  249. },
  250. /****************未读信息**************/
  251. unreadnotice(){
  252. let str = "unreadnotice" + "customer-service" + "index" + "service";
  253. let obj = {
  254. headers: {
  255. "Content-Type": "application/x-www-form-urlencoded",
  256. apiToken: this.$md5(str),
  257. userToken: this.user_info.token
  258. },
  259. };
  260. this.$http.post(this.$ports.center.unreadnotice,{
  261. user_id: this.userID
  262. },obj).then(res => {
  263. if(res.data.code === 1){
  264. // console.log(res.data.data)
  265. this.unreadNum = res.data.data.length;
  266. }
  267. });
  268. },
  269. /************获取客服和用户会话信息************/
  270. handleNodeClick(data,i,j){
  271. if(!data.children){
  272. if(this.isGetList) return false
  273. clearInterval(this.ession_int);
  274. this.servicelog = data;
  275. console.log(this.servicelog)
  276. this.init();
  277. this.get_session_lise();
  278. this.ession_int = setInterval(()=>{
  279. this.get_session_lise(this.newTime);
  280. },1000*5)
  281. }
  282. },
  283. /***************会话总览关闭前回掉处理************/
  284. handleClose(){
  285. this.innerDrawer = false;
  286. //清除列表定时请求
  287. clearInterval(this.interval);
  288. //
  289. clearInterval(this.ession_int);
  290. this.init();
  291. },
  292. /*************获取会话总览数据************/
  293. getInnerDrawer(){
  294. if(this.innerDrawer) return false;
  295. this.innerDrawer = true;
  296. let obj = {
  297. headers: {
  298. apiToken: this.$md5("allconversation" + "customer-service" + "history" + "service"),
  299. userToken: this.user_info.token
  300. }
  301. };
  302. this.$http.post(this.$ports.overview.allConversation,'',obj).then(res => {
  303. if(res.data.code === 1){
  304. // console.log('会话',res.data)
  305. this.dataTree = res.data.data;
  306. this.interval = setInterval(()=>{
  307. this.$http.post(this.$ports.overview.allConversation,'',obj).then(res => {
  308. if(res.data.code === 1){
  309. this.serverList = res.data.serverList;
  310. this.dataTree = res.data.data;
  311. //this.unreadNum = res.data.data.length;
  312. let step;
  313. for (let i = 0; i < this.serverList.length; i++) {
  314. if (this.servicelog.servicelog_id == this.serverList) {
  315. step = false;
  316. break;
  317. } else {
  318. step = true;
  319. }
  320. }
  321. if (step == true) {
  322. this.init();
  323. }
  324. }
  325. });
  326. },1000*60);
  327. }
  328. });
  329. },
  330. /******************会话详情列表******************/
  331. get_session_lise(time){
  332. // if() return false
  333. let str ="chatbytime" + "customer-service" + "history" + "service";
  334. this.$http.get(this.$ports.overview.chatByTime,{
  335. params:{
  336. servicelog_id:this.servicelog.servicelog_id,
  337. lastTime:time,
  338. },
  339. headers:{
  340. 'apiToken': this.$md5(str),
  341. 'userToken': this.user_info.token
  342. }
  343. }).then(res => {
  344. if(res.data.code == 1){
  345. res.data.data.list = res.data.data.list.reverse();
  346. // console.log(res.data.data.list,'详情列表')
  347. this.isGetList = false;
  348. //本次最新时间
  349. // console.log(res.data.data.list.length, res.data.data.list)
  350. if(res.data.data.list.length > 0){
  351. this.newTime = res.data.data.list[res.data.data.list.length -1].time_line;
  352. }
  353. this.alarm = res.data.data.alarm;
  354. //访客信息
  355. this.visitorsInfo = res.data.data.account;
  356. let name = this.visitorsInfo.nick_name ? this.visitorsInfo.nick_name : this.visitorsInfo.account_name
  357. this.session_litle = '(组)'+res.data.data.groupName +'->(客服)'+ res.data.data.serverName +'->(会话)'+name
  358. res.data.data.list.forEach(e => {
  359. //时间戳转时间
  360. e.time_line = this.$public.customFormatDateTime(e.time_line);
  361. //字符串转换成对象
  362. e.content =JSON.parse(e.content);
  363. //文字转表情符号
  364. e.content.text = this.$public.turnFace(e.content.text,this.$frce);
  365. this.dataList.push(e)
  366. });
  367. }
  368. });
  369. },
  370. /*******************会话总览数据初始化****************/
  371. init(){
  372. this.visitorsInfo = {};//访客信息
  373. this.dataList = [];//会话信息列表
  374. this.servicelog_id = '';//会话工单号
  375. this.session_litle = '';//会话标题
  376. this.newTime = '';
  377. }
  378. }
  379. }
  380. </script>
  381. <style scoped>
  382. .header {
  383. width: 90vw;
  384. height: 7vh;
  385. border-bottom: 1px solid #D5E5FF;
  386. }
  387. .box_div {
  388. width: 50%;
  389. height: 100%;
  390. background: #ECF4FF;
  391. }
  392. .msg p {
  393. margin-left: 30px;
  394. display: flex;
  395. align-items: center;
  396. }
  397. .msg p img {
  398. margin-right: 6px;
  399. }
  400. .el-span-1 {
  401. margin-left: 14px;
  402. margin-right: 14px;
  403. font-size: 14px;
  404. color: #666;
  405. }
  406. .el-span-1:hover {
  407. color: #5399f5;
  408. cursor: pointer;
  409. font-weight: 400;
  410. }
  411. button {
  412. outline: none;
  413. /* border: 1px solid #ECF4FF; */
  414. }
  415. .el-button {
  416. background: #ECF4FF;
  417. font-size: 14px;
  418. color: #666;
  419. }
  420. .el-button:hover {
  421. color: #5399f5;
  422. }
  423. .msg_left {
  424. width: 360px;
  425. height: 400px !important
  426. }
  427. .msg_right {
  428. width: 440px;
  429. }
  430. .el-popover {
  431. height: 700px !important;
  432. }
  433. /* 会话总览 */
  434. .session_overview{
  435. /* padding:0 20px; */
  436. border: 1px solid #d5e5ff !important;
  437. /* border-top:1px solid #d5e5ff; */
  438. height: 92vh;
  439. }
  440. .session_list{
  441. /* margin-top: 10px; */
  442. padding: 10px 20px;
  443. height: 92vh;
  444. }
  445. .session_box{
  446. border-left: 1px solid #d5e5ff !important;
  447. border-right: 1px solid #d5e5ff !important;
  448. height: 92vh;
  449. padding:10px 0;
  450. }
  451. .session_box_title{
  452. padding: 0 20px;
  453. padding-bottom:10px;
  454. border-bottom: 1px solid #d5e5ff !important;
  455. font-size: 14px;
  456. font-weight:400;
  457. color:rgba(102,102,102,1);
  458. }
  459. .session_box_content{
  460. padding: 10px 20px;
  461. height: 70vh;
  462. border-bottom: 1px solid #d5e5ff !important;
  463. font-size: 14px;
  464. font-weight:400;
  465. color:rgba(102,102,102,1);
  466. overflow:auto
  467. }
  468. .user_info{
  469. padding:10px 20px;
  470. height: 92vh;
  471. font-size:14px;
  472. color:rgba(153,153,153,1);
  473. font-weight:400;
  474. }
  475. .user_info li{
  476. margin: 5px 0;
  477. }
  478. .title_time{
  479. font-size:12px;
  480. font-weight:400;
  481. color:rgba(187,187,187,1);
  482. }
  483. .left_session{
  484. border:1px solid rgba(221,221,221,1);
  485. margin-right: 50px;
  486. max-width: 100%;
  487. min-height: 20px;
  488. padding: 6px;
  489. background:rgba(245,245,245,1);
  490. border-radius:0px 10px 10px 10px;
  491. margin-top:6px;
  492. word-wrap: break-word;
  493. }
  494. .right_session{
  495. margin-top:6px;
  496. border:1px solid rgba(221,221,221,1);
  497. margin-left: 50px;
  498. max-width: 100%;
  499. min-height: 20px;
  500. padding: 6px;
  501. background:rgba(223,240,255,1);
  502. justify-content: flex-end;
  503. border-radius:10px 0px 10px 10px;
  504. word-wrap: break-word;
  505. }
  506. </style>
  507. <style>
  508. .el-badge__content.is-fixed {
  509. top: 8px !important;
  510. right: 20px !important;
  511. }
  512. </style>