optimize(projects): 优化系统代码质量
This commit is contained in:
@@ -21,7 +21,7 @@ const columns = defineModel<NaiveUI.TableColumnCheck[]>('columns', {
|
||||
{{ $t('common.columnSetting') }}
|
||||
</NButton>
|
||||
</template>
|
||||
<VueDraggable v-model="columns" :animation="150" filter=".none_draggable">
|
||||
<VueDraggable v-model="columns" :animation="150" filter=".none_draggable" class="table-column-setting-list">
|
||||
<div
|
||||
v-for="item in columns"
|
||||
:key="item.key"
|
||||
@@ -40,4 +40,15 @@ const columns = defineModel<NaiveUI.TableColumnCheck[]>('columns', {
|
||||
</NPopover>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
<style scoped lang="scss">
|
||||
.table-column-setting-list {
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none;
|
||||
}
|
||||
|
||||
.table-column-setting-list::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -60,7 +60,7 @@ export function fetchGetTenantPackageMenuTreeSelect(packageId: CommonType.IdType
|
||||
});
|
||||
}
|
||||
|
||||
// 级联删除菜单
|
||||
/** 级联删除菜单 */
|
||||
export function fetchCascadeDeleteMenu(menuIds: CommonType.IdType[]) {
|
||||
return request<boolean>({
|
||||
url: `/system/menu/cascade/${menuIds.join(',')}`,
|
||||
|
||||
@@ -17,7 +17,7 @@ export function fetchBatchDeleteOss(ossIds: CommonType.IdType[]) {
|
||||
});
|
||||
}
|
||||
|
||||
// 查询OSS对象基于id串
|
||||
/** 查询OSS对象基于id串 */
|
||||
export function fetchGetOssListByIds(ossIds: CommonType.IdType[]) {
|
||||
return request<Api.System.Oss[]>({
|
||||
url: `/resource/oss/listByIds/${ossIds.join(',')}`,
|
||||
@@ -25,7 +25,7 @@ export function fetchGetOssListByIds(ossIds: CommonType.IdType[]) {
|
||||
});
|
||||
}
|
||||
|
||||
// 上传文件
|
||||
/** 上传文件 */
|
||||
export function fetchUploadFile(file: File) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
@@ -56,6 +56,14 @@ export function fetchSyncTenantPackage(params: Api.System.TenantPackageSyncParam
|
||||
});
|
||||
}
|
||||
|
||||
/** 同步租户参数配置 */
|
||||
export function fetchSyncTenantConfig() {
|
||||
return request<boolean>({
|
||||
url: '/system/tenant/syncTenantConfig',
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
/** 动态切换租户 */
|
||||
export function fetchChangeTenant(tenantId: CommonType.IdType) {
|
||||
return request<boolean>({
|
||||
|
||||
@@ -127,6 +127,8 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
}
|
||||
// @ts-expect-error no hidden field
|
||||
route.meta.hideInMenu = route.hidden;
|
||||
// @ts-expect-error route.meta.activeMenu is activeMenu type
|
||||
route.meta.activeMenu = route.meta?.activeMenu?.substring(1);
|
||||
if (route.meta.hideInMenu && parent && !route.meta.activeMenu) {
|
||||
// @ts-expect-error parent.name is activeMenu type
|
||||
route.meta.activeMenu = parent.name;
|
||||
@@ -142,10 +144,12 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
|
||||
route.name = random;
|
||||
route.component = 'layout.base$view.iframe-page';
|
||||
} else {
|
||||
try {
|
||||
route.props = {
|
||||
// @ts-expect-error no query field
|
||||
url: route.query
|
||||
url: JSON.parse(route.query)?.url
|
||||
};
|
||||
} catch {}
|
||||
}
|
||||
route.component = parent && !isExternalLink ? 'view.iframe-page' : 'layout.base$view.iframe-page';
|
||||
} else if (!isLayout && !isParentLayout) {
|
||||
|
||||
+6
-2
@@ -4,8 +4,12 @@ import useNoticeStore from '@/store/modules/notice';
|
||||
import { $t } from '@/locales';
|
||||
import { localStg } from './storage';
|
||||
|
||||
// 初始化
|
||||
export const initSSE = (url: any) => {
|
||||
/**
|
||||
* 初始化 SSE
|
||||
*
|
||||
* @param url - SSE 地址
|
||||
*/
|
||||
export const initSSE = (url: string) => {
|
||||
const token = localStg.get('token');
|
||||
if (import.meta.env.VITE_APP_SSE === 'N' || !token) {
|
||||
return;
|
||||
|
||||
+37
-121
@@ -1,144 +1,60 @@
|
||||
/**
|
||||
* socket 通信
|
||||
*
|
||||
* @module initWebSocket 初始化
|
||||
* @module websocketonopen 连接成功
|
||||
* @module websocketonerror 连接失败
|
||||
* @module websocketclose 断开连接
|
||||
* @module resetHeart 重置心跳
|
||||
* @module sendSocketHeart 心跳发送
|
||||
* @module reconnect 重连
|
||||
* @module sendMsg 发送数据
|
||||
* @module websocketonmessage 接收数据
|
||||
* @module test 测试收到消息传递
|
||||
* @param {any} url socket地址
|
||||
* @param {any} websocket websocket 实例
|
||||
* @param {any} heartTime 心跳定时器实例
|
||||
* @param {number} socketHeart 心跳次数
|
||||
* @param {number} HeartTimeOut 心跳超时时间
|
||||
* @param {number} socketError 错误次数
|
||||
*/
|
||||
|
||||
import { useWebSocket } from '@vueuse/core';
|
||||
import useNoticeStore from '@/store/modules/notice';
|
||||
import { localStg } from './storage';
|
||||
|
||||
let socketUrl: any = ''; // socket地址
|
||||
let websocket: any = null; // websocket 实例
|
||||
let heartTime: any = null; // 心跳定时器实例
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
let socketHeart = 0; // 心跳次数
|
||||
const HeartTimeOut = 10000; // 心跳超时时间 10000 = 10s
|
||||
let socketError = 0; // 错误次数
|
||||
|
||||
// 初始化socket
|
||||
export function initWebSocket(url: any) {
|
||||
/**
|
||||
* 初始化 WebSocket
|
||||
*
|
||||
* @param url - WebSocket 地址
|
||||
*/
|
||||
export const initWebSocket = (url: string) => {
|
||||
const token = localStg.get('token');
|
||||
if (import.meta.env.VITE_APP_WEBSOCKET === 'N' || !token) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
socketUrl = url;
|
||||
// 初始化 websocket
|
||||
websocket = new WebSocket(`${url}?Authorization=Bearer ${token}&clientid=${import.meta.env.VITE_APP_CLIENT_ID}`);
|
||||
websocketonopen();
|
||||
websocketonmessage();
|
||||
websocketonerror();
|
||||
websocketclose();
|
||||
sendSocketHeart();
|
||||
return websocket;
|
||||
}
|
||||
|
||||
// socket 连接成功
|
||||
export function websocketonopen() {
|
||||
websocket.onopen = () => {
|
||||
const socketUrl = `${url}?Authorization=Bearer ${token}&clientid=${import.meta.env.VITE_APP_CLIENT_ID}`;
|
||||
useWebSocket(socketUrl, {
|
||||
autoReconnect: {
|
||||
// 重连最大次数
|
||||
retries: 3,
|
||||
// 重连间隔
|
||||
delay: 1000,
|
||||
onFailed() {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('连接 websocket 成功');
|
||||
resetHeart();
|
||||
};
|
||||
}
|
||||
|
||||
// socket 连接失败
|
||||
export function websocketonerror() {
|
||||
websocket.onerror = (e: any) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('连接 websocket 失败', e);
|
||||
};
|
||||
}
|
||||
|
||||
// socket 断开链接
|
||||
export function websocketclose() {
|
||||
websocket.onclose = (e: any) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('断开连接', e);
|
||||
};
|
||||
}
|
||||
|
||||
// socket 重置心跳
|
||||
export function resetHeart() {
|
||||
socketHeart = 0;
|
||||
socketError = 0;
|
||||
clearInterval(heartTime);
|
||||
sendSocketHeart();
|
||||
}
|
||||
|
||||
// socket心跳发送
|
||||
export function sendSocketHeart() {
|
||||
heartTime = setInterval(() => {
|
||||
// 如果连接正常则发送心跳
|
||||
if (websocket.readyState === 1) {
|
||||
// if (socketHeart <= 30) {
|
||||
websocket.send(
|
||||
JSON.stringify({
|
||||
type: 'ping'
|
||||
})
|
||||
);
|
||||
socketHeart += 1;
|
||||
} else {
|
||||
// 重连
|
||||
reconnect();
|
||||
console.warn('WebSocket 重连失败');
|
||||
}
|
||||
}, HeartTimeOut);
|
||||
}
|
||||
|
||||
// socket重连
|
||||
export function reconnect() {
|
||||
if (socketError <= 2) {
|
||||
clearInterval(heartTime);
|
||||
initWebSocket(socketUrl);
|
||||
socketError += 1;
|
||||
},
|
||||
heartbeat: {
|
||||
message: JSON.stringify({ type: 'ping' }),
|
||||
// 发送心跳的间隔
|
||||
interval: 10000,
|
||||
// 接收到心跳response的超时时间
|
||||
pongTimeout: 2000
|
||||
},
|
||||
onConnected() {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('socket重连', socketError);
|
||||
} else {
|
||||
console.log('WebSocket 已经连接');
|
||||
},
|
||||
onDisconnected() {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('重试次数已用完');
|
||||
clearInterval(heartTime);
|
||||
}
|
||||
}
|
||||
|
||||
// socket 发送数据
|
||||
export function sendMsg(data: any) {
|
||||
websocket.send(data);
|
||||
}
|
||||
|
||||
// socket 接收数据
|
||||
export function websocketonmessage() {
|
||||
websocket.onmessage = (e: any) => {
|
||||
if (e.data.indexOf('heartbeat') > 0) {
|
||||
resetHeart();
|
||||
}
|
||||
console.warn('WebSocket 已经断开连接');
|
||||
},
|
||||
onMessage: (_, e) => {
|
||||
if (e.data.indexOf('ping') > 0) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
useNoticeStore().addNotice({
|
||||
message: e.data,
|
||||
read: false,
|
||||
time: new Date().toLocaleString()
|
||||
});
|
||||
|
||||
window.$notification?.create({
|
||||
title: '消息',
|
||||
content: e.data,
|
||||
type: 'success',
|
||||
duration: 3000
|
||||
});
|
||||
return e.data;
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user