guhongwei 4 lat temu
rodzic
commit
a2a9f1ccee
1 zmienionych plików z 15 dodań i 11 usunięć
  1. 15 11
      src/views/achieveLive/detail/chatData.vue

+ 15 - 11
src/views/achieveLive/detail/chatData.vue

@@ -32,7 +32,8 @@
 </template>
 
 <script>
-const _ = require('lodash');
+var moment = require('moment');
+import _ from 'lodash';
 import { mapState, createNamespacedHelpers } from 'vuex';
 const { mapActions: dockChat } = createNamespacedHelpers('dockChat');
 export default {
@@ -45,14 +46,7 @@ export default {
   data: function() {
     return {
       active: 'first',
-      list: [
-        {
-          send_time: '2020-12-12 12:00:00',
-          sender_name: '发言人',
-          content: '发言内容发言内容发言内容发言内容发言内容发言内容发言内容发言内容',
-        },
-        { send_time: '2020-12-12 12:00:00', sender_name: '发言人', content: '发言内容' },
-      ],
+      list: [],
       // 发言内容
       text: '',
     };
@@ -74,14 +68,19 @@ export default {
     async sendMessage() {
       if (this.text != '') {
         const content = _.cloneDeep(this.text);
-        const obj = { content, dock_id: this.id, sender_id: this.user.id, sender_name: this.user.name };
+        let obj = {};
+        if (this.user) {
+          obj = { content, dock_id: this.id, sender_id: this.user.id, sender_name: this.user.name };
+        } else {
+          obj = { content, dock_id: this.id, sender_id: this.getData(), sender_name: this.getData() + '游客' };
+        }
         const check = Object.values(obj).every(f => f);
         if (!check) {
           this.$message.error('发言所需信息不全,请联系管理人员');
           return;
         }
         const res = await this.create(obj);
-        this.$checkRes(res, null, res.errmsg || '发言失败');
+        this.$checkRes(res, null, '发言成功' || '发言失败');
         this.$set(this, 'text', '');
       } else this.$message.error('请输入信息后发送');
     },
@@ -101,6 +100,11 @@ export default {
         this.list.push(body);
       }
     },
+    // 获取时间戳
+    getData() {
+      let date = moment(new Date()).valueOf();
+      if (date) return date;
+    },
   },
   computed: {
     ...mapState(['user']),