lrf402788946 5 gadi atpakaļ
vecāks
revīzija
1fea86fd31
2 mainītis faili ar 27 papildinājumiem un 26 dzēšanām
  1. 23 21
      src/layout/enterprise/mainMenu.vue
  2. 4 5
      src/views/hall/parts/chat.vue

+ 23 - 21
src/layout/enterprise/mainMenu.vue

@@ -1,23 +1,5 @@
 <template>
   <div id="fenlei">
-    <!-- <el-col class="swfl" :span="24">
-      <el-image style="width:22px;height:22px;margin:0 5px -5px 0;" :src="src"></el-image>
-      <span>个人中心</span>
-    </el-col>
-    <el-col>
-      <el-menu default-active="1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" text-color="#215299" active-text-color="#215299">
-        <el-menu-item index="1" v-for="(item, index) in liebiaoList" :key="index">
-          <template v-if="item.name.includes('消息')">
-            <span slot="title" @click="clickUrl(item.name)" :style="`color:${haveMsg ? 'red' : ''}`">
-              {{ item.name }}
-            </span>
-          </template>
-          <template v-else>
-            <span slot="title" @click="clickUrl(item.name)">{{ item.name }}</span>
-          </template>
-        </el-menu-item>
-      </el-menu>
-    </el-col> -->
     <el-col class="menu" :span="24">
       <el-image :src="squareImage"></el-image>
       <span>个人中心</span>
@@ -40,6 +22,8 @@
 </template>
 
 <script>
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: personalChat } = createNamespacedHelpers('personalchat');
 export default {
   name: 'fenlei',
   props: {
@@ -51,13 +35,31 @@ export default {
     squareImage: require('@/assets/live/square_big.png'),
     haveMsg: false,
   }),
-  created() {},
-  computed: {},
+  created() {
+    this.onMessage();
+  },
+  mounted() {
+    this.channel();
+  },
+  computed: {
+    ...mapState(['user']),
+  },
   methods: {
+    ...personalChat({ getChatList: 'query' }),
     clickUrl(id) {
       this.$emit('onsave', { id });
     },
-
+    channel() {
+      this.$stomp({
+        [`/exchange/chat_message/${this.user.uid}`]: this.onMessage,
+      });
+    },
+    async onMessage(message) {
+      let res = await this.getChatList({ status: 0, receiver_id: this.user.uid });
+      if (this.$checkRes(res)) {
+        this.$set(this, `haveMsg`, res.data.length > 0);
+      }
+    },
     handleOpen(key, keyPath) {
       console.log(key, keyPath);
     },

+ 4 - 5
src/views/hall/parts/chat.vue

@@ -52,11 +52,10 @@ export default {
       if (this.$checkRes(res)) this.$set(this, `list`, _.reverse(res.data));
     },
     async send() {
-      console.log('in function:');
-      // if (!this.user.uid) {
-      //   this.$message.error('游客不能发言,请先注册');
-      //   return;
-      // }
+      if (!this.user.uid) {
+        this.$message.error('游客不能发言,请先注册');
+        return;
+      }
       if (this.text != '') {
         let object = { sender_name: this.user.name, content: this.text };
         if (this.user.uid) object.sender_id = this.user.uid;