diff --git a/src/api/laboratory/alarm/current.ts b/src/api/laboratory/alarm/current.ts index e9003a4..b11c617 100644 --- a/src/api/laboratory/alarm/current.ts +++ b/src/api/laboratory/alarm/current.ts @@ -25,7 +25,7 @@ } // 操作报警 -export function operateAlarm(data: { id: string; alarmStatus: string }) { +export function operateAlarm(data: { ids: string[]; alarmStatus: string }) { return request({ url: `${prefix}/operate`, method: 'post', diff --git a/src/api/laboratory/alarm/current.ts b/src/api/laboratory/alarm/current.ts index e9003a4..b11c617 100644 --- a/src/api/laboratory/alarm/current.ts +++ b/src/api/laboratory/alarm/current.ts @@ -25,7 +25,7 @@ } // 操作报警 -export function operateAlarm(data: { id: string; alarmStatus: string }) { +export function operateAlarm(data: { ids: string[]; alarmStatus: string }) { return request({ url: `${prefix}/operate`, method: 'post', diff --git a/src/api/laboratory/equipment/list.ts b/src/api/laboratory/equipment/list.ts index 75e7f1e..26b6090 100644 --- a/src/api/laboratory/equipment/list.ts +++ b/src/api/laboratory/equipment/list.ts @@ -61,4 +61,3 @@ data, }) } - diff --git a/src/api/laboratory/alarm/current.ts b/src/api/laboratory/alarm/current.ts index e9003a4..b11c617 100644 --- a/src/api/laboratory/alarm/current.ts +++ b/src/api/laboratory/alarm/current.ts @@ -25,7 +25,7 @@ } // 操作报警 -export function operateAlarm(data: { id: string; alarmStatus: string }) { +export function operateAlarm(data: { ids: string[]; alarmStatus: string }) { return request({ url: `${prefix}/operate`, method: 'post', diff --git a/src/api/laboratory/equipment/list.ts b/src/api/laboratory/equipment/list.ts index 75e7f1e..26b6090 100644 --- a/src/api/laboratory/equipment/list.ts +++ b/src/api/laboratory/equipment/list.ts @@ -61,4 +61,3 @@ data, }) } - diff --git a/src/api/laboratory/overView.ts b/src/api/laboratory/overView.ts index 31ed06c..0b6603b 100644 --- a/src/api/laboratory/overView.ts +++ b/src/api/laboratory/overView.ts @@ -11,3 +11,11 @@ method: 'get', }) } + +// 查询各个实验室数据 +export function getLocationDetail() { + return request({ + url: `${prefix}/workshop/environment`, + method: 'get', + }) +} diff --git a/src/api/laboratory/alarm/current.ts b/src/api/laboratory/alarm/current.ts index e9003a4..b11c617 100644 --- a/src/api/laboratory/alarm/current.ts +++ b/src/api/laboratory/alarm/current.ts @@ -25,7 +25,7 @@ } // 操作报警 -export function operateAlarm(data: { id: string; alarmStatus: string }) { +export function operateAlarm(data: { ids: string[]; alarmStatus: string }) { return request({ url: `${prefix}/operate`, method: 'post', diff --git a/src/api/laboratory/equipment/list.ts b/src/api/laboratory/equipment/list.ts index 75e7f1e..26b6090 100644 --- a/src/api/laboratory/equipment/list.ts +++ b/src/api/laboratory/equipment/list.ts @@ -61,4 +61,3 @@ data, }) } - diff --git a/src/api/laboratory/overView.ts b/src/api/laboratory/overView.ts index 31ed06c..0b6603b 100644 --- a/src/api/laboratory/overView.ts +++ b/src/api/laboratory/overView.ts @@ -11,3 +11,11 @@ method: 'get', }) } + +// 查询各个实验室数据 +export function getLocationDetail() { + return request({ + url: `${prefix}/workshop/environment`, + method: 'get', + }) +} diff --git a/src/router/index.ts b/src/router/index.ts index 579b155..d244fb7 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -10,6 +10,7 @@ import useUserStore from '@/store/modules/user' import useMenuStore from '@/store/modules/menu' import useRouteStore from '@/store/modules/route' +import { queryString, stripscript } from '@/utils/validate' const { isLoading } = useNProgress() @@ -31,6 +32,16 @@ next() } else { + // 携带token 需要去掉 + const hrefIdx = window.location.href.indexOf('token') // url中是否携带token + if (hrefIdx > -1) { + const params = queryString(window.location.href) + const token = stripscript(params.token) + localStorage.setItem('token', token) + // 刷新页面并隐藏token + window.location.href = window.location.href.replace(`?token=${token}`, '') + history.go(0) + } if (!userStore.hasUserInfo) { // 获取用户信息 await userStore.getUserInfo() @@ -113,6 +124,22 @@ } } else { + console.log('未登录') + // 携带token + const hrefIdx = window.location.href.indexOf('token') // url中是否携带token + if (hrefIdx > -1 && (!userStore.hasUserInfo || userStore === undefined || userStore === null)) { + const params = queryString(window.location.href) + if (params?.token) { + // 过滤token(哈希路由中可能携带一些特殊符号,需要去除) + const token = stripscript(params.token) + localStorage.setItem('token', token) + // 刷新页面并隐藏token + window.location.href = window.location.href.replace(`?token=${token}`, '') + history.go(0) + next() + } + } + // 未登录跳转到登录 if (to.name !== 'login') { next({ diff --git a/src/api/laboratory/alarm/current.ts b/src/api/laboratory/alarm/current.ts index e9003a4..b11c617 100644 --- a/src/api/laboratory/alarm/current.ts +++ b/src/api/laboratory/alarm/current.ts @@ -25,7 +25,7 @@ } // 操作报警 -export function operateAlarm(data: { id: string; alarmStatus: string }) { +export function operateAlarm(data: { ids: string[]; alarmStatus: string }) { return request({ url: `${prefix}/operate`, method: 'post', diff --git a/src/api/laboratory/equipment/list.ts b/src/api/laboratory/equipment/list.ts index 75e7f1e..26b6090 100644 --- a/src/api/laboratory/equipment/list.ts +++ b/src/api/laboratory/equipment/list.ts @@ -61,4 +61,3 @@ data, }) } - diff --git a/src/api/laboratory/overView.ts b/src/api/laboratory/overView.ts index 31ed06c..0b6603b 100644 --- a/src/api/laboratory/overView.ts +++ b/src/api/laboratory/overView.ts @@ -11,3 +11,11 @@ method: 'get', }) } + +// 查询各个实验室数据 +export function getLocationDetail() { + return request({ + url: `${prefix}/workshop/environment`, + method: 'get', + }) +} diff --git a/src/router/index.ts b/src/router/index.ts index 579b155..d244fb7 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -10,6 +10,7 @@ import useUserStore from '@/store/modules/user' import useMenuStore from '@/store/modules/menu' import useRouteStore from '@/store/modules/route' +import { queryString, stripscript } from '@/utils/validate' const { isLoading } = useNProgress() @@ -31,6 +32,16 @@ next() } else { + // 携带token 需要去掉 + const hrefIdx = window.location.href.indexOf('token') // url中是否携带token + if (hrefIdx > -1) { + const params = queryString(window.location.href) + const token = stripscript(params.token) + localStorage.setItem('token', token) + // 刷新页面并隐藏token + window.location.href = window.location.href.replace(`?token=${token}`, '') + history.go(0) + } if (!userStore.hasUserInfo) { // 获取用户信息 await userStore.getUserInfo() @@ -113,6 +124,22 @@ } } else { + console.log('未登录') + // 携带token + const hrefIdx = window.location.href.indexOf('token') // url中是否携带token + if (hrefIdx > -1 && (!userStore.hasUserInfo || userStore === undefined || userStore === null)) { + const params = queryString(window.location.href) + if (params?.token) { + // 过滤token(哈希路由中可能携带一些特殊符号,需要去除) + const token = stripscript(params.token) + localStorage.setItem('token', token) + // 刷新页面并隐藏token + window.location.href = window.location.href.replace(`?token=${token}`, '') + history.go(0) + next() + } + } + // 未登录跳转到登录 if (to.name !== 'login') { next({ diff --git a/src/utils/validate.ts b/src/utils/validate.ts index c59fdc6..dc215f6 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -129,3 +129,27 @@ const re = /[0-9A-Za-z\\W]{6,18}$/ return re.test(value) } + +// 提取url params参数 +export function queryString(str: string) { + const params = str.split('?')[1] // 截取?号后的字符串即name=itclanCoder&study=css + const param = params.split('&') // 通过&符号进行分割即["name=itclanCoder", "study=css"] + const obj: { [key: string]: string } = {} // 用一个对象存储目标值 + for (let i = 0; i < param.length; i++) { + // 循环遍历截取出来的param数组 + const paramsA = param[i].split('=') // 通过split,=继续对数组params每一项进行分割,生成数组["name", "itclanCoder"] + const key = paramsA[0] // 取数组项["name", "itclanCoder"]中第0位,即name + const value = paramsA[1] // 取数组项["name", "itclanCoder"]中第1位,即itclanCoder + obj[key] = value + } + return obj +} +// 去除字符串中的特殊符号 +export function stripscript(s: string) { + var pattern = /[[\]\/:*?"<>|#]/ + var rs = '' + for (var i = 0; i < s.length; i++) { + rs = rs + s.substr(i, 1).replace(pattern, '') + } + return rs +} diff --git a/src/api/laboratory/alarm/current.ts b/src/api/laboratory/alarm/current.ts index e9003a4..b11c617 100644 --- a/src/api/laboratory/alarm/current.ts +++ b/src/api/laboratory/alarm/current.ts @@ -25,7 +25,7 @@ } // 操作报警 -export function operateAlarm(data: { id: string; alarmStatus: string }) { +export function operateAlarm(data: { ids: string[]; alarmStatus: string }) { return request({ url: `${prefix}/operate`, method: 'post', diff --git a/src/api/laboratory/equipment/list.ts b/src/api/laboratory/equipment/list.ts index 75e7f1e..26b6090 100644 --- a/src/api/laboratory/equipment/list.ts +++ b/src/api/laboratory/equipment/list.ts @@ -61,4 +61,3 @@ data, }) } - diff --git a/src/api/laboratory/overView.ts b/src/api/laboratory/overView.ts index 31ed06c..0b6603b 100644 --- a/src/api/laboratory/overView.ts +++ b/src/api/laboratory/overView.ts @@ -11,3 +11,11 @@ method: 'get', }) } + +// 查询各个实验室数据 +export function getLocationDetail() { + return request({ + url: `${prefix}/workshop/environment`, + method: 'get', + }) +} diff --git a/src/router/index.ts b/src/router/index.ts index 579b155..d244fb7 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -10,6 +10,7 @@ import useUserStore from '@/store/modules/user' import useMenuStore from '@/store/modules/menu' import useRouteStore from '@/store/modules/route' +import { queryString, stripscript } from '@/utils/validate' const { isLoading } = useNProgress() @@ -31,6 +32,16 @@ next() } else { + // 携带token 需要去掉 + const hrefIdx = window.location.href.indexOf('token') // url中是否携带token + if (hrefIdx > -1) { + const params = queryString(window.location.href) + const token = stripscript(params.token) + localStorage.setItem('token', token) + // 刷新页面并隐藏token + window.location.href = window.location.href.replace(`?token=${token}`, '') + history.go(0) + } if (!userStore.hasUserInfo) { // 获取用户信息 await userStore.getUserInfo() @@ -113,6 +124,22 @@ } } else { + console.log('未登录') + // 携带token + const hrefIdx = window.location.href.indexOf('token') // url中是否携带token + if (hrefIdx > -1 && (!userStore.hasUserInfo || userStore === undefined || userStore === null)) { + const params = queryString(window.location.href) + if (params?.token) { + // 过滤token(哈希路由中可能携带一些特殊符号,需要去除) + const token = stripscript(params.token) + localStorage.setItem('token', token) + // 刷新页面并隐藏token + window.location.href = window.location.href.replace(`?token=${token}`, '') + history.go(0) + next() + } + } + // 未登录跳转到登录 if (to.name !== 'login') { next({ diff --git a/src/utils/validate.ts b/src/utils/validate.ts index c59fdc6..dc215f6 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -129,3 +129,27 @@ const re = /[0-9A-Za-z\\W]{6,18}$/ return re.test(value) } + +// 提取url params参数 +export function queryString(str: string) { + const params = str.split('?')[1] // 截取?号后的字符串即name=itclanCoder&study=css + const param = params.split('&') // 通过&符号进行分割即["name=itclanCoder", "study=css"] + const obj: { [key: string]: string } = {} // 用一个对象存储目标值 + for (let i = 0; i < param.length; i++) { + // 循环遍历截取出来的param数组 + const paramsA = param[i].split('=') // 通过split,=继续对数组params每一项进行分割,生成数组["name", "itclanCoder"] + const key = paramsA[0] // 取数组项["name", "itclanCoder"]中第0位,即name + const value = paramsA[1] // 取数组项["name", "itclanCoder"]中第1位,即itclanCoder + obj[key] = value + } + return obj +} +// 去除字符串中的特殊符号 +export function stripscript(s: string) { + var pattern = /[[\]\/:*?"<>|#]/ + var rs = '' + for (var i = 0; i < s.length; i++) { + rs = rs + s.substr(i, 1).replace(pattern, '') + } + return rs +} diff --git a/src/views/laboratory/alarm/current/list.vue b/src/views/laboratory/alarm/current/list.vue index 1f199e1..fce8225 100644 --- a/src/views/laboratory/alarm/current/list.vue +++ b/src/views/laboratory/alarm/current/list.vue @@ -29,7 +29,8 @@ { text: '事件名称', value: 'eventName', align: 'center' }, { text: '报警等级', value: 'alarmLevel', align: 'center' }, { text: '数值', value: 'alarmValue', align: 'center' }, - { text: '报警时间', value: 'alarmTime', align: 'center' }, + { text: '报警时间', value: 'alarmTime', align: 'center', width: '180' }, + { text: '报警状态', value: 'alarmStatusName', align: 'center', width: '90' }, ]) const list = ref([]) // 列表 const total = ref(0) // 数据总条数 @@ -50,54 +51,18 @@ // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } - // getCurrentList(listQuery.value).then((response) => { - // list.value = response.data.rows - // total.value = parseInt(response.data.total) - // loadingTable.value = false - // }).catch(() => { - loadingTable.value = false - // }) - list.value = [{ - alarmLevel: 'test1', // 报警等级 - alarmStatus: 'test1', // 报警状态(字典code) - alarmStatusName: '未确认', // 报警状态(字典value) - alarmTime: 'test1', // 报警时间 - alarmValue: 'test1', // 报警数值 - createTime: 'test1', // 创建时间 - deptId: 'test1', // 负责部门id - deptName: 'test1', // 负责部门 - deviceId: 'test1', // 设备表id - deviceName: 'test1', // 设备名称 - deviceNo: 'test1', // 设备编号 - eventName: 'test1', // 事件名称 - id: 'test11', // 主键id - locationId: 'test1', // 安装地点id - locationName: 'test1', // 安装地点 - updateTime: 'test1', // 更新时间 - userId: 'test1', // 负责人id - userName: 'test1', // 负责人 - }, - { - alarmLevel: 'test2', // 报警等级 - alarmStatus: 'test2', // 报警状态(字典code) - alarmStatusName: '已确认', // 报警状态(字典value) - alarmTime: 'test2', // 报警时间 - alarmValue: 'test2', // 报警数值 - createTime: 'test2', // 创建时间 - deptId: 'test2', // 负责部门id - deptName: 'test2', // 负责部门 - deviceId: 'test2', // 设备表id - deviceName: 'test2', // 设备名称 - deviceNo: 'test2', // 设备编号 - eventName: 'test2', // 事件名称 - id: 'test22', // 主键id - locationId: 'test2', // 安装地点id - locationName: 'test2', // 安装地点 - updateTime: 'test2', // 更新时间 - userId: 'test2', // 负责人id - userName: 'test2', // 负责人 - }, - ] + getCurrentList(listQuery.value).then((response) => { + list.value = response.data.rows.map((item: { alarmStatus: string }) => { + return { + ...item, + alarmStatusName: `${item.alarmStatus}` === '1' ? '未确认' : `${item.alarmStatus}` === '2' ? '已确认' : `${item.alarmStatus}` === '3' ? '已消警' : '', + } + }) + total.value = parseInt(response.data.total) + loadingTable.value = false + }).catch(() => { + loadingTable.value = false + }) } // 清除条件 const clearList = () => { @@ -142,7 +107,7 @@ ) .then(() => { loadingTable.value = true - operateAlarm({ id: row.id, alarmStatus }).then((res) => { + operateAlarm({ ids: [row.id], alarmStatus }).then((res) => { ElMessage({ type: 'success', message: `${title}成功`, @@ -155,8 +120,33 @@ } // -------------------------------------------表格右上角几个图标方法----------------------------------------------- // 点击全部消警 -const removeAllAlarm = () => { - ElMessage.info('敬请期待') +const removeAllAlarm = (alarmStatus = '3') => { + if (!checkoutList.value.length) { + ElMessage.warning('请选中数据') + return false + } + + ElMessageBox.confirm( + '确认消警吗?', + '提示', + { + confirmButtonText: '确认', + cancelButtonText: '取消', + type: 'warning', + }, + ) + .then(() => { + loadingTable.value = true + operateAlarm({ ids: checkoutList.value, alarmStatus }).then((res) => { + ElMessage({ + type: 'success', + message: '消警成功', + }) + fetchData(true) + }).catch(() => { + loadingTable.value = false + }) + }) } // 导出 @@ -254,16 +244,16 @@ >