|
@@ -46,6 +46,7 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
|
+const { mapActions: dockChat } = createNamespacedHelpers('dockChat');
|
|
var moment = require('moment');
|
|
var moment = require('moment');
|
|
export default {
|
|
export default {
|
|
name: 'chatData',
|
|
name: 'chatData',
|
|
@@ -66,20 +67,37 @@ export default {
|
|
textList: [{ name: '欢迎欢迎' }, { name: '科技创新' }, { name: '大咖云集' }],
|
|
textList: [{ name: '欢迎欢迎' }, { name: '科技创新' }, { name: '大咖云集' }],
|
|
};
|
|
};
|
|
},
|
|
},
|
|
- created() {},
|
|
|
|
|
|
+ created() {
|
|
|
|
+ if (this.dock_id) this.search();
|
|
|
|
+ },
|
|
|
|
+ mounted() {
|
|
|
|
+ this.scrollToBottom();
|
|
|
|
+ },
|
|
|
|
+ //每次页面渲染完之后滚动条在最底部
|
|
|
|
+ updated() {
|
|
|
|
+ this.scrollToBottom();
|
|
|
|
+ },
|
|
methods: {
|
|
methods: {
|
|
|
|
+ ...dockChat(['query', 'create']),
|
|
|
|
+ async search() {
|
|
|
|
+ let res = await this.query({ dock_id: this.dock_id });
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ this.$set(this, `list`, res.data);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
async send() {
|
|
async send() {
|
|
let data = {
|
|
let data = {
|
|
dock_id: this.dock_id,
|
|
dock_id: this.dock_id,
|
|
content: this.text,
|
|
content: this.text,
|
|
sender_id: this.user ? this.user.id : this.getData(),
|
|
sender_id: this.user ? this.user.id : this.getData(),
|
|
sender_name: this.user ? this.user.name : this.getData() + '游客',
|
|
sender_name: this.user ? this.user.name : this.getData() + '游客',
|
|
|
|
+ send_time: moment().format('yyyy-MM-DD HH:mm:ss'),
|
|
};
|
|
};
|
|
if (data.content != '') {
|
|
if (data.content != '') {
|
|
- console.log(data);
|
|
|
|
- // const res = await this.create(data);
|
|
|
|
- // this.$checkRes(res, null, '发言成功' || '发言失败');
|
|
|
|
|
|
+ const res = await this.create(data);
|
|
|
|
+ this.$checkRes(res, null, '发言成功' || '发言失败');
|
|
this.$set(this, 'text', '');
|
|
this.$set(this, 'text', '');
|
|
|
|
+ this.search();
|
|
} else this.$message.error('请输入信息后发送');
|
|
} else this.$message.error('请输入信息后发送');
|
|
},
|
|
},
|
|
textBtn(text) {
|
|
textBtn(text) {
|
|
@@ -91,6 +109,13 @@ export default {
|
|
let date = moment(new Date()).valueOf();
|
|
let date = moment(new Date()).valueOf();
|
|
if (date) return date;
|
|
if (date) return date;
|
|
},
|
|
},
|
|
|
|
+ // 整理滚动条
|
|
|
|
+ scrollToBottom: function() {
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ var container = this.$el.querySelector('.first_1');
|
|
|
|
+ container.scrollTop = container.scrollHeight;
|
|
|
|
+ });
|
|
|
|
+ },
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
...mapState(['user']),
|
|
...mapState(['user']),
|