refactor: 重构项目结构
- 优化 `车站-设备-告警` 轮询机制 - 改进设备卡片的布局 - 支持修改设备 - 告警轮询中获取完整告警数据 - 车站告警详情支持导出完整的 `今日告警列表` - 支持将状态持久化到 `IndexedDB` - 新增轮询控制 (调试模式) - 新增离线开发模式 (调试模式) - 新增 `IndexedDB` 数据控制 (调试模式)
This commit is contained in:
2
src/apis/client/index.ts
Normal file
2
src/apis/client/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './ndm-client';
|
||||
export * from './user-client';
|
||||
32
src/apis/client/ndm-client.ts
Normal file
32
src/apis/client/ndm-client.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { useUserStore } from '@/stores';
|
||||
import { getAppEnvConfig, RequestClient } from '@/utils';
|
||||
import type { AxiosError } from 'axios';
|
||||
|
||||
export const ndmClient = new RequestClient({
|
||||
requestInterceptor: async (config) => {
|
||||
const userStore = useUserStore();
|
||||
const { lampAuthorization, lampClientId, lampClientSecret } = getAppEnvConfig();
|
||||
const newAuthorization = window.btoa(`${lampClientId}:${lampClientSecret}`);
|
||||
const authorization = lampAuthorization.trim() !== '' ? lampAuthorization : newAuthorization;
|
||||
config.headers.set('accept-language', 'zh-CN,zh;q=0.9');
|
||||
config.headers.set('accept', 'application/json, text/plain, */*');
|
||||
config.headers.set('Applicationid', '');
|
||||
config.headers.set('Tenantid', '1');
|
||||
config.headers.set('Authorization', authorization);
|
||||
const staticCode = config.url?.split('/api').at(0)?.split('/').at(-1) ?? '';
|
||||
config.headers.set('token', userStore.lampLoginResultRecord?.[staticCode]?.token ?? '');
|
||||
return config;
|
||||
},
|
||||
responseErrorInterceptor: async (error) => {
|
||||
const err = error as AxiosError;
|
||||
if (err.response?.status === 401) {
|
||||
// 当车站请求由于token时效而失败时,需要重新登录车站获取token,然后重新请求
|
||||
const stationCode = err.config?.url?.split('/api').at(0)?.split('/').at(-1) ?? '';
|
||||
const userStore = useUserStore();
|
||||
await userStore.lampLogin(stationCode);
|
||||
error.config.headers.token = userStore.lampLoginResultRecord?.[stationCode]?.token ?? '';
|
||||
return ndmClient.requestInstance(error.config);
|
||||
}
|
||||
return Promise.reject(error);
|
||||
},
|
||||
});
|
||||
33
src/apis/client/user-client.ts
Normal file
33
src/apis/client/user-client.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import router from '@/router';
|
||||
import { useUserStore } from '@/stores';
|
||||
import { getAppEnvConfig, RequestClient } from '@/utils';
|
||||
import type { AxiosError } from 'axios';
|
||||
|
||||
export const userClient = new RequestClient({
|
||||
requestInterceptor: (config) => {
|
||||
const userStore = useUserStore();
|
||||
const { lampAuthorization, lampClientId, lampClientSecret } = getAppEnvConfig();
|
||||
const newAuthorization = window.btoa(`${lampClientId}:${lampClientSecret}`);
|
||||
const authorization = lampAuthorization.trim() !== '' ? lampAuthorization : newAuthorization;
|
||||
config.headers.set('accept-language', 'zh-CN,zh;q=0.9');
|
||||
config.headers.set('accept', 'application/json, text/plain, */*');
|
||||
config.headers.set('Applicationid', '');
|
||||
config.headers.set('Tenantid', '1');
|
||||
config.headers.set('Authorization', authorization);
|
||||
config.headers.set('token', userStore.userLoginResult?.token ?? '');
|
||||
return config;
|
||||
},
|
||||
responseInterceptor: (response) => {
|
||||
return response;
|
||||
},
|
||||
responseErrorInterceptor: (error) => {
|
||||
const err = error as AxiosError;
|
||||
if (err.response?.status === 401) {
|
||||
window.$message.error('登录超时,请重新登录');
|
||||
const userStore = useUserStore();
|
||||
userStore.resetStore();
|
||||
router.push({ path: '/login' });
|
||||
}
|
||||
return Promise.reject(error);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user