From 095c432363044a884ce1d14d154b534fe12b4b45 Mon Sep 17 00:00:00 2001 From: Soybean Date: Thu, 19 May 2022 00:15:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor(projects):=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ISSUES CLOSED: \ --- src/store/modules/theme/helpers.ts | 5 ++--- src/utils/common/console.ts | 16 ---------------- src/utils/common/index.ts | 1 - src/utils/router/component.ts | 3 +-- src/utils/router/helpers.ts | 11 +++++------ src/utils/router/module.ts | 4 +--- src/utils/service/msg.ts | 3 +-- src/views/plugin/map/components/GaodeMap.vue | 3 +-- src/views/plugin/map/components/TencentMap.vue | 3 +-- 9 files changed, 12 insertions(+), 37 deletions(-) delete mode 100644 src/utils/common/console.ts diff --git a/src/store/modules/theme/helpers.ts b/src/store/modules/theme/helpers.ts index f2b173ba7..1614c5780 100644 --- a/src/store/modules/theme/helpers.ts +++ b/src/store/modules/theme/helpers.ts @@ -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>; + interface ColorAction { scene: ColorScene; handler: (color: string) => string; diff --git a/src/utils/common/console.ts b/src/utils/common/console.ts deleted file mode 100644 index df38a75ca..000000000 --- a/src/utils/common/console.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-disable no-console */ - -/** 打印log */ -export function consoleLog(message?: any, ...optionalParams: any[]) { - console.log(message, ...optionalParams); -} - -/** 打印警告 */ -export function consoleWarn(message?: any, ...optionalParams: any[]) { - console.warn(message, ...optionalParams); -} - -/** 打印错误 */ -export function consoleError(message?: any, ...optionalParams: any[]) { - console.error(message, ...optionalParams); -} diff --git a/src/utils/common/index.ts b/src/utils/common/index.ts index 5050e9062..7e3e03827 100644 --- a/src/utils/common/index.ts +++ b/src/utils/common/index.ts @@ -1,5 +1,4 @@ export * from './typeof'; -export * from './console'; export * from './color'; export * from './number'; export * from './object'; diff --git a/src/utils/router/component.ts b/src/utils/router/component.ts index 925cd1e23..8c8b37d9b 100644 --- a/src/utils/router/component.ts +++ b/src/utils/router/component.ts @@ -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 Promise>; @@ -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; } diff --git a/src/utils/router/helpers.ts b/src/utils/router/helpers.ts index 317447db2..c9d608e9e 100644 --- a/src/utils/router/helpers.ts +++ b/src/utils/router/helpers.ts @@ -1,5 +1,4 @@ import type { RouteRecordRaw } from 'vue-router'; -import { consoleError } from '../common'; import { getLayoutComponent, getViewComponent } from './component'; /** @@ -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() { @@ -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); } // 捕获无效路由的需特殊处理 @@ -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') { diff --git a/src/utils/router/module.ts b/src/utils/router/module.ts index 017289ead..5f5a43403 100644 --- a/src/utils/router/module.ts +++ b/src/utils/router/module.ts @@ -1,5 +1,3 @@ -import { consoleError } from '../common'; - /** * 权限路由排序 * @param routes - 权限路由 @@ -20,7 +18,7 @@ export function handleModuleRoutes(modules: AuthRoute.RouteModule) { if (item) { routes.push(item); } else { - consoleError(`路由模块解析出错: key = ${key}`); + window.console.error(`路由模块解析出错: key = ${key}`); } }); diff --git a/src/utils/service/msg.ts b/src/utils/service/msg.ts index c697b5513..c9ec0c6b6 100644 --- a/src/utils/service/msg.ts +++ b/src/utils/service/msg.ts @@ -1,5 +1,4 @@ import { NO_ERROR_MSG_CODE, ERROR_MSG_DURATION } from '@/config'; -import { consoleWarn } from '../common'; /** 错误消息栈,防止同一错误同时出现 */ const errorMsgStack = new Map([]); @@ -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); diff --git a/src/views/plugin/map/components/GaodeMap.vue b/src/views/plugin/map/components/GaodeMap.vue index 355be585a..b95b80263 100644 --- a/src/views/plugin/map/components/GaodeMap.vue +++ b/src/views/plugin/map/components/GaodeMap.vue @@ -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(() => { diff --git a/src/views/plugin/map/components/TencentMap.vue b/src/views/plugin/map/components/TencentMap.vue index 000701afd..78a22126f 100644 --- a/src/views/plugin/map/components/TencentMap.vue +++ b/src/views/plugin/map/components/TencentMap.vue @@ -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(() => {