diff --git a/public/config/config.json b/public/config/config.json index 5407bac..2ecfbfe 100644 --- a/public/config/config.json +++ b/public/config/config.json @@ -55,5 +55,7 @@ "appStreamUrlDesc": "代理流播放地址", "appStreamUrl": "casic", "useApprovalDesc": "是否使用审批", - "useApproval": "true" + "useApproval": "false", + "useGatewayDesc": "sm是否走网关", + "useGateway": "false" } diff --git a/public/config/config.json b/public/config/config.json index 5407bac..2ecfbfe 100644 --- a/public/config/config.json +++ b/public/config/config.json @@ -55,5 +55,7 @@ "appStreamUrlDesc": "代理流播放地址", "appStreamUrl": "casic", "useApprovalDesc": "是否使用审批", - "useApproval": "true" + "useApproval": "false", + "useGatewayDesc": "sm是否走网关", + "useGateway": "false" } diff --git a/public/playerVideo6/jessibuca.js b/public/playerVideo6/jessibuca.js index 1450494..601f208 100644 --- a/public/playerVideo6/jessibuca.js +++ b/public/playerVideo6/jessibuca.js @@ -37,8 +37,8 @@ hasControl: !1, loadingText: '', background: '', - decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 - // decoder: `/playerVideo6/decoder.js`, // 本地使用 + // decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 + decoder: `/playerVideo6/decoder.js`, // 本地使用 // decoder: import.meta.env.MODE === 'development' ? `/playerVideo6/decoder.js` : `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, url: '', rotate: 0, diff --git a/public/config/config.json b/public/config/config.json index 5407bac..2ecfbfe 100644 --- a/public/config/config.json +++ b/public/config/config.json @@ -55,5 +55,7 @@ "appStreamUrlDesc": "代理流播放地址", "appStreamUrl": "casic", "useApprovalDesc": "是否使用审批", - "useApproval": "true" + "useApproval": "false", + "useGatewayDesc": "sm是否走网关", + "useGateway": "false" } diff --git a/public/playerVideo6/jessibuca.js b/public/playerVideo6/jessibuca.js index 1450494..601f208 100644 --- a/public/playerVideo6/jessibuca.js +++ b/public/playerVideo6/jessibuca.js @@ -37,8 +37,8 @@ hasControl: !1, loadingText: '', background: '', - decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 - // decoder: `/playerVideo6/decoder.js`, // 本地使用 + // decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 + decoder: `/playerVideo6/decoder.js`, // 本地使用 // decoder: import.meta.env.MODE === 'development' ? `/playerVideo6/decoder.js` : `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, url: '', rotate: 0, diff --git a/src/api/indexGm.ts b/src/api/indexGm.ts new file mode 100644 index 0000000..7f0fa35 --- /dev/null +++ b/src/api/indexGm.ts @@ -0,0 +1,186 @@ +import axios from 'axios' +// import qs from 'qs' +import { ElLoading, ElMessage } from 'element-plus' +// import config from '../../public/config/config.json' +import router from '@/router/index' +import useUserStore from '@/store/modules/user' +import { log } from '@/utils/log' + +// 错误码枚举 +enum responseCode { + success = 200, // 成功 + noPermission = 401, // 未授权 + error = 500, // 服务器异常 + hikSuccess = '0', // 海康成功 +} +// 以下地址发生错误直接跳转至登录页 +const toLoginPath = ['/sys/user/permission', '/sys/user/info'] + +// 跳转到登录页面 +const toLogin = () => { + useUserStore().logout() + router.push({ + path: '/login', + query: { + redirect: router.currentRoute.value.path !== '/login' ? router.currentRoute.value.fullPath : undefined, + }, + }) +} + +const request = axios.create({ + // baseURL: config.baseUrl, + baseURL: window.localStorage.getItem('baseURL')!, + // baseURL: import.meta.env.DEV && import.meta.env.VITE_OPEN_PROXY === 'true' ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL, + timeout: 1000 * 60, + responseType: 'json', +}) + +request.interceptors.request.use( + (request) => { + const userStore = useUserStore() + /** + * 全局拦截请求发送前提交的参数 + * 以下代码为示例,在请求头里带上 token 信息 + */ + if (userStore.isLogin && request.headers) { + // request.headers.token = userStore.token + request.headers.token = localStorage.getItem('token') + } + if (!userStore.isLogin && localStorage.getItem('tokenBak') === 'true') { // 未登录且url带token + request.headers.token = localStorage.getItem('token') + } + + // 是否将 POST 请求参数进行字符串化处理 + if (request.method === 'post') { + // request.data = qs.stringify(request.data, { + // arrayFormat: 'brackets', + // }) + } + return request + }, +) + +request.interceptors.response.use( + (response) => { + /** + * 全局拦截请求发送后返回的数据,如果数据有报错则在这做全局的错误提示 + * 如果是文件直接返回整个response对象 + */ + if (response.data instanceof Blob) { + return Promise.resolve(response) + } + else if (response.data.code !== responseCode.success && response.data.code !== responseCode.hikSuccess) { + if (response.data.code === responseCode.noPermission) { // token失效状态跳转到登录页 + // toLogin() + // if (useUserStore().isLogout === 0) { + // ElMessage.error(response.data.message || '发生错误') + // } + // useUserStore().toLogout()// 携带token + const hrefIdx = localStorage.getItem('tokenBak') + if (hrefIdx === 'true') { + console.log('跳转到404') + router.push({ + path: '/noPage', + }) + } + else { + console.log('跳转到404以外其他页面') + + if (window.localStorage.getItem('systemType') === 'gm') { + // token失效状态跳转到登录页 + // toLogin() + router.push({ + path: '/noPage', + }) + } else if (window.localStorage.getItem('systemType') === 'sm') { + // sm走网关 + router.push({ + path: '/smGateway', + }) + } + if (useUserStore().isLogout === 0) { + // ElMessage.warning(response.data.message || '发生错误') + console.log(response.data.message || '发生错误') + } + useUserStore().toLogout() + } + } + else if (response.data.code === 500 && response.data.message === '数据格式不正确' && response.data.data) { + const mes = response.data.data.filter((item: any, index: number) => index < 2).join(',') + // ElMessage.warning(mes) + console.log(mes) + } + else if (response.data.code === 500 && response.data.msg) { + // ElMessage.warning(response.data.msg) + console.log(response.data.mes) + } + else { + // 这里做错误提 + if (response.data.message) { + // ElMessage.warning(`${response.data.message}` || '发生错误') + console.log(`${response.data.message}` || '发生错误') + } + if (response.data.msg) { + // ElMessage.warning(`${response.data.msg}` || '发生错误') + console.log(`${response.data.msg}` || '发生错误') + } + const loadingInstance = ElLoading.service({}) + nextTick(() => { + // Loading should be closed asynchronously + loadingInstance.close() + }) + } + + return Promise.reject(response.data) + } + else { // 成功 + return Promise.resolve(response.data) + } + }, + (error) => { + // 处理文件下载的错误提示 + if (error.response && error.response.data instanceof Blob) { + const reader = new FileReader() + reader.onload = (e) => { + let errMsg = '发生错误!' + if (e && e.target!.result) { + errMsg = JSON.parse(e.target!.result as string) + } + ElMessage.warning(errMsg) + } + } + else if (error.response && error.response.data) { + // 如果是发生错误必须回到登录页的api + const needLogin = toLoginPath.findIndex(path => error.request.responseURL.includes(path)) + if (needLogin > -1) { + toLogin() + } + else { + const message: string = error.response.data.message + ElMessage({ + message, + type: 'warning', + }) + } + } + else if (error.message) { + let message = error.message + if (message === 'Network Error') { + message = '后端网络故障' + } + else if (message.includes('timeout')) { + message = '接口请求超时' + } + else if (message.includes('Request failed with status code')) { + message = `接口${message.substr(message.length - 3)}异常` + } + ElMessage({ + message, + type: 'warning', + }) + } + return Promise.reject(error) + }, +) + +export default request diff --git a/public/config/config.json b/public/config/config.json index 5407bac..2ecfbfe 100644 --- a/public/config/config.json +++ b/public/config/config.json @@ -55,5 +55,7 @@ "appStreamUrlDesc": "代理流播放地址", "appStreamUrl": "casic", "useApprovalDesc": "是否使用审批", - "useApproval": "true" + "useApproval": "false", + "useGatewayDesc": "sm是否走网关", + "useGateway": "false" } diff --git a/public/playerVideo6/jessibuca.js b/public/playerVideo6/jessibuca.js index 1450494..601f208 100644 --- a/public/playerVideo6/jessibuca.js +++ b/public/playerVideo6/jessibuca.js @@ -37,8 +37,8 @@ hasControl: !1, loadingText: '', background: '', - decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 - // decoder: `/playerVideo6/decoder.js`, // 本地使用 + // decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 + decoder: `/playerVideo6/decoder.js`, // 本地使用 // decoder: import.meta.env.MODE === 'development' ? `/playerVideo6/decoder.js` : `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, url: '', rotate: 0, diff --git a/src/api/indexGm.ts b/src/api/indexGm.ts new file mode 100644 index 0000000..7f0fa35 --- /dev/null +++ b/src/api/indexGm.ts @@ -0,0 +1,186 @@ +import axios from 'axios' +// import qs from 'qs' +import { ElLoading, ElMessage } from 'element-plus' +// import config from '../../public/config/config.json' +import router from '@/router/index' +import useUserStore from '@/store/modules/user' +import { log } from '@/utils/log' + +// 错误码枚举 +enum responseCode { + success = 200, // 成功 + noPermission = 401, // 未授权 + error = 500, // 服务器异常 + hikSuccess = '0', // 海康成功 +} +// 以下地址发生错误直接跳转至登录页 +const toLoginPath = ['/sys/user/permission', '/sys/user/info'] + +// 跳转到登录页面 +const toLogin = () => { + useUserStore().logout() + router.push({ + path: '/login', + query: { + redirect: router.currentRoute.value.path !== '/login' ? router.currentRoute.value.fullPath : undefined, + }, + }) +} + +const request = axios.create({ + // baseURL: config.baseUrl, + baseURL: window.localStorage.getItem('baseURL')!, + // baseURL: import.meta.env.DEV && import.meta.env.VITE_OPEN_PROXY === 'true' ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL, + timeout: 1000 * 60, + responseType: 'json', +}) + +request.interceptors.request.use( + (request) => { + const userStore = useUserStore() + /** + * 全局拦截请求发送前提交的参数 + * 以下代码为示例,在请求头里带上 token 信息 + */ + if (userStore.isLogin && request.headers) { + // request.headers.token = userStore.token + request.headers.token = localStorage.getItem('token') + } + if (!userStore.isLogin && localStorage.getItem('tokenBak') === 'true') { // 未登录且url带token + request.headers.token = localStorage.getItem('token') + } + + // 是否将 POST 请求参数进行字符串化处理 + if (request.method === 'post') { + // request.data = qs.stringify(request.data, { + // arrayFormat: 'brackets', + // }) + } + return request + }, +) + +request.interceptors.response.use( + (response) => { + /** + * 全局拦截请求发送后返回的数据,如果数据有报错则在这做全局的错误提示 + * 如果是文件直接返回整个response对象 + */ + if (response.data instanceof Blob) { + return Promise.resolve(response) + } + else if (response.data.code !== responseCode.success && response.data.code !== responseCode.hikSuccess) { + if (response.data.code === responseCode.noPermission) { // token失效状态跳转到登录页 + // toLogin() + // if (useUserStore().isLogout === 0) { + // ElMessage.error(response.data.message || '发生错误') + // } + // useUserStore().toLogout()// 携带token + const hrefIdx = localStorage.getItem('tokenBak') + if (hrefIdx === 'true') { + console.log('跳转到404') + router.push({ + path: '/noPage', + }) + } + else { + console.log('跳转到404以外其他页面') + + if (window.localStorage.getItem('systemType') === 'gm') { + // token失效状态跳转到登录页 + // toLogin() + router.push({ + path: '/noPage', + }) + } else if (window.localStorage.getItem('systemType') === 'sm') { + // sm走网关 + router.push({ + path: '/smGateway', + }) + } + if (useUserStore().isLogout === 0) { + // ElMessage.warning(response.data.message || '发生错误') + console.log(response.data.message || '发生错误') + } + useUserStore().toLogout() + } + } + else if (response.data.code === 500 && response.data.message === '数据格式不正确' && response.data.data) { + const mes = response.data.data.filter((item: any, index: number) => index < 2).join(',') + // ElMessage.warning(mes) + console.log(mes) + } + else if (response.data.code === 500 && response.data.msg) { + // ElMessage.warning(response.data.msg) + console.log(response.data.mes) + } + else { + // 这里做错误提 + if (response.data.message) { + // ElMessage.warning(`${response.data.message}` || '发生错误') + console.log(`${response.data.message}` || '发生错误') + } + if (response.data.msg) { + // ElMessage.warning(`${response.data.msg}` || '发生错误') + console.log(`${response.data.msg}` || '发生错误') + } + const loadingInstance = ElLoading.service({}) + nextTick(() => { + // Loading should be closed asynchronously + loadingInstance.close() + }) + } + + return Promise.reject(response.data) + } + else { // 成功 + return Promise.resolve(response.data) + } + }, + (error) => { + // 处理文件下载的错误提示 + if (error.response && error.response.data instanceof Blob) { + const reader = new FileReader() + reader.onload = (e) => { + let errMsg = '发生错误!' + if (e && e.target!.result) { + errMsg = JSON.parse(e.target!.result as string) + } + ElMessage.warning(errMsg) + } + } + else if (error.response && error.response.data) { + // 如果是发生错误必须回到登录页的api + const needLogin = toLoginPath.findIndex(path => error.request.responseURL.includes(path)) + if (needLogin > -1) { + toLogin() + } + else { + const message: string = error.response.data.message + ElMessage({ + message, + type: 'warning', + }) + } + } + else if (error.message) { + let message = error.message + if (message === 'Network Error') { + message = '后端网络故障' + } + else if (message.includes('timeout')) { + message = '接口请求超时' + } + else if (message.includes('Request failed with status code')) { + message = `接口${message.substr(message.length - 3)}异常` + } + ElMessage({ + message, + type: 'warning', + }) + } + return Promise.reject(error) + }, +) + +export default request diff --git a/src/api/monitor/index-new-gm.ts b/src/api/monitor/index-new-gm.ts index 3b3665f..800f767 100644 --- a/src/api/monitor/index-new-gm.ts +++ b/src/api/monitor/index-new-gm.ts @@ -1,5 +1,5 @@ // 流媒体 -import request from '../index' +import request from '../indexGm' // 创建流 export function createStream(deviceId: string) { const sendData = { diff --git a/public/config/config.json b/public/config/config.json index 5407bac..2ecfbfe 100644 --- a/public/config/config.json +++ b/public/config/config.json @@ -55,5 +55,7 @@ "appStreamUrlDesc": "代理流播放地址", "appStreamUrl": "casic", "useApprovalDesc": "是否使用审批", - "useApproval": "true" + "useApproval": "false", + "useGatewayDesc": "sm是否走网关", + "useGateway": "false" } diff --git a/public/playerVideo6/jessibuca.js b/public/playerVideo6/jessibuca.js index 1450494..601f208 100644 --- a/public/playerVideo6/jessibuca.js +++ b/public/playerVideo6/jessibuca.js @@ -37,8 +37,8 @@ hasControl: !1, loadingText: '', background: '', - decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 - // decoder: `/playerVideo6/decoder.js`, // 本地使用 + // decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 + decoder: `/playerVideo6/decoder.js`, // 本地使用 // decoder: import.meta.env.MODE === 'development' ? `/playerVideo6/decoder.js` : `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, url: '', rotate: 0, diff --git a/src/api/indexGm.ts b/src/api/indexGm.ts new file mode 100644 index 0000000..7f0fa35 --- /dev/null +++ b/src/api/indexGm.ts @@ -0,0 +1,186 @@ +import axios from 'axios' +// import qs from 'qs' +import { ElLoading, ElMessage } from 'element-plus' +// import config from '../../public/config/config.json' +import router from '@/router/index' +import useUserStore from '@/store/modules/user' +import { log } from '@/utils/log' + +// 错误码枚举 +enum responseCode { + success = 200, // 成功 + noPermission = 401, // 未授权 + error = 500, // 服务器异常 + hikSuccess = '0', // 海康成功 +} +// 以下地址发生错误直接跳转至登录页 +const toLoginPath = ['/sys/user/permission', '/sys/user/info'] + +// 跳转到登录页面 +const toLogin = () => { + useUserStore().logout() + router.push({ + path: '/login', + query: { + redirect: router.currentRoute.value.path !== '/login' ? router.currentRoute.value.fullPath : undefined, + }, + }) +} + +const request = axios.create({ + // baseURL: config.baseUrl, + baseURL: window.localStorage.getItem('baseURL')!, + // baseURL: import.meta.env.DEV && import.meta.env.VITE_OPEN_PROXY === 'true' ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL, + timeout: 1000 * 60, + responseType: 'json', +}) + +request.interceptors.request.use( + (request) => { + const userStore = useUserStore() + /** + * 全局拦截请求发送前提交的参数 + * 以下代码为示例,在请求头里带上 token 信息 + */ + if (userStore.isLogin && request.headers) { + // request.headers.token = userStore.token + request.headers.token = localStorage.getItem('token') + } + if (!userStore.isLogin && localStorage.getItem('tokenBak') === 'true') { // 未登录且url带token + request.headers.token = localStorage.getItem('token') + } + + // 是否将 POST 请求参数进行字符串化处理 + if (request.method === 'post') { + // request.data = qs.stringify(request.data, { + // arrayFormat: 'brackets', + // }) + } + return request + }, +) + +request.interceptors.response.use( + (response) => { + /** + * 全局拦截请求发送后返回的数据,如果数据有报错则在这做全局的错误提示 + * 如果是文件直接返回整个response对象 + */ + if (response.data instanceof Blob) { + return Promise.resolve(response) + } + else if (response.data.code !== responseCode.success && response.data.code !== responseCode.hikSuccess) { + if (response.data.code === responseCode.noPermission) { // token失效状态跳转到登录页 + // toLogin() + // if (useUserStore().isLogout === 0) { + // ElMessage.error(response.data.message || '发生错误') + // } + // useUserStore().toLogout()// 携带token + const hrefIdx = localStorage.getItem('tokenBak') + if (hrefIdx === 'true') { + console.log('跳转到404') + router.push({ + path: '/noPage', + }) + } + else { + console.log('跳转到404以外其他页面') + + if (window.localStorage.getItem('systemType') === 'gm') { + // token失效状态跳转到登录页 + // toLogin() + router.push({ + path: '/noPage', + }) + } else if (window.localStorage.getItem('systemType') === 'sm') { + // sm走网关 + router.push({ + path: '/smGateway', + }) + } + if (useUserStore().isLogout === 0) { + // ElMessage.warning(response.data.message || '发生错误') + console.log(response.data.message || '发生错误') + } + useUserStore().toLogout() + } + } + else if (response.data.code === 500 && response.data.message === '数据格式不正确' && response.data.data) { + const mes = response.data.data.filter((item: any, index: number) => index < 2).join(',') + // ElMessage.warning(mes) + console.log(mes) + } + else if (response.data.code === 500 && response.data.msg) { + // ElMessage.warning(response.data.msg) + console.log(response.data.mes) + } + else { + // 这里做错误提 + if (response.data.message) { + // ElMessage.warning(`${response.data.message}` || '发生错误') + console.log(`${response.data.message}` || '发生错误') + } + if (response.data.msg) { + // ElMessage.warning(`${response.data.msg}` || '发生错误') + console.log(`${response.data.msg}` || '发生错误') + } + const loadingInstance = ElLoading.service({}) + nextTick(() => { + // Loading should be closed asynchronously + loadingInstance.close() + }) + } + + return Promise.reject(response.data) + } + else { // 成功 + return Promise.resolve(response.data) + } + }, + (error) => { + // 处理文件下载的错误提示 + if (error.response && error.response.data instanceof Blob) { + const reader = new FileReader() + reader.onload = (e) => { + let errMsg = '发生错误!' + if (e && e.target!.result) { + errMsg = JSON.parse(e.target!.result as string) + } + ElMessage.warning(errMsg) + } + } + else if (error.response && error.response.data) { + // 如果是发生错误必须回到登录页的api + const needLogin = toLoginPath.findIndex(path => error.request.responseURL.includes(path)) + if (needLogin > -1) { + toLogin() + } + else { + const message: string = error.response.data.message + ElMessage({ + message, + type: 'warning', + }) + } + } + else if (error.message) { + let message = error.message + if (message === 'Network Error') { + message = '后端网络故障' + } + else if (message.includes('timeout')) { + message = '接口请求超时' + } + else if (message.includes('Request failed with status code')) { + message = `接口${message.substr(message.length - 3)}异常` + } + ElMessage({ + message, + type: 'warning', + }) + } + return Promise.reject(error) + }, +) + +export default request diff --git a/src/api/monitor/index-new-gm.ts b/src/api/monitor/index-new-gm.ts index 3b3665f..800f767 100644 --- a/src/api/monitor/index-new-gm.ts +++ b/src/api/monitor/index-new-gm.ts @@ -1,5 +1,5 @@ // 流媒体 -import request from '../index' +import request from '../indexGm' // 创建流 export function createStream(deviceId: string) { const sendData = { diff --git a/src/main.ts b/src/main.ts index 6ed4312..b2527bc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -65,6 +65,8 @@ window.localStorage.setItem('lineColors', JSON.stringify(result.data.lineColors)) // 是否使用审批 window.localStorage.setItem('useApproval', result.data.useApproval) + // sm是否走网关 + window.localStorage.setItem('useGateway', result.data.useGateway) const app = createApp(App) app.config.globalProperties.hasPerm = hasPermission app.config.globalProperties.buttonPerm = buttonPerm diff --git a/public/config/config.json b/public/config/config.json index 5407bac..2ecfbfe 100644 --- a/public/config/config.json +++ b/public/config/config.json @@ -55,5 +55,7 @@ "appStreamUrlDesc": "代理流播放地址", "appStreamUrl": "casic", "useApprovalDesc": "是否使用审批", - "useApproval": "true" + "useApproval": "false", + "useGatewayDesc": "sm是否走网关", + "useGateway": "false" } diff --git a/public/playerVideo6/jessibuca.js b/public/playerVideo6/jessibuca.js index 1450494..601f208 100644 --- a/public/playerVideo6/jessibuca.js +++ b/public/playerVideo6/jessibuca.js @@ -37,8 +37,8 @@ hasControl: !1, loadingText: '', background: '', - decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 - // decoder: `/playerVideo6/decoder.js`, // 本地使用 + // decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 + decoder: `/playerVideo6/decoder.js`, // 本地使用 // decoder: import.meta.env.MODE === 'development' ? `/playerVideo6/decoder.js` : `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, url: '', rotate: 0, diff --git a/src/api/indexGm.ts b/src/api/indexGm.ts new file mode 100644 index 0000000..7f0fa35 --- /dev/null +++ b/src/api/indexGm.ts @@ -0,0 +1,186 @@ +import axios from 'axios' +// import qs from 'qs' +import { ElLoading, ElMessage } from 'element-plus' +// import config from '../../public/config/config.json' +import router from '@/router/index' +import useUserStore from '@/store/modules/user' +import { log } from '@/utils/log' + +// 错误码枚举 +enum responseCode { + success = 200, // 成功 + noPermission = 401, // 未授权 + error = 500, // 服务器异常 + hikSuccess = '0', // 海康成功 +} +// 以下地址发生错误直接跳转至登录页 +const toLoginPath = ['/sys/user/permission', '/sys/user/info'] + +// 跳转到登录页面 +const toLogin = () => { + useUserStore().logout() + router.push({ + path: '/login', + query: { + redirect: router.currentRoute.value.path !== '/login' ? router.currentRoute.value.fullPath : undefined, + }, + }) +} + +const request = axios.create({ + // baseURL: config.baseUrl, + baseURL: window.localStorage.getItem('baseURL')!, + // baseURL: import.meta.env.DEV && import.meta.env.VITE_OPEN_PROXY === 'true' ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL, + timeout: 1000 * 60, + responseType: 'json', +}) + +request.interceptors.request.use( + (request) => { + const userStore = useUserStore() + /** + * 全局拦截请求发送前提交的参数 + * 以下代码为示例,在请求头里带上 token 信息 + */ + if (userStore.isLogin && request.headers) { + // request.headers.token = userStore.token + request.headers.token = localStorage.getItem('token') + } + if (!userStore.isLogin && localStorage.getItem('tokenBak') === 'true') { // 未登录且url带token + request.headers.token = localStorage.getItem('token') + } + + // 是否将 POST 请求参数进行字符串化处理 + if (request.method === 'post') { + // request.data = qs.stringify(request.data, { + // arrayFormat: 'brackets', + // }) + } + return request + }, +) + +request.interceptors.response.use( + (response) => { + /** + * 全局拦截请求发送后返回的数据,如果数据有报错则在这做全局的错误提示 + * 如果是文件直接返回整个response对象 + */ + if (response.data instanceof Blob) { + return Promise.resolve(response) + } + else if (response.data.code !== responseCode.success && response.data.code !== responseCode.hikSuccess) { + if (response.data.code === responseCode.noPermission) { // token失效状态跳转到登录页 + // toLogin() + // if (useUserStore().isLogout === 0) { + // ElMessage.error(response.data.message || '发生错误') + // } + // useUserStore().toLogout()// 携带token + const hrefIdx = localStorage.getItem('tokenBak') + if (hrefIdx === 'true') { + console.log('跳转到404') + router.push({ + path: '/noPage', + }) + } + else { + console.log('跳转到404以外其他页面') + + if (window.localStorage.getItem('systemType') === 'gm') { + // token失效状态跳转到登录页 + // toLogin() + router.push({ + path: '/noPage', + }) + } else if (window.localStorage.getItem('systemType') === 'sm') { + // sm走网关 + router.push({ + path: '/smGateway', + }) + } + if (useUserStore().isLogout === 0) { + // ElMessage.warning(response.data.message || '发生错误') + console.log(response.data.message || '发生错误') + } + useUserStore().toLogout() + } + } + else if (response.data.code === 500 && response.data.message === '数据格式不正确' && response.data.data) { + const mes = response.data.data.filter((item: any, index: number) => index < 2).join(',') + // ElMessage.warning(mes) + console.log(mes) + } + else if (response.data.code === 500 && response.data.msg) { + // ElMessage.warning(response.data.msg) + console.log(response.data.mes) + } + else { + // 这里做错误提 + if (response.data.message) { + // ElMessage.warning(`${response.data.message}` || '发生错误') + console.log(`${response.data.message}` || '发生错误') + } + if (response.data.msg) { + // ElMessage.warning(`${response.data.msg}` || '发生错误') + console.log(`${response.data.msg}` || '发生错误') + } + const loadingInstance = ElLoading.service({}) + nextTick(() => { + // Loading should be closed asynchronously + loadingInstance.close() + }) + } + + return Promise.reject(response.data) + } + else { // 成功 + return Promise.resolve(response.data) + } + }, + (error) => { + // 处理文件下载的错误提示 + if (error.response && error.response.data instanceof Blob) { + const reader = new FileReader() + reader.onload = (e) => { + let errMsg = '发生错误!' + if (e && e.target!.result) { + errMsg = JSON.parse(e.target!.result as string) + } + ElMessage.warning(errMsg) + } + } + else if (error.response && error.response.data) { + // 如果是发生错误必须回到登录页的api + const needLogin = toLoginPath.findIndex(path => error.request.responseURL.includes(path)) + if (needLogin > -1) { + toLogin() + } + else { + const message: string = error.response.data.message + ElMessage({ + message, + type: 'warning', + }) + } + } + else if (error.message) { + let message = error.message + if (message === 'Network Error') { + message = '后端网络故障' + } + else if (message.includes('timeout')) { + message = '接口请求超时' + } + else if (message.includes('Request failed with status code')) { + message = `接口${message.substr(message.length - 3)}异常` + } + ElMessage({ + message, + type: 'warning', + }) + } + return Promise.reject(error) + }, +) + +export default request diff --git a/src/api/monitor/index-new-gm.ts b/src/api/monitor/index-new-gm.ts index 3b3665f..800f767 100644 --- a/src/api/monitor/index-new-gm.ts +++ b/src/api/monitor/index-new-gm.ts @@ -1,5 +1,5 @@ // 流媒体 -import request from '../index' +import request from '../indexGm' // 创建流 export function createStream(deviceId: string) { const sendData = { diff --git a/src/main.ts b/src/main.ts index 6ed4312..b2527bc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -65,6 +65,8 @@ window.localStorage.setItem('lineColors', JSON.stringify(result.data.lineColors)) // 是否使用审批 window.localStorage.setItem('useApproval', result.data.useApproval) + // sm是否走网关 + window.localStorage.setItem('useGateway', result.data.useGateway) const app = createApp(App) app.config.globalProperties.hasPerm = hasPermission app.config.globalProperties.buttonPerm = buttonPerm diff --git a/src/router/index.ts b/src/router/index.ts index b242003..0f8d62f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -7,7 +7,7 @@ asyncRoutes, asyncRoutesByFilesystem, constantRoutes, - constantRoutesByFilesystem + constantRoutesByFilesystem, } from './routes' import pinia from '@/store' import useSettingsStore from '@/store/modules/settings' @@ -24,7 +24,7 @@ routes: useSettingsStore(pinia).app.routeBaseOn === 'filesystem' ? constantRoutesByFilesystem - : (constantRoutes as RouteRecordRaw[]) + : (constantRoutes as RouteRecordRaw[]), }) router.beforeEach(async (to, from, next) => { @@ -41,14 +41,21 @@ // 如果还要进入登录页,直接跳转 if (window.localStorage.getItem('systemType') === 'gm') { next() - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true - }) } - } else { + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next() + } + } + } + else { // 携带token 需要去掉 const hrefIdx = window.location.href.indexOf('token') // url中是否携带token if (hrefIdx > -1) { @@ -57,7 +64,8 @@ console.log('已登录状态设置新的Token:', token) localStorage.setItem('token', token) localStorage.setItem('tokenBak', 'true') - } else { + } + else { localStorage.setItem('tokenBak', 'false') } @@ -68,31 +76,31 @@ // 是否已根据权限动态生成并注册路由 if (routeStore.isGenerate) { // 导航栏如果不是 single 模式,则需要根据 path 定位主导航的选中状态 - settingsStore.menu.menuMode !== 'single' && - menuStore.setActived(to.path) + settingsStore.menu.menuMode !== 'single' + && menuStore.setActived(to.path) // 如果已登录状态下,进入登录页会强制跳转到控制台页面 if (to.name === 'login') { console.log('跳转控制台') next({ name: 'index', - replace: true + replace: true, }) } // 如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块 else if (!settingsStore.dashboard.enable && to.name === 'dashboard') { if (menuStore.sidebarMenus.length > 0) { console.log( - '如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块' + '如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块', ) next({ path: menuStore.sidebarMenusFirstDeepestPath, - replace: true + replace: true, }) } // 如果侧边栏导航第一个模块无法命中,则还是进入控制台页面 else { console.log( - '如果侧边栏导航第一个模块无法命中,则还是进入控制台页面' + '如果侧边栏导航第一个模块无法命中,则还是进入控制台页面', ) next() } @@ -101,7 +109,8 @@ else { next() } - } else { + } + else { // 生成动态路由 switch (settingsStore.app.routeBaseOn) { @@ -113,7 +122,7 @@ break case 'filesystem': await routeStore.generateRoutesAtFilesystem( - asyncRoutesByFilesystem + asyncRoutesByFilesystem, ) // 文件系统生成的路由,需要手动生成导航数据 switch (settingsStore.menu.baseOn) { @@ -129,14 +138,14 @@ // 注册并记录路由数据 // 记录的数据会在登出时会使用到,不使用 router.removeRoute 是考虑配置的路由可能不一定有设置 name ,则通过调用 router.addRoute() 返回的回调进行删除 const removeRoutes: Function[] = [] - routeStore.flatRoutes.forEach(route => { + routeStore.flatRoutes.forEach((route) => { if (!/^(https?:|mailto:|tel:)/.test(route.path)) { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) } }) // 添加静态路由 if (settingsStore.app.routeBaseOn !== 'filesystem') { - routeStore.flatSystemRoutes.forEach(route => { + routeStore.flatSystemRoutes.forEach((route) => { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) }) } @@ -145,11 +154,12 @@ next({ path: to.path, query: to.query, - replace: true + replace: true, }) } } - } else { + } + else { console.log('未登录') // 携带token 需要去掉 @@ -163,20 +173,21 @@ localStorage.setItem('token', token) console.log('url中携带token', token) localStorage.setItem('tokenBak', 'true') - } else { + } + else { localStorage.setItem('tokenBak', 'false') } if (localStorage.getItem('tokenBak') === 'true') { // 是否已根据权限动态生成并注册路由 if (routeStore.isGenerate) { // 导航栏如果不是 single 模式,则需要根据 path 定位主导航的选中状态 - settingsStore.menu.menuMode !== 'single' && - menuStore.setActived(to.path) + settingsStore.menu.menuMode !== 'single' + && menuStore.setActived(to.path) // 如果已登录状态下,进入登录页会强制跳转到控制台页面 if (to.name === 'login') { next({ name: 'index', - replace: true + replace: true, }) } // 如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块 @@ -184,7 +195,7 @@ if (menuStore.sidebarMenus.length > 0) { next({ path: menuStore.sidebarMenusFirstDeepestPath, - replace: true + replace: true, }) } // 如果侧边栏导航第一个模块无法命中,则还是进入控制台页面 @@ -196,7 +207,8 @@ else { next() } - } else { + } + else { // 生成动态路由 switch (settingsStore.app.routeBaseOn) { case 'frontend': @@ -207,7 +219,7 @@ break case 'filesystem': await routeStore.generateRoutesAtFilesystem( - asyncRoutesByFilesystem + asyncRoutesByFilesystem, ) // 文件系统生成的路由,需要手动生成导航数据 switch (settingsStore.menu.baseOn) { @@ -223,14 +235,14 @@ // 注册并记录路由数据 // 记录的数据会在登出时会使用到,不使用 router.removeRoute 是考虑配置的路由可能不一定有设置 name ,则通过调用 router.addRoute() 返回的回调进行删除 const removeRoutes: Function[] = [] - routeStore.flatRoutes.forEach(route => { + routeStore.flatRoutes.forEach((route) => { if (!/^(https?:|mailto:|tel:)/.test(route.path)) { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) } }) // 添加静态路由 if (settingsStore.app.routeBaseOn !== 'filesystem') { - routeStore.flatSystemRoutes.forEach(route => { + routeStore.flatSystemRoutes.forEach((route) => { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) }) } @@ -239,7 +251,7 @@ next({ path: to.path, query: to.query, - replace: true + replace: true, }) } await userStore.setToken(localStorage.getItem('token') as string) @@ -254,49 +266,70 @@ console.log('跳转实时监控') next({ path: '/realTime/page', - replace: true + replace: true, }) // next({ // path: menuStore.sidebarMenusFirstDeepestPath, // replace: true // }) - } else { + } + else { console.log('跳转noPage') next({ name: '/noPage', - replace: true + replace: true, }) } - } else { + } + else { if (window.localStorage.getItem('systemType') === 'gm') { next({ name: 'login', query: { - redirect: to.fullPath - } - }) - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true + redirect: to.fullPath, + }, }) } + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next({ + name: 'login', + query: { + redirect: to.fullPath, + }, + }) + } + } } - } else { + } + else { // 未登录跳转到登录 if (window.localStorage.getItem('systemType') === 'gm') { next() - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true - }) + } + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next() + } } } } - } else { + } + else { next() } }) @@ -306,25 +339,26 @@ const keepAliveStore = useKeepAliveStore() settingsStore.app.enableProgress && (isLoading.value = false) // 设置页面 title - to.meta.title && - settingsStore.setTitle( - typeof to.meta.title === 'function' ? to.meta.title() : to.meta.title + to.meta.title + && settingsStore.setTitle( + typeof to.meta.title === 'function' ? to.meta.title() : to.meta.title, ) // 判断当前页面是否开启缓存,如果开启,则将当前页面的 name 信息存入 keep-alive 全局状态 if (to.meta.cache) { - const componentName = - to.matched[to.matched.length - 1].components?.default.name + const componentName + = to.matched[to.matched.length - 1].components?.default.name // if (componentName) { keepAliveStore.add(componentName) - } else { + } + else { console.warn('该页面组件未设置组件名,会导致缓存失效,请检查') } } // 判断离开页面是否开启缓存,如果开启,则根据缓存规则判断是否需要清空 keep-alive 全局状态里离开页面的 name 信息 if (from.meta.cache) { - const componentName = - from.matched[to.matched.length - 1].components?.default.name + const componentName + = from.matched[to.matched.length - 1].components?.default.name if (componentName) { // 通过 meta.cache 判断针对哪些页面进行缓存 switch (typeof from.meta.cache) { diff --git a/public/config/config.json b/public/config/config.json index 5407bac..2ecfbfe 100644 --- a/public/config/config.json +++ b/public/config/config.json @@ -55,5 +55,7 @@ "appStreamUrlDesc": "代理流播放地址", "appStreamUrl": "casic", "useApprovalDesc": "是否使用审批", - "useApproval": "true" + "useApproval": "false", + "useGatewayDesc": "sm是否走网关", + "useGateway": "false" } diff --git a/public/playerVideo6/jessibuca.js b/public/playerVideo6/jessibuca.js index 1450494..601f208 100644 --- a/public/playerVideo6/jessibuca.js +++ b/public/playerVideo6/jessibuca.js @@ -37,8 +37,8 @@ hasControl: !1, loadingText: '', background: '', - decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 - // decoder: `/playerVideo6/decoder.js`, // 本地使用 + // decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 + decoder: `/playerVideo6/decoder.js`, // 本地使用 // decoder: import.meta.env.MODE === 'development' ? `/playerVideo6/decoder.js` : `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, url: '', rotate: 0, diff --git a/src/api/indexGm.ts b/src/api/indexGm.ts new file mode 100644 index 0000000..7f0fa35 --- /dev/null +++ b/src/api/indexGm.ts @@ -0,0 +1,186 @@ +import axios from 'axios' +// import qs from 'qs' +import { ElLoading, ElMessage } from 'element-plus' +// import config from '../../public/config/config.json' +import router from '@/router/index' +import useUserStore from '@/store/modules/user' +import { log } from '@/utils/log' + +// 错误码枚举 +enum responseCode { + success = 200, // 成功 + noPermission = 401, // 未授权 + error = 500, // 服务器异常 + hikSuccess = '0', // 海康成功 +} +// 以下地址发生错误直接跳转至登录页 +const toLoginPath = ['/sys/user/permission', '/sys/user/info'] + +// 跳转到登录页面 +const toLogin = () => { + useUserStore().logout() + router.push({ + path: '/login', + query: { + redirect: router.currentRoute.value.path !== '/login' ? router.currentRoute.value.fullPath : undefined, + }, + }) +} + +const request = axios.create({ + // baseURL: config.baseUrl, + baseURL: window.localStorage.getItem('baseURL')!, + // baseURL: import.meta.env.DEV && import.meta.env.VITE_OPEN_PROXY === 'true' ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL, + timeout: 1000 * 60, + responseType: 'json', +}) + +request.interceptors.request.use( + (request) => { + const userStore = useUserStore() + /** + * 全局拦截请求发送前提交的参数 + * 以下代码为示例,在请求头里带上 token 信息 + */ + if (userStore.isLogin && request.headers) { + // request.headers.token = userStore.token + request.headers.token = localStorage.getItem('token') + } + if (!userStore.isLogin && localStorage.getItem('tokenBak') === 'true') { // 未登录且url带token + request.headers.token = localStorage.getItem('token') + } + + // 是否将 POST 请求参数进行字符串化处理 + if (request.method === 'post') { + // request.data = qs.stringify(request.data, { + // arrayFormat: 'brackets', + // }) + } + return request + }, +) + +request.interceptors.response.use( + (response) => { + /** + * 全局拦截请求发送后返回的数据,如果数据有报错则在这做全局的错误提示 + * 如果是文件直接返回整个response对象 + */ + if (response.data instanceof Blob) { + return Promise.resolve(response) + } + else if (response.data.code !== responseCode.success && response.data.code !== responseCode.hikSuccess) { + if (response.data.code === responseCode.noPermission) { // token失效状态跳转到登录页 + // toLogin() + // if (useUserStore().isLogout === 0) { + // ElMessage.error(response.data.message || '发生错误') + // } + // useUserStore().toLogout()// 携带token + const hrefIdx = localStorage.getItem('tokenBak') + if (hrefIdx === 'true') { + console.log('跳转到404') + router.push({ + path: '/noPage', + }) + } + else { + console.log('跳转到404以外其他页面') + + if (window.localStorage.getItem('systemType') === 'gm') { + // token失效状态跳转到登录页 + // toLogin() + router.push({ + path: '/noPage', + }) + } else if (window.localStorage.getItem('systemType') === 'sm') { + // sm走网关 + router.push({ + path: '/smGateway', + }) + } + if (useUserStore().isLogout === 0) { + // ElMessage.warning(response.data.message || '发生错误') + console.log(response.data.message || '发生错误') + } + useUserStore().toLogout() + } + } + else if (response.data.code === 500 && response.data.message === '数据格式不正确' && response.data.data) { + const mes = response.data.data.filter((item: any, index: number) => index < 2).join(',') + // ElMessage.warning(mes) + console.log(mes) + } + else if (response.data.code === 500 && response.data.msg) { + // ElMessage.warning(response.data.msg) + console.log(response.data.mes) + } + else { + // 这里做错误提 + if (response.data.message) { + // ElMessage.warning(`${response.data.message}` || '发生错误') + console.log(`${response.data.message}` || '发生错误') + } + if (response.data.msg) { + // ElMessage.warning(`${response.data.msg}` || '发生错误') + console.log(`${response.data.msg}` || '发生错误') + } + const loadingInstance = ElLoading.service({}) + nextTick(() => { + // Loading should be closed asynchronously + loadingInstance.close() + }) + } + + return Promise.reject(response.data) + } + else { // 成功 + return Promise.resolve(response.data) + } + }, + (error) => { + // 处理文件下载的错误提示 + if (error.response && error.response.data instanceof Blob) { + const reader = new FileReader() + reader.onload = (e) => { + let errMsg = '发生错误!' + if (e && e.target!.result) { + errMsg = JSON.parse(e.target!.result as string) + } + ElMessage.warning(errMsg) + } + } + else if (error.response && error.response.data) { + // 如果是发生错误必须回到登录页的api + const needLogin = toLoginPath.findIndex(path => error.request.responseURL.includes(path)) + if (needLogin > -1) { + toLogin() + } + else { + const message: string = error.response.data.message + ElMessage({ + message, + type: 'warning', + }) + } + } + else if (error.message) { + let message = error.message + if (message === 'Network Error') { + message = '后端网络故障' + } + else if (message.includes('timeout')) { + message = '接口请求超时' + } + else if (message.includes('Request failed with status code')) { + message = `接口${message.substr(message.length - 3)}异常` + } + ElMessage({ + message, + type: 'warning', + }) + } + return Promise.reject(error) + }, +) + +export default request diff --git a/src/api/monitor/index-new-gm.ts b/src/api/monitor/index-new-gm.ts index 3b3665f..800f767 100644 --- a/src/api/monitor/index-new-gm.ts +++ b/src/api/monitor/index-new-gm.ts @@ -1,5 +1,5 @@ // 流媒体 -import request from '../index' +import request from '../indexGm' // 创建流 export function createStream(deviceId: string) { const sendData = { diff --git a/src/main.ts b/src/main.ts index 6ed4312..b2527bc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -65,6 +65,8 @@ window.localStorage.setItem('lineColors', JSON.stringify(result.data.lineColors)) // 是否使用审批 window.localStorage.setItem('useApproval', result.data.useApproval) + // sm是否走网关 + window.localStorage.setItem('useGateway', result.data.useGateway) const app = createApp(App) app.config.globalProperties.hasPerm = hasPermission app.config.globalProperties.buttonPerm = buttonPerm diff --git a/src/router/index.ts b/src/router/index.ts index b242003..0f8d62f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -7,7 +7,7 @@ asyncRoutes, asyncRoutesByFilesystem, constantRoutes, - constantRoutesByFilesystem + constantRoutesByFilesystem, } from './routes' import pinia from '@/store' import useSettingsStore from '@/store/modules/settings' @@ -24,7 +24,7 @@ routes: useSettingsStore(pinia).app.routeBaseOn === 'filesystem' ? constantRoutesByFilesystem - : (constantRoutes as RouteRecordRaw[]) + : (constantRoutes as RouteRecordRaw[]), }) router.beforeEach(async (to, from, next) => { @@ -41,14 +41,21 @@ // 如果还要进入登录页,直接跳转 if (window.localStorage.getItem('systemType') === 'gm') { next() - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true - }) } - } else { + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next() + } + } + } + else { // 携带token 需要去掉 const hrefIdx = window.location.href.indexOf('token') // url中是否携带token if (hrefIdx > -1) { @@ -57,7 +64,8 @@ console.log('已登录状态设置新的Token:', token) localStorage.setItem('token', token) localStorage.setItem('tokenBak', 'true') - } else { + } + else { localStorage.setItem('tokenBak', 'false') } @@ -68,31 +76,31 @@ // 是否已根据权限动态生成并注册路由 if (routeStore.isGenerate) { // 导航栏如果不是 single 模式,则需要根据 path 定位主导航的选中状态 - settingsStore.menu.menuMode !== 'single' && - menuStore.setActived(to.path) + settingsStore.menu.menuMode !== 'single' + && menuStore.setActived(to.path) // 如果已登录状态下,进入登录页会强制跳转到控制台页面 if (to.name === 'login') { console.log('跳转控制台') next({ name: 'index', - replace: true + replace: true, }) } // 如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块 else if (!settingsStore.dashboard.enable && to.name === 'dashboard') { if (menuStore.sidebarMenus.length > 0) { console.log( - '如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块' + '如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块', ) next({ path: menuStore.sidebarMenusFirstDeepestPath, - replace: true + replace: true, }) } // 如果侧边栏导航第一个模块无法命中,则还是进入控制台页面 else { console.log( - '如果侧边栏导航第一个模块无法命中,则还是进入控制台页面' + '如果侧边栏导航第一个模块无法命中,则还是进入控制台页面', ) next() } @@ -101,7 +109,8 @@ else { next() } - } else { + } + else { // 生成动态路由 switch (settingsStore.app.routeBaseOn) { @@ -113,7 +122,7 @@ break case 'filesystem': await routeStore.generateRoutesAtFilesystem( - asyncRoutesByFilesystem + asyncRoutesByFilesystem, ) // 文件系统生成的路由,需要手动生成导航数据 switch (settingsStore.menu.baseOn) { @@ -129,14 +138,14 @@ // 注册并记录路由数据 // 记录的数据会在登出时会使用到,不使用 router.removeRoute 是考虑配置的路由可能不一定有设置 name ,则通过调用 router.addRoute() 返回的回调进行删除 const removeRoutes: Function[] = [] - routeStore.flatRoutes.forEach(route => { + routeStore.flatRoutes.forEach((route) => { if (!/^(https?:|mailto:|tel:)/.test(route.path)) { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) } }) // 添加静态路由 if (settingsStore.app.routeBaseOn !== 'filesystem') { - routeStore.flatSystemRoutes.forEach(route => { + routeStore.flatSystemRoutes.forEach((route) => { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) }) } @@ -145,11 +154,12 @@ next({ path: to.path, query: to.query, - replace: true + replace: true, }) } } - } else { + } + else { console.log('未登录') // 携带token 需要去掉 @@ -163,20 +173,21 @@ localStorage.setItem('token', token) console.log('url中携带token', token) localStorage.setItem('tokenBak', 'true') - } else { + } + else { localStorage.setItem('tokenBak', 'false') } if (localStorage.getItem('tokenBak') === 'true') { // 是否已根据权限动态生成并注册路由 if (routeStore.isGenerate) { // 导航栏如果不是 single 模式,则需要根据 path 定位主导航的选中状态 - settingsStore.menu.menuMode !== 'single' && - menuStore.setActived(to.path) + settingsStore.menu.menuMode !== 'single' + && menuStore.setActived(to.path) // 如果已登录状态下,进入登录页会强制跳转到控制台页面 if (to.name === 'login') { next({ name: 'index', - replace: true + replace: true, }) } // 如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块 @@ -184,7 +195,7 @@ if (menuStore.sidebarMenus.length > 0) { next({ path: menuStore.sidebarMenusFirstDeepestPath, - replace: true + replace: true, }) } // 如果侧边栏导航第一个模块无法命中,则还是进入控制台页面 @@ -196,7 +207,8 @@ else { next() } - } else { + } + else { // 生成动态路由 switch (settingsStore.app.routeBaseOn) { case 'frontend': @@ -207,7 +219,7 @@ break case 'filesystem': await routeStore.generateRoutesAtFilesystem( - asyncRoutesByFilesystem + asyncRoutesByFilesystem, ) // 文件系统生成的路由,需要手动生成导航数据 switch (settingsStore.menu.baseOn) { @@ -223,14 +235,14 @@ // 注册并记录路由数据 // 记录的数据会在登出时会使用到,不使用 router.removeRoute 是考虑配置的路由可能不一定有设置 name ,则通过调用 router.addRoute() 返回的回调进行删除 const removeRoutes: Function[] = [] - routeStore.flatRoutes.forEach(route => { + routeStore.flatRoutes.forEach((route) => { if (!/^(https?:|mailto:|tel:)/.test(route.path)) { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) } }) // 添加静态路由 if (settingsStore.app.routeBaseOn !== 'filesystem') { - routeStore.flatSystemRoutes.forEach(route => { + routeStore.flatSystemRoutes.forEach((route) => { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) }) } @@ -239,7 +251,7 @@ next({ path: to.path, query: to.query, - replace: true + replace: true, }) } await userStore.setToken(localStorage.getItem('token') as string) @@ -254,49 +266,70 @@ console.log('跳转实时监控') next({ path: '/realTime/page', - replace: true + replace: true, }) // next({ // path: menuStore.sidebarMenusFirstDeepestPath, // replace: true // }) - } else { + } + else { console.log('跳转noPage') next({ name: '/noPage', - replace: true + replace: true, }) } - } else { + } + else { if (window.localStorage.getItem('systemType') === 'gm') { next({ name: 'login', query: { - redirect: to.fullPath - } - }) - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true + redirect: to.fullPath, + }, }) } + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next({ + name: 'login', + query: { + redirect: to.fullPath, + }, + }) + } + } } - } else { + } + else { // 未登录跳转到登录 if (window.localStorage.getItem('systemType') === 'gm') { next() - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true - }) + } + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next() + } } } } - } else { + } + else { next() } }) @@ -306,25 +339,26 @@ const keepAliveStore = useKeepAliveStore() settingsStore.app.enableProgress && (isLoading.value = false) // 设置页面 title - to.meta.title && - settingsStore.setTitle( - typeof to.meta.title === 'function' ? to.meta.title() : to.meta.title + to.meta.title + && settingsStore.setTitle( + typeof to.meta.title === 'function' ? to.meta.title() : to.meta.title, ) // 判断当前页面是否开启缓存,如果开启,则将当前页面的 name 信息存入 keep-alive 全局状态 if (to.meta.cache) { - const componentName = - to.matched[to.matched.length - 1].components?.default.name + const componentName + = to.matched[to.matched.length - 1].components?.default.name // if (componentName) { keepAliveStore.add(componentName) - } else { + } + else { console.warn('该页面组件未设置组件名,会导致缓存失效,请检查') } } // 判断离开页面是否开启缓存,如果开启,则根据缓存规则判断是否需要清空 keep-alive 全局状态里离开页面的 name 信息 if (from.meta.cache) { - const componentName = - from.matched[to.matched.length - 1].components?.default.name + const componentName + = from.matched[to.matched.length - 1].components?.default.name if (componentName) { // 通过 meta.cache 判断针对哪些页面进行缓存 switch (typeof from.meta.cache) { diff --git a/src/views/alarm/policyConfig/monitorPoint/drawArea.vue b/src/views/alarm/policyConfig/monitorPoint/drawArea.vue index bfc404a..d30474a 100644 --- a/src/views/alarm/policyConfig/monitorPoint/drawArea.vue +++ b/src/views/alarm/policyConfig/monitorPoint/drawArea.vue @@ -78,18 +78,21 @@ ctx.fillStyle = window.localStorage.getItem('fontColor') || '#1aa034' } if (lineColors.value.length) { - const textX = 0 - const textY = 20 + index * 20 + // const textX = 0 + // const textY = 20 + index * 20 + const x = Number(e.boundary[0].x) + const y = Number(e.boundary[0].y) + const textX = x === 0 ? 0 : x + 3 > props.width - 60 ? props.width - 60 : x + 5 + const textY = y < 16 ? 16 : y > props.height - 12 ? props.height - 12 : y - 5 ctx.fillText(e.remark, textX, textY) } else { - console.log('e.boundary[0].x', e.boundary[0].x) - console.log('e.boundary[0].y', e.boundary[0].y) - const textX = e.boundary[0].x === 0 ? 0 : e.boundary[0].x + 3 > props.width - 60 ? props.width - 60 : e.boundary[0].x + 5 - const textY = e.boundary[0].y < 15 ? 15 : e.boundary[0].y > props.height - 12 ? props.height - 12 : e.boundary[0].y - 5 - console.log('文字位置x', Number(textX)) - console.log('文字位置y', Number(textY)) - ctx.fillText(e.remark, e.boundary[0].x, textY) + const x = Number(e.boundary[0].x) + const y = Number(e.boundary[0].y) + const textX = x === 0 ? 0 : x + 3 > props.width - 60 ? props.width - 60 : x + 5 + const textY = y < 15 ? 15 : y > props.height - 12 ? props.height - 12 : y - 5 + // ctx.fillText(e.remark, x, textY) + ctx.fillText(e.remark, textX, textY) } }) } diff --git a/public/config/config.json b/public/config/config.json index 5407bac..2ecfbfe 100644 --- a/public/config/config.json +++ b/public/config/config.json @@ -55,5 +55,7 @@ "appStreamUrlDesc": "代理流播放地址", "appStreamUrl": "casic", "useApprovalDesc": "是否使用审批", - "useApproval": "true" + "useApproval": "false", + "useGatewayDesc": "sm是否走网关", + "useGateway": "false" } diff --git a/public/playerVideo6/jessibuca.js b/public/playerVideo6/jessibuca.js index 1450494..601f208 100644 --- a/public/playerVideo6/jessibuca.js +++ b/public/playerVideo6/jessibuca.js @@ -37,8 +37,8 @@ hasControl: !1, loadingText: '', background: '', - decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 - // decoder: `/playerVideo6/decoder.js`, // 本地使用 + // decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 + decoder: `/playerVideo6/decoder.js`, // 本地使用 // decoder: import.meta.env.MODE === 'development' ? `/playerVideo6/decoder.js` : `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, url: '', rotate: 0, diff --git a/src/api/indexGm.ts b/src/api/indexGm.ts new file mode 100644 index 0000000..7f0fa35 --- /dev/null +++ b/src/api/indexGm.ts @@ -0,0 +1,186 @@ +import axios from 'axios' +// import qs from 'qs' +import { ElLoading, ElMessage } from 'element-plus' +// import config from '../../public/config/config.json' +import router from '@/router/index' +import useUserStore from '@/store/modules/user' +import { log } from '@/utils/log' + +// 错误码枚举 +enum responseCode { + success = 200, // 成功 + noPermission = 401, // 未授权 + error = 500, // 服务器异常 + hikSuccess = '0', // 海康成功 +} +// 以下地址发生错误直接跳转至登录页 +const toLoginPath = ['/sys/user/permission', '/sys/user/info'] + +// 跳转到登录页面 +const toLogin = () => { + useUserStore().logout() + router.push({ + path: '/login', + query: { + redirect: router.currentRoute.value.path !== '/login' ? router.currentRoute.value.fullPath : undefined, + }, + }) +} + +const request = axios.create({ + // baseURL: config.baseUrl, + baseURL: window.localStorage.getItem('baseURL')!, + // baseURL: import.meta.env.DEV && import.meta.env.VITE_OPEN_PROXY === 'true' ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL, + timeout: 1000 * 60, + responseType: 'json', +}) + +request.interceptors.request.use( + (request) => { + const userStore = useUserStore() + /** + * 全局拦截请求发送前提交的参数 + * 以下代码为示例,在请求头里带上 token 信息 + */ + if (userStore.isLogin && request.headers) { + // request.headers.token = userStore.token + request.headers.token = localStorage.getItem('token') + } + if (!userStore.isLogin && localStorage.getItem('tokenBak') === 'true') { // 未登录且url带token + request.headers.token = localStorage.getItem('token') + } + + // 是否将 POST 请求参数进行字符串化处理 + if (request.method === 'post') { + // request.data = qs.stringify(request.data, { + // arrayFormat: 'brackets', + // }) + } + return request + }, +) + +request.interceptors.response.use( + (response) => { + /** + * 全局拦截请求发送后返回的数据,如果数据有报错则在这做全局的错误提示 + * 如果是文件直接返回整个response对象 + */ + if (response.data instanceof Blob) { + return Promise.resolve(response) + } + else if (response.data.code !== responseCode.success && response.data.code !== responseCode.hikSuccess) { + if (response.data.code === responseCode.noPermission) { // token失效状态跳转到登录页 + // toLogin() + // if (useUserStore().isLogout === 0) { + // ElMessage.error(response.data.message || '发生错误') + // } + // useUserStore().toLogout()// 携带token + const hrefIdx = localStorage.getItem('tokenBak') + if (hrefIdx === 'true') { + console.log('跳转到404') + router.push({ + path: '/noPage', + }) + } + else { + console.log('跳转到404以外其他页面') + + if (window.localStorage.getItem('systemType') === 'gm') { + // token失效状态跳转到登录页 + // toLogin() + router.push({ + path: '/noPage', + }) + } else if (window.localStorage.getItem('systemType') === 'sm') { + // sm走网关 + router.push({ + path: '/smGateway', + }) + } + if (useUserStore().isLogout === 0) { + // ElMessage.warning(response.data.message || '发生错误') + console.log(response.data.message || '发生错误') + } + useUserStore().toLogout() + } + } + else if (response.data.code === 500 && response.data.message === '数据格式不正确' && response.data.data) { + const mes = response.data.data.filter((item: any, index: number) => index < 2).join(',') + // ElMessage.warning(mes) + console.log(mes) + } + else if (response.data.code === 500 && response.data.msg) { + // ElMessage.warning(response.data.msg) + console.log(response.data.mes) + } + else { + // 这里做错误提 + if (response.data.message) { + // ElMessage.warning(`${response.data.message}` || '发生错误') + console.log(`${response.data.message}` || '发生错误') + } + if (response.data.msg) { + // ElMessage.warning(`${response.data.msg}` || '发生错误') + console.log(`${response.data.msg}` || '发生错误') + } + const loadingInstance = ElLoading.service({}) + nextTick(() => { + // Loading should be closed asynchronously + loadingInstance.close() + }) + } + + return Promise.reject(response.data) + } + else { // 成功 + return Promise.resolve(response.data) + } + }, + (error) => { + // 处理文件下载的错误提示 + if (error.response && error.response.data instanceof Blob) { + const reader = new FileReader() + reader.onload = (e) => { + let errMsg = '发生错误!' + if (e && e.target!.result) { + errMsg = JSON.parse(e.target!.result as string) + } + ElMessage.warning(errMsg) + } + } + else if (error.response && error.response.data) { + // 如果是发生错误必须回到登录页的api + const needLogin = toLoginPath.findIndex(path => error.request.responseURL.includes(path)) + if (needLogin > -1) { + toLogin() + } + else { + const message: string = error.response.data.message + ElMessage({ + message, + type: 'warning', + }) + } + } + else if (error.message) { + let message = error.message + if (message === 'Network Error') { + message = '后端网络故障' + } + else if (message.includes('timeout')) { + message = '接口请求超时' + } + else if (message.includes('Request failed with status code')) { + message = `接口${message.substr(message.length - 3)}异常` + } + ElMessage({ + message, + type: 'warning', + }) + } + return Promise.reject(error) + }, +) + +export default request diff --git a/src/api/monitor/index-new-gm.ts b/src/api/monitor/index-new-gm.ts index 3b3665f..800f767 100644 --- a/src/api/monitor/index-new-gm.ts +++ b/src/api/monitor/index-new-gm.ts @@ -1,5 +1,5 @@ // 流媒体 -import request from '../index' +import request from '../indexGm' // 创建流 export function createStream(deviceId: string) { const sendData = { diff --git a/src/main.ts b/src/main.ts index 6ed4312..b2527bc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -65,6 +65,8 @@ window.localStorage.setItem('lineColors', JSON.stringify(result.data.lineColors)) // 是否使用审批 window.localStorage.setItem('useApproval', result.data.useApproval) + // sm是否走网关 + window.localStorage.setItem('useGateway', result.data.useGateway) const app = createApp(App) app.config.globalProperties.hasPerm = hasPermission app.config.globalProperties.buttonPerm = buttonPerm diff --git a/src/router/index.ts b/src/router/index.ts index b242003..0f8d62f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -7,7 +7,7 @@ asyncRoutes, asyncRoutesByFilesystem, constantRoutes, - constantRoutesByFilesystem + constantRoutesByFilesystem, } from './routes' import pinia from '@/store' import useSettingsStore from '@/store/modules/settings' @@ -24,7 +24,7 @@ routes: useSettingsStore(pinia).app.routeBaseOn === 'filesystem' ? constantRoutesByFilesystem - : (constantRoutes as RouteRecordRaw[]) + : (constantRoutes as RouteRecordRaw[]), }) router.beforeEach(async (to, from, next) => { @@ -41,14 +41,21 @@ // 如果还要进入登录页,直接跳转 if (window.localStorage.getItem('systemType') === 'gm') { next() - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true - }) } - } else { + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next() + } + } + } + else { // 携带token 需要去掉 const hrefIdx = window.location.href.indexOf('token') // url中是否携带token if (hrefIdx > -1) { @@ -57,7 +64,8 @@ console.log('已登录状态设置新的Token:', token) localStorage.setItem('token', token) localStorage.setItem('tokenBak', 'true') - } else { + } + else { localStorage.setItem('tokenBak', 'false') } @@ -68,31 +76,31 @@ // 是否已根据权限动态生成并注册路由 if (routeStore.isGenerate) { // 导航栏如果不是 single 模式,则需要根据 path 定位主导航的选中状态 - settingsStore.menu.menuMode !== 'single' && - menuStore.setActived(to.path) + settingsStore.menu.menuMode !== 'single' + && menuStore.setActived(to.path) // 如果已登录状态下,进入登录页会强制跳转到控制台页面 if (to.name === 'login') { console.log('跳转控制台') next({ name: 'index', - replace: true + replace: true, }) } // 如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块 else if (!settingsStore.dashboard.enable && to.name === 'dashboard') { if (menuStore.sidebarMenus.length > 0) { console.log( - '如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块' + '如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块', ) next({ path: menuStore.sidebarMenusFirstDeepestPath, - replace: true + replace: true, }) } // 如果侧边栏导航第一个模块无法命中,则还是进入控制台页面 else { console.log( - '如果侧边栏导航第一个模块无法命中,则还是进入控制台页面' + '如果侧边栏导航第一个模块无法命中,则还是进入控制台页面', ) next() } @@ -101,7 +109,8 @@ else { next() } - } else { + } + else { // 生成动态路由 switch (settingsStore.app.routeBaseOn) { @@ -113,7 +122,7 @@ break case 'filesystem': await routeStore.generateRoutesAtFilesystem( - asyncRoutesByFilesystem + asyncRoutesByFilesystem, ) // 文件系统生成的路由,需要手动生成导航数据 switch (settingsStore.menu.baseOn) { @@ -129,14 +138,14 @@ // 注册并记录路由数据 // 记录的数据会在登出时会使用到,不使用 router.removeRoute 是考虑配置的路由可能不一定有设置 name ,则通过调用 router.addRoute() 返回的回调进行删除 const removeRoutes: Function[] = [] - routeStore.flatRoutes.forEach(route => { + routeStore.flatRoutes.forEach((route) => { if (!/^(https?:|mailto:|tel:)/.test(route.path)) { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) } }) // 添加静态路由 if (settingsStore.app.routeBaseOn !== 'filesystem') { - routeStore.flatSystemRoutes.forEach(route => { + routeStore.flatSystemRoutes.forEach((route) => { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) }) } @@ -145,11 +154,12 @@ next({ path: to.path, query: to.query, - replace: true + replace: true, }) } } - } else { + } + else { console.log('未登录') // 携带token 需要去掉 @@ -163,20 +173,21 @@ localStorage.setItem('token', token) console.log('url中携带token', token) localStorage.setItem('tokenBak', 'true') - } else { + } + else { localStorage.setItem('tokenBak', 'false') } if (localStorage.getItem('tokenBak') === 'true') { // 是否已根据权限动态生成并注册路由 if (routeStore.isGenerate) { // 导航栏如果不是 single 模式,则需要根据 path 定位主导航的选中状态 - settingsStore.menu.menuMode !== 'single' && - menuStore.setActived(to.path) + settingsStore.menu.menuMode !== 'single' + && menuStore.setActived(to.path) // 如果已登录状态下,进入登录页会强制跳转到控制台页面 if (to.name === 'login') { next({ name: 'index', - replace: true + replace: true, }) } // 如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块 @@ -184,7 +195,7 @@ if (menuStore.sidebarMenus.length > 0) { next({ path: menuStore.sidebarMenusFirstDeepestPath, - replace: true + replace: true, }) } // 如果侧边栏导航第一个模块无法命中,则还是进入控制台页面 @@ -196,7 +207,8 @@ else { next() } - } else { + } + else { // 生成动态路由 switch (settingsStore.app.routeBaseOn) { case 'frontend': @@ -207,7 +219,7 @@ break case 'filesystem': await routeStore.generateRoutesAtFilesystem( - asyncRoutesByFilesystem + asyncRoutesByFilesystem, ) // 文件系统生成的路由,需要手动生成导航数据 switch (settingsStore.menu.baseOn) { @@ -223,14 +235,14 @@ // 注册并记录路由数据 // 记录的数据会在登出时会使用到,不使用 router.removeRoute 是考虑配置的路由可能不一定有设置 name ,则通过调用 router.addRoute() 返回的回调进行删除 const removeRoutes: Function[] = [] - routeStore.flatRoutes.forEach(route => { + routeStore.flatRoutes.forEach((route) => { if (!/^(https?:|mailto:|tel:)/.test(route.path)) { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) } }) // 添加静态路由 if (settingsStore.app.routeBaseOn !== 'filesystem') { - routeStore.flatSystemRoutes.forEach(route => { + routeStore.flatSystemRoutes.forEach((route) => { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) }) } @@ -239,7 +251,7 @@ next({ path: to.path, query: to.query, - replace: true + replace: true, }) } await userStore.setToken(localStorage.getItem('token') as string) @@ -254,49 +266,70 @@ console.log('跳转实时监控') next({ path: '/realTime/page', - replace: true + replace: true, }) // next({ // path: menuStore.sidebarMenusFirstDeepestPath, // replace: true // }) - } else { + } + else { console.log('跳转noPage') next({ name: '/noPage', - replace: true + replace: true, }) } - } else { + } + else { if (window.localStorage.getItem('systemType') === 'gm') { next({ name: 'login', query: { - redirect: to.fullPath - } - }) - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true + redirect: to.fullPath, + }, }) } + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next({ + name: 'login', + query: { + redirect: to.fullPath, + }, + }) + } + } } - } else { + } + else { // 未登录跳转到登录 if (window.localStorage.getItem('systemType') === 'gm') { next() - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true - }) + } + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next() + } } } } - } else { + } + else { next() } }) @@ -306,25 +339,26 @@ const keepAliveStore = useKeepAliveStore() settingsStore.app.enableProgress && (isLoading.value = false) // 设置页面 title - to.meta.title && - settingsStore.setTitle( - typeof to.meta.title === 'function' ? to.meta.title() : to.meta.title + to.meta.title + && settingsStore.setTitle( + typeof to.meta.title === 'function' ? to.meta.title() : to.meta.title, ) // 判断当前页面是否开启缓存,如果开启,则将当前页面的 name 信息存入 keep-alive 全局状态 if (to.meta.cache) { - const componentName = - to.matched[to.matched.length - 1].components?.default.name + const componentName + = to.matched[to.matched.length - 1].components?.default.name // if (componentName) { keepAliveStore.add(componentName) - } else { + } + else { console.warn('该页面组件未设置组件名,会导致缓存失效,请检查') } } // 判断离开页面是否开启缓存,如果开启,则根据缓存规则判断是否需要清空 keep-alive 全局状态里离开页面的 name 信息 if (from.meta.cache) { - const componentName = - from.matched[to.matched.length - 1].components?.default.name + const componentName + = from.matched[to.matched.length - 1].components?.default.name if (componentName) { // 通过 meta.cache 判断针对哪些页面进行缓存 switch (typeof from.meta.cache) { diff --git a/src/views/alarm/policyConfig/monitorPoint/drawArea.vue b/src/views/alarm/policyConfig/monitorPoint/drawArea.vue index bfc404a..d30474a 100644 --- a/src/views/alarm/policyConfig/monitorPoint/drawArea.vue +++ b/src/views/alarm/policyConfig/monitorPoint/drawArea.vue @@ -78,18 +78,21 @@ ctx.fillStyle = window.localStorage.getItem('fontColor') || '#1aa034' } if (lineColors.value.length) { - const textX = 0 - const textY = 20 + index * 20 + // const textX = 0 + // const textY = 20 + index * 20 + const x = Number(e.boundary[0].x) + const y = Number(e.boundary[0].y) + const textX = x === 0 ? 0 : x + 3 > props.width - 60 ? props.width - 60 : x + 5 + const textY = y < 16 ? 16 : y > props.height - 12 ? props.height - 12 : y - 5 ctx.fillText(e.remark, textX, textY) } else { - console.log('e.boundary[0].x', e.boundary[0].x) - console.log('e.boundary[0].y', e.boundary[0].y) - const textX = e.boundary[0].x === 0 ? 0 : e.boundary[0].x + 3 > props.width - 60 ? props.width - 60 : e.boundary[0].x + 5 - const textY = e.boundary[0].y < 15 ? 15 : e.boundary[0].y > props.height - 12 ? props.height - 12 : e.boundary[0].y - 5 - console.log('文字位置x', Number(textX)) - console.log('文字位置y', Number(textY)) - ctx.fillText(e.remark, e.boundary[0].x, textY) + const x = Number(e.boundary[0].x) + const y = Number(e.boundary[0].y) + const textX = x === 0 ? 0 : x + 3 > props.width - 60 ? props.width - 60 : x + 5 + const textY = y < 15 ? 15 : y > props.height - 12 ? props.height - 12 : y - 5 + // ctx.fillText(e.remark, x, textY) + ctx.fillText(e.remark, textX, textY) } }) } diff --git a/src/views/alarm/policyConfig/monitorPoint/drawAreaRealTime.vue b/src/views/alarm/policyConfig/monitorPoint/drawAreaRealTime.vue index 0cdecc0..d52b38b 100644 --- a/src/views/alarm/policyConfig/monitorPoint/drawAreaRealTime.vue +++ b/src/views/alarm/policyConfig/monitorPoint/drawAreaRealTime.vue @@ -78,18 +78,23 @@ ctx.fillStyle = window.localStorage.getItem('fontColor') || '#1aa034' } if (lineColors.value.length) { - const textX = 0 - const textY = 20 + index * 20 + // const textX = 0 + // const textY = 20 + index * 20 + const textX = e.boundary[0].x === 0 ? 0 : e.boundary[0].x + 3 > props.width - 60 ? props.width - 60 : e.boundary[0].x + 5 + const textY = e.boundary[0].y < 16 ? 16 : e.boundary[0].y > props.height - 12 ? props.height - 12 : e.boundary[0].y - 5 + console.log('-----', textX, textY); + ctx.fillText(e.remark, textX, textY) } else { console.log('e.boundary[0].x', e.boundary[0].x) console.log('e.boundary[0].y', e.boundary[0].y) const textX = e.boundary[0].x === 0 ? 0 : e.boundary[0].x + 3 > props.width - 60 ? props.width - 60 : e.boundary[0].x + 5 - const textY = e.boundary[0].y < 15 ? 15 : e.boundary[0].y > props.height - 12 ? props.height - 12 : e.boundary[0].y - 5 + const textY = e.boundary[0].y < 16 ? 16 : e.boundary[0].y > props.height - 12 ? props.height - 12 : e.boundary[0].y - 5 console.log('文字位置x', Number(textX)) console.log('文字位置y', Number(textY)) - ctx.fillText(e.remark, e.boundary[0].x, textY) + // ctx.fillText(e.remark, e.boundary[0].x, textY) + ctx.fillText(e.remark, textX, textY) } }) } diff --git a/public/config/config.json b/public/config/config.json index 5407bac..2ecfbfe 100644 --- a/public/config/config.json +++ b/public/config/config.json @@ -55,5 +55,7 @@ "appStreamUrlDesc": "代理流播放地址", "appStreamUrl": "casic", "useApprovalDesc": "是否使用审批", - "useApproval": "true" + "useApproval": "false", + "useGatewayDesc": "sm是否走网关", + "useGateway": "false" } diff --git a/public/playerVideo6/jessibuca.js b/public/playerVideo6/jessibuca.js index 1450494..601f208 100644 --- a/public/playerVideo6/jessibuca.js +++ b/public/playerVideo6/jessibuca.js @@ -37,8 +37,8 @@ hasControl: !1, loadingText: '', background: '', - decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 - // decoder: `/playerVideo6/decoder.js`, // 本地使用 + // decoder: `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, // 线上使用 + decoder: `/playerVideo6/decoder.js`, // 本地使用 // decoder: import.meta.env.MODE === 'development' ? `/playerVideo6/decoder.js` : `${window.localStorage.getItem('deployPath')}/playerVideo6/decoder.js`, url: '', rotate: 0, diff --git a/src/api/indexGm.ts b/src/api/indexGm.ts new file mode 100644 index 0000000..7f0fa35 --- /dev/null +++ b/src/api/indexGm.ts @@ -0,0 +1,186 @@ +import axios from 'axios' +// import qs from 'qs' +import { ElLoading, ElMessage } from 'element-plus' +// import config from '../../public/config/config.json' +import router from '@/router/index' +import useUserStore from '@/store/modules/user' +import { log } from '@/utils/log' + +// 错误码枚举 +enum responseCode { + success = 200, // 成功 + noPermission = 401, // 未授权 + error = 500, // 服务器异常 + hikSuccess = '0', // 海康成功 +} +// 以下地址发生错误直接跳转至登录页 +const toLoginPath = ['/sys/user/permission', '/sys/user/info'] + +// 跳转到登录页面 +const toLogin = () => { + useUserStore().logout() + router.push({ + path: '/login', + query: { + redirect: router.currentRoute.value.path !== '/login' ? router.currentRoute.value.fullPath : undefined, + }, + }) +} + +const request = axios.create({ + // baseURL: config.baseUrl, + baseURL: window.localStorage.getItem('baseURL')!, + // baseURL: import.meta.env.DEV && import.meta.env.VITE_OPEN_PROXY === 'true' ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL, + timeout: 1000 * 60, + responseType: 'json', +}) + +request.interceptors.request.use( + (request) => { + const userStore = useUserStore() + /** + * 全局拦截请求发送前提交的参数 + * 以下代码为示例,在请求头里带上 token 信息 + */ + if (userStore.isLogin && request.headers) { + // request.headers.token = userStore.token + request.headers.token = localStorage.getItem('token') + } + if (!userStore.isLogin && localStorage.getItem('tokenBak') === 'true') { // 未登录且url带token + request.headers.token = localStorage.getItem('token') + } + + // 是否将 POST 请求参数进行字符串化处理 + if (request.method === 'post') { + // request.data = qs.stringify(request.data, { + // arrayFormat: 'brackets', + // }) + } + return request + }, +) + +request.interceptors.response.use( + (response) => { + /** + * 全局拦截请求发送后返回的数据,如果数据有报错则在这做全局的错误提示 + * 如果是文件直接返回整个response对象 + */ + if (response.data instanceof Blob) { + return Promise.resolve(response) + } + else if (response.data.code !== responseCode.success && response.data.code !== responseCode.hikSuccess) { + if (response.data.code === responseCode.noPermission) { // token失效状态跳转到登录页 + // toLogin() + // if (useUserStore().isLogout === 0) { + // ElMessage.error(response.data.message || '发生错误') + // } + // useUserStore().toLogout()// 携带token + const hrefIdx = localStorage.getItem('tokenBak') + if (hrefIdx === 'true') { + console.log('跳转到404') + router.push({ + path: '/noPage', + }) + } + else { + console.log('跳转到404以外其他页面') + + if (window.localStorage.getItem('systemType') === 'gm') { + // token失效状态跳转到登录页 + // toLogin() + router.push({ + path: '/noPage', + }) + } else if (window.localStorage.getItem('systemType') === 'sm') { + // sm走网关 + router.push({ + path: '/smGateway', + }) + } + if (useUserStore().isLogout === 0) { + // ElMessage.warning(response.data.message || '发生错误') + console.log(response.data.message || '发生错误') + } + useUserStore().toLogout() + } + } + else if (response.data.code === 500 && response.data.message === '数据格式不正确' && response.data.data) { + const mes = response.data.data.filter((item: any, index: number) => index < 2).join(',') + // ElMessage.warning(mes) + console.log(mes) + } + else if (response.data.code === 500 && response.data.msg) { + // ElMessage.warning(response.data.msg) + console.log(response.data.mes) + } + else { + // 这里做错误提 + if (response.data.message) { + // ElMessage.warning(`${response.data.message}` || '发生错误') + console.log(`${response.data.message}` || '发生错误') + } + if (response.data.msg) { + // ElMessage.warning(`${response.data.msg}` || '发生错误') + console.log(`${response.data.msg}` || '发生错误') + } + const loadingInstance = ElLoading.service({}) + nextTick(() => { + // Loading should be closed asynchronously + loadingInstance.close() + }) + } + + return Promise.reject(response.data) + } + else { // 成功 + return Promise.resolve(response.data) + } + }, + (error) => { + // 处理文件下载的错误提示 + if (error.response && error.response.data instanceof Blob) { + const reader = new FileReader() + reader.onload = (e) => { + let errMsg = '发生错误!' + if (e && e.target!.result) { + errMsg = JSON.parse(e.target!.result as string) + } + ElMessage.warning(errMsg) + } + } + else if (error.response && error.response.data) { + // 如果是发生错误必须回到登录页的api + const needLogin = toLoginPath.findIndex(path => error.request.responseURL.includes(path)) + if (needLogin > -1) { + toLogin() + } + else { + const message: string = error.response.data.message + ElMessage({ + message, + type: 'warning', + }) + } + } + else if (error.message) { + let message = error.message + if (message === 'Network Error') { + message = '后端网络故障' + } + else if (message.includes('timeout')) { + message = '接口请求超时' + } + else if (message.includes('Request failed with status code')) { + message = `接口${message.substr(message.length - 3)}异常` + } + ElMessage({ + message, + type: 'warning', + }) + } + return Promise.reject(error) + }, +) + +export default request diff --git a/src/api/monitor/index-new-gm.ts b/src/api/monitor/index-new-gm.ts index 3b3665f..800f767 100644 --- a/src/api/monitor/index-new-gm.ts +++ b/src/api/monitor/index-new-gm.ts @@ -1,5 +1,5 @@ // 流媒体 -import request from '../index' +import request from '../indexGm' // 创建流 export function createStream(deviceId: string) { const sendData = { diff --git a/src/main.ts b/src/main.ts index 6ed4312..b2527bc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -65,6 +65,8 @@ window.localStorage.setItem('lineColors', JSON.stringify(result.data.lineColors)) // 是否使用审批 window.localStorage.setItem('useApproval', result.data.useApproval) + // sm是否走网关 + window.localStorage.setItem('useGateway', result.data.useGateway) const app = createApp(App) app.config.globalProperties.hasPerm = hasPermission app.config.globalProperties.buttonPerm = buttonPerm diff --git a/src/router/index.ts b/src/router/index.ts index b242003..0f8d62f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -7,7 +7,7 @@ asyncRoutes, asyncRoutesByFilesystem, constantRoutes, - constantRoutesByFilesystem + constantRoutesByFilesystem, } from './routes' import pinia from '@/store' import useSettingsStore from '@/store/modules/settings' @@ -24,7 +24,7 @@ routes: useSettingsStore(pinia).app.routeBaseOn === 'filesystem' ? constantRoutesByFilesystem - : (constantRoutes as RouteRecordRaw[]) + : (constantRoutes as RouteRecordRaw[]), }) router.beforeEach(async (to, from, next) => { @@ -41,14 +41,21 @@ // 如果还要进入登录页,直接跳转 if (window.localStorage.getItem('systemType') === 'gm') { next() - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true - }) } - } else { + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next() + } + } + } + else { // 携带token 需要去掉 const hrefIdx = window.location.href.indexOf('token') // url中是否携带token if (hrefIdx > -1) { @@ -57,7 +64,8 @@ console.log('已登录状态设置新的Token:', token) localStorage.setItem('token', token) localStorage.setItem('tokenBak', 'true') - } else { + } + else { localStorage.setItem('tokenBak', 'false') } @@ -68,31 +76,31 @@ // 是否已根据权限动态生成并注册路由 if (routeStore.isGenerate) { // 导航栏如果不是 single 模式,则需要根据 path 定位主导航的选中状态 - settingsStore.menu.menuMode !== 'single' && - menuStore.setActived(to.path) + settingsStore.menu.menuMode !== 'single' + && menuStore.setActived(to.path) // 如果已登录状态下,进入登录页会强制跳转到控制台页面 if (to.name === 'login') { console.log('跳转控制台') next({ name: 'index', - replace: true + replace: true, }) } // 如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块 else if (!settingsStore.dashboard.enable && to.name === 'dashboard') { if (menuStore.sidebarMenus.length > 0) { console.log( - '如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块' + '如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块', ) next({ path: menuStore.sidebarMenusFirstDeepestPath, - replace: true + replace: true, }) } // 如果侧边栏导航第一个模块无法命中,则还是进入控制台页面 else { console.log( - '如果侧边栏导航第一个模块无法命中,则还是进入控制台页面' + '如果侧边栏导航第一个模块无法命中,则还是进入控制台页面', ) next() } @@ -101,7 +109,8 @@ else { next() } - } else { + } + else { // 生成动态路由 switch (settingsStore.app.routeBaseOn) { @@ -113,7 +122,7 @@ break case 'filesystem': await routeStore.generateRoutesAtFilesystem( - asyncRoutesByFilesystem + asyncRoutesByFilesystem, ) // 文件系统生成的路由,需要手动生成导航数据 switch (settingsStore.menu.baseOn) { @@ -129,14 +138,14 @@ // 注册并记录路由数据 // 记录的数据会在登出时会使用到,不使用 router.removeRoute 是考虑配置的路由可能不一定有设置 name ,则通过调用 router.addRoute() 返回的回调进行删除 const removeRoutes: Function[] = [] - routeStore.flatRoutes.forEach(route => { + routeStore.flatRoutes.forEach((route) => { if (!/^(https?:|mailto:|tel:)/.test(route.path)) { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) } }) // 添加静态路由 if (settingsStore.app.routeBaseOn !== 'filesystem') { - routeStore.flatSystemRoutes.forEach(route => { + routeStore.flatSystemRoutes.forEach((route) => { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) }) } @@ -145,11 +154,12 @@ next({ path: to.path, query: to.query, - replace: true + replace: true, }) } } - } else { + } + else { console.log('未登录') // 携带token 需要去掉 @@ -163,20 +173,21 @@ localStorage.setItem('token', token) console.log('url中携带token', token) localStorage.setItem('tokenBak', 'true') - } else { + } + else { localStorage.setItem('tokenBak', 'false') } if (localStorage.getItem('tokenBak') === 'true') { // 是否已根据权限动态生成并注册路由 if (routeStore.isGenerate) { // 导航栏如果不是 single 模式,则需要根据 path 定位主导航的选中状态 - settingsStore.menu.menuMode !== 'single' && - menuStore.setActived(to.path) + settingsStore.menu.menuMode !== 'single' + && menuStore.setActived(to.path) // 如果已登录状态下,进入登录页会强制跳转到控制台页面 if (to.name === 'login') { next({ name: 'index', - replace: true + replace: true, }) } // 如果未开启控制台,但进入的是控制台页面,则会进入侧边栏导航第一个模块 @@ -184,7 +195,7 @@ if (menuStore.sidebarMenus.length > 0) { next({ path: menuStore.sidebarMenusFirstDeepestPath, - replace: true + replace: true, }) } // 如果侧边栏导航第一个模块无法命中,则还是进入控制台页面 @@ -196,7 +207,8 @@ else { next() } - } else { + } + else { // 生成动态路由 switch (settingsStore.app.routeBaseOn) { case 'frontend': @@ -207,7 +219,7 @@ break case 'filesystem': await routeStore.generateRoutesAtFilesystem( - asyncRoutesByFilesystem + asyncRoutesByFilesystem, ) // 文件系统生成的路由,需要手动生成导航数据 switch (settingsStore.menu.baseOn) { @@ -223,14 +235,14 @@ // 注册并记录路由数据 // 记录的数据会在登出时会使用到,不使用 router.removeRoute 是考虑配置的路由可能不一定有设置 name ,则通过调用 router.addRoute() 返回的回调进行删除 const removeRoutes: Function[] = [] - routeStore.flatRoutes.forEach(route => { + routeStore.flatRoutes.forEach((route) => { if (!/^(https?:|mailto:|tel:)/.test(route.path)) { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) } }) // 添加静态路由 if (settingsStore.app.routeBaseOn !== 'filesystem') { - routeStore.flatSystemRoutes.forEach(route => { + routeStore.flatSystemRoutes.forEach((route) => { removeRoutes.push(router.addRoute(route as RouteRecordRaw)) }) } @@ -239,7 +251,7 @@ next({ path: to.path, query: to.query, - replace: true + replace: true, }) } await userStore.setToken(localStorage.getItem('token') as string) @@ -254,49 +266,70 @@ console.log('跳转实时监控') next({ path: '/realTime/page', - replace: true + replace: true, }) // next({ // path: menuStore.sidebarMenusFirstDeepestPath, // replace: true // }) - } else { + } + else { console.log('跳转noPage') next({ name: '/noPage', - replace: true + replace: true, }) } - } else { + } + else { if (window.localStorage.getItem('systemType') === 'gm') { next({ name: 'login', query: { - redirect: to.fullPath - } - }) - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true + redirect: to.fullPath, + }, }) } + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next({ + name: 'login', + query: { + redirect: to.fullPath, + }, + }) + } + } } - } else { + } + else { // 未登录跳转到登录 if (window.localStorage.getItem('systemType') === 'gm') { next() - } else if (window.localStorage.getItem('systemType') === 'sm') { - // sm走网关 - next({ - name: 'SmGateway', - replace: true - }) + } + else if (window.localStorage.getItem('systemType') === 'sm') { + if (window.localStorage.getItem('useGateway') === 'true') { + // sm走网关 + next({ + name: 'SmGateway', + replace: true, + }) + } + else { + next() + } } } } - } else { + } + else { next() } }) @@ -306,25 +339,26 @@ const keepAliveStore = useKeepAliveStore() settingsStore.app.enableProgress && (isLoading.value = false) // 设置页面 title - to.meta.title && - settingsStore.setTitle( - typeof to.meta.title === 'function' ? to.meta.title() : to.meta.title + to.meta.title + && settingsStore.setTitle( + typeof to.meta.title === 'function' ? to.meta.title() : to.meta.title, ) // 判断当前页面是否开启缓存,如果开启,则将当前页面的 name 信息存入 keep-alive 全局状态 if (to.meta.cache) { - const componentName = - to.matched[to.matched.length - 1].components?.default.name + const componentName + = to.matched[to.matched.length - 1].components?.default.name // if (componentName) { keepAliveStore.add(componentName) - } else { + } + else { console.warn('该页面组件未设置组件名,会导致缓存失效,请检查') } } // 判断离开页面是否开启缓存,如果开启,则根据缓存规则判断是否需要清空 keep-alive 全局状态里离开页面的 name 信息 if (from.meta.cache) { - const componentName = - from.matched[to.matched.length - 1].components?.default.name + const componentName + = from.matched[to.matched.length - 1].components?.default.name if (componentName) { // 通过 meta.cache 判断针对哪些页面进行缓存 switch (typeof from.meta.cache) { diff --git a/src/views/alarm/policyConfig/monitorPoint/drawArea.vue b/src/views/alarm/policyConfig/monitorPoint/drawArea.vue index bfc404a..d30474a 100644 --- a/src/views/alarm/policyConfig/monitorPoint/drawArea.vue +++ b/src/views/alarm/policyConfig/monitorPoint/drawArea.vue @@ -78,18 +78,21 @@ ctx.fillStyle = window.localStorage.getItem('fontColor') || '#1aa034' } if (lineColors.value.length) { - const textX = 0 - const textY = 20 + index * 20 + // const textX = 0 + // const textY = 20 + index * 20 + const x = Number(e.boundary[0].x) + const y = Number(e.boundary[0].y) + const textX = x === 0 ? 0 : x + 3 > props.width - 60 ? props.width - 60 : x + 5 + const textY = y < 16 ? 16 : y > props.height - 12 ? props.height - 12 : y - 5 ctx.fillText(e.remark, textX, textY) } else { - console.log('e.boundary[0].x', e.boundary[0].x) - console.log('e.boundary[0].y', e.boundary[0].y) - const textX = e.boundary[0].x === 0 ? 0 : e.boundary[0].x + 3 > props.width - 60 ? props.width - 60 : e.boundary[0].x + 5 - const textY = e.boundary[0].y < 15 ? 15 : e.boundary[0].y > props.height - 12 ? props.height - 12 : e.boundary[0].y - 5 - console.log('文字位置x', Number(textX)) - console.log('文字位置y', Number(textY)) - ctx.fillText(e.remark, e.boundary[0].x, textY) + const x = Number(e.boundary[0].x) + const y = Number(e.boundary[0].y) + const textX = x === 0 ? 0 : x + 3 > props.width - 60 ? props.width - 60 : x + 5 + const textY = y < 15 ? 15 : y > props.height - 12 ? props.height - 12 : y - 5 + // ctx.fillText(e.remark, x, textY) + ctx.fillText(e.remark, textX, textY) } }) } diff --git a/src/views/alarm/policyConfig/monitorPoint/drawAreaRealTime.vue b/src/views/alarm/policyConfig/monitorPoint/drawAreaRealTime.vue index 0cdecc0..d52b38b 100644 --- a/src/views/alarm/policyConfig/monitorPoint/drawAreaRealTime.vue +++ b/src/views/alarm/policyConfig/monitorPoint/drawAreaRealTime.vue @@ -78,18 +78,23 @@ ctx.fillStyle = window.localStorage.getItem('fontColor') || '#1aa034' } if (lineColors.value.length) { - const textX = 0 - const textY = 20 + index * 20 + // const textX = 0 + // const textY = 20 + index * 20 + const textX = e.boundary[0].x === 0 ? 0 : e.boundary[0].x + 3 > props.width - 60 ? props.width - 60 : e.boundary[0].x + 5 + const textY = e.boundary[0].y < 16 ? 16 : e.boundary[0].y > props.height - 12 ? props.height - 12 : e.boundary[0].y - 5 + console.log('-----', textX, textY); + ctx.fillText(e.remark, textX, textY) } else { console.log('e.boundary[0].x', e.boundary[0].x) console.log('e.boundary[0].y', e.boundary[0].y) const textX = e.boundary[0].x === 0 ? 0 : e.boundary[0].x + 3 > props.width - 60 ? props.width - 60 : e.boundary[0].x + 5 - const textY = e.boundary[0].y < 15 ? 15 : e.boundary[0].y > props.height - 12 ? props.height - 12 : e.boundary[0].y - 5 + const textY = e.boundary[0].y < 16 ? 16 : e.boundary[0].y > props.height - 12 ? props.height - 12 : e.boundary[0].y - 5 console.log('文字位置x', Number(textX)) console.log('文字位置y', Number(textY)) - ctx.fillText(e.remark, e.boundary[0].x, textY) + // ctx.fillText(e.remark, e.boundary[0].x, textY) + ctx.fillText(e.remark, textX, textY) } }) } diff --git a/src/views/bigScreen/jessibuca.vue b/src/views/bigScreen/jessibuca.vue index bac5024..3c36045 100644 --- a/src/views/bigScreen/jessibuca.vue +++ b/src/views/bigScreen/jessibuca.vue @@ -1,5 +1,6 @@