hader.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. <el-badge :value="unreadNum" class="item">
  31. <el-button @click="openDrawer" style="margin:0 15px">
  32. <i style="font-size:14px; color:#5399F5;" class="el-icon-chat-dot-square"> </i>消息中心
  33. </el-button>
  34. </el-badge>
  35. <span @click="isExit()" class="el-span-1"><i style="font-size:13px; margin-right: 3px; color:#5399F5;" class="el-icon-switch-button"></i>退出</span>
  36. </div>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. import Vue from 'vue';
  42. import '@/css/index.css'
  43. export default {
  44. name: 'hader',
  45. data() {
  46. return {
  47. state: true,//在线状态
  48. announcement: true,//公告
  49. network: true,
  50. HeadPortrait: '',
  51. loginTo: false,//登录状态
  52. options: ['在线', '隐身', '休息'],
  53. value: '在线',
  54. user_info: '',//
  55. userID:null,
  56. unreadNum:null, // 未读数量
  57. img_http:'http://kfadmin.bocai186.com',//图片路径域
  58. // img_http: 'http://192.168.2.187:8090',//图片路径域
  59. }
  60. },
  61. computed: {
  62. get_drawer() {
  63. return this.$store.getters.get_drawer;
  64. },
  65. },
  66. watch: {
  67. get_drawer(data) {
  68. this.unreadnotice();
  69. },
  70. },
  71. methods: {
  72. openDrawer() {
  73. this.$store.dispatch("SET_DRAWER", true);
  74. },
  75. /**********************************************/
  76. //切换用户状态
  77. handleCommand(e) {
  78. console.log(e,"切换用户状态");
  79. this.websocketsend(JSON.stringify({
  80. type: 'kfOnline',
  81. data: {
  82. uid: 'KF' + this.user_info.id,
  83. status: e * 1 + 1,
  84. }
  85. }));
  86. //Vue.prototype.$stateValue = this.options[e];
  87. this.$store.dispatch("SET_STATEVALUE", this.options[e]);
  88. this.value = this.options[e];
  89. },
  90. /************************************************/
  91. //退出系统
  92. isExit() {
  93. this.$store.dispatch("SET_STATEVALUE", '在线');
  94. this.$store.dispatch("SET_SESSION",[]);//会话列表
  95. this.$store.dispatch("SET_USER",'');//用户退出
  96. this.$store.dispatch("SET_OFFLINE",[]);//离线列表
  97. this.$store.dispatch("SET_TYPE",1);//选择类型(会话/离线)
  98. this.$store.dispatch("SET_NUM",0);//列表下标
  99. this.$store.dispatch("SET_CURRENT",[]);//当前会话数据
  100. this.$store.dispatch("SET_SESSION_NAME",'');//当前会话对象名
  101. this.$store.dispatch("SET_SESSION_MESSAGE",{});
  102. this.$store.dispatch("SET_SOCKET_OPEN",false);//列表下标
  103. this.$websocket.close();
  104. // this.$socket_open = false;
  105. // console.log(this.$socket_open)
  106. this.$token = '';
  107. this.$router.push({path:'/login',query: { pid:escape("~!@#¥%……&*()——+,./;'[]") }})
  108. },
  109. /**************************************/
  110. //数据发送
  111. websocketsend(Data) {
  112. this.$websocket.send(Data);
  113. },
  114. // 未读信息
  115. unreadnotice(){
  116. let str = "unreadnotice" + "customer-service" + "index" + this.time + "service";
  117. let obj = {
  118. headers: {
  119. "Content-Type": "application/x-www-form-urlencoded",
  120. apiToken: this.$md5(str),
  121. userToken: this.token
  122. },
  123. user_id: this.userID
  124. };
  125. this.post("api/service/index/unreadnotice", obj).then(res => {
  126. if(res.data.code === 1){
  127. // console.log(res.data.data)
  128. this.unreadNum = res.data.data.length;
  129. }
  130. });
  131. },
  132. },
  133. mounted() {
  134. if (this.$store.getters.get_stateValue) {
  135. this.value = this.$store.getters.get_stateValue;
  136. }
  137. this.user_info = this.$store.getters.get_user_info;
  138. this.userID = this.$store.getters.get_user_info.id;
  139. this.unreadnotice();
  140. let _this = this;
  141. let get = setTimeout(function(){
  142. _this.unreadnotice();
  143. },1000*60)
  144. }
  145. }
  146. </script>
  147. <style scoped>
  148. .header {
  149. width: 90vw;
  150. height: 7vh;
  151. border-bottom: 1px solid #D5E5FF;
  152. }
  153. .box_div {
  154. width: 50%;
  155. height: 100%;
  156. background: #ECF4FF;
  157. }
  158. .msg p {
  159. margin-left: 30px;
  160. display: flex;
  161. align-items: center;
  162. }
  163. .msg p img {
  164. margin-right: 6px;
  165. }
  166. .el-span-1 {
  167. margin-left: 6px;
  168. font-size: 14px;
  169. color: #666;
  170. }
  171. .el-span-1:hover {
  172. color: #5399f5;
  173. cursor: pointer;
  174. font-weight: 400;
  175. }
  176. button {
  177. outline: none;
  178. /* border: 1px solid #ECF4FF; */
  179. }
  180. .el-button {
  181. background: #ECF4FF;
  182. font-size: 14px;
  183. color: #666;
  184. }
  185. .el-button:hover {
  186. color: #5399f5;
  187. }
  188. .msg_left {
  189. width: 360px;
  190. height: 400px !important
  191. }
  192. .msg_right {
  193. width: 440px;
  194. }
  195. .el-popover {
  196. height: 700px !important;
  197. }
  198. /* .el-dropdown{
  199. border: 1px solid #ECF4FF;
  200. } */
  201. </style>
  202. <style>
  203. .el-badge__content.is-fixed {
  204. position: absolute;
  205. top: -2px !important;
  206. right: 18px !important;
  207. }
  208. </style>