diff --git a/build/cool/temp/eps.json b/build/cool/temp/eps.json index 3e7c589..e6c9392 100644 --- a/build/cool/temp/eps.json +++ b/build/cool/temp/eps.json @@ -1 +1 @@ -[["/admin/base/comm",[["post","/personUpdate",""],["get","/uploadMode",""],["get","/permmenu",""],["get","/person",""],["post","/upload",""],["post","/logout",""],["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/open",[["get","/refreshToken",""],["get","/captcha",""],["post","/login",""],["get","/html",""],["get","/eps",""],["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/sys/department",[["post","/delete",""],["post","/update",""],["post","/order",""],["post","/list",""],["post","/add",""],["","/page",""],["","/info",""]]],["/admin/base/sys/log",[["post","/setKeep",""],["get","/getKeep",""],["post","/clear",""],["post","/page",""],["","/list",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/sys/menu",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/base/sys/param",[["post","/delete",""],["post","/update",""],["get","/html",""],["get","/info",""],["post","/page",""],["post","/add",""],["","/list",""]]],["/admin/base/sys/role",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/base/sys/user",[["post","/delete",""],["post","/update",""],["post","/move",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/demo/goods",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/page",""],["post","/list",""],["post","/add",""]]],["/admin/space/info",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/space/type",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/study/finish",[["post","/page",""],["","/list",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/study/learn",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/study/music",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/study/topic",[["get","/provinceCount",""],["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/study/works",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/task/info",[["post","/delete",""],["post","/update",""],["post","/start",""],["post","/once",""],["post","/stop",""],["get","/info",""],["post","/page",""],["get","/log",""],["post","/add",""],["","/list",""]]],["/admin/user/info",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]]] \ No newline at end of file +[["/admin/base/comm",[["post","/personUpdate",""],["get","/uploadMode",""],["get","/permmenu",""],["get","/person",""],["post","/upload",""],["post","/logout",""],["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/open",[["get","/refreshToken",""],["get","/captcha",""],["post","/login",""],["get","/html",""],["get","/eps",""],["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/sys/department",[["post","/delete",""],["post","/update",""],["post","/order",""],["post","/list",""],["post","/add",""],["","/page",""],["","/info",""]]],["/admin/base/sys/log",[["post","/setKeep",""],["get","/getKeep",""],["post","/clear",""],["post","/page",""],["","/list",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]],["/admin/base/sys/menu",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/base/sys/param",[["post","/delete",""],["post","/update",""],["get","/html",""],["get","/info",""],["post","/page",""],["post","/add",""],["","/list",""]]],["/admin/base/sys/role",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/base/sys/user",[["post","/delete",""],["post","/update",""],["post","/move",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/demo/goods",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/page",""],["post","/list",""],["post","/add",""]]],["/admin/space/info",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/space/type",[["post","/delete",""],["post","/update",""],["get","/info",""],["post","/list",""],["post","/page",""],["post","/add",""]]],["/admin/task/info",[["post","/delete",""],["post","/update",""],["post","/start",""],["post","/once",""],["post","/stop",""],["get","/info",""],["post","/page",""],["get","/log",""],["post","/add",""],["","/list",""]]],["/test",[["","/list",""],["","/page",""],["","/info",""],["","/update",""],["","/delete",""],["","/add",""]]]] \ No newline at end of file diff --git a/build/cool/temp/service.d.ts b/build/cool/temp/service.d.ts index 4a2c359..3733eff 100644 --- a/build/cool/temp/service.d.ts +++ b/build/cool/temp/service.d.ts @@ -635,232 +635,6 @@ declare interface SpaceType { }; } -declare interface StudyFinish { - /** - * 分页查询 - * @returns Promise - */ - page(data?: any): Promise; - /** - * list - * @returns Promise - */ - list(data?: any): Promise; - /** - * info - * @returns Promise - */ - info(data?: any): Promise; - /** - * update - * @returns Promise - */ - update(data?: any): Promise; - /** - * delete - * @returns Promise - */ - delete(data?: any): Promise; - /** - * add - * @returns Promise - */ - add(data?: any): Promise; - /** - * 权限 - */ - permission: { - page: string; - list: string; - info: string; - update: string; - delete: string; - add: string; - }; -} - -declare interface StudyLearn { - /** - * 删除 - * @returns Promise - */ - delete(data?: any): Promise; - /** - * 修改 - * @returns Promise - */ - update(data?: any): Promise; - /** - * 单个信息 - * @returns Promise - */ - info(data?: any): Promise; - /** - * 列表查询 - * @returns Promise - */ - list(data?: any): Promise; - /** - * 分页查询 - * @returns Promise - */ - page(data?: any): Promise; - /** - * 新增 - * @returns Promise - */ - add(data?: any): Promise; - /** - * 权限 - */ - permission: { - delete: string; - update: string; - info: string; - list: string; - page: string; - add: string; - }; -} - -declare interface StudyMusic { - /** - * 删除 - * @returns Promise - */ - delete(data?: any): Promise; - /** - * 修改 - * @returns Promise - */ - update(data?: any): Promise; - /** - * 单个信息 - * @returns Promise - */ - info(data?: any): Promise; - /** - * 列表查询 - * @returns Promise - */ - list(data?: any): Promise; - /** - * 分页查询 - * @returns Promise - */ - page(data?: any): Promise; - /** - * 新增 - * @returns Promise - */ - add(data?: any): Promise; - /** - * 权限 - */ - permission: { - delete: string; - update: string; - info: string; - list: string; - page: string; - add: string; - }; -} - -declare interface StudyTopic { - /** - * 省份统计 - * @returns Promise - */ - provinceCount(data?: any): Promise; - /** - * 删除 - * @returns Promise - */ - delete(data?: any): Promise; - /** - * 修改 - * @returns Promise - */ - update(data?: any): Promise; - /** - * 单个信息 - * @returns Promise - */ - info(data?: any): Promise; - /** - * 列表查询 - * @returns Promise - */ - list(data?: any): Promise; - /** - * 分页查询 - * @returns Promise - */ - page(data?: any): Promise; - /** - * 新增 - * @returns Promise - */ - add(data?: any): Promise; - /** - * 权限 - */ - permission: { - provinceCount: string; - delete: string; - update: string; - info: string; - list: string; - page: string; - add: string; - }; -} - -declare interface StudyWorks { - /** - * 删除 - * @returns Promise - */ - delete(data?: any): Promise; - /** - * 修改 - * @returns Promise - */ - update(data?: any): Promise; - /** - * 单个信息 - * @returns Promise - */ - info(data?: any): Promise; - /** - * 列表查询 - * @returns Promise - */ - list(data?: any): Promise; - /** - * 分页查询 - * @returns Promise - */ - page(data?: any): Promise; - /** - * 新增 - * @returns Promise - */ - add(data?: any): Promise; - /** - * 权限 - */ - permission: { - delete: string; - update: string; - info: string; - list: string; - page: string; - add: string; - }; -} - declare interface TaskInfo { /** * 删除 @@ -929,34 +703,34 @@ declare interface TaskInfo { }; } -declare interface UserInfo { +declare interface Test { /** - * 删除 - * @returns Promise - */ - delete(data?: any): Promise; - /** - * 修改 - * @returns Promise - */ - update(data?: any): Promise; - /** - * 单个信息 - * @returns Promise - */ - info(data?: any): Promise; - /** - * 列表查询 + * list * @returns Promise */ list(data?: any): Promise; /** - * 分页查询 + * page * @returns Promise */ page(data?: any): Promise; /** - * 新增 + * info + * @returns Promise + */ + info(data?: any): Promise; + /** + * update + * @returns Promise + */ + update(data?: any): Promise; + /** + * delete + * @returns Promise + */ + delete(data?: any): Promise; + /** + * add * @returns Promise */ add(data?: any): Promise; @@ -964,11 +738,11 @@ declare interface UserInfo { * 权限 */ permission: { - delete: string; - update: string; - info: string; list: string; page: string; + info: string; + update: string; + delete: string; add: string; }; } @@ -989,13 +763,6 @@ declare type Service = { }; demo: { goods: DemoGoods }; space: { info: SpaceInfo; type: SpaceType }; - study: { - finish: StudyFinish; - learn: StudyLearn; - music: StudyMusic; - topic: StudyTopic; - works: StudyWorks; - }; task: { info: TaskInfo }; - user: { info: UserInfo }; + test: Test; }; diff --git a/package.json b/package.json index 6ceea2d..517bfaf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "front-next", - "version": "5.1.6", + "version": "5.2.0", "scripts": { "dev": "vite --host", "build": "vite build", @@ -12,7 +12,7 @@ "@cool-vue/crud": "^5.0.7", "@element-plus/icons-vue": "^1.1.3", "@vueuse/core": "^8.2.5", - "axios": "^0.26.1", + "axios": "^0.27.2", "codemirror": "^5.62.0", "core-js": "^3.6.5", "echarts": "^5.0.2", diff --git a/src/cool/bootstrap.ts b/src/cool/bootstrap.ts index 3b20785..5168261 100644 --- a/src/cool/bootstrap.ts +++ b/src/cool/bootstrap.ts @@ -1,7 +1,7 @@ import { createPinia } from "pinia"; import { App } from "vue"; import { useModule } from "./module"; -import { router, addViews } from "./router"; +import { router, viewer } from "./router"; import { useBaseStore } from "/$/base"; import mitt from "mitt"; import VueECharts from "vue-echarts"; @@ -29,7 +29,7 @@ export async function bootstrap(Vue: App) { useModule(Vue); // 取缓存视图 - addViews(menu.routes); + viewer.add(menu.routes); // 路由 Vue.use(router); diff --git a/src/cool/config.ts b/src/cool/config.ts deleted file mode 100644 index e8b4a6d..0000000 --- a/src/cool/config.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { getUrlParam, storage } from "./utils"; - -// 开发模式 -const isDev: Boolean = import.meta.env.MODE === "development"; - -// Host -const host: String = "https://show.cool-admin.com"; - -// 请求地址 -const baseUrl: String = (function () { - let proxy = getUrlParam("proxy"); - - if (proxy) { - storage.set("proxy", proxy); - } else { - proxy = storage.get("proxy") || "dev"; - } - - return isDev ? `/${proxy}` : `/api`; -})(); - -// 应用配置 -const app = { - name: "COOL-ADMIN", - - // 菜单 - menu: { - list: [] - }, - - // 路由 - router: { - // 模式 - mode: "history", - // 页面 - pages: [], - // 视图 / 路由下的 children - views: [] - }, - - // 主题 - theme: { - // 主色 - color: "", - // 样式地址 - url: "" - }, - - // 字体图标库 - iconfont: [] -}; - -// 忽略规则 -const ignore = { - // 不显示请求进度条 - NProgress: ["/sys/info/record"], - // 页面不需要登录验证 - token: ["/login", "/401", "/403", "/404", "/500", "/502"] -}; - -// 测试 -const test = { - token: "", - mock: false, - eps: true -}; - -export { isDev, host, baseUrl, app, ignore, test }; diff --git a/src/cool/config/dev.ts b/src/cool/config/dev.ts new file mode 100644 index 0000000..f56f29c --- /dev/null +++ b/src/cool/config/dev.ts @@ -0,0 +1,20 @@ +import { getUrlParam, storage } from "../utils"; +import { proxy } from "./proxy"; + +export default { + // 根地址 + host: proxy["/dev"], + + // 请求地址 + get baseUrl() { + let proxy = getUrlParam("proxy"); + + if (proxy) { + storage.set("proxy", proxy); + } else { + proxy = storage.get("proxy") || "dev"; + } + + return `/${proxy}`; + } +}; diff --git a/src/cool/config/index.ts b/src/cool/config/index.ts new file mode 100644 index 0000000..a4f4b0a --- /dev/null +++ b/src/cool/config/index.ts @@ -0,0 +1,61 @@ +import dev from "./dev"; +import prod from "./prod"; + +// 是否开发模式 +export const isDev = import.meta.env.MODE === "development"; + +// 配置 +export const config = { + // 项目信息 + app: { + name: "COOL-ADMIN", + + // 菜单 + menu: { + list: [] + }, + + // 路由 + router: { + // 模式 + mode: "history", + // 页面 + pages: [], + // 视图 / 路由下的 children + views: [] + }, + + // 主题 + theme: { + // 主色 + color: "", + // 样式地址 + url: "", + // 显示一级菜单 + showAMenu: false + }, + + // 字体图标库 + iconfont: [] + }, + + // 忽略规则 + ignore: { + // 不显示请求进度条 + NProgress: ["/sys/info/record"], + // 页面不需要登录验证 + token: ["/login", "/401", "/403", "/404", "/500", "/502"] + }, + + // 调试 + test: { + token: "", + mock: false, + eps: true + }, + + // 当前环境 + ...(isDev ? dev : prod) +}; + +export * from "./proxy"; diff --git a/src/cool/config/prod.ts b/src/cool/config/prod.ts new file mode 100644 index 0000000..ebbd862 --- /dev/null +++ b/src/cool/config/prod.ts @@ -0,0 +1,9 @@ +import { proxy } from "./proxy"; + +export default { + // 根地址 + host: proxy["/prod"], + + // 请求地址 + baseUrl: "/api" +}; diff --git a/src/cool/config/proxy.ts b/src/cool/config/proxy.ts new file mode 100644 index 0000000..962ff9a --- /dev/null +++ b/src/cool/config/proxy.ts @@ -0,0 +1,13 @@ +export const proxy = { + "/dev": { + target: "http://127.0.0.1:8001", + changeOrigin: true, + rewrite: (path: string) => path.replace(/^\/dev/, "") + }, + + "/prod": { + target: "https://show.cool-admin.com", + changeOrigin: true, + rewrite: (path: string) => path.replace(/^\/prod/, "/api") + } +}; diff --git a/src/cool/index.ts b/src/cool/index.ts index 6a57acb..d415dad 100644 --- a/src/cool/index.ts +++ b/src/cool/index.ts @@ -2,4 +2,5 @@ export * from "./service"; export * from "./bootstrap"; export * from "./hook"; export * from "./router"; +export * from "./config"; export { storage } from "./utils"; diff --git a/src/cool/module/index.ts b/src/cool/module/index.ts index 13c6fe2..f1a2722 100644 --- a/src/cool/module/index.ts +++ b/src/cool/module/index.ts @@ -1,6 +1,6 @@ import { App } from "vue"; import modules from "/@/modules"; -import { router, addViews } from "../router"; +import { router, viewer } from "../router"; import { filename, module } from "../utils"; import { isFunction, isObject } from "lodash"; @@ -149,7 +149,7 @@ export function useModule(app: App) { } if (e.path) { - addViews([e]); + viewer.add([e]); } else { console.error(`[${name}-views]:缺少 path 参数`); } diff --git a/src/cool/router/base.ts b/src/cool/router/base.ts deleted file mode 100644 index 18a9f6a..0000000 --- a/src/cool/router/base.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { ElMessage } from "element-plus"; -import { - createRouter, - createWebHashHistory, - createWebHistory, - NavigationGuardNext, - RouteRecordRaw -} from "vue-router"; -import { storage } from "/@/cool"; -import { useBaseStore } from "/$/base"; -import { app, ignore } from "/@/cool/config"; - -const { views, pages, mode } = app.router; - -// 默认路由 -const routes: RouteRecordRaw[] = [ - { - path: "/", - name: "index", - component: () => import("/$/base/pages/layout/index.vue"), - children: [ - { - path: "/", - name: "数据统计", - component: () => import("/@/views/home/index.vue") - }, - ...views - ] - }, - ...pages, - { - path: "/:catchAll(.*)", - name: "404", - redirect: "/404" - } -]; - -// 创建 -const router = createRouter({ - history: mode == "history" ? createWebHistory() : createWebHashHistory(), - routes -}); - -// 路由守卫 -router.beforeEach((to: any, _: any, next: NavigationGuardNext) => { - const { user, process } = useBaseStore(); - - if (user.token) { - if (to.path.includes("/login")) { - // 登录成功且 token 未过期,回到首页 - if (!storage.isExpired("token")) { - return next("/"); - } - } else { - // 添加路由进程 - process.add({ - keepAlive: to.meta?.keepAlive, - label: to.meta?.label || to.name, - value: to.fullPath - }); - } - } else { - if (!ignore.token.find((e: string) => to.path == e)) { - return next("/login"); - } - } - - next(); -}); - -let lock = false; - -// 错误监听 -router.onError((err: any) => { - if (!lock) { - lock = true; - - ElMessage.error("页面不存在或者未配置!"); - console.error(err); - - setTimeout(() => { - lock = false; - }, 0); - } -}); - -export { router }; -export * from "./views"; diff --git a/src/cool/router/index.ts b/src/cool/router/index.ts index 426ec23..a6db698 100644 --- a/src/cool/router/index.ts +++ b/src/cool/router/index.ts @@ -1,2 +1,135 @@ -export * from "./base"; -export * from "./views"; +// @ts-nocheck +import { ElMessage } from "element-plus"; +import { + createRouter, + createWebHashHistory, + createWebHistory, + NavigationGuardNext, + RouteRecordRaw +} from "vue-router"; +import { storage, config } from "/@/cool"; +import { useBaseStore } from "/$/base"; +import { cloneDeep, isArray } from "lodash"; + +// 视图文件 +const views = import.meta.globEager("/src/**/views/**/*.vue"); + +for (const i in views) { + views[i.slice(5)] = views[i]; + delete views[i]; +} + +// 默认路由 +const routes: RouteRecordRaw[] = [ + { + path: "/", + name: "index", + component: () => import("/$/base/pages/layout/index.vue"), + children: [ + { + path: "/", + name: "数据统计", + component: () => import("/@/views/home/index.vue") + }, + ...config.app.router.views + ] + }, + ...config.app.router.pages, + { + path: "/:catchAll(.*)", + name: "404", + redirect: "/404" + } +]; + +// 创建 +const router = createRouter({ + history: config.app.router.mode == "history" ? createWebHistory() : createWebHashHistory(), + routes +}); + +// 路由守卫 +router.beforeEach((to: any, _: any, next: NavigationGuardNext) => { + const { user, process } = useBaseStore(); + + if (user.token) { + if (to.path.includes("/login")) { + // 登录成功且 token 未过期,回到首页 + if (!storage.isExpired("token")) { + return next("/"); + } + } else { + // 添加路由进程 + process.add({ + keepAlive: to.meta?.keepAlive, + label: to.meta?.label || to.name, + value: to.fullPath + }); + } + } else { + if (!config.ignore.token.find((e: string) => to.path == e)) { + return next("/login"); + } + } + + next(); +}); + +let lock = false; + +// 错误监听 +router.onError((err: any) => { + if (!lock) { + lock = true; + + ElMessage.error("页面不存在或者未配置!"); + console.error(err); + + setTimeout(() => { + lock = false; + }, 0); + } +}); + +// 视图 +const viewer = { + add(data: any[] | any) { + // 列表 + const list = isArray(data) ? data : [data]; + + list.forEach((e: any) => { + const d: any = cloneDeep(e); + + // 命名 + d.name = d.router; + + if (!d.component) { + const url = d.viewPath; + + if (url) { + if ( + /^(http[s]?:\/\/)([0-9a-z.]+)(:[0-9]+)?([/0-9a-z.]+)?(\?[0-9a-z&=]+)?(#[0-9-a-z]+)?/i.test( + url + ) + ) { + d.meta.iframeUrl = url; + d.component = () => import(`/$/base/pages/iframe/index.vue`); + } else { + d.component = () => Promise.resolve(views[url.replace("cool/", "")]); + } + } else { + d.redirect = "/404"; + } + } + + // 批量添加 + router.addRoute("index", d); + }); + }, + + get() { + return router.getRoutes().find((e) => e.name == "index")?.children; + } +}; + +export { router, viewer }; diff --git a/src/cool/router/views.ts b/src/cool/router/views.ts deleted file mode 100644 index d34f90e..0000000 --- a/src/cool/router/views.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { cloneDeep, isArray } from "lodash"; -import { router } from "./base"; - -const views = import.meta.globEager("/src/**/views/**/*.vue"); - -for (const i in views) { - views[i.slice(5)] = views[i]; - delete views[i]; -} - -export function addViews(data: any[] | any) { - // 列表 - const list = isArray(data) ? data : [data]; - - list.forEach((e: any) => { - const d: any = cloneDeep(e); - - // 命名 - d.name = d.router; - - if (!d.component) { - const url = d.viewPath; - - if (url) { - if ( - /^(http[s]?:\/\/)([0-9a-z.]+)(:[0-9]+)?([/0-9a-z.]+)?(\?[0-9a-z&=]+)?(#[0-9-a-z]+)?/i.test( - url - ) - ) { - d.meta.iframeUrl = url; - d.component = () => import(`/$/base/pages/iframe/index.vue`); - } else { - d.component = () => Promise.resolve(views[url.replace("cool/", "")]); - } - } else { - d.redirect = "/404"; - } - } - - // 批量添加 - router.addRoute("index", d); - }); -} - -export function getViews() { - return router.getRoutes().find((e) => e.name == "index")?.children; -} diff --git a/src/cool/service/base.ts b/src/cool/service/base.ts index 040c3ad..7fd151a 100644 --- a/src/cool/service/base.ts +++ b/src/cool/service/base.ts @@ -1,5 +1,5 @@ // @ts-nocheck -import { baseUrl, isDev, test } from "../config"; +import { isDev, config, proxy } from "../config"; import { isObject } from "lodash"; import request from "./request"; @@ -23,8 +23,13 @@ export function Service( target.prototype.namespace = value.namespace; target.prototype.mock = value.mock; - if (value.url) { - target.prototype.url = value.url; + // 代理 + if (value.proxy) { + target.prototype.url = proxy[value.proxy].target; + } else { + if (value.url) { + target.prototype.url = value.url; + } } } }; @@ -55,13 +60,13 @@ export class BaseService { let ns = ""; // 是否 mock 模式 - if (this.mock || test.mock) { + if (this.mock || config.test.mock) { // 测试 } else { if (isDev) { - ns = this.proxy || baseUrl; + ns = this.proxy || config.baseUrl; } else { - ns = this.proxy ? this.url : baseUrl; + ns = this.proxy ? this.url : config.baseUrl; } } diff --git a/src/cool/service/eps.ts b/src/cool/service/eps.ts index 7017dad..0816282 100644 --- a/src/cool/service/eps.ts +++ b/src/cool/service/eps.ts @@ -1,4 +1,4 @@ -import { isDev, test } from "../config"; +import { isDev, config } from "../config"; import { BaseService } from "./base"; import { storage, toCamel } from "../utils"; import { isArray, isEmpty } from "lodash"; @@ -66,7 +66,7 @@ export function useEps(service: Service) { // 获取 eps function getEps() { - if (isDev && test.eps) { + if (isDev && config.test.eps) { service .request({ url: "/admin/base/open/eps" diff --git a/src/cool/service/request.ts b/src/cool/service/request.ts index 6fdc974..9694f5d 100644 --- a/src/cool/service/request.ts +++ b/src/cool/service/request.ts @@ -2,15 +2,16 @@ import axios from "axios"; import NProgress from "nprogress"; import "nprogress/nprogress.css"; import { ElMessage } from "element-plus"; -import { isDev, ignore } from "/@/cool/config"; +import { isDev, config } from "/@/cool"; import { href, storage } from "/@/cool/utils"; import { useBaseStore } from "/$/base"; +import { router } from "../router"; axios.defaults.timeout = 30000; axios.defaults.withCredentials = false; NProgress.configure({ - showSpinner: false + showSpinner: true }); // 请求队列 @@ -24,39 +25,38 @@ axios.interceptors.request.eject(axios._req); // @ts-ignore axios._req = axios.interceptors.request.use( - (config: any) => { + (req: any) => { const { user } = useBaseStore(); - if (config.url) { + if (req.url) { // 请求进度条 - if (!ignore.NProgress.some((e) => config.url.includes(e))) { + if (!config.ignore.NProgress.some((e: string) => req.url.includes(e))) { NProgress.start(); } } // 请求信息 if (isDev) { - console.group(config.url); - console.log("method:", config.method); - console.table("data:", config.method == "get" ? config.params : config.data); + console.group(req.url); + console.log("method:", req.method); + console.table("data:", req.method == "get" ? req.params : req.data); console.groupEnd(); } // 验证 token if (user.token) { // 请求标识 - config.headers["Authorization"] = user.token; + req.headers["Authorization"] = user.token; - if (config.url.includes("refreshToken")) { - return config; + if (req.url.includes("refreshToken")) { + return req; } // 判断 token 是否过期 if (storage.isExpired("token")) { // 判断 refreshToken 是否过期 if (storage.isExpired("refreshToken")) { - user.clear(); - return href("/login"); + return user.logout(); } // 是否在刷新中 @@ -78,14 +78,14 @@ axios._req = axios.interceptors.request.use( // 继续请求 requests.push((token: string) => { // 重新设置 token - config.headers["Authorization"] = token; - resolve(config); + req.headers["Authorization"] = token; + resolve(req); }); }); } } - return config; + return req; }, (error) => { return Promise.reject(error); @@ -124,19 +124,19 @@ axios.interceptors.response.use( } else { switch (status) { case 401: - href("/401"); + router.push("/401"); break; case 403: - href("/403"); + router.push("/403"); break; case 500: - href("/500"); + router.push("/500"); break; case 502: - href("/502"); + router.push("/502"); break; } } diff --git a/src/cool/utils/index.ts b/src/cool/utils/index.ts index 8d45c81..1d7be11 100644 --- a/src/cool/utils/index.ts +++ b/src/cool/utils/index.ts @@ -1,5 +1,4 @@ import { isArray, orderBy } from "lodash"; -import { app } from "../config"; import storage from "./storage"; import module from "./module"; @@ -212,29 +211,6 @@ export function getBrowser() { }; } -// 跳转 -export function href(path: string, newWindow?: boolean) { - const { origin, pathname } = window.location; - - if (pathname == path) { - return false; - } - - let url = ""; - - if (app.router.mode == "history") { - url = origin + import.meta.env.BASE_URL + path.substr(1); - } else { - url = origin + import.meta.env.BASE_URL + "#" + path; - } - - if (newWindow) { - window.open(url); - } else { - window.location.href = url; - } -} - // 列表转树形 export function deepTree(list: any[]): any[] { const newList: Array = []; diff --git a/src/env.d.ts b/src/env.d.ts index f8da03d..191a0fe 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1,5 +1,4 @@ /// /// -declare const __PROXY_LIST__: any[]; declare const __EPS__: string; diff --git a/src/modules/base/common/theme.ts b/src/modules/base/common/theme.ts index 11d5cb4..756651c 100644 --- a/src/modules/base/common/theme.ts +++ b/src/modules/base/common/theme.ts @@ -1,10 +1,10 @@ -import { app } from "/@/cool/config"; +import { config } from "/@/cool"; import { basename } from "/@/cool/utils"; import { createLink } from "../utils"; // 主题初始化 -if (app.theme) { - const { url, color } = app.theme; +if (config.app.theme) { + const { url, color } = config.app.theme; if (url) { createLink(url, "theme-style"); @@ -14,8 +14,8 @@ if (app.theme) { } // 字体图标库加载 -if (app.iconfont) { - app.iconfont.forEach((e: string) => { +if (config.app.iconfont) { + config.app.iconfont.forEach((e: string) => { createLink(e); }); } diff --git a/src/modules/base/store/app.ts b/src/modules/base/store/app.ts index 283aefa..fd2781d 100644 --- a/src/modules/base/store/app.ts +++ b/src/modules/base/store/app.ts @@ -1,12 +1,12 @@ import { defineStore } from "pinia"; import { ref } from "vue"; -import { app } from "/@/cool/config"; +import { config } from "/@/cool"; import { deepMerge, getBrowser, storage } from "/@/cool/utils"; export const useAppStore = defineStore("app", function () { // 基本信息 const info = ref({ - ...app + ...config.app }); // 浏览器信息 diff --git a/src/modules/base/store/menu.ts b/src/modules/base/store/menu.ts index d1d3e36..db9012f 100644 --- a/src/modules/base/store/menu.ts +++ b/src/modules/base/store/menu.ts @@ -3,8 +3,7 @@ import { defineStore } from "pinia"; import { ref } from "vue"; import { deepTree, revDeepTree, storage } from "/@/cool/utils"; import { isArray, isEmpty, isObject, orderBy } from "lodash"; -import { app } from "/@/cool/config"; -import { addViews, service } from "/@/cool"; +import { viewer, service, config } from "/@/cool"; import { revisePath } from "../utils"; declare enum Type { @@ -57,7 +56,8 @@ export const useMenuStore = defineStore("menu", function () { i = index.value; } - if (app.showAMenu) { + // 显示一级菜单 + if (config.app.theme.showAMenu) { const { children = [] } = group.value[i] || {}; index.value = i; @@ -97,7 +97,7 @@ export const useMenuStore = defineStore("menu", function () { // 设置视图 function setRoutes(list: Item[]) { - addViews(list); + viewer.add(list); routes.value = list; storage.set("menu.routes", list); @@ -157,7 +157,7 @@ export const useMenuStore = defineStore("menu", function () { resolve(group.value); } - if (isEmpty(app.menu.list)) { + if (isEmpty(config.app.menu.list)) { service.base.comm .permmenu() .then(next) @@ -168,7 +168,7 @@ export const useMenuStore = defineStore("menu", function () { } else { // 自定义菜单 next({ - menus: revDeepTree(app.menu.list) + menus: revDeepTree(config.app.menu.list) }); } }); diff --git a/src/modules/base/store/user.ts b/src/modules/base/store/user.ts index 28845f7..bef5926 100644 --- a/src/modules/base/store/user.ts +++ b/src/modules/base/store/user.ts @@ -1,8 +1,7 @@ import { defineStore } from "pinia"; import { ref } from "vue"; import { href, storage } from "/@/cool/utils"; -import { test } from "/@/cool/config"; -import { service } from "/@/cool"; +import { service, config } from "/@/cool"; interface User { id: number; @@ -23,7 +22,7 @@ const data = storage.info(); export const useUserStore = defineStore("user", function () { // 标识 - const token = ref(test.token || data.token); + const token = ref(config.test.token || data.token); // 设置标识 function setToken(data: { @@ -77,9 +76,11 @@ export const useUserStore = defineStore("user", function () { // 退出 async function logout() { - await service.base.comm.logout(); + try { + await service.base.comm.logout(); + } catch {} clear(); - href("/login"); + location.href = "/login"; } // 获取用户信息 diff --git a/src/modules/base/views/components/dept-tree.vue b/src/modules/base/views/components/dept-tree.vue index 405414d..53bbfc7 100644 --- a/src/modules/base/views/components/dept-tree.vue +++ b/src/modules/base/views/components/dept-tree.vue @@ -17,8 +17,8 @@
  • - 保存 - 取消 + 保存 + 取消
  • diff --git a/src/modules/base/views/menu.vue b/src/modules/base/views/menu.vue index 5fae08f..a71d1fd 100644 --- a/src/modules/base/views/menu.vue +++ b/src/modules/base/views/menu.vue @@ -77,9 +77,8 @@ -