mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
refactor: code review
This commit is contained in:
@@ -41,7 +41,14 @@ class SysSocket {
|
|||||||
const sysMsgUrl = `${Config.baseWsUrl}/sysmsg?${joinClientParams()}`;
|
const sysMsgUrl = `${Config.baseWsUrl}/sysmsg?${joinClientParams()}`;
|
||||||
this.socket = SocketBuilder.builder(sysMsgUrl)
|
this.socket = SocketBuilder.builder(sysMsgUrl)
|
||||||
.message((event: { data: string }) => {
|
.message((event: { data: string }) => {
|
||||||
const message = JSON.parse(event.data);
|
let message;
|
||||||
|
try {
|
||||||
|
message = JSON.parse(event.data);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('解析ws消息失败', e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 存在消息类别对应的处理器,则进行处理,否则进行默认通知处理
|
// 存在消息类别对应的处理器,则进行处理,否则进行默认通知处理
|
||||||
const handler = this.categoryHandlers.get(message.category);
|
const handler = this.categoryHandlers.get(message.category);
|
||||||
if (handler) {
|
if (handler) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import router from '../router';
|
import router from '../router';
|
||||||
import { getClientId, getToken } from './utils/storage';
|
import { clearUser, getClientId, getToken } from './utils/storage';
|
||||||
import { templateResolve } from './utils/string';
|
import { templateResolve } from './utils/string';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
import { createFetch } from '@vueuse/core';
|
import { createFetch } from '@vueuse/core';
|
||||||
@@ -125,6 +125,7 @@ export function useApiFetch<T>(api: Api, params: any = null, reqOptions: Request
|
|||||||
|
|
||||||
// 如果提示没有权限,则跳转至无权限页面
|
// 如果提示没有权限,则跳转至无权限页面
|
||||||
if (result.code === ResultEnum.NO_PERMISSION) {
|
if (result.code === ResultEnum.NO_PERMISSION) {
|
||||||
|
clearUser();
|
||||||
router.push({
|
router.push({
|
||||||
path: '/401',
|
path: '/401',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ export function getThemeConfig() {
|
|||||||
return getLocal('themeConfig');
|
return getLocal('themeConfig');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清除用户相关的用户信息
|
/**
|
||||||
|
* 清除当前登录用户相关信息
|
||||||
|
*/
|
||||||
export function clearUser() {
|
export function clearUser() {
|
||||||
removeLocal(TokenKey);
|
removeLocal(TokenKey);
|
||||||
removeLocal(UserKey);
|
removeLocal(UserKey);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import { useKeepALiveNames } from '@/store/keepAliveNames';
|
|||||||
* @method import.meta.glob
|
* @method import.meta.glob
|
||||||
* @link 参考:https://cn.vitejs.dev/guide/features.html#json
|
* @link 参考:https://cn.vitejs.dev/guide/features.html#json
|
||||||
*/
|
*/
|
||||||
const viewsModules: any = import.meta.glob(['../views/**/*.{vue,tsx}']);
|
const viewsModules: Record<string, Function> = import.meta.glob(['../views/**/*.{vue,tsx}']);
|
||||||
const dynamicViewsModules: Record<string, Function> = Object.assign({}, { ...viewsModules });
|
const dynamicViewsModules: Record<string, Function> = Object.assign({}, { ...viewsModules });
|
||||||
|
|
||||||
// 添加静态路由
|
// 添加静态路由
|
||||||
@@ -104,7 +104,7 @@ export function backEndRouterConverter(routes: any, callbackFunc: RouterConvCall
|
|||||||
item.component = dynamicImport(dynamicViewsModules, item.meta.component);
|
item.component = dynamicImport(dynamicViewsModules, item.meta.component);
|
||||||
delete item.meta['component'];
|
delete item.meta['component'];
|
||||||
}
|
}
|
||||||
// route.path == resource.code
|
|
||||||
let path = item.code;
|
let path = item.code;
|
||||||
// 如果不是以 / 开头,则路径需要拼接父路径
|
// 如果不是以 / 开头,则路径需要拼接父路径
|
||||||
if (!path.startsWith('/')) {
|
if (!path.startsWith('/')) {
|
||||||
@@ -145,13 +145,18 @@ export function dynamicImport(dynamicViewsModules: Record<string, Function>, com
|
|||||||
const k = key.replace(/..\/views|../, '');
|
const k = key.replace(/..\/views|../, '');
|
||||||
return k.startsWith(`${component}`) || k.startsWith(`/${component}`);
|
return k.startsWith(`${component}`) || k.startsWith(`/${component}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (matchKeys?.length === 1) {
|
if (matchKeys?.length === 1) {
|
||||||
const matchKey = matchKeys[0];
|
return dynamicViewsModules[matchKeys[0]];
|
||||||
return dynamicViewsModules[matchKey];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchKeys?.length > 1) {
|
if (matchKeys?.length > 1) {
|
||||||
return false;
|
console.error('匹配到多个相似组件路径, 可添加后缀.vue或.tsx进行区分或者重命名组件名, 请调整...', matchKeys);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.error(`未匹配到[${component}]组件名对应的组件文件`);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除/重置路由
|
// 删除/重置路由
|
||||||
@@ -218,7 +223,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 不存在路由(避免刷新页面找不到路由)并且未加载过(避免token过期,导致获取权限接口报权限不足,无限获取),则重新初始化路由
|
// 不存在路由(避免刷新页面找不到路由)并且未加载过(避免token过期,导致获取权限接口报权限不足,无限获取),则重新初始化路由
|
||||||
if (useRoutesList().routesList.length == 0 && !loadRouter) {
|
if (useRoutesList().routesList?.length == 0 && !loadRouter) {
|
||||||
await initRouter();
|
await initRouter();
|
||||||
loadRouter = true;
|
loadRouter = true;
|
||||||
next({ path: to.path, query: to.query });
|
next({ path: to.path, query: to.query });
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ body,
|
|||||||
}
|
}
|
||||||
|
|
||||||
.layout-view-bg-white {
|
.layout-view-bg-white {
|
||||||
background: white;
|
background: var(--bg-main-color);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
|
|||||||
@@ -49,9 +49,9 @@
|
|||||||
</el-text>
|
</el-text>
|
||||||
|
|
||||||
<!-- 展示剩余的磁盘信息 -->
|
<!-- 展示剩余的磁盘信息 -->
|
||||||
<el-popover :show-after="300" placement="top-start" width="230" trigger="hover">
|
<el-popover :show-after="300" v-if="data.stat.fsInfos.length > 2 && idx == 1" placement="top-start" width="230" trigger="hover">
|
||||||
<template #reference>
|
<template #reference>
|
||||||
<SvgIcon class="mt5 ml5" color="var(--el-color-primary)" v-if="data.stat.fsInfos.length > 2 && idx == 1" name="MoreFilled" />
|
<SvgIcon class="mt5 ml5" color="var(--el-color-primary)" name="MoreFilled" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<el-row v-for="i in data.stat.fsInfos.slice(2)" :key="i.mountPoint">
|
<el-row v-for="i in data.stat.fsInfos.slice(2)" :key="i.mountPoint">
|
||||||
|
|||||||
@@ -114,7 +114,7 @@
|
|||||||
</el-icon>
|
</el-icon>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</template>
|
</template>
|
||||||
<el-select class="w100" @change="changeIsIframe" v-model="form.meta.linkType" placeholder="请选择">
|
<el-select class="w100" @change="changeLinkType" v-model="form.meta.linkType" placeholder="请选择">
|
||||||
<el-option :key="0" label="否" :value="0"> </el-option>
|
<el-option :key="0" label="否" :value="0"> </el-option>
|
||||||
<el-option :key="1" label="内嵌" :value="1"> </el-option>
|
<el-option :key="1" label="内嵌" :value="1"> </el-option>
|
||||||
<el-option :key="2" label="外链" :value="2"> </el-option>
|
<el-option :key="2" label="外链" :value="2"> </el-option>
|
||||||
@@ -249,13 +249,9 @@ watch(props, (newValue: any) => {
|
|||||||
state.form.meta.linkType = meta.linkType;
|
state.form.meta.linkType = meta.linkType;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 改变iframe字段,如果为是,则设置默认的组件
|
// 改变外链类型
|
||||||
const changeIsIframe = (value: boolean) => {
|
const changeLinkType = () => {
|
||||||
if (value) {
|
|
||||||
state.form.meta.component = 'layout/routerView/parent';
|
|
||||||
} else {
|
|
||||||
state.form.meta.component = '';
|
state.form.meta.component = '';
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const btnOk = () => {
|
const btnOk = () => {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const (
|
|||||||
func (dbType DbType) MetaDbName() string {
|
func (dbType DbType) MetaDbName() string {
|
||||||
switch dbType {
|
switch dbType {
|
||||||
case DbTypeMysql:
|
case DbTypeMysql:
|
||||||
return "mysql"
|
return ""
|
||||||
case DbTypePostgres:
|
case DbTypePostgres:
|
||||||
return "postgres"
|
return "postgres"
|
||||||
case DM:
|
case DM:
|
||||||
|
|||||||
Reference in New Issue
Block a user