Compare commits
19 Commits
309f83cf1f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db831e82ff | ||
|
|
6bf205f461 | ||
|
|
cf3d19d89d | ||
|
|
b020226538 | ||
|
|
b79b1df57e | ||
|
|
9b21beed0f | ||
|
|
aa4684273b | ||
|
|
36e839142a | ||
|
|
03006a8f06 | ||
|
|
0af52c62ce | ||
|
|
82789c78a9 | ||
|
|
6771abec31 | ||
|
|
b7b6b216fb | ||
|
|
97f05f21ae | ||
|
|
c4963b5b70 | ||
|
|
86775a6eb2 | ||
|
|
db3a6ddca5 | ||
|
|
b59b34e68b | ||
|
|
de35075be8 |
2
.env
2
.env
@@ -19,7 +19,7 @@ VITE_LAMP_PASSWORD = fjoc(1KHP(Ls&Bje)C
|
||||
VITE_LAMP_AUTHORIZATION = Y3VlZGVzX2FkbWluOmN1ZWRlc19hZG1pbl9zZWNyZXQ=
|
||||
|
||||
# 当需要重置localStorage时, 修改此变量
|
||||
VITE_STORAGE_VERSION = 3
|
||||
VITE_STORAGE_VERSION = 5
|
||||
|
||||
# 调试码
|
||||
VITE_DEBUG_CODE = ndm_debug
|
||||
|
||||
141
README.md
141
README.md
@@ -40,18 +40,145 @@ pnpm build
|
||||
|
||||
在执行 `pnpm build` 之前,你可以在 `package.json` 中修改 `version` 字段,将其设置为你期望的版本号,构建完成后,项目的根目录中除了 `dist` 目录外,还会生成三个压缩包,文件名的格式统一为 `ndm-web-platform_v<version>_<datetime>`,文件格式则分别为 `zip`、`tar`、`tar.gz`。
|
||||
|
||||
## 业务结构
|
||||
|
||||
所有业务相关的页面都在 `src/pages` 目录下,路由配置在 `src/router/index.ts` 文件,除登录页之外,其余页面都作为 `src/layouts/app-layout.vue` 的子路由。
|
||||
|
||||
```bash
|
||||
src/
|
||||
router/
|
||||
index.ts # 路由配置文件
|
||||
layouts/
|
||||
app-layout.vue # 布局
|
||||
pages/
|
||||
login/
|
||||
login-page.vue # 登录页面
|
||||
station/
|
||||
station-page.vue # 车站状态页面(首页)
|
||||
device/
|
||||
device-page.vue # 设备诊断页面
|
||||
alarm/
|
||||
alarm-ignore-page.vue # 告警忽略管理页面
|
||||
alarm-log-page.vue # 设备告警记录页面
|
||||
log/
|
||||
call-log-page.vue # 上级调用日志页面
|
||||
vimp-log-page.vue # 视频平台日志页面
|
||||
permission/
|
||||
permission-page.vue # 权限管理页面
|
||||
error/
|
||||
not-found-page.vue # 404 页面
|
||||
```
|
||||
|
||||
## 数据轮询
|
||||
|
||||
由于后端服务的架构限制,需要前端向所有车站服务依次发送请求来获取数据,需要获取的数据包含车站状态、设备数据以及告警数据,因此需要设计一套数据轮询方案,定期从所有车站服务获取数据。
|
||||
|
||||
在项目中,`src/composables/query/` 目录下是所有数据轮询相关的代码,其中与业务相关的代码主要包括:
|
||||
|
||||
- `use-line-stations-query.ts`: 查询所有车站
|
||||
- `use-line-devices-query.ts`: 查询所有设备
|
||||
- `use-line-alarms-query.ts`: 查询所有告警
|
||||
- `use-user-permission-query.ts`: 查询用户权限
|
||||
|
||||
在描述整个数据轮询流程之前,我们要明确项目中必须存在的几个关键概念:
|
||||
|
||||
- 车站相关:车站query + 车站store
|
||||
- 设备相关:设备query + 设备store
|
||||
- 告警相关:告警query + 告警store
|
||||
- 权限相关:权限query + 权限store
|
||||
|
||||
整个数据轮询流程采用“单点驱动 + 变更监听 + 级联触发”的模式,如下图所示。
|
||||
|
||||

|
||||
|
||||
1. 轮询入口:车站query
|
||||
- 触发条件:以120秒的周期自动轮询车站列表
|
||||
- 数据流向:车站store
|
||||
2. 核心调度:权限query
|
||||
- 触发条件:车站query执行后触发
|
||||
- 数据流向:权限store,并计算当前用户在各车站的权限
|
||||
- 数据监听:监听车站和权限变化,触发设备query和告警query
|
||||
3. 设备query & 告警query
|
||||
- 触发条件:被动触发,由权限query主动调用
|
||||
- 数据流向:设备store & 告警store
|
||||
|
||||
## 调试模式
|
||||
|
||||
在调试模式中,用户可以查看设备的原始诊断数据,也可以对轮询器进行控制,或者启用离线开发模式,系统不会自动调用一些主动触发的请求。
|
||||
在设置面板中有一系列与调试模式有关的设置项,主要用于开发和故障排查。
|
||||
|
||||
### 开启调试模式
|
||||
### 开启方式
|
||||
|
||||
在非登录页的任意页面中,使用键盘组合键 `Ctrl+Alt+D`,系统会弹出一个输入框,输入环境变量 `.env` 中的 `VITE_DEBUG_CODE` 对应的值即可开启调试模式,如需关闭调试模式,再次使用上述组合键并点击 `确认` 按钮即可。
|
||||
调试模式默认隐藏,通过以下方式开启:
|
||||
|
||||
注意调试模式与其内部的功能之间没有联动关系,例如在开启调试模式后可以关闭轮询或者启用离线开发模式,但是在关闭调试模式后,轮询不会重新被开启,离线开发模式也不会被关闭,因此在关闭离线开发模式前,请务必确保系统处于正确的运行状态下。
|
||||
1. 使用快捷键 `Ctrl + Alt + D` 唤起验证弹窗
|
||||
2. 输入授权码进行验证(授权码对应环境变量 `.env` 中的 `VITE_DEBUG_CODE`)
|
||||
3. 验证通过后,在“系统设置”面板中会出现 **调试** 分组
|
||||
|
||||
### 关于离线开发模式
|
||||
### 设置项说明
|
||||
|
||||
由于离线开发模式涉及到登录操作,因此项目中将离线开发模式暴露到了全局变量 `window.$offlineDev` 中,允许在登录页中直接开启离线开发模式。
|
||||
#### 数据设置
|
||||
|
||||
如果你第一次启动这个项目,系统在正常情况下会先跳转至登录页,此时如果希望开启离线模式,可以直接打开浏览器的开发者工具,在控制台输入 `window.$offlineDev.value = true` 即可,系统会直接跳转到首页。
|
||||
- **显示设备原始数据**
|
||||
- 控制是否在设备详情页显示“原始数据”标签页
|
||||
- 开启后可查看设备接口返回的原始 JSON 数据,便于排查字段缺失或格式错误
|
||||
|
||||
#### 网络设置
|
||||
|
||||
- **轮询车站**
|
||||
- 控制是否定时拉取车站状态,进而触发权限、设备及告警数据的更新
|
||||
- 关闭后将暂停所有业务数据的自动轮询机制
|
||||
- **主动请求**
|
||||
- 控制组件挂载时是否自动发起数据请求
|
||||
- 涵盖设备在线状态检测、用户登录验证等逻辑,关闭后组件在初始化时将不再自动拉取数据
|
||||
- **订阅消息**
|
||||
- 控制是否通过 WebSocket (STOMP) 接收实时告警或状态推送
|
||||
- 关闭后将不再处理后端推送的实时消息
|
||||
- **模拟用户**
|
||||
- 开启后使用内置的超管用户绕过登录
|
||||
- 开启时会自动进入调试模式,便于开发环境快速测试
|
||||
|
||||
#### 数据库设置
|
||||
|
||||
- **直接操作本地数据库**
|
||||
- 控制某些业务逻辑(如交换机端口、安防箱回路)是否直接读写本地 IndexedDB
|
||||
- 用于在无后端环境或特定测试场景下验证本地数据逻辑
|
||||
|
||||
## 离线开发
|
||||
|
||||
项目支持在无后端服务的情况下正常启动,具体操作取决于你的本地环境是否已有历史数据。
|
||||
|
||||
### 场景一:已有本地缓存
|
||||
|
||||
如果你的浏览器曾接入过现场环境,IndexedDB 中已保存了车站、设备等数据,只需在设置中关闭网络请求即可进入离线模式:
|
||||
|
||||
1. 开启调试模式(`Ctrl + Alt + D`)。
|
||||
2. 在“网络设置”中,关闭 **轮询车站**、**主动请求** 和 **订阅消息**。
|
||||
3. 此时平台将停止向后端发起请求,直接展示本地缓存的历史数据。
|
||||
|
||||
### 场景二:全新环境启动(新人推荐)
|
||||
|
||||
如果你是首次拉取项目且无法连接后端,需要按以下步骤操作:
|
||||
|
||||
1. **模拟登录**
|
||||
在登录页按 `F12` 打开控制台,输入以下命令强制进入平台:
|
||||
|
||||
```javascript
|
||||
window.$mockUser.value = true;
|
||||
```
|
||||
|
||||
执行后平台将自动完成以下操作:
|
||||
- 注入测试 Token 和管理员身份信息
|
||||
- 关闭所有网络请求(轮询、主动请求、消息订阅)
|
||||
- 开启调试模式
|
||||
- 自动跳转至平台首页
|
||||
|
||||
2. **导入模拟数据**
|
||||
进入平台后,页面默认为空。需导入预设数据以填充内容:
|
||||
- 打开“系统设置”(已自动开启调试模式)。
|
||||
- 在 **调试** -> **数据库设置** 中,勾选 **直接操作本地数据库**。
|
||||
- 点击该选项下方的 **导入数据** 按钮。
|
||||
- 依次导入项目根目录 `docs/data/` 下的三个文件:
|
||||
- `ndm-station-store.json`(车站数据)
|
||||
- `ndm-device-store.json`(设备数据)
|
||||
- `ndm-alarm-store.json`(告警数据)
|
||||
> **注意**:每次导入一个文件后,平台会自动刷新页面以应用数据。请等待刷新完成后,重新打开设置面板导入下一个文件。
|
||||
|
||||
BIN
docs/assets/query-chain.png
Normal file
BIN
docs/assets/query-chain.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
527708
docs/data/ndm-alarm-store.json
Normal file
527708
docs/data/ndm-alarm-store.json
Normal file
File diff suppressed because it is too large
Load Diff
195971
docs/data/ndm-device-store.json
Normal file
195971
docs/data/ndm-device-store.json
Normal file
File diff suppressed because one or more lines are too long
203
docs/data/ndm-station-store.json
Normal file
203
docs/data/ndm-station-store.json
Normal file
@@ -0,0 +1,203 @@
|
||||
{
|
||||
"stations": [
|
||||
{
|
||||
"code": "1075",
|
||||
"name": "吴中路控制中心",
|
||||
"online": true,
|
||||
"ip": "10.18.128.10",
|
||||
"occ": true
|
||||
},
|
||||
{
|
||||
"code": "1001",
|
||||
"name": "虹桥火车站",
|
||||
"online": true,
|
||||
"ip": "10.18.129.10"
|
||||
},
|
||||
{
|
||||
"code": "1002",
|
||||
"name": "虹桥2号航站楼",
|
||||
"online": true,
|
||||
"ip": "10.18.131.10"
|
||||
},
|
||||
{
|
||||
"code": "1003",
|
||||
"name": "虹桥一号航站楼",
|
||||
"online": true,
|
||||
"ip": "10.18.133.10"
|
||||
},
|
||||
{
|
||||
"code": "1004",
|
||||
"name": "上海动物园",
|
||||
"online": true,
|
||||
"ip": "10.18.135.10"
|
||||
},
|
||||
{
|
||||
"code": "1005",
|
||||
"name": "龙溪路",
|
||||
"online": true,
|
||||
"ip": "10.18.137.10"
|
||||
},
|
||||
{
|
||||
"code": "1006",
|
||||
"name": "水城路",
|
||||
"online": true,
|
||||
"ip": "10.18.139.10"
|
||||
},
|
||||
{
|
||||
"code": "1007",
|
||||
"name": "伊犁路",
|
||||
"online": true,
|
||||
"ip": "10.18.141.10"
|
||||
},
|
||||
{
|
||||
"code": "1008",
|
||||
"name": "宋园路",
|
||||
"online": true,
|
||||
"ip": "10.18.143.10"
|
||||
},
|
||||
{
|
||||
"code": "1009",
|
||||
"name": "虹桥路",
|
||||
"online": true,
|
||||
"ip": "10.18.145.10"
|
||||
},
|
||||
{
|
||||
"code": "1010",
|
||||
"name": "交通大学",
|
||||
"online": true,
|
||||
"ip": "10.18.147.10"
|
||||
},
|
||||
{
|
||||
"code": "1011",
|
||||
"name": "图书馆",
|
||||
"online": true,
|
||||
"ip": "10.18.149.10"
|
||||
},
|
||||
{
|
||||
"code": "1012",
|
||||
"name": "陕西南路",
|
||||
"online": true,
|
||||
"ip": "10.18.151.10"
|
||||
},
|
||||
{
|
||||
"code": "1013",
|
||||
"name": "新天地",
|
||||
"online": true,
|
||||
"ip": "10.18.153.10"
|
||||
},
|
||||
{
|
||||
"code": "1014",
|
||||
"name": "老西门",
|
||||
"online": true,
|
||||
"ip": "10.18.155.10"
|
||||
},
|
||||
{
|
||||
"code": "1015",
|
||||
"name": "豫园",
|
||||
"online": true,
|
||||
"ip": "10.18.157.10"
|
||||
},
|
||||
{
|
||||
"code": "1016",
|
||||
"name": "南京东路",
|
||||
"online": true,
|
||||
"ip": "10.18.159.10"
|
||||
},
|
||||
{
|
||||
"code": "1017",
|
||||
"name": "天潼路",
|
||||
"online": true,
|
||||
"ip": "10.18.161.10"
|
||||
},
|
||||
{
|
||||
"code": "1018",
|
||||
"name": "四川北路",
|
||||
"online": true,
|
||||
"ip": "10.18.163.10"
|
||||
},
|
||||
{
|
||||
"code": "1019",
|
||||
"name": "海伦路",
|
||||
"online": true,
|
||||
"ip": "10.18.165.10"
|
||||
},
|
||||
{
|
||||
"code": "1020",
|
||||
"name": "邮电新村",
|
||||
"online": true,
|
||||
"ip": "10.18.167.10"
|
||||
},
|
||||
{
|
||||
"code": "1021",
|
||||
"name": "四平路",
|
||||
"online": true,
|
||||
"ip": "10.18.169.10"
|
||||
},
|
||||
{
|
||||
"code": "1022",
|
||||
"name": "同济大学",
|
||||
"online": true,
|
||||
"ip": "10.18.171.10"
|
||||
},
|
||||
{
|
||||
"code": "1023",
|
||||
"name": "国权路",
|
||||
"online": true,
|
||||
"ip": "10.18.173.10"
|
||||
},
|
||||
{
|
||||
"code": "1024",
|
||||
"name": "五角场",
|
||||
"online": true,
|
||||
"ip": "10.18.175.10"
|
||||
},
|
||||
{
|
||||
"code": "1025",
|
||||
"name": "江湾体育场",
|
||||
"online": true,
|
||||
"ip": "10.18.177.10"
|
||||
},
|
||||
{
|
||||
"code": "1026",
|
||||
"name": "三门路",
|
||||
"online": true,
|
||||
"ip": "10.18.179.10"
|
||||
},
|
||||
{
|
||||
"code": "1027",
|
||||
"name": "殷高东路",
|
||||
"online": true,
|
||||
"ip": "10.18.181.10"
|
||||
},
|
||||
{
|
||||
"code": "1028",
|
||||
"name": "新江湾城",
|
||||
"online": true,
|
||||
"ip": "10.18.183.10"
|
||||
},
|
||||
{
|
||||
"code": "1029",
|
||||
"name": "航中路",
|
||||
"online": true,
|
||||
"ip": "10.18.185.10"
|
||||
},
|
||||
{
|
||||
"code": "1030",
|
||||
"name": "紫藤路",
|
||||
"online": true,
|
||||
"ip": "10.18.187.10"
|
||||
},
|
||||
{
|
||||
"code": "1031",
|
||||
"name": "龙柏新村",
|
||||
"online": true,
|
||||
"ip": "10.18.189.10"
|
||||
},
|
||||
{
|
||||
"code": "1032",
|
||||
"name": "吴中路基地",
|
||||
"online": true,
|
||||
"ip": "10.18.244.10"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,10 +7,10 @@ import { dateZhCN, NConfigProvider, NDialogProvider, NLoadingBarProvider, NMessa
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { themeMode, offlineDev } = storeToRefs(settingStore);
|
||||
const { themeMode, mockUser } = storeToRefs(settingStore);
|
||||
|
||||
// 允许通过控制台启用离线开发模式 (登录页适用)
|
||||
window.$offlineDev = offlineDev;
|
||||
window.$mockUser = mockUser;
|
||||
|
||||
useVersionCheckQuery();
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Nullable, Optional } from '@/types';
|
||||
import type { ReduceForPageQuery, ReduceForSaveVO, ReduceForUpdateVO } from '../../types';
|
||||
import type { ReduceForPageQuery, ReduceForSaveVO, ReduceForUpdateVO } from '../../schema';
|
||||
import type { NdmAlarmHost } from './alarm';
|
||||
import type { NdmSecurityBox, NdmSwitch } from './other';
|
||||
import type { NdmNvr } from './storage';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export * from './base';
|
||||
export * from './biz';
|
||||
export * from './common';
|
||||
export * from './schema';
|
||||
export * from './system';
|
||||
export * from './types';
|
||||
|
||||
@@ -48,3 +48,13 @@ export const reloadAllRecordCheckApi = async (dayOffset: number, options?: { sta
|
||||
if (!data) throw new Error(`${data}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const batchExportRecordCheckApi = async (params: { checkDuration: number; gapSeconds: number; stationCode: Station['code'][] }, options?: { signal?: AbortSignal }) => {
|
||||
const { signal } = options ?? {};
|
||||
const { checkDuration, gapSeconds, stationCode } = params;
|
||||
const client = userClient;
|
||||
const endpoint = `/api/ndm/ndmRecordCheck/batchExportByTemplate`;
|
||||
const resp = await client.post<Blob>(endpoint, { checkDuration, gapSeconds, stationCode }, { responseType: 'blob', retRaw: true, signal });
|
||||
const data = unwrapResponse(resp);
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -71,3 +71,13 @@ export const deletePermissionApi = async (ids: string[], options?: { stationCode
|
||||
const result = unwrapResponse(resp);
|
||||
return result;
|
||||
};
|
||||
|
||||
export const modifyPermissionApi = async (params: { employeeId: string; saveList: NdmPermissionSaveVO[]; removeList: string[] }, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
|
||||
const { stationCode, signal } = options ?? {};
|
||||
const client = stationCode ? ndmClient : userClient;
|
||||
const prefix = stationCode ? `/${stationCode}` : '';
|
||||
const endpoint = `${prefix}/api/ndm/ndmPermission/modify`;
|
||||
const resp = await client.post<boolean>(endpoint, params, { signal });
|
||||
const result = unwrapResponse(resp);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -1,34 +1,58 @@
|
||||
<script setup lang="ts">
|
||||
import { getChannelListApi, getRecordCheckApi, reloadAllRecordCheckApi, reloadRecordCheckApi, type NdmNvrResultVO, type NdmRecordCheck, type RecordItem, type Station } from '@/apis';
|
||||
import { getChannelListApi, getRecordCheckApi, reloadAllRecordCheckApi, reloadRecordCheckApi, type NdmNvrResultVO, type RecordItem, type Station } from '@/apis';
|
||||
import { exportRecordDiagCsv, transformRecordChecks } from '@/helpers';
|
||||
import { useStationStore } from '@/stores';
|
||||
import { useSettingStore } from '@/stores';
|
||||
import { parseErrorFeedback } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query';
|
||||
import { isCancel } from 'axios';
|
||||
import dayjs from 'dayjs';
|
||||
import { DownloadIcon, RotateCwIcon } from 'lucide-vue-next';
|
||||
import { NButton, NCard, NFlex, NIcon, NPagination, NPopconfirm, NPopover, NRadioButton, NRadioGroup, NTooltip, useThemeVars } from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, onBeforeUnmount, onMounted, ref, toRefs, watch } from 'vue';
|
||||
import { computed, onBeforeUnmount, ref, toRefs, watch } from 'vue';
|
||||
|
||||
const props = defineProps<{
|
||||
ndmDevice: NdmNvrResultVO;
|
||||
station: Station;
|
||||
}>();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { activeRequests } = storeToRefs(settingStore);
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
|
||||
const stationStore = useStationStore();
|
||||
const { stations } = storeToRefs(stationStore);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const { ndmDevice, station } = toRefs(props);
|
||||
|
||||
const recordChecks = ref<NdmRecordCheck[]>([]);
|
||||
|
||||
const lossInput = ref<number>(0);
|
||||
|
||||
const abortController = ref<AbortController>(new AbortController());
|
||||
|
||||
const NVR_RECORD_CHECK_KEY = 'nvr_record_check_query';
|
||||
|
||||
const {
|
||||
data: recordChecks,
|
||||
isFetching: loading,
|
||||
refetch: refetchRecordChecks,
|
||||
} = useQuery({
|
||||
queryKey: computed(() => [NVR_RECORD_CHECK_KEY, ndmDevice.value.id, ndmDevice.value.lastDiagTime]),
|
||||
enabled: computed(() => activeRequests.value),
|
||||
refetchInterval: 30 * 1000,
|
||||
gcTime: 0,
|
||||
queryFn: async ({ signal }) => {
|
||||
const checks = await getRecordCheckApi(ndmDevice.value, 90, [], { stationCode: station.value.code, signal });
|
||||
return checks;
|
||||
},
|
||||
});
|
||||
watch(activeRequests, (active) => {
|
||||
if (!active) {
|
||||
queryClient.cancelQueries({ queryKey: [NVR_RECORD_CHECK_KEY] });
|
||||
}
|
||||
});
|
||||
|
||||
const recordDiags = computed(() => {
|
||||
return transformRecordChecks(recordChecks.value).filter((recordDiag) => {
|
||||
return transformRecordChecks(recordChecks.value ?? []).filter((recordDiag) => {
|
||||
if (lossInput.value === 0) {
|
||||
return true;
|
||||
} else if (lossInput.value === 1) {
|
||||
@@ -40,26 +64,6 @@ const recordDiags = computed(() => {
|
||||
});
|
||||
});
|
||||
|
||||
const abortController = ref<AbortController>(new AbortController());
|
||||
|
||||
const { mutate: getRecordCheckByParentId, isPending: loading } = useMutation({
|
||||
mutationFn: async () => {
|
||||
abortController.value.abort();
|
||||
abortController.value = new AbortController();
|
||||
const checks = await getRecordCheckApi(ndmDevice.value, 90, [], { stationCode: station.value.code, signal: abortController.value.signal });
|
||||
return checks;
|
||||
},
|
||||
onSuccess: (checks) => {
|
||||
recordChecks.value = checks;
|
||||
},
|
||||
onError: (error) => {
|
||||
if (isCancel(error)) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
});
|
||||
|
||||
const { mutate: reloadAllRecordCheck, isPending: reloading } = useMutation({
|
||||
mutationFn: async () => {
|
||||
abortController.value.abort();
|
||||
@@ -78,9 +82,7 @@ const { mutate: reloadAllRecordCheck, isPending: reloading } = useMutation({
|
||||
});
|
||||
|
||||
const onExportRecordCheck = () => {
|
||||
const code = station.value.code;
|
||||
const stationName = stations.value.find((station) => station.code === code)?.name ?? '';
|
||||
exportRecordDiagCsv(recordDiags.value, stationName);
|
||||
exportRecordDiagCsv(recordDiags.value, station.value.name);
|
||||
};
|
||||
|
||||
const page = ref(1);
|
||||
@@ -121,7 +123,7 @@ const { mutate: reloadRecordCheckByGbId } = useMutation({
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
getRecordCheckByParentId();
|
||||
refetchRecordChecks();
|
||||
},
|
||||
onError: (error) => {
|
||||
if (isCancel(error)) return;
|
||||
@@ -131,20 +133,6 @@ const { mutate: reloadRecordCheckByGbId } = useMutation({
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
getRecordCheckByParentId();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => ndmDevice.value.id,
|
||||
(devieDbId) => {
|
||||
if (devieDbId) {
|
||||
recordChecks.value = [];
|
||||
getRecordCheckByParentId();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
abortController.value.abort();
|
||||
});
|
||||
@@ -169,7 +157,7 @@ onBeforeUnmount(() => {
|
||||
<NFlex>
|
||||
<NTooltip trigger="hover">
|
||||
<template #trigger>
|
||||
<NButton size="small" quaternary circle :loading="loading" @click="() => getRecordCheckByParentId()">
|
||||
<NButton size="small" quaternary circle :loading="loading" @click="() => refetchRecordChecks()">
|
||||
<template #icon>
|
||||
<NIcon :component="RotateCwIcon" />
|
||||
</template>
|
||||
|
||||
@@ -13,7 +13,9 @@ import {
|
||||
type Station,
|
||||
} from '@/apis';
|
||||
import { SecurityBoxCircuitLinkModal } from '@/components';
|
||||
import { usePermission } from '@/composables';
|
||||
import { SELECT_DEVICE_FN_INJECTION_KEY } from '@/constants';
|
||||
import { PERMISSION_TYPE_LITERALS } from '@/enums';
|
||||
import { useDeviceStore, useSettingStore } from '@/stores';
|
||||
import { parseErrorFeedback } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
@@ -38,7 +40,9 @@ const deviceStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(deviceStore);
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
const { useLocalDB } = storeToRefs(settingStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
const { ndmDevice, station, circuits } = toRefs(props);
|
||||
|
||||
@@ -223,6 +227,7 @@ const onSelectDropdownOption = (key: string, option: DropdownOption) => {
|
||||
const onContextmenu = (payload: PointerEvent, circuitIndex: number) => {
|
||||
payload.stopPropagation();
|
||||
payload.preventDefault();
|
||||
if (!hasPermission(station.value.code, PERMISSION_TYPE_LITERALS.OPERATION)) return;
|
||||
const { clientX, clientY } = payload;
|
||||
contextmenu.value = { x: clientX, y: clientY, circuitIndex };
|
||||
showContextmenu.value = true;
|
||||
@@ -258,8 +263,8 @@ const { mutate: unlinkDevice } = useMutation({
|
||||
delete modifiedUpperLinkDescription.downstream?.[circuitIndex];
|
||||
modifiedUpperDevice.linkDescription = JSON.stringify(modifiedUpperLinkDescription);
|
||||
|
||||
// 3. 发起update请求并获取最新的设备详情(离线模式下直接修改本地数据)
|
||||
if (offlineDev.value) {
|
||||
// 3. 发起update请求并获取最新的设备详情(使用本地数据库时直接修改本地数据)
|
||||
if (useLocalDB.value) {
|
||||
return { upperDevice: modifiedUpperDevice, lowerDevice: modifiedLowerDevice };
|
||||
}
|
||||
const stationCode = station.value.code;
|
||||
|
||||
@@ -23,7 +23,7 @@ const show = defineModel<boolean>('show', { default: false });
|
||||
const deviceStore = useDeviceStore();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
const { useLocalDB } = storeToRefs(settingStore);
|
||||
|
||||
const { ndmDevice, station, circuitIndex } = toRefs(props);
|
||||
|
||||
@@ -150,8 +150,8 @@ const { mutate: linkPortToDevice, isPending: linking } = useMutation({
|
||||
}
|
||||
modifiedLowerDevice.linkDescription = JSON.stringify(modifiedLowerDeviceLinkDescription);
|
||||
|
||||
// 3. 发起update请求并获取最新的设备详情(离线模式下直接修改本地数据)
|
||||
if (offlineDev.value) {
|
||||
// 3. 发起update请求并获取最新的设备详情(使用本地数据库时直接修改本地数据)
|
||||
if (useLocalDB.value) {
|
||||
return { upperDevice: modifiedUpperDevice, lowerDevice: modifiedLowerDevice };
|
||||
}
|
||||
const stationCode = station.value.code;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { detailDeviceApi, updateDeviceApi, type LinkDescription, type NdmDeviceResultVO, type NdmSwitchLinkDescription, type NdmSwitchPortInfo, type NdmSwitchResultVO, type Station } from '@/apis';
|
||||
import { SwitchPortLinkModal } from '@/components';
|
||||
import { usePermission } from '@/composables';
|
||||
import { SELECT_DEVICE_FN_INJECTION_KEY } from '@/constants';
|
||||
import { PERMISSION_TYPE_LITERALS } from '@/enums';
|
||||
import { getPortStatusValue, transformPortSpeed } from '@/helpers';
|
||||
import { useDeviceStore, useSettingStore } from '@/stores';
|
||||
import { parseErrorFeedback } from '@/utils';
|
||||
@@ -25,7 +27,9 @@ const deviceStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(deviceStore);
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
const { useLocalDB } = storeToRefs(settingStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
const { ndmDevice, station, ports } = toRefs(props);
|
||||
|
||||
@@ -172,6 +176,7 @@ const onSelectDropdownOption = (key: string, option: DropdownOption) => {
|
||||
const onContextmenu = (payload: PointerEvent, port: NdmSwitchPortInfo) => {
|
||||
payload.stopPropagation();
|
||||
payload.preventDefault();
|
||||
if (!hasPermission(station.value.code, PERMISSION_TYPE_LITERALS.OPERATION)) return;
|
||||
const { clientX, clientY } = payload;
|
||||
contextmenu.value = { x: clientX, y: clientY, port };
|
||||
showContextmenu.value = true;
|
||||
@@ -208,8 +213,8 @@ const { mutate: unlinkDevice } = useMutation({
|
||||
delete modifiedUpperLinkDescription.downstream?.[port.portName];
|
||||
modifiedUpperDevice.linkDescription = JSON.stringify(modifiedUpperLinkDescription);
|
||||
|
||||
// 3. 发起update请求并获取最新的设备详情(离线模式下直接修改本地数据)
|
||||
if (offlineDev.value) {
|
||||
// 3. 发起update请求并获取最新的设备详情(使用本地数据库时直接修改本地数据)
|
||||
if (useLocalDB.value) {
|
||||
return { upperDevice: modifiedUpperDevice, lowerDevice: modifiedLowerDevice };
|
||||
}
|
||||
const stationCode = station.value.code;
|
||||
|
||||
@@ -32,7 +32,7 @@ const show = defineModel<boolean>('show', { default: false });
|
||||
const deviceStore = useDeviceStore();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
const { useLocalDB } = storeToRefs(settingStore);
|
||||
|
||||
const { ndmDevice, station, port } = toRefs(props);
|
||||
|
||||
@@ -160,8 +160,8 @@ const { mutate: linkPortToDevice, isPending: linking } = useMutation({
|
||||
}
|
||||
modifiedLowerDevice.linkDescription = JSON.stringify(modifiedLowerDeviceLinkDescription);
|
||||
|
||||
// 3. 发起update请求并获取最新的设备详情(离线模式下直接修改本地数据)
|
||||
if (offlineDev.value) {
|
||||
// 3. 发起update请求并获取最新的设备详情(使用本地数据库时直接修改本地数据)
|
||||
if (useLocalDB.value) {
|
||||
return { upperDevice: modifiedUpperDevice, lowerDevice: modifiedLowerDevice };
|
||||
}
|
||||
const stationCode = station.value.code;
|
||||
|
||||
@@ -18,7 +18,7 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { debugModeEnabled } = storeToRefs(settingStore);
|
||||
const { showDeviceRawData } = storeToRefs(settingStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
@@ -35,8 +35,8 @@ const activeTabName = ref('当前诊断');
|
||||
const onTabChange = (name: string) => {
|
||||
activeTabName.value = name;
|
||||
};
|
||||
watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || !enabled) {
|
||||
watch([ndmDevice, showDeviceRawData], ([newDevice, showRaw], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || (!showRaw && activeTabName.value === '原始数据')) {
|
||||
activeTabName.value = '当前诊断';
|
||||
}
|
||||
});
|
||||
@@ -50,7 +50,7 @@ watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
<NTab name="当前诊断">当前诊断</NTab>
|
||||
<NTab name="历史诊断">历史诊断</NTab>
|
||||
<NTab v-if="hasPermission(station.code, PERMISSION_TYPE_LITERALS.OPERATION)" name="修改设备">修改设备</NTab>
|
||||
<NTab v-if="debugModeEnabled" name="原始数据">原始数据</NTab>
|
||||
<NTab v-if="showDeviceRawData" name="原始数据">原始数据</NTab>
|
||||
</NTabs>
|
||||
</template>
|
||||
<template #default>
|
||||
|
||||
@@ -18,7 +18,7 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { debugModeEnabled } = storeToRefs(settingStore);
|
||||
const { showDeviceRawData } = storeToRefs(settingStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
@@ -35,8 +35,8 @@ const activeTabName = ref('当前诊断');
|
||||
const onTabChange = (name: string) => {
|
||||
activeTabName.value = name;
|
||||
};
|
||||
watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || !enabled) {
|
||||
watch([ndmDevice, showDeviceRawData], ([newDevice, showRaw], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || (!showRaw && activeTabName.value === '原始数据')) {
|
||||
activeTabName.value = '当前诊断';
|
||||
}
|
||||
});
|
||||
@@ -50,7 +50,7 @@ watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
<NTab name="当前诊断">当前诊断</NTab>
|
||||
<NTab name="历史诊断">历史诊断</NTab>
|
||||
<NTab v-if="hasPermission(station.code, PERMISSION_TYPE_LITERALS.OPERATION)" name="修改设备">修改设备</NTab>
|
||||
<NTab v-if="debugModeEnabled" name="原始数据">原始数据</NTab>
|
||||
<NTab v-if="showDeviceRawData" name="原始数据">原始数据</NTab>
|
||||
</NTabs>
|
||||
</template>
|
||||
<template #default>
|
||||
|
||||
@@ -31,7 +31,7 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
const { activeRequests } = storeToRefs(settingStore);
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -49,7 +49,7 @@ const QUERY_KEY = 'camera-installation-area-query';
|
||||
|
||||
const { data: installationArea } = useQuery({
|
||||
queryKey: computed(() => [QUERY_KEY, ndmDevice.value.gbCode, station.value.code]),
|
||||
enabled: computed(() => !offlineDev.value),
|
||||
enabled: computed(() => activeRequests.value),
|
||||
gcTime: 0,
|
||||
queryFn: async ({ signal }) => {
|
||||
const UNKNOWN_NAME = '-';
|
||||
@@ -107,8 +107,8 @@ const { data: installationArea } = useQuery({
|
||||
return `${tier1Area.name}-${tier2Area.name}`;
|
||||
},
|
||||
});
|
||||
watch(offlineDev, (offline) => {
|
||||
if (offline) {
|
||||
watch(activeRequests, (active) => {
|
||||
if (!active) {
|
||||
queryClient.cancelQueries({ queryKey: [QUERY_KEY] });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { debugModeEnabled } = storeToRefs(settingStore);
|
||||
const { showDeviceRawData } = storeToRefs(settingStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
@@ -35,8 +35,8 @@ const activeTabName = ref('当前诊断');
|
||||
const onTabChange = (name: string) => {
|
||||
activeTabName.value = name;
|
||||
};
|
||||
watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || !enabled) {
|
||||
watch([ndmDevice, showDeviceRawData], ([newDevice, showRaw], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || (!showRaw && activeTabName.value === '原始数据')) {
|
||||
activeTabName.value = '当前诊断';
|
||||
}
|
||||
});
|
||||
@@ -50,7 +50,7 @@ watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
<NTab name="当前诊断">当前诊断</NTab>
|
||||
<NTab name="历史诊断">历史诊断</NTab>
|
||||
<NTab v-if="hasPermission(station.code, PERMISSION_TYPE_LITERALS.OPERATION)" name="修改设备">修改设备</NTab>
|
||||
<NTab v-if="debugModeEnabled" name="原始数据">原始数据</NTab>
|
||||
<NTab v-if="showDeviceRawData" name="原始数据">原始数据</NTab>
|
||||
</NTabs>
|
||||
</template>
|
||||
<template #default>
|
||||
|
||||
@@ -18,7 +18,7 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { debugModeEnabled } = storeToRefs(settingStore);
|
||||
const { showDeviceRawData } = storeToRefs(settingStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
@@ -35,8 +35,8 @@ const activeTabName = ref('当前诊断');
|
||||
const onTabChange = (name: string) => {
|
||||
activeTabName.value = name;
|
||||
};
|
||||
watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || !enabled) {
|
||||
watch([ndmDevice, showDeviceRawData], ([newDevice, showRaw], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || (!showRaw && activeTabName.value === '原始数据')) {
|
||||
activeTabName.value = '当前诊断';
|
||||
}
|
||||
});
|
||||
@@ -50,7 +50,7 @@ watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
<NTab name="当前诊断">当前诊断</NTab>
|
||||
<NTab name="历史诊断">历史诊断</NTab>
|
||||
<NTab v-if="hasPermission(station.code, PERMISSION_TYPE_LITERALS.OPERATION)" name="修改设备">修改设备</NTab>
|
||||
<NTab v-if="debugModeEnabled" name="原始数据">原始数据</NTab>
|
||||
<NTab v-if="showDeviceRawData" name="原始数据">原始数据</NTab>
|
||||
</NTabs>
|
||||
</template>
|
||||
<template #default>
|
||||
|
||||
@@ -18,7 +18,7 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { debugModeEnabled } = storeToRefs(settingStore);
|
||||
const { showDeviceRawData } = storeToRefs(settingStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
@@ -35,8 +35,8 @@ const activeTabName = ref('当前诊断');
|
||||
const onTabChange = (name: string) => {
|
||||
activeTabName.value = name;
|
||||
};
|
||||
watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || !enabled) {
|
||||
watch([ndmDevice, showDeviceRawData], ([newDevice, showRaw], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || (!showRaw && activeTabName.value === '原始数据')) {
|
||||
activeTabName.value = '当前诊断';
|
||||
}
|
||||
});
|
||||
@@ -50,7 +50,7 @@ watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
<NTab name="当前诊断">当前诊断</NTab>
|
||||
<NTab name="历史诊断">历史诊断</NTab>
|
||||
<NTab v-if="hasPermission(station.code, PERMISSION_TYPE_LITERALS.OPERATION)" name="修改设备">修改设备</NTab>
|
||||
<NTab v-if="debugModeEnabled" name="原始数据">原始数据</NTab>
|
||||
<NTab v-if="showDeviceRawData" name="原始数据">原始数据</NTab>
|
||||
</NTabs>
|
||||
</template>
|
||||
<template #default>
|
||||
|
||||
@@ -45,7 +45,7 @@ const diskArray = computed(() => lastDiagInfo.value?.info?.groupInfoList);
|
||||
<NFlex vertical>
|
||||
<DeviceHeaderCard :ndm-device="ndmDevice" :station="station" />
|
||||
<DeviceCommonCard :common-info="commonInfo" />
|
||||
<DeviceHardwareCard v-if="!isNvrCluster(ndmDevice)" :cpu-usage="cpuUsage" :mem-usage="memUsage" />
|
||||
<DeviceHardwareCard :cpu-usage="cpuUsage" :mem-usage="memUsage" />
|
||||
<NvrDiskCard :disk-health="diskHealth" :disk-array="diskArray" />
|
||||
<NvrRecordCard v-if="isNvrCluster(ndmDevice)" :ndm-device="ndmDevice" :station="station" />
|
||||
</NFlex>
|
||||
|
||||
@@ -18,7 +18,7 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { debugModeEnabled } = storeToRefs(settingStore);
|
||||
const { showDeviceRawData } = storeToRefs(settingStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
@@ -35,8 +35,8 @@ const activeTabName = ref('当前诊断');
|
||||
const onTabChange = (name: string) => {
|
||||
activeTabName.value = name;
|
||||
};
|
||||
watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || !enabled) {
|
||||
watch([ndmDevice, showDeviceRawData], ([newDevice, showRaw], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || (!showRaw && activeTabName.value === '原始数据')) {
|
||||
activeTabName.value = '当前诊断';
|
||||
}
|
||||
});
|
||||
@@ -50,7 +50,7 @@ watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
<NTab name="当前诊断">当前诊断</NTab>
|
||||
<NTab name="历史诊断">历史诊断</NTab>
|
||||
<NTab v-if="hasPermission(station.code, PERMISSION_TYPE_LITERALS.OPERATION)" name="修改设备">修改设备</NTab>
|
||||
<NTab v-if="debugModeEnabled" name="原始数据">原始数据</NTab>
|
||||
<NTab v-if="showDeviceRawData" name="原始数据">原始数据</NTab>
|
||||
</NTabs>
|
||||
</template>
|
||||
<template #default>
|
||||
|
||||
@@ -13,7 +13,7 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
const { activeRequests } = storeToRefs(settingStore);
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -25,7 +25,7 @@ const MEDIA_SERVER_ALIVE_QUERY_KEY = 'media-server-alive-query';
|
||||
const VIDEO_SERVER_ALIVE_QUERY_KEY = 'video-server-alive-query';
|
||||
const { data: isMediaServerAlive } = useQuery({
|
||||
queryKey: computed(() => [MEDIA_SERVER_ALIVE_QUERY_KEY, ndmDevice.value.id, ndmDevice.value.lastDiagTime]),
|
||||
enabled: computed(() => !offlineDev.value && deviceType.value === DEVICE_TYPE_LITERALS.ndmMediaServer),
|
||||
enabled: computed(() => activeRequests.value && deviceType.value === DEVICE_TYPE_LITERALS.ndmMediaServer),
|
||||
refetchInterval: 30 * 1000,
|
||||
gcTime: 0,
|
||||
queryFn: async ({ signal }) => {
|
||||
@@ -35,15 +35,15 @@ const { data: isMediaServerAlive } = useQuery({
|
||||
});
|
||||
const { data: isSipServerAlive } = useQuery({
|
||||
queryKey: computed(() => [VIDEO_SERVER_ALIVE_QUERY_KEY, ndmDevice.value.id, ndmDevice.value.lastDiagTime]),
|
||||
enabled: computed(() => !offlineDev.value && deviceType.value === DEVICE_TYPE_LITERALS.ndmVideoServer),
|
||||
enabled: computed(() => activeRequests.value && deviceType.value === DEVICE_TYPE_LITERALS.ndmVideoServer),
|
||||
refetchInterval: 30 * 1000,
|
||||
gcTime: 0,
|
||||
queryFn: async ({ signal }) => {
|
||||
return await isSipServerAliveApi({ stationCode: station.value.code, signal });
|
||||
},
|
||||
});
|
||||
watch(offlineDev, (offline) => {
|
||||
if (offline) {
|
||||
watch(activeRequests, (active) => {
|
||||
if (!active) {
|
||||
queryClient.cancelQueries({ queryKey: [MEDIA_SERVER_ALIVE_QUERY_KEY] });
|
||||
queryClient.cancelQueries({ queryKey: [VIDEO_SERVER_ALIVE_QUERY_KEY] });
|
||||
}
|
||||
@@ -56,7 +56,7 @@ watch(offlineDev, (offline) => {
|
||||
<span>服务状态</span>
|
||||
</template>
|
||||
<template #default>
|
||||
<template v-if="offlineDev">
|
||||
<template v-if="!activeRequests">
|
||||
<span>-</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
|
||||
@@ -18,7 +18,7 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { debugModeEnabled } = storeToRefs(settingStore);
|
||||
const { showDeviceRawData } = storeToRefs(settingStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
@@ -35,8 +35,8 @@ const activeTabName = ref('当前诊断');
|
||||
const onTabChange = (name: string) => {
|
||||
activeTabName.value = name;
|
||||
};
|
||||
watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || !enabled) {
|
||||
watch([ndmDevice, showDeviceRawData], ([newDevice, showRaw], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || (!showRaw && activeTabName.value === '原始数据')) {
|
||||
activeTabName.value = '当前诊断';
|
||||
}
|
||||
});
|
||||
@@ -50,7 +50,7 @@ watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
<NTab name="当前诊断">当前诊断</NTab>
|
||||
<NTab name="历史诊断">历史诊断</NTab>
|
||||
<NTab v-if="hasPermission(station.code, PERMISSION_TYPE_LITERALS.OPERATION)" name="修改设备">修改设备</NTab>
|
||||
<NTab v-if="debugModeEnabled" name="原始数据">原始数据</NTab>
|
||||
<NTab v-if="showDeviceRawData" name="原始数据">原始数据</NTab>
|
||||
</NTabs>
|
||||
</template>
|
||||
<template #default>
|
||||
|
||||
@@ -13,7 +13,7 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
const { activeRequests } = storeToRefs(settingStore);
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -27,7 +27,7 @@ const SERVER_STREAM_PUSH_KEY = 'server-stream-push-query';
|
||||
|
||||
const { data: streamPushes } = useQuery({
|
||||
queryKey: computed(() => [SERVER_STREAM_PUSH_KEY, ndmDevice.value.id, ndmDevice.value.lastDiagTime]),
|
||||
enabled: computed(() => !offlineDev.value && showCard.value),
|
||||
enabled: computed(() => activeRequests.value && showCard.value),
|
||||
refetchInterval: 30 * 1000,
|
||||
gcTime: 0,
|
||||
queryFn: async ({ signal }) => {
|
||||
@@ -35,8 +35,8 @@ const { data: streamPushes } = useQuery({
|
||||
return streamPushes;
|
||||
},
|
||||
});
|
||||
watch(offlineDev, (offline) => {
|
||||
if (offline) {
|
||||
watch(activeRequests, (active) => {
|
||||
if (!active) {
|
||||
queryClient.cancelQueries({ queryKey: [SERVER_STREAM_PUSH_KEY] });
|
||||
}
|
||||
});
|
||||
@@ -70,7 +70,7 @@ const streamPushStat = computed(() => {
|
||||
<span>推流统计</span>
|
||||
</template>
|
||||
<template #default>
|
||||
<template v-if="offlineDev">
|
||||
<template v-if="!activeRequests">
|
||||
<span>-</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
|
||||
@@ -18,7 +18,8 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { debugModeEnabled } = storeToRefs(settingStore);
|
||||
const { showDeviceRawData } = storeToRefs(settingStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
const { ndmDevice, station } = toRefs(props);
|
||||
@@ -34,8 +35,8 @@ const activeTabName = ref('当前诊断');
|
||||
const onTabChange = (name: string) => {
|
||||
activeTabName.value = name;
|
||||
};
|
||||
watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || !enabled) {
|
||||
watch([ndmDevice, showDeviceRawData], ([newDevice, showRaw], [oldDevice]) => {
|
||||
if (newDevice.id !== oldDevice.id || (!showRaw && activeTabName.value === '原始数据')) {
|
||||
activeTabName.value = '当前诊断';
|
||||
}
|
||||
});
|
||||
@@ -49,7 +50,7 @@ watch([ndmDevice, debugModeEnabled], ([newDevice, enabled], [oldDevice]) => {
|
||||
<NTab name="当前诊断">当前诊断</NTab>
|
||||
<NTab name="历史诊断">历史诊断</NTab>
|
||||
<NTab v-if="hasPermission(station.code, PERMISSION_TYPE_LITERALS.OPERATION)" name="修改设备">修改设备</NTab>
|
||||
<NTab v-if="debugModeEnabled" name="原始数据">原始数据</NTab>
|
||||
<NTab v-if="showDeviceRawData" name="原始数据">原始数据</NTab>
|
||||
</NTabs>
|
||||
</template>
|
||||
<template #default>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useDeviceTree, usePermission, type UseDeviceTreeReturn } from '@/compos
|
||||
import { DEVICE_TYPE_NAMES, DEVICE_TYPE_LITERALS, tryGetDeviceType, type DeviceType, PERMISSION_TYPE_LITERALS } from '@/enums';
|
||||
import { isNvrCluster } from '@/helpers';
|
||||
import { useDeviceStore, usePermissionStore } from '@/stores';
|
||||
import { watchImmediate } from '@vueuse/core';
|
||||
import { watchDebounced, watchImmediate } from '@vueuse/core';
|
||||
import destr from 'destr';
|
||||
import { isFunction } from 'es-toolkit';
|
||||
import {
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
type TreeProps,
|
||||
} from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, h, nextTick, onBeforeUnmount, ref, toRefs, useTemplateRef, watch, type CSSProperties } from 'vue';
|
||||
import { computed, h, nextTick, onBeforeUnmount, onMounted, ref, toRefs, useTemplateRef, watch, type CSSProperties } from 'vue';
|
||||
|
||||
const props = defineProps<{
|
||||
/**
|
||||
@@ -67,15 +67,15 @@ const {
|
||||
selectedStationCode,
|
||||
selectedDeviceType,
|
||||
selectedDevice,
|
||||
syncFromRoute,
|
||||
syncToRoute,
|
||||
selectDevice,
|
||||
// 设备管理
|
||||
exportDevice,
|
||||
exportDeviceTemplate,
|
||||
importDevice,
|
||||
deleteDevice,
|
||||
} = useDeviceTree({
|
||||
syncRoute: computed(() => !!syncRoute.value),
|
||||
});
|
||||
} = useDeviceTree();
|
||||
|
||||
// 将 `selectDevice` 函数暴露给父组件
|
||||
emit('exposeSelectDeviceFn', selectDevice);
|
||||
@@ -91,6 +91,7 @@ const onSelectDevice = (device: NdmDeviceResultVO, stationCode: Station['code'])
|
||||
|
||||
const permissionStore = usePermissionStore();
|
||||
const stations = computed(() => permissionStore.stations.VIEW ?? []);
|
||||
|
||||
const deviceStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(deviceStore);
|
||||
|
||||
@@ -483,11 +484,38 @@ const onLocateDeviceTree = async () => {
|
||||
|
||||
animated.value = true;
|
||||
};
|
||||
// 渲染全线设备树时,当选择的设备发生变化,则定位设备树
|
||||
|
||||
// 当选择的设备发生变化时,定位设备树,并同步选中状态到路由参数
|
||||
// 暂时不考虑多次执行的问题,因为当选择的设备在设备树视口内时,不会发生滚动
|
||||
watch(selectedDevice, async () => {
|
||||
watch(selectedDevice, async (newDevice, oldDevice) => {
|
||||
if (!!station.value) return;
|
||||
await onLocateDeviceTree();
|
||||
if (newDevice?.id === oldDevice?.id) return;
|
||||
// console.log('selectedDevice changed');
|
||||
onLocateDeviceTree();
|
||||
syncToRoute();
|
||||
});
|
||||
|
||||
// 当全线设备发生变化时,从路由参数同步选中状态
|
||||
// 但lineDevices是shallowRef,因此需要深度侦听才能获取内部变化,
|
||||
// 而单纯的深度侦听又可能会引发性能问题,因此尝试使用防抖侦听
|
||||
watchDebounced(
|
||||
lineDevices,
|
||||
(newLineDevices) => {
|
||||
if (syncRoute.value) {
|
||||
// console.log('lineDevices changed');
|
||||
syncFromRoute(newLineDevices);
|
||||
}
|
||||
},
|
||||
{
|
||||
debounce: 500,
|
||||
deep: true,
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
if (syncRoute.value) {
|
||||
syncFromRoute(lineDevices.value);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ThemeSwitch } from '@/components';
|
||||
import { usePermission } from '@/composables';
|
||||
import { NDM_ALARM_STORE_ID, NDM_DEVICE_STORE_ID, NDM_STATION_STORE_ID } from '@/constants';
|
||||
import { PERMISSION_TYPE_LITERALS } from '@/enums';
|
||||
import { usePollingStore, useSettingStore, useStationStore } from '@/stores';
|
||||
import { useSettingStore, useStationStore } from '@/stores';
|
||||
import { downloadByData, getAppEnvConfig, parseErrorFeedback, sleep } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import { useEventListener } from '@vueuse/core';
|
||||
@@ -25,7 +25,7 @@ const { stations } = storeToRefs(stationStore);
|
||||
const occStation = computed(() => stations.value.find((station) => !!station.occ));
|
||||
|
||||
const settingsStore = useSettingStore();
|
||||
const { menuCollpased, stationGridCols, debugModeEnabled, offlineDev } = storeToRefs(settingsStore);
|
||||
const { menuCollpased, stationGridCols, debugMode, showDeviceRawData, pollingStations, activeRequests, subscribeMessages, mockUser, useLocalDB } = storeToRefs(settingsStore);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
@@ -132,11 +132,11 @@ const enableDebugMode = () => {
|
||||
return;
|
||||
}
|
||||
showDebugCodeModal.value = false;
|
||||
settingsStore.enableDebugMode();
|
||||
debugMode.value = true;
|
||||
};
|
||||
const disableDebugMode = () => {
|
||||
showDebugCodeModal.value = false;
|
||||
settingsStore.disableDebugMode();
|
||||
debugMode.value = false;
|
||||
};
|
||||
useEventListener('keydown', (event) => {
|
||||
const { ctrlKey, altKey, code } = event;
|
||||
@@ -147,28 +147,18 @@ useEventListener('keydown', (event) => {
|
||||
|
||||
const expectToShowDebugCodeInput = ref(false);
|
||||
const onModalAfterEnter = () => {
|
||||
expectToShowDebugCodeInput.value = !debugModeEnabled.value;
|
||||
expectToShowDebugCodeInput.value = !debugMode.value;
|
||||
};
|
||||
const onModalAfterLeave = () => {
|
||||
expectToShowDebugCodeInput.value = false;
|
||||
debugCode.value = '';
|
||||
};
|
||||
|
||||
const pollingStore = usePollingStore();
|
||||
const { pollingEnabled } = storeToRefs(pollingStore);
|
||||
const onPollingEnabledUpdate = (enabled: boolean) => {
|
||||
if (enabled) {
|
||||
pollingStore.startPolling();
|
||||
} else {
|
||||
pollingStore.stopPolling();
|
||||
}
|
||||
};
|
||||
|
||||
type IndexedDbStoreId = typeof NDM_STATION_STORE_ID | typeof NDM_DEVICE_STORE_ID | typeof NDM_ALARM_STORE_ID;
|
||||
type IndexedDbStoreStates = {
|
||||
[NDM_STATION_STORE_ID]: { stations: Station[] };
|
||||
[NDM_DEVICE_STORE_ID]: { lineDevices: LineDevices };
|
||||
[NDM_ALARM_STORE_ID]: { lineAlarms: LineAlarms; unreadLineAlarms: LineAlarms };
|
||||
[NDM_ALARM_STORE_ID]: { lineAlarms: LineAlarms };
|
||||
};
|
||||
const exportFromIndexedDB = async <K extends IndexedDbStoreId>(storeId: K, options?: { errorMsg?: string }) => {
|
||||
const { errorMsg } = options ?? {};
|
||||
@@ -181,8 +171,9 @@ const exportFromIndexedDB = async <K extends IndexedDbStoreId>(storeId: K, optio
|
||||
};
|
||||
const importToIndexedDB = async <K extends IndexedDbStoreId>(storeId: K, options?: { successMsg?: string; errorMsg?: string }) => {
|
||||
const { successMsg, errorMsg } = options ?? {};
|
||||
pollingStore.stopPolling();
|
||||
offlineDev.value = true;
|
||||
pollingStations.value = false;
|
||||
activeRequests.value = false;
|
||||
subscribeMessages.value = false;
|
||||
const fileInput = document.createElement('input');
|
||||
fileInput.type = 'file';
|
||||
fileInput.accept = '.json';
|
||||
@@ -205,8 +196,9 @@ const importToIndexedDB = async <K extends IndexedDbStoreId>(storeId: K, options
|
||||
};
|
||||
};
|
||||
const deleteFromIndexedDB = async (storeId: IndexedDbStoreId) => {
|
||||
pollingStore.stopPolling();
|
||||
offlineDev.value = true;
|
||||
pollingStations.value = false;
|
||||
activeRequests.value = false;
|
||||
subscribeMessages.value = false;
|
||||
await localforage.removeItem(storeId).catch((error) => {
|
||||
window.$message.error(`${error}`);
|
||||
return;
|
||||
@@ -275,15 +267,14 @@ const onSelectDropdownOption = (key: string, option: DropdownOption) => {
|
||||
}
|
||||
};
|
||||
|
||||
watch([offlineDev, show], ([offline, entered]) => {
|
||||
if (!offline) {
|
||||
if (entered) {
|
||||
getRetentionDays();
|
||||
getSnapStatus();
|
||||
} else {
|
||||
abortControllers.value.retentionDays.abort();
|
||||
abortControllers.value.snapStatus.abort();
|
||||
}
|
||||
watch([activeRequests, show], ([active, entered]) => {
|
||||
if (!active) return;
|
||||
if (entered) {
|
||||
getRetentionDays();
|
||||
getSnapStatus();
|
||||
} else {
|
||||
abortControllers.value.retentionDays.abort();
|
||||
abortControllers.value.snapStatus.abort();
|
||||
}
|
||||
});
|
||||
const onDrawerAfterEnter = () => {
|
||||
@@ -334,15 +325,33 @@ const onDrawerAfterLeave = () => {
|
||||
</NFormItem>
|
||||
</template>
|
||||
|
||||
<template v-if="debugModeEnabled">
|
||||
<template v-if="debugMode">
|
||||
<NDivider title-placement="center">调试</NDivider>
|
||||
<NFormItem label="启用轮询" label-placement="left">
|
||||
<NSwitch size="small" :value="pollingEnabled" @update:value="onPollingEnabledUpdate" />
|
||||
<NFormItem label="调试模式" label-placement="left">
|
||||
<NSwitch size="small" v-model:value="debugMode" />
|
||||
</NFormItem>
|
||||
<NFormItem label="离线开发" label-placement="left">
|
||||
<NSwitch size="small" v-model:value="offlineDev" />
|
||||
<NDivider title-placement="left" dashed>数据设置</NDivider>
|
||||
<NFormItem label="显示设备原始数据" label-placement="left">
|
||||
<NSwitch size="small" v-model:value="showDeviceRawData" />
|
||||
</NFormItem>
|
||||
<NFormItem label="本地数据库" label-placement="left">
|
||||
<NDivider title-placement="left" dashed>网络设置</NDivider>
|
||||
<NFormItem label="轮询车站" label-placement="left">
|
||||
<NSwitch size="small" v-model:value="pollingStations" />
|
||||
</NFormItem>
|
||||
<NFormItem label="主动请求" label-placement="left">
|
||||
<NSwitch size="small" v-model:value="activeRequests" />
|
||||
</NFormItem>
|
||||
<NFormItem label="订阅消息" label-placement="left">
|
||||
<NSwitch size="small" v-model:value="subscribeMessages" />
|
||||
</NFormItem>
|
||||
<NFormItem label="模拟用户" label-placement="left">
|
||||
<NSwitch size="small" v-model:value="mockUser" />
|
||||
</NFormItem>
|
||||
<NDivider title-placement="left" dashed>数据库设置</NDivider>
|
||||
<NFormItem label="直接操作本地数据库" label-placement="left">
|
||||
<NSwitch size="small" v-model:value="useLocalDB" />
|
||||
</NFormItem>
|
||||
<NFormItem label="数据操作" label-placement="left">
|
||||
<NFlex>
|
||||
<NDropdown trigger="click" :options="exportDropdownOptions" @select="onSelectDropdownOption">
|
||||
<NButton secondary size="small">
|
||||
@@ -382,7 +391,7 @@ const onDrawerAfterLeave = () => {
|
||||
|
||||
<NModal v-model:show="showDebugCodeModal" preset="dialog" type="info" @after-enter="onModalAfterEnter" @after-leave="onModalAfterLeave">
|
||||
<template #header>
|
||||
<NText v-if="!debugModeEnabled">请输入调试码</NText>
|
||||
<NText v-if="!debugMode">请输入调试码</NText>
|
||||
<NText v-else>确认关闭调试模式</NText>
|
||||
</template>
|
||||
<template #default>
|
||||
@@ -390,7 +399,7 @@ const onDrawerAfterLeave = () => {
|
||||
</template>
|
||||
<template #action>
|
||||
<NButton @click="showDebugCodeModal = false">取消</NButton>
|
||||
<NButton v-if="!debugModeEnabled" type="primary" @click="enableDebugMode">启用</NButton>
|
||||
<NButton v-if="!debugMode" type="primary" @click="enableDebugMode">启用</NButton>
|
||||
<NButton v-else type="primary" @click="disableDebugMode">确认</NButton>
|
||||
</template>
|
||||
</NModal>
|
||||
|
||||
@@ -5,14 +5,14 @@ import { storeToRefs } from 'pinia';
|
||||
import type { ComponentInstance } from 'vue';
|
||||
|
||||
const settingsStore = useSettingStore();
|
||||
const { darkThemeEnabled } = storeToRefs(settingsStore);
|
||||
const { darkMode } = storeToRefs(settingsStore);
|
||||
|
||||
// 使外部能够获取NSwitch的类型提示
|
||||
defineExpose({} as ComponentInstance<typeof NSwitch>);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NSwitch v-model:value="darkThemeEnabled">
|
||||
<NSwitch v-model:value="darkMode">
|
||||
<template #unchecked-icon>
|
||||
<NIcon>
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
export * from './permission-config-modal';
|
||||
import type { ComponentInstance } from 'vue';
|
||||
import PermissionConfigModal from './permission-config-modal.vue';
|
||||
|
||||
export type PermissionConfigModalProps = ComponentInstance<typeof PermissionConfigModal>['$props'];
|
||||
|
||||
export { PermissionConfigModal };
|
||||
|
||||
302
src/components/permission/permission-config-modal.vue
Normal file
302
src/components/permission/permission-config-modal.vue
Normal file
@@ -0,0 +1,302 @@
|
||||
<script setup lang="ts">
|
||||
import { detailBaseEmployeeApi, modifyPermissionApi, pagePermissionApi, type BaseEmployeeResultVO, type NdmPermissionResultVO, type NdmPermissionSaveVO, type Station } from '@/apis';
|
||||
import { PERMISSION_TYPE_LITERALS, PERMISSION_TYPE_NAMES, type PermissionType } from '@/enums';
|
||||
import { useStationStore } from '@/stores';
|
||||
import { parseErrorFeedback } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import { objectEntries } from '@vueuse/core';
|
||||
import { isCancel } from 'axios';
|
||||
import { cloneDeep } from 'es-toolkit';
|
||||
import { NButton, NCheckbox, NDataTable, NFlex, NModal, NText, type DataTableColumn, type DataTableColumns } from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, h, ref, toRefs } from 'vue';
|
||||
|
||||
type NdmPermissionSaveOrResultVO = NdmPermissionSaveVO | NdmPermissionResultVO;
|
||||
|
||||
const props = defineProps<{
|
||||
employeeId?: string;
|
||||
}>();
|
||||
|
||||
const stationStore = useStationStore();
|
||||
const { stations } = storeToRefs(stationStore);
|
||||
|
||||
const show = defineModel<boolean>('show', { default: false });
|
||||
|
||||
const { employeeId } = toRefs(props);
|
||||
|
||||
const abortController = ref<AbortController>(new AbortController());
|
||||
|
||||
const employee = ref<BaseEmployeeResultVO>();
|
||||
const { mutateAsync: getEmployeeAsync } = useMutation({
|
||||
mutationFn: async () => {
|
||||
abortController.value.abort();
|
||||
abortController.value = new AbortController();
|
||||
|
||||
if (!employeeId.value) return;
|
||||
|
||||
const signal = abortController.value.signal;
|
||||
|
||||
const data = await detailBaseEmployeeApi(employeeId.value, { signal });
|
||||
return data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
if (!data) return;
|
||||
employee.value = data;
|
||||
},
|
||||
onError: (error) => {
|
||||
if (isCancel(error)) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
});
|
||||
|
||||
// 从后端获取的原始权限列表
|
||||
const originalList = ref<NdmPermissionResultVO[]>([]);
|
||||
// 当前用户配置的权限列表
|
||||
const currentList = ref<NdmPermissionSaveOrResultVO[]>([]);
|
||||
|
||||
const { mutate: getPermissions, isPending: permissionsLoading } = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!employeeId.value) throw new Error('员工ID不能为空');
|
||||
|
||||
abortController.value.abort();
|
||||
abortController.value = new AbortController();
|
||||
|
||||
const signal = abortController.value.signal;
|
||||
|
||||
const data = await pagePermissionApi(
|
||||
{
|
||||
model: {
|
||||
employeeId: employeeId.value,
|
||||
},
|
||||
current: 1,
|
||||
size: Object.keys(PERMISSION_TYPE_LITERALS).length * stations.value.length,
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
if (!data) return;
|
||||
const { records } = data;
|
||||
originalList.value = cloneDeep(records);
|
||||
currentList.value = cloneDeep(records);
|
||||
},
|
||||
onError: (error) => {
|
||||
if (isCancel(error)) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
});
|
||||
|
||||
const onUpdatePermissionChecked = (checked: boolean, stationCode: Station['code'], permissionType: PermissionType) => {
|
||||
if (!employeeId.value) return;
|
||||
if (checked) {
|
||||
const existed = currentList.value.some((permission) => permission.stationCode === stationCode && permission.type === permissionType);
|
||||
if (!existed) {
|
||||
const saveVO: NdmPermissionSaveVO = {
|
||||
employeeId: employeeId.value,
|
||||
stationCode,
|
||||
type: permissionType,
|
||||
};
|
||||
currentList.value.push(saveVO);
|
||||
}
|
||||
} else {
|
||||
const index = currentList.value.findIndex((permission) => permission.stationCode === stationCode && permission.type === permissionType);
|
||||
if (index !== -1) {
|
||||
currentList.value.splice(index, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const tableColumns = computed<DataTableColumns<Station>>(() => {
|
||||
return [
|
||||
{
|
||||
title: () => {
|
||||
const permissionCount = currentList.value.length;
|
||||
const permissionTypeCount = objectEntries(PERMISSION_TYPE_LITERALS).length;
|
||||
const checked = permissionCount === stations.value.length * permissionTypeCount;
|
||||
const indeterminate = permissionCount > 0 && permissionCount < stations.value.length * permissionTypeCount;
|
||||
return h(NCheckbox, {
|
||||
checked,
|
||||
indeterminate,
|
||||
onUpdateChecked: (checked) => {
|
||||
objectEntries(PERMISSION_TYPE_LITERALS).forEach(([permissionType]) => {
|
||||
stations.value.forEach((station) => {
|
||||
onUpdatePermissionChecked(checked, station.code, permissionType);
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
key: 'row-check',
|
||||
align: 'center',
|
||||
width: 60,
|
||||
fixed: 'left',
|
||||
render: (rowData) => {
|
||||
const { code: stationCode } = rowData;
|
||||
const permissionTypeCount = objectEntries(PERMISSION_TYPE_LITERALS).length;
|
||||
const stationCheckedPermissions = currentList.value.filter((permission) => permission.stationCode === stationCode);
|
||||
const checked = stationCheckedPermissions.length === permissionTypeCount;
|
||||
const indeterminate = stationCheckedPermissions.length > 0 && stationCheckedPermissions.length < permissionTypeCount;
|
||||
return h(NCheckbox, {
|
||||
checked,
|
||||
indeterminate,
|
||||
onUpdateChecked: (checked) => {
|
||||
objectEntries(PERMISSION_TYPE_LITERALS).forEach(([permissionType]) => {
|
||||
onUpdatePermissionChecked(checked, stationCode, permissionType);
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
{ title: '车站编号', key: 'code', align: 'center', width: 120 },
|
||||
{ title: '车站名称', key: 'name', align: 'center', width: 360 },
|
||||
// 「权限」列
|
||||
...objectEntries(PERMISSION_TYPE_NAMES).map<DataTableColumn<Station>>(([permissionType, title]) => ({
|
||||
title: () => {
|
||||
const permissionCount = currentList.value.filter((permission) => permission.type === permissionType).length;
|
||||
const checked = permissionCount === stations.value.length;
|
||||
const indeterminate = permissionCount > 0 && permissionCount < stations.value.length;
|
||||
return h(
|
||||
NFlex,
|
||||
{
|
||||
justify: 'center',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
default: () => [
|
||||
h(NCheckbox, {
|
||||
checked,
|
||||
indeterminate,
|
||||
onUpdateChecked: (checked) => {
|
||||
stations.value.forEach((station) => {
|
||||
onUpdatePermissionChecked(checked, station.code, permissionType);
|
||||
});
|
||||
},
|
||||
}),
|
||||
h('span', title),
|
||||
],
|
||||
},
|
||||
);
|
||||
},
|
||||
key: permissionType,
|
||||
align: 'center',
|
||||
render: (rowData) => {
|
||||
const { code: stationCode } = rowData;
|
||||
return h(NCheckbox, {
|
||||
checked: currentList.value.some((permission) => permission.stationCode === stationCode && permission.type === permissionType),
|
||||
onUpdateChecked: (checked) => onUpdatePermissionChecked(checked, stationCode, permissionType),
|
||||
});
|
||||
},
|
||||
})),
|
||||
];
|
||||
});
|
||||
|
||||
const { mutate: savePermissions, isPending: permissionsSaving } = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!employeeId.value) throw new Error('员工ID不能为空');
|
||||
|
||||
abortController.value.abort();
|
||||
abortController.value = new AbortController();
|
||||
|
||||
const signal = abortController.value.signal;
|
||||
|
||||
// 执行diff计算,生成需要保存的权限列表和需要删除的权限ID列表
|
||||
const saveList: NdmPermissionSaveVO[] = [];
|
||||
const removeList: string[] = [];
|
||||
// 遍历当前状态,如果权限不在原始权限列表中,说明是需要新增的权限
|
||||
currentList.value.forEach((permission) => {
|
||||
const { stationCode, type } = permission;
|
||||
if (!stationCode || !type) return;
|
||||
if (!originalList.value.some((permission) => permission.stationCode === stationCode && permission.type === type)) {
|
||||
saveList.push({
|
||||
employeeId: employeeId.value,
|
||||
stationCode,
|
||||
type,
|
||||
});
|
||||
}
|
||||
});
|
||||
// 遍历原始状态,如果权限不在当前状态中,说明是需要删除的权限
|
||||
originalList.value.forEach((permission) => {
|
||||
const { id, stationCode, type } = permission;
|
||||
if (!id) return;
|
||||
if (!currentList.value.some((permission) => permission.stationCode === stationCode && permission.type === type)) {
|
||||
removeList.push(id);
|
||||
}
|
||||
});
|
||||
|
||||
await modifyPermissionApi(
|
||||
{
|
||||
employeeId: employeeId.value,
|
||||
saveList,
|
||||
removeList,
|
||||
},
|
||||
{
|
||||
signal,
|
||||
},
|
||||
);
|
||||
},
|
||||
onSuccess: () => {
|
||||
window.$message.success('权限配置保存成功');
|
||||
getPermissions();
|
||||
},
|
||||
onError: (error) => {
|
||||
if (isCancel(error)) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
});
|
||||
|
||||
const onAfterEnter = () => {
|
||||
getEmployeeAsync().then(() => getPermissions());
|
||||
};
|
||||
|
||||
const onAfterLeave = () => {
|
||||
employee.value = undefined;
|
||||
originalList.value = [];
|
||||
currentList.value = [];
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
abortController.value.abort();
|
||||
show.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NModal
|
||||
v-model:show="show"
|
||||
preset="card"
|
||||
style="width: 100vw; height: 100vh"
|
||||
:content-style="{ height: '100%', overflow: 'hidden' }"
|
||||
:close-on-esc="false"
|
||||
:mask-closable="false"
|
||||
:auto-focus="false"
|
||||
@after-enter="onAfterEnter"
|
||||
@after-leave="onAfterLeave"
|
||||
@close="onClose"
|
||||
>
|
||||
<template #header>
|
||||
<span>{{ `配置权限 - ${employee?.realName ?? ''}` }}</span>
|
||||
</template>
|
||||
<template #default>
|
||||
<NDataTable flex-height style="height: 100%" :columns="tableColumns" :data="stations" :loading="permissionsLoading" :single-line="false" />
|
||||
</template>
|
||||
<template #footer>
|
||||
<NText depth="3" style="font-size: smaller">*未勾选任何权限的用户将被认为拥有所有权限</NText>
|
||||
</template>
|
||||
<template #action>
|
||||
<NFlex justify="end">
|
||||
<NButton size="small" @click="onClose">取消</NButton>
|
||||
<NButton type="primary" size="small" :loading="permissionsSaving" @click="() => savePermissions()">保存</NButton>
|
||||
</NFlex>
|
||||
</template>
|
||||
</NModal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
@@ -1,6 +0,0 @@
|
||||
import type { ComponentInstance } from 'vue';
|
||||
import PermissionConfigModal from './permission-config-modal.vue';
|
||||
|
||||
export type PermissionConfigModalProps = ComponentInstance<typeof PermissionConfigModal>['$props'];
|
||||
|
||||
export { PermissionConfigModal };
|
||||
@@ -1,263 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
deletePermissionApi,
|
||||
detailBaseEmployeeApi,
|
||||
pagePermissionApi,
|
||||
savePermissionApi,
|
||||
type BaseEmployeeResultVO,
|
||||
type NdmPermissionResultVO,
|
||||
type NdmPermissionSaveVO,
|
||||
type Station,
|
||||
} from '@/apis';
|
||||
import { PERMISSION_TYPE_NAMES, type PermissionType } from '@/enums';
|
||||
import { useStationStore } from '@/stores';
|
||||
import { parseErrorFeedback } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import { objectEntries } from '@vueuse/core';
|
||||
import { isCancel } from 'axios';
|
||||
import { cloneDeep, groupBy } from 'es-toolkit';
|
||||
import { NButton, NCheckbox, NDataTable, NFlex, NModal, NText, type DataTableColumn, type DataTableColumns } from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, h, ref, toRefs } from 'vue';
|
||||
|
||||
/**
|
||||
* 为避免修改权限记录而带来复杂的状态管理,引入 `action` 字段
|
||||
*
|
||||
* - `save`:新增权限
|
||||
* - `delete`:删除权限
|
||||
*
|
||||
* 修改权限的过程中会对本地的权限列表进行修改:
|
||||
* - 当勾选权限时,在本地新增一条权限,`action` 为 `save`
|
||||
* - 当取消勾选权限时,如果该权限来自服务器,则将`action` 改为 `delete`,否则直接删除权限记录
|
||||
*
|
||||
* 最后,保存权限时,只需要遍历本地权限列表:
|
||||
* - 如果 `action` 为 `save`,则调用 `savePermissionApi` 新增权限
|
||||
* - 如果 `action` 为 `delete`,则调用 `deletePermissionApi` 删除权限
|
||||
*/
|
||||
type PermissionAction = 'save' | 'delete';
|
||||
|
||||
type NdmPermissionSaveOrResultVO = NdmPermissionSaveVO | NdmPermissionResultVO;
|
||||
|
||||
type NdmPermissionExtendedSaveVO = NdmPermissionSaveVO & { action?: PermissionAction };
|
||||
|
||||
type NdmPermissionExtendedResultVO = NdmPermissionResultVO & { action?: PermissionAction };
|
||||
|
||||
type NdmPermissionExtendedSaveOrResultVO = NdmPermissionExtendedSaveVO | NdmPermissionExtendedResultVO;
|
||||
|
||||
const omitActionField = (extendedSaveOrResultVO: NdmPermissionExtendedSaveOrResultVO) => {
|
||||
const copy = cloneDeep(extendedSaveOrResultVO);
|
||||
delete copy.action;
|
||||
const saveOrResultVO = copy as NdmPermissionSaveOrResultVO;
|
||||
return saveOrResultVO;
|
||||
};
|
||||
|
||||
const isSaveVO = (saveOrResultVO: NdmPermissionSaveOrResultVO): saveOrResultVO is NdmPermissionSaveVO => {
|
||||
return !('id' in saveOrResultVO);
|
||||
};
|
||||
|
||||
const isResultVO = (saveOrResultVO: NdmPermissionSaveOrResultVO): saveOrResultVO is NdmPermissionResultVO => {
|
||||
return 'id' in saveOrResultVO;
|
||||
};
|
||||
|
||||
const props = defineProps<{
|
||||
employeeId?: string;
|
||||
}>();
|
||||
|
||||
const stationStore = useStationStore();
|
||||
const { stations } = storeToRefs(stationStore);
|
||||
|
||||
const show = defineModel<boolean>('show', { default: false });
|
||||
|
||||
const { employeeId } = toRefs(props);
|
||||
|
||||
const abortController = ref<AbortController>(new AbortController());
|
||||
|
||||
const employee = ref<BaseEmployeeResultVO>();
|
||||
const { mutateAsync: getEmployeeAsync } = useMutation({
|
||||
mutationFn: async () => {
|
||||
abortController.value.abort();
|
||||
abortController.value = new AbortController();
|
||||
|
||||
if (!employeeId.value) return;
|
||||
|
||||
const signal = abortController.value.signal;
|
||||
|
||||
const data = await detailBaseEmployeeApi(employeeId.value, { signal });
|
||||
return data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
if (!data) return;
|
||||
employee.value = data;
|
||||
},
|
||||
onError: (error) => {
|
||||
if (isCancel(error)) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
});
|
||||
|
||||
const permissions = ref<Record<Station['code'], NdmPermissionExtendedSaveOrResultVO[]>>({});
|
||||
const { mutate: getPermissions, isPending: permissionsLoading } = useMutation({
|
||||
mutationFn: async () => {
|
||||
abortController.value.abort();
|
||||
abortController.value = new AbortController();
|
||||
|
||||
if (!employeeId.value) return;
|
||||
|
||||
const signal = abortController.value.signal;
|
||||
|
||||
const data = await pagePermissionApi(
|
||||
{
|
||||
model: {
|
||||
employeeId: employeeId.value,
|
||||
},
|
||||
extra: {},
|
||||
current: 1,
|
||||
size: Object.keys(PERMISSION_TYPE_NAMES).length * stations.value.length,
|
||||
sort: 'id',
|
||||
order: 'ascending',
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
if (!data) return;
|
||||
const { records } = data;
|
||||
permissions.value = groupBy(records, (record) => record.stationCode ?? '');
|
||||
},
|
||||
onError: (error) => {
|
||||
if (isCancel(error)) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
});
|
||||
|
||||
const onUpdatePermissionChecked = (checked: boolean, stationCode: Station['code'], permissionType: PermissionType) => {
|
||||
if (!employeeId.value) return;
|
||||
if (checked) {
|
||||
// 勾选时,新增一条权限记录,`action` 为 `save`
|
||||
if (!permissions.value[stationCode]) permissions.value[stationCode] = [];
|
||||
permissions.value[stationCode].push({ employeeId: employeeId.value, stationCode, type: permissionType, action: 'save' });
|
||||
} else {
|
||||
if (!permissions.value[stationCode]) return;
|
||||
// 取消勾选时,先找到所有该类型的权限并遍历,
|
||||
// 如果权限来自数据库(即有 `id` 字段),则将其 `action` 设为 `delete`,
|
||||
// 否则直接从权限记录中移除
|
||||
const targets = permissions.value[stationCode].filter((permission) => permission.type === permissionType);
|
||||
for (const permission of targets) {
|
||||
if (isResultVO(permission)) {
|
||||
permission.action = 'delete';
|
||||
} else {
|
||||
permissions.value[stationCode].splice(permissions.value[stationCode].indexOf(permission), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const tableColumns = computed<DataTableColumns<Station>>(() => {
|
||||
return [
|
||||
{ title: '车站编号', key: 'code', align: 'center', width: 120 },
|
||||
{ title: '车站名称', key: 'name', align: 'center', width: 360 },
|
||||
// 「权限」列
|
||||
...objectEntries(PERMISSION_TYPE_NAMES).map<DataTableColumn<Station>>(([permissionType, title]) => ({
|
||||
title: title,
|
||||
key: permissionType,
|
||||
align: 'center',
|
||||
render: (rowData) => {
|
||||
const { code: stationCode } = rowData;
|
||||
return h(NCheckbox, {
|
||||
// 如果权限记录中存在该权限且 `action` 不为 `delete`,则处于勾选状态
|
||||
checked: !!(permissions.value[stationCode] ?? []).find((permission) => permission.type === permissionType && permission.action !== 'delete'),
|
||||
// 改变勾选状态
|
||||
onUpdateChecked: (checked) => onUpdatePermissionChecked(checked, stationCode, permissionType),
|
||||
});
|
||||
},
|
||||
})),
|
||||
];
|
||||
});
|
||||
|
||||
const { mutate: savePermissions, isPending: permissionsSaving } = useMutation({
|
||||
mutationFn: async () => {
|
||||
abortController.value.abort();
|
||||
abortController.value = new AbortController();
|
||||
|
||||
const signal = abortController.value.signal;
|
||||
|
||||
// 遍历所有的权限记录,根据 `action` 进行保存或删除
|
||||
for (const stationPermissions of Object.values(permissions.value)) {
|
||||
for (const permission of stationPermissions) {
|
||||
const saveOrResultVO = omitActionField(permission);
|
||||
if (permission.action === 'save' && isSaveVO(saveOrResultVO)) {
|
||||
await savePermissionApi(saveOrResultVO, { signal });
|
||||
}
|
||||
if (permission.action === 'delete' && isResultVO(saveOrResultVO)) {
|
||||
const id = saveOrResultVO.id;
|
||||
if (!id) continue;
|
||||
await deletePermissionApi([id], { signal });
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
window.$message.success('权限配置保存成功');
|
||||
getPermissions();
|
||||
},
|
||||
onError: (error) => {
|
||||
if (isCancel(error)) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
});
|
||||
|
||||
const onAfterEnter = () => {
|
||||
getEmployeeAsync().then(() => getPermissions());
|
||||
};
|
||||
|
||||
const onAfterLeave = () => {
|
||||
employee.value = undefined;
|
||||
permissions.value = {};
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
abortController.value.abort();
|
||||
show.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NModal
|
||||
v-model:show="show"
|
||||
preset="card"
|
||||
style="width: 100vw; height: 100vh"
|
||||
:content-style="{ height: '100%', overflow: 'hidden' }"
|
||||
:close-on-esc="false"
|
||||
:mask-closable="false"
|
||||
:auto-focus="false"
|
||||
@after-enter="onAfterEnter"
|
||||
@after-leave="onAfterLeave"
|
||||
@close="onClose"
|
||||
>
|
||||
<template #header>
|
||||
<span>{{ `配置权限 - ${employee?.realName ?? ''}` }}</span>
|
||||
</template>
|
||||
<template #default>
|
||||
<NDataTable flex-height style="height: 100%" :columns="tableColumns" :data="stations" :loading="permissionsLoading" :single-line="false" />
|
||||
</template>
|
||||
<template #footer>
|
||||
<NText depth="3" style="font-size: smaller">*未勾选任何权限的用户将被认为拥有所有权限</NText>
|
||||
</template>
|
||||
<template #action>
|
||||
<NFlex justify="end">
|
||||
<NButton size="small" @click="onClose">取消</NButton>
|
||||
<NButton type="primary" size="small" :loading="permissionsSaving" @click="() => savePermissions()">保存</NButton>
|
||||
</NFlex>
|
||||
</template>
|
||||
</NModal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
@@ -1,13 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { getRecordCheckApi, type NdmNvrResultVO, type Station } from '@/apis';
|
||||
import { exportRecordDiagCsv, isNvrCluster, transformRecordChecks } from '@/helpers';
|
||||
import { useDeviceStore } from '@/stores';
|
||||
import { parseErrorFeedback } from '@/utils';
|
||||
import { batchExportRecordCheckApi, pageDefParameterApi, type Station } from '@/apis';
|
||||
import { downloadByData, parseErrorFeedback } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import { isCancel } from 'axios';
|
||||
import { NButton, NGrid, NGridItem, NModal, NScrollbar, NSpin } from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, ref, toRefs } from 'vue';
|
||||
import dayjs from 'dayjs';
|
||||
import { NButton, NFlex, NGrid, NGridItem, NModal, NScrollbar, NSpin } from 'naive-ui';
|
||||
import { ref, toRefs } from 'vue';
|
||||
|
||||
const props = defineProps<{
|
||||
stations: Station[];
|
||||
@@ -19,50 +17,66 @@ const emit = defineEmits<{
|
||||
|
||||
const show = defineModel<boolean>('show');
|
||||
|
||||
const deviceStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(deviceStore);
|
||||
|
||||
const { stations } = toRefs(props);
|
||||
|
||||
const nvrClusterRecord = computed(() => {
|
||||
const clusterMap: Record<Station['code'], { stationName: Station['name']; clusters: NdmNvrResultVO[] }> = {};
|
||||
stations.value.forEach((station) => {
|
||||
clusterMap[station.code] = {
|
||||
stationName: station.name,
|
||||
clusters: [],
|
||||
};
|
||||
const stationDevices = lineDevices.value[station.code];
|
||||
const nvrs = stationDevices?.['ndmNvr'] ?? [];
|
||||
nvrs.forEach((nvr) => {
|
||||
if (isNvrCluster(nvr)) {
|
||||
clusterMap[station.code]?.clusters?.push(nvr);
|
||||
}
|
||||
});
|
||||
});
|
||||
return clusterMap;
|
||||
});
|
||||
|
||||
const abortController = ref<AbortController>(new AbortController());
|
||||
|
||||
const { mutate: exportRecordDiags, isPending: exporting } = useMutation({
|
||||
mutationFn: async (params: { clusters: NdmNvrResultVO[]; stationCode: Station['code'] }) => {
|
||||
const { clusters, stationCode } = params;
|
||||
if (clusters.length === 0) {
|
||||
const stationName = nvrClusterRecord.value[stationCode]?.stationName ?? '';
|
||||
window.$message.info(`${stationName} 没有录像诊断数据`);
|
||||
return;
|
||||
const { mutate: batchExportRecordCheck, isPending: batchExporting } = useMutation({
|
||||
mutationFn: async (params: { stations: Station[] }) => {
|
||||
const timer = setTimeout(() => {
|
||||
if (!batchExporting.value) return;
|
||||
window.$message.info('导出耗时较长,请耐心等待...', { duration: 0 });
|
||||
}, 3000);
|
||||
|
||||
try {
|
||||
abortController.value.abort();
|
||||
abortController.value = new AbortController();
|
||||
const { records = [] } = await pageDefParameterApi(
|
||||
{
|
||||
model: {
|
||||
key: 'NVR_GAP_SECONDS',
|
||||
},
|
||||
extra: {},
|
||||
current: 1,
|
||||
size: 1,
|
||||
sort: 'id',
|
||||
order: 'descending',
|
||||
},
|
||||
{
|
||||
signal: abortController.value.signal,
|
||||
},
|
||||
);
|
||||
const gapSeconds = parseInt(records.at(0)?.value ?? '5');
|
||||
|
||||
abortController.value.abort();
|
||||
abortController.value = new AbortController();
|
||||
const data = await batchExportRecordCheckApi(
|
||||
{
|
||||
checkDuration: 90,
|
||||
gapSeconds,
|
||||
stationCode: params.stations.map((station) => station.code),
|
||||
},
|
||||
{
|
||||
signal: abortController.value.signal,
|
||||
},
|
||||
);
|
||||
|
||||
return data;
|
||||
} finally {
|
||||
window.$message.destroyAll();
|
||||
clearTimeout(timer);
|
||||
}
|
||||
const cluster = clusters.at(0);
|
||||
if (!cluster) return;
|
||||
abortController.value.abort();
|
||||
abortController.value = new AbortController();
|
||||
const checks = await getRecordCheckApi(cluster, 90, [], { stationCode: stationCode, signal: abortController.value.signal });
|
||||
return checks;
|
||||
},
|
||||
onSuccess: (checks, { stationCode }) => {
|
||||
if (!checks || checks.length === 0) return;
|
||||
const recordDiags = transformRecordChecks(checks);
|
||||
exportRecordDiagCsv(recordDiags, nvrClusterRecord.value[stationCode]?.stationName ?? '');
|
||||
onSuccess: (data, { stations }) => {
|
||||
const time = dayjs().format('YYYY-MM-DD_HH-mm-ss');
|
||||
let stationName = '';
|
||||
if (stations.length === 1) {
|
||||
const name = stations.at(0)?.name;
|
||||
if (!!name) {
|
||||
stationName = `${name}_`;
|
||||
}
|
||||
}
|
||||
downloadByData(data, `${stationName}录像缺失记录_${time}.xlsx`);
|
||||
},
|
||||
onError: (error) => {
|
||||
if (isCancel(error)) return;
|
||||
@@ -73,6 +87,7 @@ const { mutate: exportRecordDiags, isPending: exporting } = useMutation({
|
||||
});
|
||||
|
||||
const onAfterLeave = () => {
|
||||
abortController.value.abort();
|
||||
emit('afterLeave');
|
||||
};
|
||||
</script>
|
||||
@@ -81,17 +96,22 @@ const onAfterLeave = () => {
|
||||
<NModal v-model:show="show" preset="card" title="导出录像诊断" @after-leave="onAfterLeave" style="width: 800px">
|
||||
<template #default>
|
||||
<NScrollbar style="height: 300px">
|
||||
<NSpin size="small" :show="exporting">
|
||||
<NSpin size="small" :show="batchExporting">
|
||||
<NGrid :cols="6">
|
||||
<template v-for="({ stationName, clusters }, code) in nvrClusterRecord" :key="code">
|
||||
<template v-for="station in stations" :key="station.code">
|
||||
<NGridItem>
|
||||
<NButton text type="info" style="height: 30px" @click="() => exportRecordDiags({ clusters, stationCode: code })">{{ stationName }}</NButton>
|
||||
<NButton text type="info" style="height: 30px" @click="() => batchExportRecordCheck({ stations: [station] })">{{ station.name }}</NButton>
|
||||
</NGridItem>
|
||||
</template>
|
||||
</NGrid>
|
||||
</NSpin>
|
||||
</NScrollbar>
|
||||
</template>
|
||||
<template #action>
|
||||
<NFlex justify="flex-end" align="center">
|
||||
<NButton secondary :loading="batchExporting" @click="() => batchExportRecordCheck({ stations })">导出全部</NButton>
|
||||
</NFlex>
|
||||
</template>
|
||||
</NModal>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import type { Station, SyncCameraResult } from '@/apis';
|
||||
import { useStationStore } from '@/stores';
|
||||
import { usePermissionStore } from '@/stores';
|
||||
import { watchDebounced } from '@vueuse/core';
|
||||
import { EditIcon, PlusCircleIcon, Trash2Icon } from 'lucide-vue-next';
|
||||
import { NFlex, NIcon, NList, NListItem, NModal, NScrollbar, NStatistic, NText, NThing } from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, ref, toRefs } from 'vue';
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -15,8 +14,8 @@ const emit = defineEmits<{
|
||||
afterLeave: [];
|
||||
}>();
|
||||
|
||||
const stationStore = useStationStore();
|
||||
const { stations } = storeToRefs(stationStore);
|
||||
const permissionStore = usePermissionStore();
|
||||
const stations = computed(() => permissionStore.stations.VIEW ?? []);
|
||||
|
||||
const { syncCameraResult } = toRefs(props);
|
||||
|
||||
|
||||
@@ -1,39 +1,33 @@
|
||||
import type { LineDevices, NdmDeviceResultVO, Station } from '@/apis';
|
||||
import { tryGetDeviceType, type DeviceType } from '@/enums';
|
||||
import { useDeviceStore } from '@/stores';
|
||||
import { watchDebounced } from '@vueuse/core';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { onMounted, ref, toValue, watch, type MaybeRefOrGetter } from 'vue';
|
||||
import { ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
export const useDeviceSelection = (options?: { syncRoute?: MaybeRefOrGetter<boolean> }) => {
|
||||
const { syncRoute } = options ?? {};
|
||||
|
||||
export const useDeviceSelection = () => {
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const deviceStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(deviceStore);
|
||||
|
||||
const selectedStationCode = ref<Station['code']>();
|
||||
const selectedDeviceType = ref<DeviceType>();
|
||||
const selectedDevice = ref<NdmDeviceResultVO>();
|
||||
|
||||
const initFromRoute = (lineDevices: LineDevices) => {
|
||||
const { stationCode, deviceType, deviceDbId } = route.query;
|
||||
if (stationCode) {
|
||||
selectedStationCode.value = stationCode as Station['code'];
|
||||
// 从路由参数同步选中的车站、设备类型以及设备
|
||||
const syncFromRoute = (lineDevices: LineDevices) => {
|
||||
// console.log('sync from route');
|
||||
const { stationCode: routeStationCode, deviceType: routeDeviceType, deviceDbId: routeDeviceDbId } = route.query;
|
||||
if (routeStationCode) {
|
||||
selectedStationCode.value = routeStationCode as Station['code'];
|
||||
}
|
||||
if (deviceType) {
|
||||
selectedDeviceType.value = deviceType as DeviceType;
|
||||
if (routeDeviceType) {
|
||||
selectedDeviceType.value = routeDeviceType as DeviceType;
|
||||
}
|
||||
if (deviceDbId && selectedStationCode.value && selectedDeviceType.value) {
|
||||
const selectedDeviceDbId = deviceDbId as string;
|
||||
if (routeDeviceDbId && selectedStationCode.value && selectedDeviceType.value) {
|
||||
const selectedDeviceDbId = routeDeviceDbId as string;
|
||||
const stationDevices = lineDevices[selectedStationCode.value];
|
||||
if (stationDevices) {
|
||||
const devices = stationDevices[selectedDeviceType.value];
|
||||
if (devices) {
|
||||
const device = devices.find((device) => device.id === selectedDeviceDbId);
|
||||
const classifiedDevices = stationDevices[selectedDeviceType.value];
|
||||
if (classifiedDevices) {
|
||||
const device = classifiedDevices.find((device) => device.id === selectedDeviceDbId);
|
||||
if (device) {
|
||||
selectedDevice.value = device;
|
||||
}
|
||||
@@ -51,7 +45,9 @@ export const useDeviceSelection = (options?: { syncRoute?: MaybeRefOrGetter<bool
|
||||
}
|
||||
};
|
||||
|
||||
// 将选中的车站、设备类型以及设备ID同步到路由参数
|
||||
const syncToRoute = () => {
|
||||
// console.log('sync to route');
|
||||
const query = { ...route.query };
|
||||
// 当选中的设备发生变化时,删除fromPage参数
|
||||
if (selectedDevice.value?.id && route.query.deviceDbId !== selectedDevice.value.id) {
|
||||
@@ -69,39 +65,13 @@ export const useDeviceSelection = (options?: { syncRoute?: MaybeRefOrGetter<bool
|
||||
router.replace({ query });
|
||||
};
|
||||
|
||||
watch(selectedDevice, () => {
|
||||
if (toValue(syncRoute)) {
|
||||
syncToRoute();
|
||||
}
|
||||
});
|
||||
|
||||
// lineDevices是shallowRef,因此需要深度侦听才能获取内部变化,
|
||||
// 而单纯的深度侦听又可能会引发性能问题,因此尝试使用防抖侦听
|
||||
watchDebounced(
|
||||
lineDevices,
|
||||
(newLineDevices) => {
|
||||
if (toValue(syncRoute)) {
|
||||
initFromRoute(newLineDevices);
|
||||
}
|
||||
},
|
||||
{
|
||||
debounce: 500,
|
||||
deep: true,
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
if (toValue(syncRoute)) {
|
||||
initFromRoute(lineDevices.value);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
selectedStationCode,
|
||||
selectedDeviceType,
|
||||
selectedDevice,
|
||||
|
||||
initFromRoute,
|
||||
syncFromRoute,
|
||||
syncToRoute,
|
||||
selectDevice,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import type { MaybeRefOrGetter } from 'vue';
|
||||
import { useDeviceManagement } from './use-device-management';
|
||||
import { useDeviceSelection } from './use-device-selection';
|
||||
|
||||
export const useDeviceTree = (options?: { syncRoute?: MaybeRefOrGetter<boolean> }) => {
|
||||
const { syncRoute } = options ?? {};
|
||||
|
||||
const deviceSelection = useDeviceSelection({ syncRoute });
|
||||
export const useDeviceTree = () => {
|
||||
const deviceSelection = useDeviceSelection();
|
||||
const deviceManagement = useDeviceManagement();
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { Station } from '@/apis';
|
||||
import type { PermissionType } from '@/enums';
|
||||
import { usePermissionStore } from '@/stores';
|
||||
|
||||
export const usePermission = () => {
|
||||
const permissionStore = usePermissionStore();
|
||||
|
||||
const hasPermission = (stationCode: Station['code'], permissionType: PermissionType) => {
|
||||
const hasPermission = (stationCode: string, permissionType: PermissionType) => {
|
||||
return !!permissionStore.permissions[stationCode]?.includes(permissionType);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export * from './use-line-alarms-query';
|
||||
export * from './use-line-devices-query';
|
||||
export * from './use-line-stations-query';
|
||||
export * from './use-user-permissions-query';
|
||||
export * from './use-user-permission-query';
|
||||
export * from './use-verify-user-query';
|
||||
export * from './use-version-check-query';
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { initStationAlarms, pageDeviceAlarmLogApi, type Station } from '@/apis';
|
||||
import { LINE_ALARMS_QUERY_KEY, STATION_ALARMS_MUTATION_KEY } from '@/constants';
|
||||
import { tryGetDeviceType } from '@/enums';
|
||||
import { useAlarmStore, useStationStore } from '@/stores';
|
||||
import { useAlarmStore, usePermissionStore } from '@/stores';
|
||||
import { parseErrorFeedback } from '@/utils';
|
||||
import { CancelledError, useMutation, useQuery } from '@tanstack/vue-query';
|
||||
import { isCancel } from 'axios';
|
||||
import dayjs from 'dayjs';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
|
||||
export const useStationAlarmsMutation = () => {
|
||||
@@ -56,8 +55,8 @@ export const useStationAlarmsMutation = () => {
|
||||
alarmStore.setStationAlarms(station.code, stationAlarms);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
if (isCancel(error) || error instanceof CancelledError) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
@@ -69,19 +68,22 @@ export const useStationAlarmsMutation = () => {
|
||||
* @see [use-line-stations-query.ts](./use-line-stations-query.ts)
|
||||
*/
|
||||
export const useLineAlarmsQuery = () => {
|
||||
const stationStore = useStationStore();
|
||||
const { stations } = storeToRefs(stationStore);
|
||||
const permissionStore = usePermissionStore();
|
||||
const stations = computed(() => permissionStore.stations.VIEW ?? []);
|
||||
|
||||
const { mutateAsync: getStationAlarms } = useStationAlarmsMutation();
|
||||
|
||||
return useQuery({
|
||||
queryKey: computed(() => [LINE_ALARMS_QUERY_KEY]),
|
||||
enabled: false,
|
||||
queryFn: async ({ signal }) => {
|
||||
console.time(LINE_ALARMS_QUERY_KEY);
|
||||
const startTime = performance.now();
|
||||
for (const station of stations.value) {
|
||||
await getStationAlarms({ station, signal }).catch(() => {});
|
||||
}
|
||||
console.timeEnd(LINE_ALARMS_QUERY_KEY);
|
||||
const endTime = performance.now();
|
||||
console.log(`${LINE_ALARMS_QUERY_KEY}: ${endTime - startTime} ms`);
|
||||
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { getAllDevicesApi, initStationDevices, type Station } from '@/apis';
|
||||
import { LINE_DEVICES_QUERY_KEY, STATION_DEVICES_MUTATION_KEY } from '@/constants';
|
||||
import { useDeviceStore, useStationStore } from '@/stores';
|
||||
import { useDeviceStore, usePermissionStore } from '@/stores';
|
||||
import { parseErrorFeedback } from '@/utils';
|
||||
import { CancelledError, useMutation, useQuery } from '@tanstack/vue-query';
|
||||
import { isCancel } from 'axios';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
|
||||
export const useStationDevicesMutation = () => {
|
||||
@@ -23,8 +22,8 @@ export const useStationDevicesMutation = () => {
|
||||
deviceStore.setStationDevices(station.code, devices);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
if (isCancel(error) || error instanceof CancelledError) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
@@ -36,19 +35,22 @@ export const useStationDevicesMutation = () => {
|
||||
* @see [use-line-stations-query.ts](./use-line-stations-query.ts)
|
||||
*/
|
||||
export const useLineDevicesQuery = () => {
|
||||
const stationStore = useStationStore();
|
||||
const { stations } = storeToRefs(stationStore);
|
||||
const permissionStore = usePermissionStore();
|
||||
const stations = computed(() => permissionStore.stations.VIEW ?? []);
|
||||
|
||||
const { mutateAsync: getStationDevices } = useStationDevicesMutation();
|
||||
|
||||
return useQuery({
|
||||
queryKey: computed(() => [LINE_DEVICES_QUERY_KEY]),
|
||||
enabled: false,
|
||||
queryFn: async ({ signal }) => {
|
||||
console.time(LINE_DEVICES_QUERY_KEY);
|
||||
const startTime = performance.now();
|
||||
for (const station of stations.value) {
|
||||
await getStationDevices({ station, signal }).catch(() => {});
|
||||
}
|
||||
console.timeEnd(LINE_DEVICES_QUERY_KEY);
|
||||
const endTime = performance.now();
|
||||
console.log(`${LINE_DEVICES_QUERY_KEY}: ${endTime - startTime} ms`);
|
||||
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { batchVerifyApi, type Station } from '@/apis';
|
||||
import { LINE_STATIONS_MUTATION_KEY, LINE_STATIONS_QUERY_KEY } from '@/constants';
|
||||
import { usePollingStore, useStationStore } from '@/stores';
|
||||
import { useSettingStore, useStationStore } from '@/stores';
|
||||
import { getAppEnvConfig, parseErrorFeedback } from '@/utils';
|
||||
import { CancelledError, useMutation, useQuery } from '@tanstack/vue-query';
|
||||
import axios, { isCancel } from 'axios';
|
||||
import dayjs from 'dayjs';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
import { useLineDevicesQuery } from './use-line-devices-query';
|
||||
import { useLineAlarmsQuery } from './use-line-alarms-query';
|
||||
|
||||
export const useLineStationsMutation = () => {
|
||||
const stationStore = useStationStore();
|
||||
@@ -36,8 +34,8 @@ export const useLineStationsMutation = () => {
|
||||
stationStore.setStations(stations);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
if (isCancel(error) || error instanceof CancelledError) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
@@ -45,28 +43,21 @@ export const useLineStationsMutation = () => {
|
||||
};
|
||||
|
||||
export const useLineStationsQuery = () => {
|
||||
const pollingStore = usePollingStore();
|
||||
const { pollingEnabled } = storeToRefs(pollingStore);
|
||||
const settingStore = useSettingStore();
|
||||
const { pollingStations } = storeToRefs(settingStore);
|
||||
const { requestInterval } = getAppEnvConfig();
|
||||
const { mutateAsync: getLineStations } = useLineStationsMutation();
|
||||
const { refetch: refetchLineDevicesQuery } = useLineDevicesQuery();
|
||||
const { refetch: refetchLineAlarmsQuery } = useLineAlarmsQuery();
|
||||
|
||||
return useQuery({
|
||||
queryKey: computed(() => [LINE_STATIONS_QUERY_KEY]),
|
||||
enabled: computed(() => pollingEnabled.value),
|
||||
enabled: computed(() => pollingStations.value),
|
||||
refetchInterval: requestInterval * 1000,
|
||||
staleTime: (requestInterval * 1000) / 2,
|
||||
queryFn: async ({ signal }) => {
|
||||
console.time(LINE_STATIONS_QUERY_KEY);
|
||||
const startTime = performance.now();
|
||||
await getLineStations({ signal }).catch(() => {});
|
||||
console.timeEnd(LINE_STATIONS_QUERY_KEY);
|
||||
|
||||
if (!pollingEnabled.value) return null;
|
||||
await refetchLineDevicesQuery();
|
||||
|
||||
if (!pollingEnabled.value) return null;
|
||||
await refetchLineAlarmsQuery();
|
||||
const endTime = performance.now();
|
||||
console.log(`${LINE_STATIONS_QUERY_KEY}: ${endTime - startTime} ms`);
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
67
src/composables/query/use-user-permission-query.ts
Normal file
67
src/composables/query/use-user-permission-query.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { useLineDevicesQuery } from './use-line-devices-query';
|
||||
import { useLineAlarmsQuery } from './use-line-alarms-query';
|
||||
import { pagePermissionApi } from '@/apis';
|
||||
import { USER_PERMISSION_QUERY_KEY } from '@/constants';
|
||||
import { PERMISSION_TYPE_LITERALS } from '@/enums';
|
||||
import { usePermissionStore, useSettingStore, useStationStore, useUserStore } from '@/stores';
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, watch } from 'vue';
|
||||
import { useLineStationsQuery } from './use-line-stations-query';
|
||||
|
||||
export const useUserPermissionQuery = () => {
|
||||
const settingStore = useSettingStore();
|
||||
const { pollingStations, activeRequests } = storeToRefs(settingStore);
|
||||
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
|
||||
const stationStore = useStationStore();
|
||||
const { stations } = storeToRefs(stationStore);
|
||||
|
||||
const permissionStore = usePermissionStore();
|
||||
const { permissions } = storeToRefs(permissionStore);
|
||||
|
||||
const { dataUpdatedAt: stationsUpdatedTime } = useLineStationsQuery();
|
||||
const { refetch: refetchLineDevicesQuery } = useLineDevicesQuery();
|
||||
const { refetch: refetchLineAlarmsQuery } = useLineAlarmsQuery();
|
||||
|
||||
watch([permissions, stationsUpdatedTime], async ([newPermissions, newUpdatedTime], [oldPermissions, oldUpdatedTime]) => {
|
||||
const newPermissionsJson = JSON.stringify(newPermissions);
|
||||
const oldPermissionsJson = JSON.stringify(oldPermissions);
|
||||
if (newPermissionsJson === oldPermissionsJson && newUpdatedTime === oldUpdatedTime) return;
|
||||
// 设备查询和告警查询依赖pollingEnabdled
|
||||
// 当关闭轮询时,只会取消当前正在执行的查询,
|
||||
// 所以如果在关闭轮询时refetch还未执行,那么这一次取消就是无效的,refetch依然会执行,
|
||||
// 所以在每个refetch被调用前都需要检查pollingEnabled,否则就可能会取消失败
|
||||
if (!pollingStations.value) return;
|
||||
await refetchLineDevicesQuery();
|
||||
if (!pollingStations.value) return;
|
||||
await refetchLineAlarmsQuery();
|
||||
});
|
||||
|
||||
return useQuery({
|
||||
queryKey: computed(() => [USER_PERMISSION_QUERY_KEY]),
|
||||
// 启用【车站轮询】或【主动请求】时,都认为查询被启用
|
||||
enabled: computed(() => (pollingStations.value || activeRequests.value) && userInfo.value?.['employeeId'] && stations.value.length > 0),
|
||||
// 当启用【车站轮询】时,刷新间隔为10秒,缓存时间为5秒
|
||||
refetchInterval: computed(() => (pollingStations.value ? 10 * 1000 : undefined)),
|
||||
staleTime: computed(() => (pollingStations.value ? 5 * 1000 : undefined)),
|
||||
queryFn: async ({ signal }) => {
|
||||
const { records } = await pagePermissionApi(
|
||||
{
|
||||
model: {
|
||||
employeeId: userInfo.value['employeeId'],
|
||||
},
|
||||
current: 1,
|
||||
size: Object.keys(PERMISSION_TYPE_LITERALS).length * stations.value.length,
|
||||
},
|
||||
{
|
||||
signal,
|
||||
},
|
||||
);
|
||||
permissionStore.setPermRecords(records);
|
||||
return null;
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -1,55 +0,0 @@
|
||||
import { pagePermissionApi } from '@/apis';
|
||||
import { USER_PERMISSIONS_QUERY_KEY } from '@/constants';
|
||||
import { PERMISSION_TYPE_NAMES } from '@/enums';
|
||||
import { usePermissionStore, useSettingStore, useStationStore, useUserStore } from '@/stores';
|
||||
import { useQuery, useQueryClient } from '@tanstack/vue-query';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, watch } from 'vue';
|
||||
|
||||
export const useUserPermissionsQuery = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
|
||||
const stationStore = useStationStore();
|
||||
const { stations } = storeToRefs(stationStore);
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
const permissionStore = usePermissionStore();
|
||||
|
||||
watch(offlineDev, (offline) => {
|
||||
if (offline) {
|
||||
queryClient.cancelQueries({ queryKey: [USER_PERMISSIONS_QUERY_KEY] });
|
||||
}
|
||||
});
|
||||
|
||||
return useQuery({
|
||||
queryKey: computed(() => [USER_PERMISSIONS_QUERY_KEY]),
|
||||
enabled: computed(() => !offlineDev.value),
|
||||
refetchInterval: 10 * 1000,
|
||||
queryFn: async ({ signal }) => {
|
||||
const { employeeId } = userInfo.value ?? {};
|
||||
if (!employeeId) return null;
|
||||
|
||||
const { records } = await pagePermissionApi(
|
||||
{
|
||||
model: {
|
||||
employeeId,
|
||||
},
|
||||
extra: {},
|
||||
current: 1,
|
||||
size: Object.keys(PERMISSION_TYPE_NAMES).length * stations.value.length,
|
||||
sort: 'id',
|
||||
order: 'ascending',
|
||||
},
|
||||
{
|
||||
signal,
|
||||
},
|
||||
);
|
||||
permissionStore.setPermRecords(records);
|
||||
|
||||
return null;
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -8,17 +8,17 @@ import { computed, watch } from 'vue';
|
||||
export const useVerifyUserQuery = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
const { activeRequests } = storeToRefs(settingStore);
|
||||
|
||||
watch(offlineDev, (offline) => {
|
||||
if (offline) {
|
||||
watch(activeRequests, (active) => {
|
||||
if (!active) {
|
||||
queryClient.cancelQueries({ queryKey: [VERIFY_USER_QUERY_KEY] });
|
||||
}
|
||||
});
|
||||
|
||||
return useQuery({
|
||||
queryKey: [VERIFY_USER_QUERY_KEY],
|
||||
enabled: computed(() => !offlineDev.value),
|
||||
enabled: computed(() => activeRequests.value),
|
||||
refetchInterval: 10 * 1000,
|
||||
queryFn: async ({ signal }) => {
|
||||
await verifyApi({ signal });
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { usePermission } from '../permission';
|
||||
import { type Station } from '@/apis';
|
||||
import { PERMISSION_TYPE_LITERALS, type PermissionType } from '@/enums';
|
||||
import { objectEntries } from '@vueuse/core';
|
||||
import type { CheckboxProps } from 'naive-ui';
|
||||
import { computed, ref, watch, type Ref } from 'vue';
|
||||
|
||||
type BatchActionKey = 'export-icmp' | 'export-record' | 'sync-camera' | 'sync-nvr';
|
||||
@@ -60,6 +62,21 @@ export const useBatchActions = (stations: Ref<Station[]>, abortController?: Ref<
|
||||
|
||||
const stationSelection = ref<Record<Station['code'], boolean>>({});
|
||||
|
||||
const selectionProps = computed<CheckboxProps>(() => {
|
||||
const selectableStationsLength = selectableStations.value.length;
|
||||
const selectedStationsLength = objectEntries(stationSelection.value).filter(([, selected]) => selected).length;
|
||||
|
||||
const disabled = selectableStationsLength === 0;
|
||||
const checked = selectableStationsLength > 0 && selectedStationsLength === selectableStationsLength;
|
||||
const indeterminate = selectableStationsLength > 0 && selectedStationsLength > 0 && selectedStationsLength < selectableStationsLength;
|
||||
|
||||
return {
|
||||
disabled,
|
||||
checked,
|
||||
indeterminate,
|
||||
};
|
||||
});
|
||||
|
||||
const toggleSelectAction = (action: BatchAction) => {
|
||||
batchActions.value.forEach((batchAction) => {
|
||||
if (batchAction.key === action.key) {
|
||||
@@ -111,6 +128,8 @@ export const useBatchActions = (stations: Ref<Station[]>, abortController?: Ref<
|
||||
selectableStations,
|
||||
stationSelection,
|
||||
|
||||
selectionProps,
|
||||
|
||||
toggleSelectAction,
|
||||
toggleSelectAllStations,
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { NdmDeviceAlarmLogResultVO, Station, SyncCameraResult } from '@/apis';
|
||||
import { ALARM_TOPIC, SYNC_CAMERA_STATUS_TOPIC } from '@/constants';
|
||||
import { useAlarmStore, useSettingStore, useStationStore } from '@/stores';
|
||||
import { ALARM_TOPIC, PERMISSION_TOPIC, SYNC_CAMERA_STATUS_TOPIC } from '@/constants';
|
||||
import { useSettingStore, useStationStore, useUnreadStore, useUserStore } from '@/stores';
|
||||
import { Client } from '@stomp/stompjs';
|
||||
import { watchDebounced } from '@vueuse/core';
|
||||
import destr from 'destr';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { useStationAlarmsMutation } from '../query';
|
||||
import { useStationAlarmsMutation, useUserPermissionQuery } from '../query';
|
||||
|
||||
const getBrokerUrl = () => {
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
@@ -19,11 +19,17 @@ const getBrokerUrl = () => {
|
||||
export const useStompClient = () => {
|
||||
const stationStore = useStationStore();
|
||||
const { stations } = storeToRefs(stationStore);
|
||||
const alarmStore = useAlarmStore();
|
||||
const { unreadLineAlarms } = storeToRefs(alarmStore);
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
|
||||
const unreadStore = useUnreadStore();
|
||||
const { unreadLineAlarms } = storeToRefs(unreadStore);
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { subscribeMessages } = storeToRefs(settingStore);
|
||||
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
|
||||
const { refetch: refetchUserPermissionQuery } = useUserPermissionQuery();
|
||||
const { mutate: refreshStationAlarms } = useStationAlarmsMutation();
|
||||
|
||||
const stompClient = ref<Client | null>(null);
|
||||
@@ -40,10 +46,16 @@ export const useStompClient = () => {
|
||||
console.log('Stomp连接成功');
|
||||
stompClient.value?.subscribe(ALARM_TOPIC, (message) => {
|
||||
const alarm = destr<NdmDeviceAlarmLogResultVO>(message.body);
|
||||
if (alarm.alarmCategory === '1') {
|
||||
alarmStore.pushUnreadAlarm(alarm);
|
||||
const { alarmCategory, stationCode } = alarm;
|
||||
if (alarmCategory === '1' && !!stations.value.find((station) => station.code === stationCode)) {
|
||||
unreadStore.pushUnreadAlarm(alarm);
|
||||
}
|
||||
});
|
||||
stompClient.value?.subscribe(PERMISSION_TOPIC, (message) => {
|
||||
const employeeId = destr<string>(message.body);
|
||||
if (userInfo.value?.['employeeId'] !== employeeId) return;
|
||||
refetchUserPermissionQuery();
|
||||
});
|
||||
stompClient.value?.subscribe(SYNC_CAMERA_STATUS_TOPIC, (message) => {
|
||||
const { stationCode, startTime, endTime, insertList, updateList, deleteList } = destr<SyncCameraResult>(message.body);
|
||||
syncCameraResult.value[stationCode] = { stationCode, startTime, endTime, insertList, updateList, deleteList };
|
||||
@@ -52,6 +64,7 @@ export const useStompClient = () => {
|
||||
onDisconnect: () => {
|
||||
console.log('Stomp连接断开');
|
||||
stompClient.value?.unsubscribe(ALARM_TOPIC);
|
||||
stompClient.value?.unsubscribe(PERMISSION_TOPIC);
|
||||
stompClient.value?.unsubscribe(SYNC_CAMERA_STATUS_TOPIC);
|
||||
},
|
||||
onStompError: (frame) => {
|
||||
@@ -63,7 +76,7 @@ export const useStompClient = () => {
|
||||
window.$message.error('WebSocket错误');
|
||||
},
|
||||
});
|
||||
if (!offlineDev.value) {
|
||||
if (subscribeMessages.value) {
|
||||
stompClient.value.activate();
|
||||
}
|
||||
});
|
||||
@@ -73,11 +86,11 @@ export const useStompClient = () => {
|
||||
stompClient.value = null;
|
||||
});
|
||||
|
||||
watch(offlineDev, (offline) => {
|
||||
if (offline) {
|
||||
stompClient.value?.deactivate();
|
||||
} else {
|
||||
watch(subscribeMessages, (subscribe) => {
|
||||
if (subscribe) {
|
||||
stompClient.value?.activate();
|
||||
} else {
|
||||
stompClient.value?.deactivate();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -87,8 +100,8 @@ export const useStompClient = () => {
|
||||
watchDebounced(
|
||||
() => Object.entries(unreadLineAlarms.value).map(([stationCode, stationAlarms]) => ({ stationCode, count: stationAlarms['unclassified'].length })),
|
||||
(newValue, oldValue) => {
|
||||
// 启用离线模式时,跳过处理
|
||||
if (offlineDev.value) return;
|
||||
// 关闭消息订阅时,跳过处理
|
||||
if (!subscribeMessages.value) return;
|
||||
if (newValue.length === 0) return;
|
||||
const codes: Station['code'][] = [];
|
||||
newValue.forEach(({ stationCode, count }) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const LINE_ALARMS_QUERY_KEY = 'line-alarms';
|
||||
export const LINE_DEVICES_QUERY_KEY = 'line-devices';
|
||||
export const LINE_STATIONS_QUERY_KEY = 'line-stations';
|
||||
export const USER_PERMISSIONS_QUERY_KEY = 'user-permissions';
|
||||
export const USER_PERMISSION_QUERY_KEY = 'user-permission';
|
||||
export const VERIFY_USER_QUERY_KEY = 'verify-user';
|
||||
export const VERSION_CHECK_QUERY_KEY = 'version-check';
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export const ALARM_TOPIC = '/topic/deviceAlarm';
|
||||
|
||||
export const PERMISSION_TOPIC = '/topic/permission';
|
||||
export const SYNC_CAMERA_STATUS_TOPIC = '/topic/syncCameraStatus';
|
||||
|
||||
@@ -4,4 +4,5 @@ export const NDM_PERMISSION_STORE_ID = 'ndm-permission-store';
|
||||
export const NDM_POLLIING_STORE_ID = 'ndm-polling-store';
|
||||
export const NDM_SETTING_STORE_ID = 'ndm-setting-store';
|
||||
export const NDM_STATION_STORE_ID = 'ndm-station-store';
|
||||
export const NDM_UNREAD_STORE_ID = 'ndm-unread-store';
|
||||
export const NDM_USER_STORE_ID = 'ndm-user-store';
|
||||
|
||||
2
src/global.d.ts
vendored
2
src/global.d.ts
vendored
@@ -7,6 +7,6 @@ declare global {
|
||||
$loadingBar: ReturnType<typeof useLoadingBar>;
|
||||
$message: ReturnType<typeof useMessage>;
|
||||
$notification: ReturnType<typeof useNotification>;
|
||||
$offlineDev: Ref<boolean>;
|
||||
$mockUser: Ref<boolean>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { SettingsDrawer, SyncCameraResultModal } from '@/components';
|
||||
import { useLineStationsQuery, useStompClient, useUserPermissionsQuery, useVerifyUserQuery } from '@/composables';
|
||||
import { useLineStationsQuery, useStompClient, useUserPermissionQuery, useVerifyUserQuery } from '@/composables';
|
||||
import { LINE_ALARMS_QUERY_KEY, LINE_DEVICES_QUERY_KEY, LINE_STATIONS_MUTATION_KEY, LINE_STATIONS_QUERY_KEY, STATION_ALARMS_MUTATION_KEY, STATION_DEVICES_MUTATION_KEY } from '@/constants';
|
||||
import { useAlarmStore, useSettingStore, useUserStore } from '@/stores';
|
||||
import { parseErrorFeedback } from '@/utils';
|
||||
import { useIsFetching, useIsMutating, useMutation } from '@tanstack/vue-query';
|
||||
import { isCancel } from 'axios';
|
||||
import { ChevronDownIcon, ChevronsLeftIcon, ChevronsRightIcon, ComputerIcon, KeyIcon, LogOutIcon, LogsIcon, MapPinIcon, SettingsIcon, SirenIcon } from 'lucide-vue-next';
|
||||
import { useSettingStore, useUnreadStore, useUserStore } from '@/stores';
|
||||
import { useIsFetching, useIsMutating } from '@tanstack/vue-query';
|
||||
import { ChevronDownIcon, ChevronsLeftIcon, ChevronsRightIcon, ComputerIcon, KeyRoundIcon, LogOutIcon, LogsIcon, MapPinIcon, SettingsIcon, SirenIcon } from 'lucide-vue-next';
|
||||
import {
|
||||
NBadge,
|
||||
NButton,
|
||||
@@ -24,26 +22,26 @@ import {
|
||||
type MenuOption,
|
||||
} from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, h, ref, watchEffect, type Component, type VNode } from 'vue';
|
||||
import { computed, h, ref, type Component, type VNode } from 'vue';
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
const { userInfo, isLamp } = storeToRefs(userStore);
|
||||
|
||||
const alarmStore = useAlarmStore();
|
||||
const { unreadAlarmCount } = storeToRefs(alarmStore);
|
||||
const unreadStore = useUnreadStore();
|
||||
const { unreadAlarmCount } = storeToRefs(unreadStore);
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { menuCollpased, offlineDev } = storeToRefs(settingStore);
|
||||
const { menuCollpased } = storeToRefs(settingStore);
|
||||
|
||||
const { syncCameraResult, afterCheckSyncCameraResult } = useStompClient();
|
||||
|
||||
useVerifyUserQuery();
|
||||
useLineStationsQuery();
|
||||
useUserPermissionsQuery();
|
||||
useUserPermissionQuery();
|
||||
|
||||
// 全局loading状态依赖于轮询query的queryKey以及相关的mutationKey
|
||||
const queryingCount = useIsFetching({
|
||||
@@ -66,7 +64,7 @@ const onToggleMenuCollapsed = () => {
|
||||
menuCollpased.value = !menuCollpased.value;
|
||||
};
|
||||
|
||||
const menuOptions: MenuOption[] = [
|
||||
const menuOptions = computed<MenuOption[]>(() => [
|
||||
{
|
||||
label: () => h(RouterLink, { to: '/station' }, { default: () => '车站状态' }),
|
||||
key: '/station',
|
||||
@@ -110,10 +108,10 @@ const menuOptions: MenuOption[] = [
|
||||
{
|
||||
label: () => h(RouterLink, { to: '/permission' }, { default: () => '权限管理' }),
|
||||
key: '/permission',
|
||||
show: userStore.isLamp,
|
||||
icon: renderIcon(KeyIcon),
|
||||
show: isLamp.value,
|
||||
icon: renderIcon(KeyRoundIcon),
|
||||
},
|
||||
];
|
||||
]);
|
||||
|
||||
const dropdownOptions: DropdownOption[] = [
|
||||
{
|
||||
@@ -148,33 +146,12 @@ const routeToRoot = () => {
|
||||
};
|
||||
|
||||
const routeToAlarmPage = () => {
|
||||
alarmStore.clearUnreadAlarms();
|
||||
unreadStore.clearUnreadAlarms();
|
||||
if (route.path !== '/alarm/alarm-log') {
|
||||
router.push({ path: '/alarm/alarm-log' });
|
||||
}
|
||||
};
|
||||
|
||||
const { mutate: getUserInfo } = useMutation({
|
||||
mutationFn: async (params?: { signal?: AbortSignal }) => {
|
||||
const { signal } = params ?? {};
|
||||
await userStore.userGetInfo({ signal });
|
||||
},
|
||||
onError: (error) => {
|
||||
if (isCancel(error)) return;
|
||||
console.error(error);
|
||||
const errorFeedback = parseErrorFeedback(error);
|
||||
window.$message.error(errorFeedback);
|
||||
},
|
||||
});
|
||||
|
||||
// 判断是否为离线开发模式 决定是否自动发送获取用户信息请求
|
||||
watchEffect((onCleanup) => {
|
||||
if (offlineDev.value) return;
|
||||
const abortController = new AbortController();
|
||||
getUserInfo({ signal: abortController.signal });
|
||||
onCleanup(() => abortController.abort());
|
||||
});
|
||||
|
||||
function renderIcon(icon: Component): () => VNode {
|
||||
return () => h(NIcon, null, { default: () => h(icon) });
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ interface SearchFields extends PageQueryExtra<NdmCameraIgnore> {
|
||||
stationCode?: Station['code'];
|
||||
// deviceId_like?: string;
|
||||
}
|
||||
const deviceStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(deviceStore);
|
||||
|
||||
const permissionStore = usePermissionStore();
|
||||
const { permissions } = storeToRefs(permissionStore);
|
||||
|
||||
@@ -55,6 +54,9 @@ const { hasPermission } = usePermission();
|
||||
|
||||
const stations = computed(() => permissionStore.stations.VIEW ?? []);
|
||||
|
||||
const deviceStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(deviceStore);
|
||||
|
||||
const stationSelectOptions = computed<SelectOption[]>(() => {
|
||||
return stations.value.map((station) => ({
|
||||
label: station.name,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { exportDeviceAlarmLogApi, pageDeviceAlarmLogApi, type NdmDeviceAlarmLog,
|
||||
import { useAlarmActionColumn, useCameraSnapColumn } from '@/composables';
|
||||
import { ALARM_TYPES, DEVICE_TYPE_CODES, DEVICE_TYPE_LITERALS, DEVICE_TYPE_NAMES, FAULT_LEVELS, tryGetDeviceType, type DeviceType } from '@/enums';
|
||||
import { renderAlarmDateCell, renderAlarmTypeCell, renderDeviceTypeCell, renderFaultLevelCell } from '@/helpers';
|
||||
import { useAlarmStore, useDeviceStore, usePermissionStore } from '@/stores';
|
||||
import { useDeviceStore, usePermissionStore, useUnreadStore } from '@/stores';
|
||||
import { downloadByData, parseErrorFeedback } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import { watchDebounced } from '@vueuse/core';
|
||||
@@ -37,20 +37,24 @@ interface SearchFields extends PageQueryExtra<NdmDeviceAlarmLog> {
|
||||
alarmType_in: string[];
|
||||
faultLevel_in: string[];
|
||||
alarmDate: [number, number];
|
||||
alarmCategory: string;
|
||||
alarmConfirm: string;
|
||||
}
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const deviceStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(deviceStore);
|
||||
const alarmStore = useAlarmStore();
|
||||
const { unreadAlarmCount } = storeToRefs(alarmStore);
|
||||
const permissionStore = usePermissionStore();
|
||||
const { permissions } = storeToRefs(permissionStore);
|
||||
|
||||
const stations = computed(() => permissionStore.stations.VIEW ?? []);
|
||||
|
||||
const deviceStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(deviceStore);
|
||||
|
||||
const unreadStore = useUnreadStore();
|
||||
const { unreadAlarmCount } = storeToRefs(unreadStore);
|
||||
|
||||
const stationSelectOptions = computed<SelectOption[]>(() => {
|
||||
return stations.value.map((station) => ({
|
||||
label: station.name,
|
||||
@@ -113,6 +117,8 @@ const searchFields = ref<SearchFields>({
|
||||
alarmType_in: [],
|
||||
faultLevel_in: [],
|
||||
alarmDate: [dayjs().startOf('date').valueOf(), dayjs().endOf('date').valueOf()],
|
||||
alarmCategory: '',
|
||||
alarmConfirm: '',
|
||||
});
|
||||
const resetSearchFields = () => {
|
||||
searchFields.value = {
|
||||
@@ -122,6 +128,8 @@ const resetSearchFields = () => {
|
||||
alarmType_in: [],
|
||||
faultLevel_in: [],
|
||||
alarmDate: [dayjs().startOf('date').valueOf(), dayjs().endOf('date').valueOf()],
|
||||
alarmCategory: '',
|
||||
alarmConfirm: '',
|
||||
};
|
||||
};
|
||||
const getExtraFields = (): PageQueryExtra<NdmDeviceAlarmLog> => {
|
||||
@@ -236,7 +244,10 @@ const { mutate: getTableData, isPending: tableLoading } = useMutation({
|
||||
|
||||
const res = await pageDeviceAlarmLogApi(
|
||||
{
|
||||
model: {},
|
||||
model: {
|
||||
alarmCategory: searchFields.value.alarmCategory || undefined,
|
||||
alarmConfirm: searchFields.value.alarmConfirm || undefined,
|
||||
},
|
||||
extra: getExtraFields(),
|
||||
current: pagination.page ?? 1,
|
||||
size: pagination.pageSize ?? DEFAULT_PAGE_SIZE,
|
||||
@@ -344,6 +355,28 @@ onBeforeUnmount(() => {
|
||||
<NFormItemGi span="1" label="告警级别" label-placement="left">
|
||||
<NSelect multiple clearable placeholder="请选择告警级别" v-model:value="searchFields.faultLevel_in" :options="faultLevelSelectOptions" />
|
||||
</NFormItemGi>
|
||||
<NFormItemGi span="1" label="恢复状态" label-placement="left">
|
||||
<NSelect
|
||||
clearable
|
||||
placeholder="请选择恢复状态"
|
||||
v-model:value="searchFields.alarmCategory"
|
||||
:options="[
|
||||
{ label: '未恢复', value: '1' },
|
||||
{ label: '已恢复', value: '2' },
|
||||
]"
|
||||
/>
|
||||
</NFormItemGi>
|
||||
<NFormItemGi span="1" label="确认状态" label-placement="left">
|
||||
<NSelect
|
||||
clearable
|
||||
placeholder="请选择确认状态"
|
||||
v-model:value="searchFields.alarmConfirm"
|
||||
:options="[
|
||||
{ label: '未确认', value: '2' },
|
||||
{ label: '已确认', value: '1' },
|
||||
]"
|
||||
/>
|
||||
</NFormItemGi>
|
||||
<NFormItemGi span="1" label="告警时间" label-placement="left">
|
||||
<NDatePicker v-model:value="searchFields.alarmDate" type="datetimerange" />
|
||||
</NFormItemGi>
|
||||
|
||||
@@ -8,7 +8,6 @@ import { NLayout, NLayoutContent, NLayoutSider } from 'naive-ui';
|
||||
import { computed, provide, ref } from 'vue';
|
||||
|
||||
const permissionStore = usePermissionStore();
|
||||
|
||||
const stations = computed(() => permissionStore.stations.VIEW ?? []);
|
||||
|
||||
const selectedStation = ref<Station>();
|
||||
|
||||
@@ -22,8 +22,7 @@ const { mutate: login, isPending: loading } = useMutation({
|
||||
mutationFn: async (params: LoginParams) => {
|
||||
const userStore = useUserStore();
|
||||
await userStore.userLogin(params);
|
||||
const [err] = await userClient.post<void>(`/api/ndm/ndmKeepAlive/verify`, {}, { timeout: 5000 });
|
||||
if (err) throw err;
|
||||
await userStore.userGetInfo();
|
||||
},
|
||||
onSuccess: () => {
|
||||
window.$message.success('登录成功');
|
||||
|
||||
@@ -4,27 +4,48 @@ import { AlarmDetailModal, DeviceDetailModal, DeviceParamConfigModal, IcmpExport
|
||||
import { useBatchActions, useLineDevicesQuery } from '@/composables';
|
||||
import { useAlarmStore, useDeviceStore, usePermissionStore, useSettingStore } from '@/stores';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import { useElementSize } from '@vueuse/core';
|
||||
import { isCancel } from 'axios';
|
||||
import { NButton, NButtonGroup, NCheckbox, NFlex, NGrid, NGridItem, NScrollbar } from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed, ref, useTemplateRef } from 'vue';
|
||||
|
||||
const settingStore = useSettingStore();
|
||||
const { stationGridCols: stationGridColumns } = storeToRefs(settingStore);
|
||||
const { stationGridCols } = storeToRefs(settingStore);
|
||||
|
||||
const permissionStore = usePermissionStore();
|
||||
const stations = computed(() => permissionStore.stations.VIEW ?? []);
|
||||
|
||||
const deviceStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(deviceStore);
|
||||
|
||||
const alarmStore = useAlarmStore();
|
||||
const { lineAlarms } = storeToRefs(alarmStore);
|
||||
const permissionStore = usePermissionStore();
|
||||
|
||||
const stations = computed(() => permissionStore.stations.VIEW ?? []);
|
||||
const STATION_CARD_MIN_WIDTH = 230;
|
||||
const STATION_GRID_PADDING = 8;
|
||||
const STATION_GRID_GAP = 6;
|
||||
const STATION_GRID_REF_NAME = 'stationGridRef';
|
||||
const stationGridRef = useTemplateRef<HTMLDivElement>(STATION_GRID_REF_NAME);
|
||||
const { width: stationGridWidth } = useElementSize(stationGridRef);
|
||||
// 计算合适的车站布局列数
|
||||
const actualStationGridColumns = computed(() => {
|
||||
const currentStationCardWidth = (stationGridWidth.value - STATION_GRID_PADDING * 2 - (stationGridCols.value - 1) * STATION_GRID_GAP) / stationGridCols.value;
|
||||
// 当卡片宽度大于最小宽度时,说明用户的设置没有问题,直接返回列数
|
||||
if (currentStationCardWidth > STATION_CARD_MIN_WIDTH) return stationGridCols.value;
|
||||
// 否则,说明用户的设置不合适,需要根据当前布局宽度重新计算列数
|
||||
return Math.floor((stationGridWidth.value - STATION_GRID_PADDING * 2 + STATION_GRID_GAP) / STATION_CARD_MIN_WIDTH);
|
||||
});
|
||||
|
||||
const showIcmpExportModal = ref(false);
|
||||
const showRecordCheckExportModal = ref(false);
|
||||
|
||||
const abortController = ref(new AbortController());
|
||||
|
||||
const { batchActions, selectedAction, selectableStations, stationSelection, toggleSelectAction, toggleSelectAllStations, confirmAction, cancelAction } = useBatchActions(stations, abortController);
|
||||
const { batchActions, selectedAction, selectableStations, stationSelection, selectionProps, toggleSelectAction, toggleSelectAllStations, confirmAction, cancelAction } = useBatchActions(
|
||||
stations,
|
||||
abortController,
|
||||
);
|
||||
|
||||
const { refetch: refetchLineDevicesQuery } = useLineDevicesQuery();
|
||||
|
||||
@@ -60,7 +81,7 @@ const { mutate: syncCamera, isPending: cameraSyncing } = useMutation({
|
||||
window.$notification.info({
|
||||
title: '摄像机同步结果',
|
||||
content: notices.join(','),
|
||||
duration: 3000,
|
||||
duration: 10000,
|
||||
});
|
||||
if (successRequests.length > 0) {
|
||||
// 摄像机同步后,需要重新查询一次设备
|
||||
@@ -102,7 +123,7 @@ const { mutate: syncNvrChannels, isPending: nvrChannelsSyncing } = useMutation({
|
||||
window.$notification.info({
|
||||
title: '录像机通道同步结果',
|
||||
content: notices.join(','),
|
||||
duration: 3000,
|
||||
duration: 10000,
|
||||
});
|
||||
cancelAction();
|
||||
},
|
||||
@@ -152,33 +173,35 @@ const onClickDetail: StationCardProps['onClickDetail'] = (type, station) => {
|
||||
<template>
|
||||
<NScrollbar content-style="padding-right: 8px" style="width: 100%; height: 100%">
|
||||
<!-- 工具栏 -->
|
||||
<NFlex align="center" style="padding: 8px 8px 0 8px">
|
||||
<NFlex align="center" :style="{ padding: `${STATION_GRID_PADDING}px ${STATION_GRID_PADDING}px 0 ${STATION_GRID_PADDING}px` }">
|
||||
<NButtonGroup>
|
||||
<template v-for="batchAction in batchActions" :key="batchAction.key">
|
||||
<NButton :secondary="!batchAction.active" :focusable="false" @click="() => toggleSelectAction(batchAction)">{{ batchAction.label }}</NButton>
|
||||
</template>
|
||||
</NButtonGroup>
|
||||
<template v-if="selectedAction">
|
||||
<NCheckbox label="全选" :checked="selectableStations.length === Object.keys(stationSelection).length" @update:checked="toggleSelectAllStations" />
|
||||
<NCheckbox label="全选" :disabled="selectionProps.disabled" :checked="selectionProps.checked" :indeterminate="selectionProps.indeterminate" @update:checked="toggleSelectAllStations" />
|
||||
<NButton tertiary size="small" type="primary" :focusable="false" :loading="confirming" @click="onClickConfirmAction">确定</NButton>
|
||||
<NButton tertiary size="small" type="tertiary" :focusable="false" @click="cancelAction">取消</NButton>
|
||||
</template>
|
||||
</NFlex>
|
||||
|
||||
<!-- 车站 -->
|
||||
<NGrid :cols="stationGridColumns" :x-gap="6" :y-gap="6" style="padding: 8px">
|
||||
<NGridItem v-for="station in stations" :key="station.code">
|
||||
<StationCard
|
||||
:station="station"
|
||||
:devices="lineDevices[station.code] ?? initStationDevices()"
|
||||
:alarms="lineAlarms[station.code] ?? initStationAlarms()"
|
||||
:selectable="!!selectableStations.find((selectable) => selectable.code === station.code)"
|
||||
v-model:selected="stationSelection[station.code]"
|
||||
@click-detail="onClickDetail"
|
||||
@click-config="onClickConfig"
|
||||
/>
|
||||
</NGridItem>
|
||||
</NGrid>
|
||||
<div :ref="STATION_GRID_REF_NAME">
|
||||
<NGrid :cols="actualStationGridColumns" :x-gap="STATION_GRID_GAP" :y-gap="STATION_GRID_GAP" :style="{ padding: `${STATION_GRID_PADDING}px` }">
|
||||
<NGridItem v-for="station in stations" :key="station.code">
|
||||
<StationCard
|
||||
:station="station"
|
||||
:devices="lineDevices[station.code] ?? initStationDevices()"
|
||||
:alarms="lineAlarms[station.code] ?? initStationAlarms()"
|
||||
:selectable="!!selectableStations.find((selectable) => selectable.code === station.code)"
|
||||
v-model:selected="stationSelection[station.code]"
|
||||
@click-detail="onClickDetail"
|
||||
@click-config="onClickConfig"
|
||||
/>
|
||||
</NGridItem>
|
||||
</NGrid>
|
||||
</div>
|
||||
</NScrollbar>
|
||||
|
||||
<IcmpExportModal v-model:show="showIcmpExportModal" :stations="stations.filter((station) => stationSelection[station.code])" @after-leave="cancelAction" />
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { initStationAlarms, type LineAlarms, type NdmDeviceAlarmLogResultVO, type Station, type StationAlarms } from '@/apis';
|
||||
import { type LineAlarms, type Station, type StationAlarms } from '@/apis';
|
||||
import { NDM_ALARM_STORE_ID } from '@/constants';
|
||||
import { tryGetDeviceType } from '@/enums';
|
||||
import { defineStore } from 'pinia';
|
||||
import { computed, shallowRef, triggerRef } from 'vue';
|
||||
import { shallowRef, triggerRef } from 'vue';
|
||||
|
||||
export const useAlarmStore = defineStore(
|
||||
NDM_ALARM_STORE_ID,
|
||||
@@ -18,42 +17,10 @@ export const useAlarmStore = defineStore(
|
||||
triggerRef(lineAlarms);
|
||||
};
|
||||
|
||||
// 全线所有车站的未读告警 (来自stomp订阅)
|
||||
const unreadLineAlarms = shallowRef<LineAlarms>({});
|
||||
const unreadAlarmCount = computed(() => {
|
||||
let count = 0;
|
||||
Object.values(unreadLineAlarms.value).forEach((stationAlarms) => {
|
||||
count += stationAlarms['unclassified'].length;
|
||||
});
|
||||
return count;
|
||||
});
|
||||
const pushUnreadAlarm = (alarm: NdmDeviceAlarmLogResultVO) => {
|
||||
const stationCode = alarm.stationCode;
|
||||
if (!stationCode) return;
|
||||
if (!unreadLineAlarms.value[stationCode]) {
|
||||
unreadLineAlarms.value[stationCode] = initStationAlarms();
|
||||
}
|
||||
const deviceType = tryGetDeviceType(alarm.deviceType);
|
||||
if (!deviceType) return;
|
||||
const stationAlarms = unreadLineAlarms.value[stationCode];
|
||||
stationAlarms[deviceType].push(alarm);
|
||||
stationAlarms['unclassified'].push(alarm);
|
||||
triggerRef(unreadLineAlarms);
|
||||
};
|
||||
const clearUnreadAlarms = () => {
|
||||
unreadLineAlarms.value = {};
|
||||
triggerRef(unreadLineAlarms);
|
||||
};
|
||||
|
||||
return {
|
||||
lineAlarms,
|
||||
setLineAlarms,
|
||||
setStationAlarms,
|
||||
|
||||
unreadLineAlarms,
|
||||
unreadAlarmCount,
|
||||
pushUnreadAlarm,
|
||||
clearUnreadAlarms,
|
||||
};
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export * from './alarm';
|
||||
export * from './device';
|
||||
export * from './permission';
|
||||
export * from './polling';
|
||||
export * from './setting';
|
||||
export * from './station';
|
||||
export * from './unread';
|
||||
export * from './user';
|
||||
|
||||
@@ -11,22 +11,27 @@ type Permissions = Record<Station['code'], PermissionType[]>;
|
||||
export const usePermissionStore = defineStore(
|
||||
NDM_PERMISSION_STORE_ID,
|
||||
() => {
|
||||
const permRecords = ref<NdmPermissionResultVO[]>([]);
|
||||
const stationStore = useStationStore();
|
||||
|
||||
const permissionRecords = ref<NdmPermissionResultVO[] | null>(null);
|
||||
|
||||
const permissions = computed<Permissions>(() => {
|
||||
const stationStore = useStationStore();
|
||||
|
||||
const result: Permissions = {};
|
||||
|
||||
const records = permissionRecords.value;
|
||||
|
||||
// 如果权限记录不存在,则不做权限配置
|
||||
if (!records) return result;
|
||||
|
||||
// 如果该用户没有任何权限记录,则开放所有权限,否则根据记录配置权限
|
||||
if (permRecords.value.length === 0) {
|
||||
if (records.length === 0) {
|
||||
stationStore.stations.forEach((station) => {
|
||||
result[station.code] = [...objectEntries(PERMISSION_TYPE_NAMES).map(([permType]) => permType)];
|
||||
});
|
||||
} else {
|
||||
stationStore.stations.forEach((station) => {
|
||||
result[station.code] = [];
|
||||
const stationPermRecords = permRecords.value.filter((record) => record.stationCode === station.code);
|
||||
const stationPermRecords = records.filter((record) => record.stationCode === station.code);
|
||||
if (stationPermRecords.length === 0) return;
|
||||
stationPermRecords.forEach(({ type: permType }) => {
|
||||
if (!permType) return;
|
||||
@@ -40,7 +45,6 @@ export const usePermissionStore = defineStore(
|
||||
|
||||
// 按权限对车站进行分类
|
||||
const stations = computed(() => {
|
||||
const stationStore = useStationStore();
|
||||
const result: Partial<Record<PermissionType, Station[]>> = {};
|
||||
// 按原始的车站顺序进行遍历,保持显示顺序不变
|
||||
stationStore.stations.forEach((station) => {
|
||||
@@ -55,11 +59,11 @@ export const usePermissionStore = defineStore(
|
||||
});
|
||||
|
||||
const setPermRecords = (records: NdmPermissionResultVO[]) => {
|
||||
permRecords.value = records;
|
||||
permissionRecords.value = records;
|
||||
};
|
||||
|
||||
return {
|
||||
permRecords,
|
||||
permissionRecords,
|
||||
|
||||
permissions,
|
||||
stations,
|
||||
|
||||
@@ -1,36 +1,72 @@
|
||||
import { NDM_SETTING_STORE_ID } from '@/constants';
|
||||
import { useUserStore } from './user';
|
||||
import { LINE_ALARMS_QUERY_KEY, LINE_DEVICES_QUERY_KEY, LINE_STATIONS_QUERY_KEY, NDM_SETTING_STORE_ID } from '@/constants';
|
||||
import router from '@/router';
|
||||
import { useQueryClient } from '@tanstack/vue-query';
|
||||
import { darkTheme, lightTheme } from 'naive-ui';
|
||||
import { defineStore } from 'pinia';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useUserStore } from './user';
|
||||
import router from '@/router';
|
||||
|
||||
export const useSettingStore = defineStore(
|
||||
NDM_SETTING_STORE_ID,
|
||||
() => {
|
||||
const darkThemeEnabled = ref(true);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// 主题设置
|
||||
const darkMode = ref(true);
|
||||
const themeMode = computed(() => {
|
||||
return darkThemeEnabled.value ? darkTheme : lightTheme;
|
||||
return darkMode.value ? darkTheme : lightTheme;
|
||||
});
|
||||
|
||||
// 布局设置
|
||||
const menuCollpased = ref(false);
|
||||
|
||||
const stationGridCols = ref(6);
|
||||
|
||||
const debugModeEnabled = ref(false);
|
||||
const enableDebugMode = () => {
|
||||
debugModeEnabled.value = true;
|
||||
};
|
||||
const disableDebugMode = () => {
|
||||
debugModeEnabled.value = false;
|
||||
};
|
||||
// 调试模式
|
||||
const debugMode = ref(false);
|
||||
/* 数据设置 */
|
||||
// 显示设备原始数据
|
||||
const showDeviceRawData = ref(false);
|
||||
/* 网络设置 */
|
||||
// 轮询车站
|
||||
const pollingStations = ref(true);
|
||||
// 主动请求
|
||||
const activeRequests = ref(true);
|
||||
// 订阅消息
|
||||
const subscribeMessages = ref(true);
|
||||
// 模拟用户
|
||||
const mockUser = ref(false);
|
||||
/* 数据库设置 */
|
||||
// 使用本地数据库
|
||||
const useLocalDB = ref(false);
|
||||
|
||||
// 离线开发模式
|
||||
// 控制 版本轮询 stomp连接 app-layout中的自动getUserInfo
|
||||
const offlineDev = ref(false);
|
||||
watch(offlineDev, (newValue, oldValue) => {
|
||||
// 如果启用离线开发模式且当前未登录 自动填写token以绕过路由守卫并跳过登录页
|
||||
watch(debugMode, (newValue, oldValue) => {
|
||||
// 监听关闭调试模式
|
||||
if (oldValue && !newValue) {
|
||||
showDeviceRawData.value = false;
|
||||
pollingStations.value = true;
|
||||
activeRequests.value = true;
|
||||
subscribeMessages.value = false;
|
||||
mockUser.value = false;
|
||||
useLocalDB.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
watch(pollingStations, (newValue, oldValue) => {
|
||||
// 监听关闭车站轮询
|
||||
if (oldValue && !newValue) {
|
||||
queryClient.cancelQueries({ queryKey: [LINE_STATIONS_QUERY_KEY] });
|
||||
queryClient.cancelQueries({ queryKey: [LINE_DEVICES_QUERY_KEY] });
|
||||
queryClient.cancelQueries({ queryKey: [LINE_ALARMS_QUERY_KEY] });
|
||||
queryClient.invalidateQueries({ queryKey: [LINE_STATIONS_QUERY_KEY] });
|
||||
queryClient.invalidateQueries({ queryKey: [LINE_DEVICES_QUERY_KEY] });
|
||||
queryClient.invalidateQueries({ queryKey: [LINE_ALARMS_QUERY_KEY] });
|
||||
}
|
||||
});
|
||||
|
||||
watch(mockUser, (newValue, oldValue) => {
|
||||
// 监听启用模拟用户
|
||||
if (!oldValue && newValue) {
|
||||
// 如果启当前未登录,填写token以绕过路由守卫
|
||||
const userStore = useUserStore();
|
||||
if (!userStore.userLoginResult) {
|
||||
userStore.userLoginResult = {
|
||||
@@ -42,9 +78,11 @@ export const useSettingStore = defineStore(
|
||||
expiration: '',
|
||||
};
|
||||
}
|
||||
// 如果token为空,填写token
|
||||
if (!userStore.userLoginResult.token) {
|
||||
userStore.userLoginResult.token = 'test';
|
||||
}
|
||||
// 如果用户信息为空,填写用户信息
|
||||
if (!userStore.userInfo) {
|
||||
userStore.userInfo = {
|
||||
id: '2',
|
||||
@@ -55,35 +93,42 @@ export const useSettingStore = defineStore(
|
||||
tenantId: '1',
|
||||
};
|
||||
}
|
||||
// 如果当前路由为登录页,跳转到首页
|
||||
if (router.currentRoute.value.path === '/login') {
|
||||
router.push({ path: '/' });
|
||||
}
|
||||
// 开启模拟用户时,也开启调试模式,但关闭其他的网络设置
|
||||
debugMode.value = true;
|
||||
pollingStations.value = false;
|
||||
activeRequests.value = false;
|
||||
subscribeMessages.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
darkThemeEnabled,
|
||||
darkMode,
|
||||
themeMode,
|
||||
|
||||
menuCollpased,
|
||||
|
||||
stationGridCols,
|
||||
|
||||
debugModeEnabled,
|
||||
enableDebugMode,
|
||||
disableDebugMode,
|
||||
|
||||
offlineDev,
|
||||
debugMode,
|
||||
showDeviceRawData,
|
||||
pollingStations,
|
||||
activeRequests,
|
||||
subscribeMessages,
|
||||
mockUser,
|
||||
useLocalDB,
|
||||
};
|
||||
},
|
||||
{
|
||||
persist: [
|
||||
{
|
||||
omit: ['debugModeEnabled'],
|
||||
omit: ['showDeviceRawData'],
|
||||
storage: window.localStorage,
|
||||
},
|
||||
{
|
||||
pick: ['debugModeEnabled'],
|
||||
pick: ['showDeviceRawData'],
|
||||
storage: window.sessionStorage,
|
||||
},
|
||||
],
|
||||
|
||||
44
src/stores/unread.ts
Normal file
44
src/stores/unread.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { initStationAlarms, type LineAlarms, type NdmDeviceAlarmLogResultVO } from '@/apis';
|
||||
import { NDM_UNREAD_STORE_ID } from '@/constants';
|
||||
import { tryGetDeviceType } from '@/enums';
|
||||
import { defineStore } from 'pinia';
|
||||
import { computed, shallowRef, triggerRef } from 'vue';
|
||||
|
||||
export const useUnreadStore = defineStore(NDM_UNREAD_STORE_ID, () => {
|
||||
// 全线所有车站的未读告警 (来自stomp订阅)
|
||||
const unreadLineAlarms = shallowRef<LineAlarms>({});
|
||||
const unreadAlarmCount = computed(() => {
|
||||
let count = 0;
|
||||
Object.values(unreadLineAlarms.value).forEach((stationAlarms) => {
|
||||
count += stationAlarms['unclassified'].length;
|
||||
});
|
||||
return count;
|
||||
});
|
||||
|
||||
const pushUnreadAlarm = (alarm: NdmDeviceAlarmLogResultVO) => {
|
||||
const stationCode = alarm.stationCode;
|
||||
if (!stationCode) return;
|
||||
if (!unreadLineAlarms.value[stationCode]) {
|
||||
unreadLineAlarms.value[stationCode] = initStationAlarms();
|
||||
}
|
||||
const deviceType = tryGetDeviceType(alarm.deviceType);
|
||||
if (!deviceType) return;
|
||||
const stationAlarms = unreadLineAlarms.value[stationCode];
|
||||
stationAlarms[deviceType].push(alarm);
|
||||
stationAlarms['unclassified'].push(alarm);
|
||||
triggerRef(unreadLineAlarms);
|
||||
};
|
||||
|
||||
const clearUnreadAlarms = () => {
|
||||
unreadLineAlarms.value = {};
|
||||
triggerRef(unreadLineAlarms);
|
||||
};
|
||||
|
||||
return {
|
||||
unreadLineAlarms,
|
||||
unreadAlarmCount,
|
||||
|
||||
pushUnreadAlarm,
|
||||
clearUnreadAlarms,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user