完善交互
This commit is contained in:
@ -11,26 +11,11 @@
|
||||
|
||||
<div class="right-menu">
|
||||
<template v-if="device !== 'mobile'">
|
||||
<!-- <search id="header-search" class="right-menu-item" /> -->
|
||||
|
||||
<!-- <el-tooltip content="源码地址" effect="dark" placement="bottom">
|
||||
<ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />
|
||||
</el-tooltip> -->
|
||||
|
||||
<!-- <el-tooltip content="文档地址" effect="dark" placement="bottom">
|
||||
<ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" />
|
||||
</el-tooltip> -->
|
||||
|
||||
<!-- <screenfull id="screenfull" class="right-menu-item hover-effect" /> -->
|
||||
|
||||
<!-- <el-tooltip content="布局大小" effect="dark" placement="bottom">
|
||||
<size-select id="size-select" class="right-menu-item hover-effect" />
|
||||
</el-tooltip> -->
|
||||
<div
|
||||
class="right-menu-item hover-effect badge_style"
|
||||
@click="handleOnMessageClick"
|
||||
>
|
||||
<el-badge :value="12">
|
||||
<el-badge :value="msgUnreadCount">
|
||||
<el-tooltip content="消息" effect="dark" placement="bottom">
|
||||
<em class="el-icon-message" :style="{ fontSize: '28px' }" />
|
||||
</el-tooltip>
|
||||
@ -66,25 +51,30 @@
|
||||
import { mapGetters, mapActions } from "vuex";
|
||||
import Breadcrumb from "@/components/Breadcrumb";
|
||||
import Hamburger from "@/components/Hamburger";
|
||||
// import Screenfull from "@/components/Screenfull";
|
||||
// import SizeSelect from "@/components/SizeSelect";
|
||||
// import Search from "@/components/HeaderSearch";
|
||||
// import RuoYiGit from "@/components/RuoYi/Git";
|
||||
// import RuoYiDoc from "@/components/RuoYi/Doc";
|
||||
import { keys } from "@/utils/websocket";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Breadcrumb,
|
||||
Hamburger,
|
||||
// Screenfull,
|
||||
// SizeSelect,
|
||||
// Search,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
msgNum: 0,
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.init();
|
||||
},
|
||||
mounted() {
|
||||
window.postMessage({ type: keys.GET_UNREAD_COUNT }, window.location.origin);
|
||||
window.addEventListener("message", this.handleOnMessage);
|
||||
},
|
||||
unmounted() {
|
||||
window.removeEventListener("message", this.handleOnMessage);
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(["sidebar", "avatar", "device"]),
|
||||
...mapGetters(["sidebar", "avatar", "device", "msgUnreadCount"]),
|
||||
setting: {
|
||||
get() {
|
||||
return this.$store.state.settings.showSettings;
|
||||
@ -98,7 +88,14 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
...mapActions(["init"]),
|
||||
...mapActions(["init", "updateUnreadCount"]),
|
||||
handleOnMessage({ data }) {
|
||||
if (data.type === keys.WS_TYPE_MESSAGE_COUNT) {
|
||||
this.updateUnreadCount({
|
||||
msgUnreadCount: data.data.count,
|
||||
});
|
||||
}
|
||||
},
|
||||
toggleSideBar() {
|
||||
this.$store.dispatch("app/toggleSideBar");
|
||||
},
|
||||
|
@ -26,6 +26,7 @@ import { init } from "@/utils/websocket";
|
||||
import exportingInit from "highcharts/modules/exporting";
|
||||
exportingInit(Highcharts);
|
||||
|
||||
// websocket 初始化
|
||||
init();
|
||||
|
||||
import {
|
||||
|
@ -1,6 +1,9 @@
|
||||
const actions = {
|
||||
async init({ dispatch }, payload) {
|
||||
dispatch("global/init", payload);
|
||||
},
|
||||
async updateUnreadCount({ commit }, payload) {
|
||||
commit("global/save", payload);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -9,12 +9,11 @@ const getters = {
|
||||
name: state => state.user.name,
|
||||
introduction: state => state.user.introduction,
|
||||
roles: state => state.user.roles,
|
||||
// roles: state => ["dietician"],
|
||||
permissions: state => state.user.permissions,
|
||||
userId: state => state.user.userId,
|
||||
// userId: state => 131,
|
||||
userRemark: state => state.user.remark,
|
||||
permission_routes: state => state.permission.routes,
|
||||
msgUnreadCount: state => state.global.msgUnreadCount,
|
||||
//
|
||||
nutritionistIdOptions: state => state.global.nutritionistIdOptions,
|
||||
nutriAssisIdOptions: state => state.global.nutriAssisIdOptions,
|
||||
|
@ -9,7 +9,8 @@ const oriState = {
|
||||
plannerIdOptions: [],
|
||||
plannerAssisIdOptions: [],
|
||||
operatorIdOptions: [],
|
||||
operatorAssisIdOptions: []
|
||||
operatorAssisIdOptions: [],
|
||||
msgUnreadCount: 0,
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
|
@ -6,6 +6,7 @@ import {
|
||||
} from "@/api/custom/message";
|
||||
|
||||
const oriState = {
|
||||
pageNum: 1,
|
||||
topicList: [],
|
||||
detailData: {},
|
||||
selTopicId: ""
|
||||
@ -28,23 +29,35 @@ const mutations = {
|
||||
};
|
||||
|
||||
const actions = {
|
||||
async init({ rootGetters, commit, dispatch }, payload) {
|
||||
async init({ dispatch }, payload) {
|
||||
dispatch("fetchTopicListApi", {});
|
||||
},
|
||||
async fetchTopicListApi({ dispatch, commit, rootGetters, state }, payload) {
|
||||
const {
|
||||
roles: [role],
|
||||
userId
|
||||
} = rootGetters;
|
||||
const result = await fetchTopicList({ role, uid: userId });
|
||||
const { detailData, pageNum, topicList } = state;
|
||||
const result = await fetchTopicList({
|
||||
role,
|
||||
uid: userId,
|
||||
pageSize: 20,
|
||||
pageNum
|
||||
});
|
||||
if (result.code === 200) {
|
||||
const [defTopic] = result.rows;
|
||||
|
||||
dispatch("fetchTopicDetailActions", {
|
||||
topicId: defTopic.topicId,
|
||||
id: defTopic.id
|
||||
});
|
||||
|
||||
commit("save", {
|
||||
topicList: result.rows
|
||||
});
|
||||
if (!detailData.topicId) {
|
||||
const [defTopic] = result.rows;
|
||||
dispatch("fetchTopicDetailActions", {
|
||||
topicId: defTopic.topicId,
|
||||
id: defTopic.id
|
||||
});
|
||||
}
|
||||
if (result.rows.length) {
|
||||
commit("save", {
|
||||
pageNum: pageNum + 1,
|
||||
topicList: [...topicList, ...result.rows]
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
async fetchTopicDetailActions({ commit }, payload) {
|
||||
|
@ -6,8 +6,10 @@ const url = `${wsProtocol}://${hostname}${
|
||||
let ws = undefined;
|
||||
let intervalRef = undefined;
|
||||
|
||||
function handleOnMessageReceive(event) {
|
||||
console.log({ event });
|
||||
function handleOnMessageReceive({ data = {} }) {
|
||||
if (data.type && data.type === keys.GET_UNREAD_COUNT) {
|
||||
ws.send(keys.GET_UNREAD_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
function connect() {
|
||||
@ -18,11 +20,15 @@ function connect() {
|
||||
console.log("ws连接成功");
|
||||
intervalRef && clearInterval(intervalRef);
|
||||
|
||||
document.addEventListener("message", handleOnMessageReceive);
|
||||
setInterval(() => {
|
||||
ws.send("ping");
|
||||
}, 30000);
|
||||
|
||||
window.addEventListener("message", handleOnMessageReceive);
|
||||
};
|
||||
|
||||
ws.onmessage = event => {
|
||||
console.log({ event });
|
||||
// console.log({ event });
|
||||
|
||||
const dataObj = JSON.parse(event.data || "{}");
|
||||
|
||||
@ -32,24 +38,35 @@ function connect() {
|
||||
};
|
||||
|
||||
ws.onerror = event => {
|
||||
console.log({ event });
|
||||
// console.log({ event });
|
||||
ws = undefined;
|
||||
document.removeEventListener("message", handleOnMessageReceive);
|
||||
window.removeEventListener("message", handleOnMessageReceive);
|
||||
};
|
||||
|
||||
ws.onclose = event => {
|
||||
ws = undefined;
|
||||
document.removeEventListener("message", handleOnMessageReceive);
|
||||
window.removeEventListener("message", handleOnMessageReceive);
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
// console.log(error);
|
||||
ws = undefined;
|
||||
init();
|
||||
console.log("浏览器不支持websocket");
|
||||
}
|
||||
}
|
||||
|
||||
export function init() {
|
||||
intervalRef = setInterval(() => {
|
||||
console.log("尝试连接websocket");
|
||||
!ws && connect();
|
||||
}, 10000);
|
||||
!ws && connect();
|
||||
|
||||
!ws &&
|
||||
(intervalRef = setInterval(() => {
|
||||
console.log("尝试连接websocket");
|
||||
!ws && connect();
|
||||
}, 10000));
|
||||
}
|
||||
|
||||
export const keys = {
|
||||
GET_UNREAD_COUNT: "GET_UNREAD_COUNT",
|
||||
WS_TYPE_MESSAGE_COUNT: "WS_TYPE_MESSAGE_COUNT",
|
||||
WS_TYPE_NEW_CUSTOMER_REPLY: "WS_TYPE_NEW_CUSTOMER_REPLY"
|
||||
};
|
||||
|
@ -1,28 +1,35 @@
|
||||
<template>
|
||||
<div class="message_browser_wrapper">
|
||||
<div class="topic_list">
|
||||
<div
|
||||
v-for="topic in topicList"
|
||||
:key="topic.topicId"
|
||||
:class="`topic_item ${
|
||||
selTopicId === topic.topicId ? 'topic_item_sel' : ''
|
||||
}`"
|
||||
@click="handleOnTopicClick(topic)"
|
||||
>
|
||||
<div class="topic_status topic_status_read" />
|
||||
<div class="topic_item_content">
|
||||
<div class="topic_content">{{ topic.content }}</div>
|
||||
<div class="topic_user_name">by {{ topic.name }}</div>
|
||||
</div>
|
||||
<div class="topic_info">
|
||||
<el-tag size="small">{{ topicTypeDict[topic.topicType] }}</el-tag>
|
||||
<div class="topic_time">{{ formatDate(topic.createTime) }}</div>
|
||||
<div class="topic_list" @scroll="handleOnScroll">
|
||||
<div v-if="topicList && topicList.length">
|
||||
<div
|
||||
v-for="topic in topicList"
|
||||
:key="topic.topicId"
|
||||
:class="`topic_item ${
|
||||
selTopicId === topic.topicId ? 'topic_item_sel' : ''
|
||||
}`"
|
||||
@click="handleOnTopicClick(topic)"
|
||||
>
|
||||
<div
|
||||
:class="`topic_status ${
|
||||
topic.read ? 'topic_status_read' : 'topic_status_unread'
|
||||
}`"
|
||||
/>
|
||||
<div class="topic_item_content">
|
||||
<div class="topic_content">{{ topic.content }}</div>
|
||||
<div class="topic_user_name">by {{ topic.name }}</div>
|
||||
</div>
|
||||
<div class="topic_info">
|
||||
<el-tag size="small">{{ topicTypeDict[topic.topicType] }}</el-tag>
|
||||
<div class="topic_time">{{ formatDate(topic.createTime) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="topic_list_empty">暂无消息</div>
|
||||
</div>
|
||||
<div class="topic_detail">
|
||||
<div class="topic_detail_list">
|
||||
<div class="topic_detail_title">
|
||||
<div class="topic_detail_title" v-if="!!detailData.content">
|
||||
<div>{{ detailData.content }}</div>
|
||||
<div class="content_time" :style="{ marginTop: '4px' }">
|
||||
{{ formatDate(detailData.createTime) }}
|
||||
@ -50,7 +57,12 @@
|
||||
>
|
||||
回复:{{ replyTarget }}
|
||||
</div>
|
||||
<el-input type="textarea" :rows="3" v-model="replyContent" />
|
||||
<el-input
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
v-model="replyContent"
|
||||
:disabled="!detailData.content"
|
||||
/>
|
||||
<div class="send_btn_zone">
|
||||
<el-button
|
||||
type="primary"
|
||||
@ -65,9 +77,10 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { createNamespacedHelpers } from "vuex";
|
||||
import { createNamespacedHelpers, mapActions as globalMapActions } from "vuex";
|
||||
import Comment from "./Comment";
|
||||
import dayjs from "dayjs";
|
||||
import { keys } from "@/utils/websocket";
|
||||
const {
|
||||
mapActions,
|
||||
mapState,
|
||||
@ -91,10 +104,61 @@ export default {
|
||||
created() {
|
||||
this.init();
|
||||
},
|
||||
mounted() {
|
||||
window.addEventListener("message", this.handleOnMessage);
|
||||
},
|
||||
unmounted() {
|
||||
window.removeEventListener("message", this.handleOnMessage);
|
||||
},
|
||||
computed: {
|
||||
...mapState(["topicList", "selTopicId", "detailData"]),
|
||||
},
|
||||
methods: {
|
||||
handleOnScroll({ target }) {
|
||||
if (
|
||||
target.clientHeight + parseInt(target.scrollTop) ===
|
||||
target.scrollHeight
|
||||
) {
|
||||
this.fetchTopicListApi();
|
||||
}
|
||||
},
|
||||
handleOnMessage({ data }) {
|
||||
if (data.type === keys.WS_TYPE_MESSAGE_COUNT) {
|
||||
const { data: tData } = data.data;
|
||||
const time = dayjs(tData.createTime).format("YYYY-MM-DD HH:mm:ss");
|
||||
const newTopicList = [
|
||||
{
|
||||
id: tData.id,
|
||||
content: tData.content,
|
||||
createTime: time,
|
||||
img: tData.img,
|
||||
topicId: tData.topicId,
|
||||
role: "customer",
|
||||
uid: tData.uid,
|
||||
updateTime: time,
|
||||
topicType: tData.topicType,
|
||||
read: tData.read,
|
||||
},
|
||||
...this.topicList,
|
||||
];
|
||||
this.save({
|
||||
topicList: newTopicList,
|
||||
});
|
||||
} else if (data.type === keys.WS_TYPE_NEW_CUSTOMER_REPLY) {
|
||||
const { count, topicId } = data.data;
|
||||
this.updateUnreadCount({
|
||||
msgUnreadCount: count,
|
||||
});
|
||||
if (this.selTopicId === topicId) {
|
||||
const tarTopic = this.topicList.find(
|
||||
(obj) => obj.topicId === topicId
|
||||
);
|
||||
if (tarTopic) {
|
||||
this.fetchTopicDetailActions({ topicId, id: tarTopic.id });
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
formatDate(date) {
|
||||
return dayjs(date).format("MM-DD HH:mm");
|
||||
},
|
||||
@ -147,8 +211,14 @@ export default {
|
||||
this.$message.error("请选择回复对象");
|
||||
}
|
||||
},
|
||||
...mapActions(["init", "fetchTopicDetailActions", "postTopicReplyActions"]),
|
||||
...mapMutations(["clean"]),
|
||||
...mapActions([
|
||||
"init",
|
||||
"fetchTopicDetailActions",
|
||||
"postTopicReplyActions",
|
||||
"fetchTopicListApi",
|
||||
]),
|
||||
...mapMutations(["clean", "save"]),
|
||||
...globalMapActions(["updateUnreadCount"]),
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@ -157,6 +227,7 @@ export default {
|
||||
display: flex;
|
||||
.topic_list {
|
||||
flex: 2;
|
||||
overflow: auto;
|
||||
|
||||
.topic_item {
|
||||
display: flex;
|
||||
@ -223,6 +294,13 @@ export default {
|
||||
.topic_item_sel {
|
||||
background: #dedede;
|
||||
}
|
||||
|
||||
.topic_list_empty {
|
||||
height: 100px;
|
||||
text-align: center;
|
||||
line-height: 100px;
|
||||
color: #8c8c8c;
|
||||
}
|
||||
}
|
||||
|
||||
.topic_detail {
|
||||
|
Reference in New Issue
Block a user