Commit 32e5791c authored by chenqikuai's avatar chenqikuai

fix: 那点击聊天的时候那怎么交互

parent 05e1ca51
...@@ -18,13 +18,13 @@ import { getMasterIdFromDisplayMsg, getTargetIdFromDisplayMsg } from "./utils/ch ...@@ -18,13 +18,13 @@ import { getMasterIdFromDisplayMsg, getTargetIdFromDisplayMsg } from "./utils/ch
import isChattingWith from "./utils/isChattingWith"; import isChattingWith from "./utils/isChattingWith";
import { ChatMessageTypes } from "@/types/chatMessageTypes" import { ChatMessageTypes } from "@/types/chatMessageTypes"
import { chatCardTimeStamp } from "./store/chatCardStore"; import { chatCardTimeStamp } from "./store/chatCardStore";
import { getVisitorId } from "./utils/visitorId";
import { getUserMsg } from "./utils/userMsg"; import { getUserMsg } from "./utils/userMsg";
import { chatLoginActionMark, eLoginType } from "./store/chatStore"; import { chatLoginActionMark, eLoginType } from "./store/chatStore";
import { Toast } from "vant"; import { Toast } from "vant";
import router from "./router"; import router from "./router";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import Bridge from '@/utils/jsBridge2' import Bridge from '@/utils/jsBridge2'
import { chatAuthCheck } from "./utils/authCheck";
export default defineComponent({ export default defineComponent({
...@@ -69,7 +69,7 @@ export default defineComponent({ ...@@ -69,7 +69,7 @@ export default defineComponent({
watch(chatLoginActionMark, (newMark) => { watch(chatLoginActionMark, (newMark) => {
if (newMark === eLoginType.login) { if (newMark === eLoginType.login) {
connect(); chatAuthCheck(connect)
} else if (newMark === eLoginType.logout) { } else if (newMark === eLoginType.logout) {
connectionState.connection?.disconnect(); connectionState.connection?.disconnect();
} }
...@@ -100,13 +100,13 @@ export default defineComponent({ ...@@ -100,13 +100,13 @@ export default defineComponent({
onMounted(() => { onMounted(() => {
if (getUserMsg()) { if (getUserMsg()) {
connect(); chatAuthCheck(connect)
} }
}) })
watch(() => connectionState.error, () => { watch(() => connectionState.error, () => {
if (connectionState.error) { if (connectionState.error) {
connect(); chatAuthCheck(connect);
} }
}) })
......
import { eRole } from '@/types/roleType'
import { chatAuthCheck } from '@/utils/authCheck'
import { getUserMsg } from '@/utils/userMsg' import { getUserMsg } from '@/utils/userMsg'
import { Toast } from 'vant'
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router' import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
const routes: Array<RouteRecordRaw> = [ const routes: Array<RouteRecordRaw> = [
...@@ -36,7 +39,7 @@ const routes: Array<RouteRecordRaw> = [ ...@@ -36,7 +39,7 @@ const routes: Array<RouteRecordRaw> = [
path: '/chatList', path: '/chatList',
name: 'ChatList', name: 'ChatList',
meta: { meta: {
needAuth: true needAuth: true,
}, },
component: () => component: () =>
import( import(
...@@ -233,7 +236,19 @@ router.beforeEach((to, from, next) => { ...@@ -233,7 +236,19 @@ router.beforeEach((to, from, next) => {
const userMsg = getUserMsg() const userMsg = getUserMsg()
if (to.meta.needAuth) { if (to.meta.needAuth) {
if (!!userMsg) { if (!!userMsg) {
if (userMsg.role === eRole.user) next()
else if (userMsg.role === eRole.staff) {
if (to.name === 'ChatList') {
chatAuthCheck(
() => {
next() next()
},
() => {
Toast('由于您现在是不在岗状态所以无法进入聊天!')
},
)
}
}
} else { } else {
next({ name: 'Login' }) next({ name: 'Login' })
} }
......
import baseAxios from '../index'
export function getStaffOnDutyStatus() {
return baseAxios<boolean>({
url: '/staff/on_duty',
method: 'get',
})
}
import router from '@/router' import router from '@/router'
import { getStaffOnDutyStatus } from '@/service/StaffService'
import { eRole } from '@/types/roleType'
import { getUserMsg } from './userMsg' import { getUserMsg } from './userMsg'
export function authCheck(cb: Function) { export function authCheck(cb: Function) {
...@@ -9,3 +11,18 @@ export function authCheck(cb: Function) { ...@@ -9,3 +11,18 @@ export function authCheck(cb: Function) {
}) })
} }
} }
export async function chatAuthCheck(cb: Function, cb2?: Function) {
const msg = getUserMsg()
if (msg?.role === eRole.user) return true
else if (msg?.role === eRole.staff) {
const ret = await getStaffOnDutyStatus()
if (ret.code === 200 && ret.data) {
cb()
} else {
cb2 && cb2()
}
} else {
cb2 && cb2()
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment