Skip to content

Commit

Permalink
refactor(projects): 代码优化
Browse files Browse the repository at this point in the history
ISSUES CLOSED: \
  • Loading branch information
honghuangdc committed May 18, 2022
1 parent 028096e commit 095c432
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 37 deletions.
5 changes: 2 additions & 3 deletions src/store/modules/theme/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export function getThemeSettings() {
type ColorType = 'primary' | 'info' | 'success' | 'warning' | 'error';
type ColorScene = '' | 'Suppl' | 'Hover' | 'Pressed' | 'Active';
type ColorKey = `${ColorType}Color${ColorScene}`;
type ThemeColor = {
[key in ColorKey]?: string;
};
type ThemeColor = Partial<Record<ColorKey, string>>;

interface ColorAction {
scene: ColorScene;
handler: (color: string) => string;
Expand Down
16 changes: 0 additions & 16 deletions src/utils/common/console.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './typeof';
export * from './console';
export * from './color';
export * from './number';
export * from './object';
Expand Down
3 changes: 1 addition & 2 deletions src/utils/router/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Component } from 'vue';
import { EnumLayoutComponentName } from '@/enum';
import { BasicLayout, BlankLayout } from '@/layouts';
import { views } from '@/views';
import { consoleError } from '../common';

type LayoutComponent = Record<EnumType.LayoutComponentName, () => Promise<Component>>;

Expand All @@ -24,7 +23,7 @@ export function getLayoutComponent(layoutType: EnumType.LayoutComponentName) {
*/
export function getViewComponent(routeKey: AuthRoute.RouteKey) {
if (!views[routeKey]) {
consoleError(`路由“${routeKey}”没有对应的组件文件!`);
window.console.error(`路由“${routeKey}”没有对应的组件文件!`);
}
return () => setViewComponentName(views[routeKey], routeKey) as Promise<Component>;
}
Expand Down
11 changes: 5 additions & 6 deletions src/utils/router/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { RouteRecordRaw } from 'vue-router';
import { consoleError } from '../common';
import { getLayoutComponent, getViewComponent } from './component';

/**
Expand Down Expand Up @@ -113,7 +112,7 @@ function transformAuthRouteToVueRoute(item: AuthRoute.Route) {
Object.assign(itemRoute, { meta: { ...itemRoute.meta, multi: true } });
delete itemRoute.component;
} else {
consoleError('多级路由缺少子路由: ', item);
window.console.error('多级路由缺少子路由: ', item);
}
},
self() {
Expand All @@ -124,17 +123,17 @@ function transformAuthRouteToVueRoute(item: AuthRoute.Route) {
if (item.component) {
action[item.component]();
} else {
consoleError('路由组件解析失败: ', item);
window.console.error('路由组件解析失败: ', item);
}
} catch {
consoleError('路由组件解析失败: ', item);
window.console.error('路由组件解析失败: ', item);
}
}

// 注意:单独路由没有children
if (isSingleRoute(item)) {
if (hasChildren(item)) {
consoleError('单独路由不应该有子路由: ', item);
window.console.error('单独路由不应该有子路由: ', item);
}

// 捕获无效路由的需特殊处理
Expand Down Expand Up @@ -169,7 +168,7 @@ function transformAuthRouteToVueRoute(item: AuthRoute.Route) {
// 找出第一个不为多级路由中间级的子路由路径作为重定向路径
const redirectPath: AuthRoute.RoutePath = (children.find(v => !v.meta?.multi)?.path || '/') as AuthRoute.RoutePath;
if (redirectPath === '/') {
consoleError('该多级路由没有有效的子路径', item);
window.console.error('该多级路由没有有效的子路径', item);
}

if (item.component === 'multi') {
Expand Down
4 changes: 1 addition & 3 deletions src/utils/router/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { consoleError } from '../common';

/**
* 权限路由排序
* @param routes - 权限路由
Expand All @@ -20,7 +18,7 @@ export function handleModuleRoutes(modules: AuthRoute.RouteModule) {
if (item) {
routes.push(item);
} else {
consoleError(`路由模块解析出错: key = ${key}`);
window.console.error(`路由模块解析出错: key = ${key}`);
}
});

Expand Down
3 changes: 1 addition & 2 deletions src/utils/service/msg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NO_ERROR_MSG_CODE, ERROR_MSG_DURATION } from '@/config';
import { consoleWarn } from '../common';

/** 错误消息栈,防止同一错误同时出现 */
const errorMsgStack = new Map<string | number, string>([]);
Expand All @@ -23,7 +22,7 @@ export function showErrorMsg(error: Service.RequestError) {
if (!NO_ERROR_MSG_CODE.includes(error.code)) {
if (!hasErrorMsg(error)) {
addErrorMsg(error);
consoleWarn(error.code, error.msg);
window.console.warn(error.code, error.msg);
window.$message?.error(error.msg, { duration: ERROR_MSG_DURATION });
setTimeout(() => {
removeErrorMsg(error);
Expand Down
3 changes: 1 addition & 2 deletions src/views/plugin/map/components/GaodeMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ async function renderBaiduMap() {
center: [114.05834626586915, 22.546789983033168],
viewMode: '3D'
});
// eslint-disable-next-line no-console
console.log('map: ', map);
window.console.log(map);
}
onMounted(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/views/plugin/map/components/TencentMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ async function renderBaiduMap() {
zoom: 11,
viewMode: '3D'
});
// eslint-disable-next-line no-console
console.log('map: ', map);
window.console.log(map);
}
onMounted(() => {
Expand Down

1 comment on commit 095c432

@vercel
Copy link

@vercel vercel bot commented on 095c432 May 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.