|
@@ -1,27 +1,93 @@
|
|
|
<template>
|
|
|
<div id="message">
|
|
|
<el-row>
|
|
|
- <el-col :span="24">
|
|
|
- <p>message</p>
|
|
|
+ <el-col :span="24" class="main">
|
|
|
+ <el-col :span="24" class="one">
|
|
|
+ 消息管理
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="two">
|
|
|
+ <list :messageList="messageList" @toView="toView"></list>
|
|
|
+ </el-col>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
+ <el-dialog title="聊天" :visible.sync="dialog" width="35%" :before-close="handleClose">
|
|
|
+ <chat :chatList="chatList" @send="toSend"></chat>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import list from '../message/list.vue';
|
|
|
+import chat from '../message/chat.vue';
|
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: mapPersonRoom } = createNamespacedHelpers('personRoom');
|
|
|
+const { mapActions: personChat } = createNamespacedHelpers('personChat');
|
|
|
export default {
|
|
|
metaInfo() {
|
|
|
return { title: this.$route.meta.title };
|
|
|
},
|
|
|
name: 'message',
|
|
|
props: {},
|
|
|
- components: {},
|
|
|
+ components: {
|
|
|
+ list,
|
|
|
+ chat,
|
|
|
+ },
|
|
|
data: function() {
|
|
|
- return {};
|
|
|
+ return {
|
|
|
+ messageList: [],
|
|
|
+ // 聊天
|
|
|
+ dialog: false,
|
|
|
+ chatList: [],
|
|
|
+ // 房间信息
|
|
|
+ room: {},
|
|
|
+ };
|
|
|
+ },
|
|
|
+ async created() {
|
|
|
+ await this.search();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...mapPersonRoom({ roomQuery: 'query' }),
|
|
|
+ ...personChat({ chatQuery: 'query', chatCreate: 'create' }),
|
|
|
+ async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
|
+ let res = await this.roomQuery({ p_id: this.user.id, ...info });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `messageList`, res.data);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 查看未读消息
|
|
|
+ async toView(data) {
|
|
|
+ this.$set(this, `room`, data);
|
|
|
+ let res = await this.chatQuery({ room_id: data.id });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `chatList`, res.data);
|
|
|
+ }
|
|
|
+ this.dialog = true;
|
|
|
+ },
|
|
|
+ // 关闭
|
|
|
+ handleClose() {
|
|
|
+ this.dialog = false;
|
|
|
+ this.search();
|
|
|
+ },
|
|
|
+ // 发言提交
|
|
|
+ async toSend(text) {
|
|
|
+ if (text) {
|
|
|
+ let data = {
|
|
|
+ room_id: this.room.id,
|
|
|
+ content: text,
|
|
|
+ sender_id: this.user.id,
|
|
|
+ sender_name: this.user.name,
|
|
|
+ receiver_id: this.room.p1_id == this.user.id ? this.room.p2_id : this.room.p1_id,
|
|
|
+ receiver_name: this.room.p1_id == this.user.id ? this.room.p2 : this.room.p1,
|
|
|
+ };
|
|
|
+ let res = await this.chatCreate(data);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.chatList.push(res.data);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$message({ message: '内容不能为空', type: 'warning' });
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
- created() {},
|
|
|
- methods: {},
|
|
|
computed: {
|
|
|
...mapState(['user']),
|
|
|
},
|
|
@@ -29,4 +95,22 @@ export default {
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
-<style lang="less" scoped></style>
|
|
|
+<style lang="less" scoped>
|
|
|
+.main {
|
|
|
+ padding: 10px;
|
|
|
+ .one {
|
|
|
+ height: 40px;
|
|
|
+ line-height: 30px;
|
|
|
+ padding: 0 10px;
|
|
|
+ border-bottom: 1px solid #e5e5e5;
|
|
|
+ font-size: 18px;
|
|
|
+ font-weight: bold;
|
|
|
+ color: #22529a;
|
|
|
+ margin: 0 0 10px 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+/deep/.el-dialog__body {
|
|
|
+ height: 400px;
|
|
|
+ padding: 10px 20px;
|
|
|
+}
|
|
|
+</style>
|