|
@@ -0,0 +1,258 @@
|
|
|
|
+<template>
|
|
|
|
+ <div id="detail">
|
|
|
|
+ <el-row>
|
|
|
|
+ <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
|
|
|
|
+ <el-col :span="24" class="one">
|
|
|
|
+ <cSearch :is_back="true" @toBack="toBack"></cSearch>
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="14" class="two">
|
|
|
|
+ <div style="overflow: auto" v-scrollBottom>
|
|
|
|
+ <ul v-infinite-scroll="load" class="infinite-list">
|
|
|
|
+ <el-col :span="24" class="list" v-for="item in list" :key="item._id">
|
|
|
|
+ <el-col :span="24" class="two_1" v-if="item.speaker == user._id">
|
|
|
|
+ <el-col class="time" v-if="item.time != ''">{{ item.time }}</el-col>
|
|
|
|
+ <el-col :span="24" class="content">
|
|
|
|
+ <el-col :span="2" class="logo">
|
|
|
|
+ <el-image
|
|
|
|
+ v-if="user && user.logo.length != 0"
|
|
|
|
+ :src="user.logo[0].url || '../../assets/bglogin.jpg'"
|
|
|
|
+ style="width: 60px; height: 60px; border-radius: 60px"
|
|
|
|
+ mode="widthFix"
|
|
|
|
+ ></el-image>
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="8" v-if="item.msg_type == '0'">
|
|
|
|
+ <text class="text">{{ item.content }}</text>
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="8" class="image" v-else>
|
|
|
|
+ <el-image :src="item.content" style="width: 15vw" mode="widthFix"></el-image>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="24" class="two_2" v-else>
|
|
|
|
+ <el-col class="time" v-if="item.time != ''">{{ item.time }}</el-col>
|
|
|
|
+ <el-col :span="24" class="content">
|
|
|
|
+ <el-col :span="8" v-if="item.msg_type == '0'">
|
|
|
|
+ <text class="text">{{ item.content }}</text>
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="8" class="image" v-else>
|
|
|
|
+ <el-image :src="item.content" style="width: 15vw" mode="widthFix"></el-image>
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="2" class="logo">
|
|
|
|
+ <el-image
|
|
|
|
+ v-if="config && config.file.length != 0"
|
|
|
|
+ :src="config.file[0].url"
|
|
|
|
+ style="width: 60px; height: 60px; border-radius: 60px"
|
|
|
|
+ mode="widthFix"
|
|
|
|
+ ></el-image>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-col>
|
|
|
|
+ </ul>
|
|
|
|
+ </div>
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="14" class="bottom">
|
|
|
|
+ <el-col :span="20" class="input">
|
|
|
|
+ <el-input v-model="input" type="textarea" placeholder="请输入" />
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="4" class="button">
|
|
|
|
+ <el-button type="primary" @click="toSend">发送</el-button>
|
|
|
|
+ <cUpload class="upload" :limit="1" accept="*" url="/files/notarization/chat/upload" :list="file" @change="onUpload"> </cUpload>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-row>
|
|
|
|
+ </div>
|
|
|
|
+</template>
|
|
|
|
+<script setup lang="ts">
|
|
|
|
+// 基础
|
|
|
|
+import moment from 'moment';
|
|
|
|
+import type { Ref } from 'vue';
|
|
|
|
+import { onMounted, ref, getCurrentInstance } from 'vue';
|
|
|
|
+import { useRoute } from 'vue-router';
|
|
|
|
+import store from '@/stores/counter';
|
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
|
+// 接口
|
|
|
|
+import { ChatStore } from '@/stores/users/chat';
|
|
|
|
+import { ConfigStore } from '@/stores/system/config';
|
|
|
|
+import { UserStore } from '@/stores/users/user';
|
|
|
|
+import type { IQueryResult } from '@/util/types.util';
|
|
|
|
+const { proxy } = getCurrentInstance() as any;
|
|
|
|
+
|
|
|
|
+const chatAxios = ChatStore();
|
|
|
|
+const configAxios = ConfigStore();
|
|
|
|
+const userAxios = UserStore();
|
|
|
|
+let admin: Ref<any> = ref(store.state.user);
|
|
|
|
+// 路由
|
|
|
|
+const route = useRoute();
|
|
|
|
+// 加载中
|
|
|
|
+const loading: Ref<any> = ref(false);
|
|
|
|
+let list: Ref<any> = ref([]);
|
|
|
|
+let total: Ref<number> = ref(0);
|
|
|
|
+let skip = 0;
|
|
|
|
+let page = 0;
|
|
|
|
+let limit: number = proxy.$limit;
|
|
|
|
+const user: Ref<any> = ref({ logo: [] });
|
|
|
|
+const config: Ref<any> = ref({ file: [] });
|
|
|
|
+const file: Ref<any> = ref([]);
|
|
|
|
+const input: Ref<any> = ref('');
|
|
|
|
+// 字典表
|
|
|
|
+// 请求
|
|
|
|
+onMounted(async () => {
|
|
|
|
+ loading.value = true;
|
|
|
|
+ await searchOther();
|
|
|
|
+ await search({ skip, limit });
|
|
|
|
+ loading.value = false;
|
|
|
|
+});
|
|
|
|
+const search = async (e: { skip: number; limit: number }) => {
|
|
|
|
+ if (user.value._id) {
|
|
|
|
+ const info = { skip: e.skip, limit: e.limit, user: user.value._id };
|
|
|
|
+ const res: any = await chatAxios.query(info);
|
|
|
|
+ if (res.errcode == '0') {
|
|
|
|
+ list.value = res.data.reverse();
|
|
|
|
+ total.value = res.total;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+// 查询其他信息
|
|
|
|
+const searchOther = async () => {
|
|
|
|
+ let id = route.query.id;
|
|
|
|
+ let res: IQueryResult;
|
|
|
|
+ if (id) {
|
|
|
|
+ res = await userAxios.fetch(id);
|
|
|
|
+ if (res.errcode == '0') user.value = res.data;
|
|
|
|
+ // 全部已读
|
|
|
|
+ await chatAxios.read({ user: id });
|
|
|
|
+ }
|
|
|
|
+ res = await configAxios.query();
|
|
|
|
+ if (res.errcode == '0') {
|
|
|
|
+ config.value = res.data;
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+// 发送
|
|
|
|
+const toSend = async () => {
|
|
|
|
+ let res: IQueryResult;
|
|
|
|
+ let form: any = { user: user.value._id, speaker: admin.value._id, content: input.value, msg_type: '0', time: moment().format('YYYY-MM-DD HH:mm:ss') };
|
|
|
|
+ // 发送给服务器消息
|
|
|
|
+ res = await chatAxios.create(form);
|
|
|
|
+ if (res.errcode == 0) {
|
|
|
|
+ ElMessage({ type: `success`, message: `发送消息信息成功` });
|
|
|
|
+ input.value = '';
|
|
|
|
+ search({ skip, limit });
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+// 上传
|
|
|
|
+const onUpload = async (e: { value: Array<any> }) => {
|
|
|
|
+ const { value } = e;
|
|
|
|
+ let res: IQueryResult;
|
|
|
|
+ let form: any = { user: user.value._id, speaker: admin.value._id, content: value[0].url, msg_type: '1', time: moment().format('YYYY-MM-DD HH:mm:ss') };
|
|
|
|
+ // 发送给服务器消息
|
|
|
|
+ res = await chatAxios.create(form);
|
|
|
|
+ if (res.errcode == 0) {
|
|
|
|
+ ElMessage({ type: `success`, message: `发送消息信息成功` });
|
|
|
|
+ file.value = [];
|
|
|
|
+ search({ skip, limit });
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+// 下拉查看聊天记录
|
|
|
|
+const load = () => {
|
|
|
|
+ if (total.value != 0) {
|
|
|
|
+ if (total.value > limit) {
|
|
|
|
+ page = page + 1;
|
|
|
|
+ limit = limit * page;
|
|
|
|
+ search({ skip, limit });
|
|
|
|
+ } else ElMessage({ type: `warning`, message: `已经到底了!` });
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+// 返回上一页
|
|
|
|
+const toBack = () => {
|
|
|
|
+ window.history.go(-1);
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+<style scoped lang="scss">
|
|
|
|
+.main {
|
|
|
|
+ .two {
|
|
|
|
+ padding: 20px;
|
|
|
|
+ border: 1px solid #d5d5da;
|
|
|
|
+ background: #f1f1f1;
|
|
|
|
+ border-radius: 5px;
|
|
|
|
+
|
|
|
|
+ .infinite-list {
|
|
|
|
+ height: 550px;
|
|
|
|
+ padding: 0;
|
|
|
|
+ margin: 0;
|
|
|
|
+ list-style: none;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .list {
|
|
|
|
+ display: flex;
|
|
|
|
+ flex-direction: column;
|
|
|
|
+
|
|
|
|
+ .two_1 {
|
|
|
|
+ .time {
|
|
|
|
+ text-align: center;
|
|
|
|
+ color: #858585;
|
|
|
|
+ font-size: 12px;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .content {
|
|
|
|
+ display: flex;
|
|
|
|
+ align-items: center;
|
|
|
|
+
|
|
|
|
+ .logo {
|
|
|
|
+ height: 60px;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .text {
|
|
|
|
+ padding: 12px;
|
|
|
|
+ background: #ffffff;
|
|
|
|
+ border-radius: 0px 12px 12px 12px;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .two_2 {
|
|
|
|
+ text-align: right;
|
|
|
|
+
|
|
|
|
+ .time {
|
|
|
|
+ text-align: center;
|
|
|
|
+ color: #858585;
|
|
|
|
+ font-size: 12px;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .content {
|
|
|
|
+ display: flex;
|
|
|
|
+ align-items: center;
|
|
|
|
+ justify-content: right;
|
|
|
|
+
|
|
|
|
+ .logo {
|
|
|
|
+ height: 60px;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .text {
|
|
|
|
+ padding: 12px;
|
|
|
|
+ border-radius: 12px 0px 12px 12px;
|
|
|
|
+ background: #16f80f;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .bottom {
|
|
|
|
+ display: flex;
|
|
|
|
+ align-items: center;
|
|
|
|
+ padding: 5px 0 0 0;
|
|
|
|
+
|
|
|
|
+ .button {
|
|
|
|
+ display: flex;
|
|
|
|
+ margin: 10px 0 0 5px;
|
|
|
|
+
|
|
|
|
+ .upload {
|
|
|
|
+ text-align: right;
|
|
|
|
+ padding: 0 0 0 5px;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+</style>
|