mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-11-11 03:03:42 +08:00
build(projects): update tsconfig、eslintrc
This commit is contained in:
@@ -37,7 +37,7 @@ export function getUserInfo() {
|
||||
userId: '',
|
||||
userName: '',
|
||||
userPhone: '',
|
||||
userRole: 'visitor'
|
||||
userRole: 'visitor',
|
||||
};
|
||||
const userInfo: Auth.UserInfo = getLocal<Auth.UserInfo>(EnumStorageKey['user-info']) || emptyInfo;
|
||||
return userInfo;
|
||||
|
||||
@@ -30,7 +30,7 @@ export function getColorPalette(color: string, index: ColorIndex) {
|
||||
const newHsv: HsvColor = {
|
||||
h: getHue(hsv, i, isLight),
|
||||
s: getSaturation(hsv, i, isLight),
|
||||
v: getValue(hsv, i, isLight)
|
||||
v: getValue(hsv, i, isLight),
|
||||
};
|
||||
|
||||
return colord(newHsv).toHex();
|
||||
@@ -42,7 +42,7 @@ export function getColorPalette(color: string, index: ColorIndex) {
|
||||
*/
|
||||
export function getAllColorPalette(color: string) {
|
||||
const indexs: ColorIndex[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
return indexs.map(index => getColorPalette(color, index));
|
||||
return indexs.map((index) => getColorPalette(color, index));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** 执行策略模式 */
|
||||
export function exeStrategyActions(actions: Common.StrategyAction[]) {
|
||||
actions.some(item => {
|
||||
actions.some((item) => {
|
||||
const [flag, action] = item;
|
||||
if (flag) {
|
||||
action();
|
||||
|
||||
@@ -27,7 +27,7 @@ export function transformToTimeCountDown(seconds: number) {
|
||||
* @param start - 开始范围
|
||||
* @param end - 结束范围
|
||||
*/
|
||||
export function getRandomInterger(end: number, start: number = 0) {
|
||||
export function getRandomInterger(end: number, start = 0) {
|
||||
const range = end - start;
|
||||
const random = Math.floor(Math.random() * range + start);
|
||||
return random;
|
||||
|
||||
@@ -18,17 +18,17 @@ interface CustomFormRules {
|
||||
export const formRules: CustomFormRules = {
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号码' },
|
||||
{ pattern: REGEXP_PHONE, message: '手机号码格式错误', trigger: 'input' }
|
||||
{ pattern: REGEXP_PHONE, message: '手机号码格式错误', trigger: 'input' },
|
||||
],
|
||||
pwd: [
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ pattern: REGEXP_PWD, message: '密码为8-18位数字/字符/符号,至少2种组合', trigger: 'input' }
|
||||
{ pattern: REGEXP_PWD, message: '密码为8-18位数字/字符/符号,至少2种组合', trigger: 'input' },
|
||||
],
|
||||
code: [
|
||||
{ required: true, message: '请输入验证码' },
|
||||
{ pattern: REGEXP_CODE_SIX, message: '验证码格式错误', trigger: 'input' }
|
||||
{ pattern: REGEXP_CODE_SIX, message: '验证码格式错误', trigger: 'input' },
|
||||
],
|
||||
email: [{ pattern: REGEXP_EMAIL, message: '邮箱格式错误', trigger: 'blur' }]
|
||||
email: [{ pattern: REGEXP_EMAIL, message: '邮箱格式错误', trigger: 'blur' }],
|
||||
};
|
||||
|
||||
/** 获取确认密码的表单规则 */
|
||||
@@ -43,8 +43,8 @@ export function getConfirmPwdRule(pwd: Ref<string>) {
|
||||
return Promise.resolve();
|
||||
},
|
||||
message: '输入的值与密码不一致',
|
||||
trigger: 'input'
|
||||
}
|
||||
trigger: 'input',
|
||||
},
|
||||
];
|
||||
return confirmPwdRule;
|
||||
}
|
||||
@@ -61,8 +61,8 @@ export function getImgCodeRule(imgCode: Ref<string>) {
|
||||
return Promise.resolve();
|
||||
},
|
||||
message: '验证码不正确',
|
||||
trigger: 'blur'
|
||||
}
|
||||
trigger: 'blur',
|
||||
},
|
||||
];
|
||||
return imgCodeRule;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { GlobalMenuOption, GlobalBreadcrumb } from '@/interface';
|
||||
*/
|
||||
export function getBreadcrumbByRouteKey(activeKey: string, menus: GlobalMenuOption[], rootPath: string) {
|
||||
const breadcrumbMenu = getBreadcrumbMenu(activeKey, menus);
|
||||
const breadcrumb = breadcrumbMenu.map(item => transformBreadcrumbMenuToBreadcrumb(item, rootPath));
|
||||
const breadcrumb = breadcrumbMenu.map((item) => transformBreadcrumbMenuToBreadcrumb(item, rootPath));
|
||||
return breadcrumb;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export function getBreadcrumbByRouteKey(activeKey: string, menus: GlobalMenuOpti
|
||||
*/
|
||||
function getBreadcrumbMenu(activeKey: string, menus: GlobalMenuOption[]) {
|
||||
const breadcrumbMenu: GlobalMenuOption[] = [];
|
||||
menus.some(menu => {
|
||||
menus.some((menu) => {
|
||||
const flag = activeKey.includes(menu.routeName);
|
||||
if (flag) {
|
||||
breadcrumbMenu.push(...getBreadcrumbMenuItem(activeKey, menu));
|
||||
@@ -42,7 +42,7 @@ function getBreadcrumbMenuItem(activeKey: string, menu: GlobalMenuOption) {
|
||||
if (activeKey.includes(menu.routeName) && menu.children && menu.children.length) {
|
||||
breadcrumbMenu.push(menu);
|
||||
breadcrumbMenu.push(
|
||||
...menu.children.map(item => getBreadcrumbMenuItem(activeKey, item as GlobalMenuOption)).flat(1)
|
||||
...menu.children.map((item) => getBreadcrumbMenuItem(activeKey, item as GlobalMenuOption)).flat(1)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ function transformBreadcrumbMenuToBreadcrumb(menu: GlobalMenuOption, rootPath: s
|
||||
label: menu.label as string,
|
||||
routeName: menu.routeName,
|
||||
disabled: menu.routePath === rootPath,
|
||||
hasChildren
|
||||
hasChildren,
|
||||
};
|
||||
if (menu.icon) {
|
||||
breadcrumb.icon = menu.icon;
|
||||
}
|
||||
if (hasChildren) {
|
||||
breadcrumb.children = menu.children?.map(item =>
|
||||
breadcrumb.children = menu.children?.map((item) =>
|
||||
transformBreadcrumbMenuToBreadcrumb(item as GlobalMenuOption, rootPath)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import type { RouteRecordRaw } from 'vue-router';
|
||||
*/
|
||||
export function getCacheRoutes(routes: RouteRecordRaw[]) {
|
||||
const cacheNames: string[] = [];
|
||||
routes.forEach(route => {
|
||||
routes.forEach((route) => {
|
||||
// 只需要获取二级路由的缓存的组件名
|
||||
if (hasChildren(route)) {
|
||||
route.children!.forEach(item => {
|
||||
(route.children as RouteRecordRaw[]).forEach((item) => {
|
||||
if (isKeepAlive(item)) {
|
||||
cacheNames.push(item.name as string);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ type LayoutComponent = Record<LayoutComponentName, () => Promise<Component>>;
|
||||
export function getLayoutComponent(layoutType: LayoutComponentName) {
|
||||
const layoutComponent: LayoutComponent = {
|
||||
basic: BasicLayout,
|
||||
blank: BlankLayout
|
||||
blank: BlankLayout,
|
||||
};
|
||||
return () => setViewComponentName(layoutComponent[layoutType], EnumLayoutComponentName[layoutType]);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ type ComponentAction = Record<AuthRoute.RouteComponent, () => void>;
|
||||
* @description 所有多级路由都会被转换成二级路由
|
||||
*/
|
||||
export function transformAuthRoutesToVueRoutes(routes: AuthRoute.Route[]) {
|
||||
return routes.map(route => transformAuthRouteToVueRoute(route)).flat(1);
|
||||
return routes.map((route) => transformAuthRouteToVueRoute(route)).flat(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,10 +70,14 @@ function transformAuthRouteToVueRoute(item: AuthRoute.Route) {
|
||||
},
|
||||
self() {
|
||||
itemRoute.component = getViewComponent(item.name);
|
||||
}
|
||||
},
|
||||
};
|
||||
try {
|
||||
action[item.component!]();
|
||||
if (item.component) {
|
||||
action[item.component]();
|
||||
} else {
|
||||
consoleError('路由组件解析失败: ', item);
|
||||
}
|
||||
} catch {
|
||||
consoleError('路由组件解析失败: ', item);
|
||||
}
|
||||
@@ -91,8 +95,8 @@ function transformAuthRouteToVueRoute(item: AuthRoute.Route) {
|
||||
{
|
||||
path: '',
|
||||
name: item.name,
|
||||
component: getViewComponent('not-found-page')
|
||||
}
|
||||
component: getViewComponent('not-found-page'),
|
||||
},
|
||||
];
|
||||
} else {
|
||||
const parentPath = `${itemRoute.path}-parent` as AuthRoute.SingleRouteParentPath;
|
||||
@@ -103,7 +107,7 @@ function transformAuthRouteToVueRoute(item: AuthRoute.Route) {
|
||||
path: parentPath,
|
||||
component: layout,
|
||||
redirect: item.path,
|
||||
children: [itemRoute]
|
||||
children: [itemRoute],
|
||||
};
|
||||
|
||||
return [parentRoute];
|
||||
@@ -112,10 +116,10 @@ function transformAuthRouteToVueRoute(item: AuthRoute.Route) {
|
||||
|
||||
// 子路由
|
||||
if (hasChildren(item)) {
|
||||
const children = item.children!.map(child => transformAuthRouteToVueRoute(child)).flat();
|
||||
const children = (item.children as AuthRoute.Route[]).map((child) => transformAuthRouteToVueRoute(child)).flat();
|
||||
|
||||
// 找出第一个不为多级路由中间级的子路由路径作为重定向路径
|
||||
const redirectPath: AuthRoute.RoutePath = (children.find(item => !item.meta?.multi)?.path ||
|
||||
const redirectPath: AuthRoute.RoutePath = (children.find((v) => !v.meta?.multi)?.path ||
|
||||
'/') as AuthRoute.RoutePath;
|
||||
if (redirectPath === '/') {
|
||||
consoleError('该多级路由没有有效的子路径', item);
|
||||
|
||||
@@ -24,7 +24,7 @@ function addPartialProps(menuItem: GlobalMenuOption, icon?: string, children?: G
|
||||
*/
|
||||
export function transformAuthRouteToMenu(routes: AuthRoute.Route[]): GlobalMenuOption[] {
|
||||
const globalMenu: GlobalMenuOption[] = [];
|
||||
routes.forEach(route => {
|
||||
routes.forEach((route) => {
|
||||
const { name, path, meta } = route;
|
||||
const routeName = name as string;
|
||||
let menuChildren: GlobalMenuOption[] | undefined;
|
||||
@@ -36,7 +36,7 @@ export function transformAuthRouteToMenu(routes: AuthRoute.Route[]): GlobalMenuO
|
||||
key: routeName,
|
||||
label: meta.title,
|
||||
routeName,
|
||||
routePath: path
|
||||
routePath: path,
|
||||
},
|
||||
meta?.icon,
|
||||
menuChildren
|
||||
@@ -56,7 +56,7 @@ export function transformAuthRouteToMenu(routes: AuthRoute.Route[]): GlobalMenuO
|
||||
* @param menus - 菜单数据
|
||||
*/
|
||||
export function getActiveKeyPathsOfMenus(activeKey: string, menus: GlobalMenuOption[]) {
|
||||
const keys = menus.map(menu => getActiveKeyPathsOfMenu(activeKey, menu)).flat(1);
|
||||
const keys = menus.map((menu) => getActiveKeyPathsOfMenu(activeKey, menu)).flat(1);
|
||||
return keys;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ function getActiveKeyPathsOfMenu(activeKey: string, menu: GlobalMenuOption) {
|
||||
keys.push(menu.routeName);
|
||||
}
|
||||
if (menu.children) {
|
||||
keys.push(...menu.children.map(item => getActiveKeyPathsOfMenu(activeKey, item)).flat(1));
|
||||
keys.push(...menu.children.map((item) => getActiveKeyPathsOfMenu(activeKey, item)).flat(1));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ export function getTabRoutes() {
|
||||
const routes: GlobalTabRoute[] = [];
|
||||
const data = getLocal<GlobalTabRoute[]>(EnumStorageKey['tab-routes']);
|
||||
if (data) {
|
||||
const defaultTabRoutes = data.map(item => ({
|
||||
const defaultTabRoutes = data.map((item) => ({
|
||||
...item,
|
||||
scrollPosition: {
|
||||
left: 0,
|
||||
top: 0
|
||||
}
|
||||
top: 0,
|
||||
},
|
||||
}));
|
||||
routes.push(...defaultTabRoutes);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
NETWORK_ERROR_MSG,
|
||||
REQUEST_TIMEOUT_CODE,
|
||||
REQUEST_TIMEOUT_MSG,
|
||||
ERROR_STATUS
|
||||
ERROR_STATUS,
|
||||
} from '@/config';
|
||||
import { exeStrategyActions } from '../common';
|
||||
import { showErrorMsg } from './msg';
|
||||
@@ -21,7 +21,7 @@ export function handleAxiosError(axiosError: AxiosError) {
|
||||
const error: Service.RequestError = {
|
||||
type: 'axios',
|
||||
code: DEFAULT_REQUEST_ERROR_CODE,
|
||||
msg: DEFAULT_REQUEST_ERROR_MSG
|
||||
msg: DEFAULT_REQUEST_ERROR_MSG,
|
||||
};
|
||||
|
||||
const actions: Common.StrategyAction[] = [
|
||||
@@ -30,14 +30,14 @@ export function handleAxiosError(axiosError: AxiosError) {
|
||||
!window.navigator.onLine || axiosError.message === 'Network Error',
|
||||
() => {
|
||||
Object.assign(error, { code: NETWORK_ERROR_CODE, msg: NETWORK_ERROR_MSG });
|
||||
}
|
||||
},
|
||||
],
|
||||
[
|
||||
// 超时错误
|
||||
axiosError.code === REQUEST_TIMEOUT_CODE && axiosError.message.includes('timeout'),
|
||||
() => {
|
||||
Object.assign(error, { code: REQUEST_TIMEOUT_CODE, msg: REQUEST_TIMEOUT_MSG });
|
||||
}
|
||||
},
|
||||
],
|
||||
[
|
||||
// 请求不成功的错误
|
||||
@@ -46,8 +46,8 @@ export function handleAxiosError(axiosError: AxiosError) {
|
||||
const errorCode: ErrorStatus = (axiosError.response?.status as ErrorStatus) || 'DEFAULT';
|
||||
const msg = ERROR_STATUS[errorCode];
|
||||
Object.assign(error, { code: errorCode, msg });
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
exeStrategyActions(actions);
|
||||
@@ -65,7 +65,7 @@ export function handleResponseError(response: AxiosResponse) {
|
||||
const error: Service.RequestError = {
|
||||
type: 'axios',
|
||||
code: DEFAULT_REQUEST_ERROR_CODE,
|
||||
msg: DEFAULT_REQUEST_ERROR_MSG
|
||||
msg: DEFAULT_REQUEST_ERROR_MSG,
|
||||
};
|
||||
|
||||
if (!window.navigator.onLine) {
|
||||
@@ -92,7 +92,7 @@ export function handleBackendError(backendResult: Record<string, any>, config: S
|
||||
const error: Service.RequestError = {
|
||||
type: 'backend',
|
||||
code: backendResult[codeKey],
|
||||
msg: backendResult[msgKey]
|
||||
msg: backendResult[msgKey],
|
||||
};
|
||||
|
||||
showErrorMsg(error);
|
||||
|
||||
@@ -3,13 +3,13 @@ export async function handleServiceResult<T = any>(error: Service.RequestError |
|
||||
if (error) {
|
||||
const fail: Service.FailedResult = {
|
||||
error,
|
||||
data: null
|
||||
data: null,
|
||||
};
|
||||
return fail;
|
||||
}
|
||||
const success: Service.SuccessResult<T> = {
|
||||
error: null,
|
||||
data
|
||||
data,
|
||||
};
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ async function transformFile(file: File[] | File, key: string) {
|
||||
if (isArray(file)) {
|
||||
// 多文件
|
||||
await Promise.all(
|
||||
(file as File[]).map(item => {
|
||||
(file as File[]).map((item) => {
|
||||
formData.append(key, item);
|
||||
return true;
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user