|
@@ -0,0 +1,135 @@
|
|
|
|
+<template>
|
|
|
|
+ <div id="afterClassChat">
|
|
|
|
+ <el-row>
|
|
|
|
+ <el-col :span="24" class="style">
|
|
|
|
+ <el-col :span="24" class="top">
|
|
|
|
+ <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="24" class="main">
|
|
|
|
+ <chat :chatList="chatList" @speak="speak"></chat>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-row>
|
|
|
|
+ </div>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script>
|
|
|
|
+import _ from 'lodash';
|
|
|
|
+import moment from 'moment';
|
|
|
|
+import chat from '@/components/chat.vue';
|
|
|
|
+import NavBar from '@/layout/common/topTitle.vue';
|
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
|
+const { mapActions: answerapply } = createNamespacedHelpers('answerapply');
|
|
|
|
+const { mapActions: answerchat } = createNamespacedHelpers('answerchat');
|
|
|
|
+export default {
|
|
|
|
+ metaInfo: { title: '请假管理' },
|
|
|
|
+ name: 'afterClassChat',
|
|
|
|
+ props: {},
|
|
|
|
+ components: {
|
|
|
|
+ NavBar, //头部导航
|
|
|
|
+ chat, //聊天
|
|
|
|
+ },
|
|
|
|
+ data: function() {
|
|
|
|
+ return {
|
|
|
|
+ title: '',
|
|
|
|
+ isleftarrow: '',
|
|
|
|
+ transitionName: 'fade',
|
|
|
|
+ navShow: true,
|
|
|
|
+ // 聊天列表
|
|
|
|
+ chatList: [],
|
|
|
|
+ // 房间信息
|
|
|
|
+ room: {},
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ async created() {
|
|
|
|
+ await this.searchInfo();
|
|
|
|
+ await this.search();
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ ...answerchat(['query', 'fetch', 'create']),
|
|
|
|
+ ...answerapply({ answerapplyFetch: 'fetch' }),
|
|
|
|
+ async searchInfo() {
|
|
|
|
+ if (this.id) {
|
|
|
|
+ // 房间详情
|
|
|
|
+ let res = await this.answerapplyFetch(this.id);
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ this.$set(this, `room`, res.data);
|
|
|
|
+ this.channel();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 房间聊天列表
|
|
|
|
+ async search() {
|
|
|
|
+ let res = await this.query({ room: this.room._id });
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ this.$set(this, `chatList`, res.data);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ channel() {
|
|
|
|
+ //TODO 修改订阅地址
|
|
|
|
+ if (!this.room.id) {
|
|
|
|
+ console.warn('未获取到房间id,无法进行订阅');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this.$stomp({
|
|
|
|
+ [`/exchange/answerchat/${this.room.id}`]: this.onMessage,
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ onMessage(message) {
|
|
|
|
+ let body = _.get(message, 'body');
|
|
|
|
+ if (body) {
|
|
|
|
+ if (body == '消息已查收') return;
|
|
|
|
+ body = JSON.parse(body);
|
|
|
|
+ this.chatList.push(body);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 发言提交
|
|
|
|
+ async speak(content) {
|
|
|
|
+ let data = {
|
|
|
|
+ sender_id: this.user.userid,
|
|
|
|
+ sender_name: this.user.name,
|
|
|
|
+ content: content,
|
|
|
|
+ receiver_id: this.room.teacherid,
|
|
|
|
+ receiver_name: this.room.teacher,
|
|
|
|
+ room: this.room._id,
|
|
|
|
+ };
|
|
|
|
+ let res = await this.create(data);
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ console.log(res.data);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ computed: {
|
|
|
|
+ ...mapState(['user']),
|
|
|
|
+ id() {
|
|
|
|
+ return this.$route.query.id;
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ mounted() {
|
|
|
|
+ this.title = this.$route.meta.title;
|
|
|
|
+ this.isleftarrow = this.$route.meta.isleftarrow;
|
|
|
|
+ },
|
|
|
|
+ watch: {
|
|
|
|
+ $route(to, from) {
|
|
|
|
+ this.title = to.meta.title;
|
|
|
|
+ this.isleftarrow = to.meta.isleftarrow;
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style lang="less" scoped>
|
|
|
|
+.style {
|
|
|
|
+ width: 100%;
|
|
|
|
+ min-height: 667px;
|
|
|
|
+ position: relative;
|
|
|
|
+ background-color: #f9fafc;
|
|
|
|
+}
|
|
|
|
+.top {
|
|
|
|
+ height: 46px;
|
|
|
|
+ overflow: hidden;
|
|
|
|
+}
|
|
|
|
+.main {
|
|
|
|
+ min-height: 620px;
|
|
|
|
+}
|
|
|
|
+</style>
|