调整 config 配置方式

This commit is contained in:
icssoa 2022-05-18 15:09:13 +08:00
parent 9572a73791
commit 94ae17dee4
31 changed files with 371 additions and 578 deletions

View File

@ -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",""]]]] [["/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",""]]]]

View File

@ -635,232 +635,6 @@ declare interface SpaceType {
}; };
} }
declare interface StudyFinish {
/**
*
* @returns Promise<PageResponse>
*/
page(data?: any): Promise<PageResponse>;
/**
* list
* @returns Promise<any>
*/
list(data?: any): Promise<any>;
/**
* info
* @returns Promise<any>
*/
info(data?: any): Promise<any>;
/**
* update
* @returns Promise<any>
*/
update(data?: any): Promise<any>;
/**
* delete
* @returns Promise<any>
*/
delete(data?: any): Promise<any>;
/**
* add
* @returns Promise<any>
*/
add(data?: any): Promise<any>;
/**
*
*/
permission: {
page: string;
list: string;
info: string;
update: string;
delete: string;
add: string;
};
}
declare interface StudyLearn {
/**
*
* @returns Promise<any>
*/
delete(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
update(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
info(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
list(data?: any): Promise<any>;
/**
*
* @returns Promise<PageResponse>
*/
page(data?: any): Promise<PageResponse>;
/**
*
* @returns Promise<any>
*/
add(data?: any): Promise<any>;
/**
*
*/
permission: {
delete: string;
update: string;
info: string;
list: string;
page: string;
add: string;
};
}
declare interface StudyMusic {
/**
*
* @returns Promise<any>
*/
delete(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
update(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
info(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
list(data?: any): Promise<any>;
/**
*
* @returns Promise<PageResponse>
*/
page(data?: any): Promise<PageResponse>;
/**
*
* @returns Promise<any>
*/
add(data?: any): Promise<any>;
/**
*
*/
permission: {
delete: string;
update: string;
info: string;
list: string;
page: string;
add: string;
};
}
declare interface StudyTopic {
/**
*
* @returns Promise<any>
*/
provinceCount(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
delete(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
update(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
info(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
list(data?: any): Promise<any>;
/**
*
* @returns Promise<PageResponse>
*/
page(data?: any): Promise<PageResponse>;
/**
*
* @returns Promise<any>
*/
add(data?: any): Promise<any>;
/**
*
*/
permission: {
provinceCount: string;
delete: string;
update: string;
info: string;
list: string;
page: string;
add: string;
};
}
declare interface StudyWorks {
/**
*
* @returns Promise<any>
*/
delete(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
update(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
info(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
list(data?: any): Promise<any>;
/**
*
* @returns Promise<PageResponse>
*/
page(data?: any): Promise<PageResponse>;
/**
*
* @returns Promise<any>
*/
add(data?: any): Promise<any>;
/**
*
*/
permission: {
delete: string;
update: string;
info: string;
list: string;
page: string;
add: string;
};
}
declare interface TaskInfo { declare interface TaskInfo {
/** /**
* *
@ -929,34 +703,34 @@ declare interface TaskInfo {
}; };
} }
declare interface UserInfo { declare interface Test {
/** /**
* * list
* @returns Promise<any>
*/
delete(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
update(data?: any): Promise<any>;
/**
*
* @returns Promise<any>
*/
info(data?: any): Promise<any>;
/**
*
* @returns Promise<any> * @returns Promise<any>
*/ */
list(data?: any): Promise<any>; list(data?: any): Promise<any>;
/** /**
* * page
* @returns Promise<PageResponse> * @returns Promise<PageResponse>
*/ */
page(data?: any): Promise<PageResponse>; page(data?: any): Promise<PageResponse>;
/** /**
* * info
* @returns Promise<any>
*/
info(data?: any): Promise<any>;
/**
* update
* @returns Promise<any>
*/
update(data?: any): Promise<any>;
/**
* delete
* @returns Promise<any>
*/
delete(data?: any): Promise<any>;
/**
* add
* @returns Promise<any> * @returns Promise<any>
*/ */
add(data?: any): Promise<any>; add(data?: any): Promise<any>;
@ -964,11 +738,11 @@ declare interface UserInfo {
* *
*/ */
permission: { permission: {
delete: string;
update: string;
info: string;
list: string; list: string;
page: string; page: string;
info: string;
update: string;
delete: string;
add: string; add: string;
}; };
} }
@ -989,13 +763,6 @@ declare type Service = {
}; };
demo: { goods: DemoGoods }; demo: { goods: DemoGoods };
space: { info: SpaceInfo; type: SpaceType }; space: { info: SpaceInfo; type: SpaceType };
study: {
finish: StudyFinish;
learn: StudyLearn;
music: StudyMusic;
topic: StudyTopic;
works: StudyWorks;
};
task: { info: TaskInfo }; task: { info: TaskInfo };
user: { info: UserInfo }; test: Test;
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "front-next", "name": "front-next",
"version": "5.1.6", "version": "5.2.0",
"scripts": { "scripts": {
"dev": "vite --host", "dev": "vite --host",
"build": "vite build", "build": "vite build",
@ -12,7 +12,7 @@
"@cool-vue/crud": "^5.0.7", "@cool-vue/crud": "^5.0.7",
"@element-plus/icons-vue": "^1.1.3", "@element-plus/icons-vue": "^1.1.3",
"@vueuse/core": "^8.2.5", "@vueuse/core": "^8.2.5",
"axios": "^0.26.1", "axios": "^0.27.2",
"codemirror": "^5.62.0", "codemirror": "^5.62.0",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"echarts": "^5.0.2", "echarts": "^5.0.2",

View File

@ -1,7 +1,7 @@
import { createPinia } from "pinia"; import { createPinia } from "pinia";
import { App } from "vue"; import { App } from "vue";
import { useModule } from "./module"; import { useModule } from "./module";
import { router, addViews } from "./router"; import { router, viewer } from "./router";
import { useBaseStore } from "/$/base"; import { useBaseStore } from "/$/base";
import mitt from "mitt"; import mitt from "mitt";
import VueECharts from "vue-echarts"; import VueECharts from "vue-echarts";
@ -29,7 +29,7 @@ export async function bootstrap(Vue: App) {
useModule(Vue); useModule(Vue);
// 取缓存视图 // 取缓存视图
addViews(menu.routes); viewer.add(menu.routes);
// 路由 // 路由
Vue.use(router); Vue.use(router);

View File

@ -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 };

20
src/cool/config/dev.ts Normal file
View File

@ -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}`;
}
};

61
src/cool/config/index.ts Normal file
View File

@ -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";

9
src/cool/config/prod.ts Normal file
View File

@ -0,0 +1,9 @@
import { proxy } from "./proxy";
export default {
// 根地址
host: proxy["/prod"],
// 请求地址
baseUrl: "/api"
};

13
src/cool/config/proxy.ts Normal file
View File

@ -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")
}
};

View File

@ -2,4 +2,5 @@ export * from "./service";
export * from "./bootstrap"; export * from "./bootstrap";
export * from "./hook"; export * from "./hook";
export * from "./router"; export * from "./router";
export * from "./config";
export { storage } from "./utils"; export { storage } from "./utils";

View File

@ -1,6 +1,6 @@
import { App } from "vue"; import { App } from "vue";
import modules from "/@/modules"; import modules from "/@/modules";
import { router, addViews } from "../router"; import { router, viewer } from "../router";
import { filename, module } from "../utils"; import { filename, module } from "../utils";
import { isFunction, isObject } from "lodash"; import { isFunction, isObject } from "lodash";
@ -149,7 +149,7 @@ export function useModule(app: App) {
} }
if (e.path) { if (e.path) {
addViews([e]); viewer.add([e]);
} else { } else {
console.error(`[${name}-views]:缺少 path 参数`); console.error(`[${name}-views]:缺少 path 参数`);
} }

View File

@ -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";

View File

@ -1,2 +1,135 @@
export * from "./base"; // @ts-nocheck
export * from "./views"; 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 };

View File

@ -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;
}

View File

@ -1,5 +1,5 @@
// @ts-nocheck // @ts-nocheck
import { baseUrl, isDev, test } from "../config"; import { isDev, config, proxy } from "../config";
import { isObject } from "lodash"; import { isObject } from "lodash";
import request from "./request"; import request from "./request";
@ -23,8 +23,13 @@ export function Service(
target.prototype.namespace = value.namespace; target.prototype.namespace = value.namespace;
target.prototype.mock = value.mock; 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 = ""; let ns = "";
// 是否 mock 模式 // 是否 mock 模式
if (this.mock || test.mock) { if (this.mock || config.test.mock) {
// 测试 // 测试
} else { } else {
if (isDev) { if (isDev) {
ns = this.proxy || baseUrl; ns = this.proxy || config.baseUrl;
} else { } else {
ns = this.proxy ? this.url : baseUrl; ns = this.proxy ? this.url : config.baseUrl;
} }
} }

View File

@ -1,4 +1,4 @@
import { isDev, test } from "../config"; import { isDev, config } from "../config";
import { BaseService } from "./base"; import { BaseService } from "./base";
import { storage, toCamel } from "../utils"; import { storage, toCamel } from "../utils";
import { isArray, isEmpty } from "lodash"; import { isArray, isEmpty } from "lodash";
@ -66,7 +66,7 @@ export function useEps(service: Service) {
// 获取 eps // 获取 eps
function getEps() { function getEps() {
if (isDev && test.eps) { if (isDev && config.test.eps) {
service service
.request({ .request({
url: "/admin/base/open/eps" url: "/admin/base/open/eps"

View File

@ -2,15 +2,16 @@ import axios from "axios";
import NProgress from "nprogress"; import NProgress from "nprogress";
import "nprogress/nprogress.css"; import "nprogress/nprogress.css";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { isDev, ignore } from "/@/cool/config"; import { isDev, config } from "/@/cool";
import { href, storage } from "/@/cool/utils"; import { href, storage } from "/@/cool/utils";
import { useBaseStore } from "/$/base"; import { useBaseStore } from "/$/base";
import { router } from "../router";
axios.defaults.timeout = 30000; axios.defaults.timeout = 30000;
axios.defaults.withCredentials = false; axios.defaults.withCredentials = false;
NProgress.configure({ NProgress.configure({
showSpinner: false showSpinner: true
}); });
// 请求队列 // 请求队列
@ -24,39 +25,38 @@ axios.interceptors.request.eject(axios._req);
// @ts-ignore // @ts-ignore
axios._req = axios.interceptors.request.use( axios._req = axios.interceptors.request.use(
(config: any) => { (req: any) => {
const { user } = useBaseStore(); 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(); NProgress.start();
} }
} }
// 请求信息 // 请求信息
if (isDev) { if (isDev) {
console.group(config.url); console.group(req.url);
console.log("method:", config.method); console.log("method:", req.method);
console.table("data:", config.method == "get" ? config.params : config.data); console.table("data:", req.method == "get" ? req.params : req.data);
console.groupEnd(); console.groupEnd();
} }
// 验证 token // 验证 token
if (user.token) { if (user.token) {
// 请求标识 // 请求标识
config.headers["Authorization"] = user.token; req.headers["Authorization"] = user.token;
if (config.url.includes("refreshToken")) { if (req.url.includes("refreshToken")) {
return config; return req;
} }
// 判断 token 是否过期 // 判断 token 是否过期
if (storage.isExpired("token")) { if (storage.isExpired("token")) {
// 判断 refreshToken 是否过期 // 判断 refreshToken 是否过期
if (storage.isExpired("refreshToken")) { if (storage.isExpired("refreshToken")) {
user.clear(); return user.logout();
return href("/login");
} }
// 是否在刷新中 // 是否在刷新中
@ -78,14 +78,14 @@ axios._req = axios.interceptors.request.use(
// 继续请求 // 继续请求
requests.push((token: string) => { requests.push((token: string) => {
// 重新设置 token // 重新设置 token
config.headers["Authorization"] = token; req.headers["Authorization"] = token;
resolve(config); resolve(req);
}); });
}); });
} }
} }
return config; return req;
}, },
(error) => { (error) => {
return Promise.reject(error); return Promise.reject(error);
@ -124,19 +124,19 @@ axios.interceptors.response.use(
} else { } else {
switch (status) { switch (status) {
case 401: case 401:
href("/401"); router.push("/401");
break; break;
case 403: case 403:
href("/403"); router.push("/403");
break; break;
case 500: case 500:
href("/500"); router.push("/500");
break; break;
case 502: case 502:
href("/502"); router.push("/502");
break; break;
} }
} }

View File

@ -1,5 +1,4 @@
import { isArray, orderBy } from "lodash"; import { isArray, orderBy } from "lodash";
import { app } from "../config";
import storage from "./storage"; import storage from "./storage";
import module from "./module"; 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[] { export function deepTree(list: any[]): any[] {
const newList: Array<any> = []; const newList: Array<any> = [];

1
src/env.d.ts vendored
View File

@ -1,5 +1,4 @@
/// <reference types="@cool-vue/crud" /> /// <reference types="@cool-vue/crud" />
/// <reference types="../build/cool/temp/service" /> /// <reference types="../build/cool/temp/service" />
declare const __PROXY_LIST__: any[];
declare const __EPS__: string; declare const __EPS__: string;

View File

@ -1,10 +1,10 @@
import { app } from "/@/cool/config"; import { config } from "/@/cool";
import { basename } from "/@/cool/utils"; import { basename } from "/@/cool/utils";
import { createLink } from "../utils"; import { createLink } from "../utils";
// 主题初始化 // 主题初始化
if (app.theme) { if (config.app.theme) {
const { url, color } = app.theme; const { url, color } = config.app.theme;
if (url) { if (url) {
createLink(url, "theme-style"); createLink(url, "theme-style");
@ -14,8 +14,8 @@ if (app.theme) {
} }
// 字体图标库加载 // 字体图标库加载
if (app.iconfont) { if (config.app.iconfont) {
app.iconfont.forEach((e: string) => { config.app.iconfont.forEach((e: string) => {
createLink(e); createLink(e);
}); });
} }

View File

@ -1,12 +1,12 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { ref } from "vue"; import { ref } from "vue";
import { app } from "/@/cool/config"; import { config } from "/@/cool";
import { deepMerge, getBrowser, storage } from "/@/cool/utils"; import { deepMerge, getBrowser, storage } from "/@/cool/utils";
export const useAppStore = defineStore("app", function () { export const useAppStore = defineStore("app", function () {
// 基本信息 // 基本信息
const info = ref<any>({ const info = ref<any>({
...app ...config.app
}); });
// 浏览器信息 // 浏览器信息

View File

@ -3,8 +3,7 @@ import { defineStore } from "pinia";
import { ref } from "vue"; import { ref } from "vue";
import { deepTree, revDeepTree, storage } from "/@/cool/utils"; import { deepTree, revDeepTree, storage } from "/@/cool/utils";
import { isArray, isEmpty, isObject, orderBy } from "lodash"; import { isArray, isEmpty, isObject, orderBy } from "lodash";
import { app } from "/@/cool/config"; import { viewer, service, config } from "/@/cool";
import { addViews, service } from "/@/cool";
import { revisePath } from "../utils"; import { revisePath } from "../utils";
declare enum Type { declare enum Type {
@ -57,7 +56,8 @@ export const useMenuStore = defineStore("menu", function () {
i = index.value; i = index.value;
} }
if (app.showAMenu) { // 显示一级菜单
if (config.app.theme.showAMenu) {
const { children = [] } = group.value[i] || {}; const { children = [] } = group.value[i] || {};
index.value = i; index.value = i;
@ -97,7 +97,7 @@ export const useMenuStore = defineStore("menu", function () {
// 设置视图 // 设置视图
function setRoutes(list: Item[]) { function setRoutes(list: Item[]) {
addViews(list); viewer.add(list);
routes.value = list; routes.value = list;
storage.set("menu.routes", list); storage.set("menu.routes", list);
@ -157,7 +157,7 @@ export const useMenuStore = defineStore("menu", function () {
resolve(group.value); resolve(group.value);
} }
if (isEmpty(app.menu.list)) { if (isEmpty(config.app.menu.list)) {
service.base.comm service.base.comm
.permmenu() .permmenu()
.then(next) .then(next)
@ -168,7 +168,7 @@ export const useMenuStore = defineStore("menu", function () {
} else { } else {
// 自定义菜单 // 自定义菜单
next({ next({
menus: revDeepTree(app.menu.list) menus: revDeepTree(config.app.menu.list)
}); });
} }
}); });

View File

@ -1,8 +1,7 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { ref } from "vue"; import { ref } from "vue";
import { href, storage } from "/@/cool/utils"; import { href, storage } from "/@/cool/utils";
import { test } from "/@/cool/config"; import { service, config } from "/@/cool";
import { service } from "/@/cool";
interface User { interface User {
id: number; id: number;
@ -23,7 +22,7 @@ const data = storage.info();
export const useUserStore = defineStore("user", function () { export const useUserStore = defineStore("user", function () {
// 标识 // 标识
const token = ref<string>(test.token || data.token); const token = ref<string>(config.test.token || data.token);
// 设置标识 // 设置标识
function setToken(data: { function setToken(data: {
@ -77,9 +76,11 @@ export const useUserStore = defineStore("user", function () {
// 退出 // 退出
async function logout() { async function logout() {
await service.base.comm.logout(); try {
await service.base.comm.logout();
} catch {}
clear(); clear();
href("/login"); location.href = "/login";
} }
// 获取用户信息 // 获取用户信息

View File

@ -17,8 +17,8 @@
</li> </li>
<li v-show="isDrag" class="no"> <li v-show="isDrag" class="no">
<el-button type="text" @click="treeOrder(true)" size="small">保存</el-button> <el-button @click="treeOrder(true)" size="small">保存</el-button>
<el-button type="text" @click="treeOrder(false)" size="small">取消</el-button> <el-button @click="treeOrder(false)" size="small">取消</el-button>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -77,9 +77,8 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useCool } from "/@/cool"; import { useCool, isDev } from "/@/cool";
import { deepTree } from "/@/cool/utils"; import { deepTree } from "/@/cool/utils";
import { isDev } from "/@/cool/config";
import { useCrud, useTable, useUpsert } from "@cool-vue/crud"; import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import MenuCreate from "./components/menu-create.vue"; import MenuCreate from "./components/menu-create.vue";
import MenuCheck from "./components/menu-check.vue"; import MenuCheck from "./components/menu-check.vue";

View File

@ -66,7 +66,8 @@
<template #slot-btn="{ scope }"> <template #slot-btn="{ scope }">
<el-button <el-button
v-permission="service.base.sys.user.permission.move" v-permission="service.base.sys.user.permission.move"
type="text" text
bg
@click="toMove(scope.row)" @click="toMove(scope.row)"
>转移</el-button >转移</el-button
> >

View File

@ -44,16 +44,6 @@
</div> </div>
</template> </template>
<script lang="tsx">
export default {
cool: {
route: {
path: "/crud"
}
}
};
</script>
<script lang="tsx" setup> <script lang="tsx" setup>
import { useCrud, useUpsert, useTable, useForm, useAdvSearch } from "@cool-vue/crud"; import { useCrud, useUpsert, useTable, useForm, useAdvSearch } from "@cool-vue/crud";

View File

@ -9,7 +9,6 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue";
import ContextMenu from "../components/demo/context-menu.vue"; import ContextMenu from "../components/demo/context-menu.vue";
import Crud from "../components/demo/crud.vue"; import Crud from "../components/demo/crud.vue";
import Upload from "../components/demo/upload.vue"; import Upload from "../components/demo/upload.vue";
@ -17,7 +16,7 @@ import EditorQuill from "../components/demo/editor-quill.vue";
import Svg from "../components/demo/svg.vue"; import Svg from "../components/demo/svg.vue";
import Copy from "../components/demo/copy.vue"; import Copy from "../components/demo/copy.vue";
const list = ref([ContextMenu, Crud, Upload, EditorQuill, Svg, Copy]); const list = [ContextMenu, Crud, Upload, EditorQuill, Svg, Copy];
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@ -118,7 +118,7 @@
<el-button <el-button
v-if="item.pagination.total >= item.pagination.size" v-if="item.pagination.total >= item.pagination.size"
class="more" class="more"
type="text" text
@click="moreTask(index)" @click="moreTask(index)"
>查看更多</el-button >查看更多</el-button
> >

View File

@ -3,11 +3,12 @@ import { UserConfig } from "vite";
import vue from "@vitejs/plugin-vue"; import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx"; import vueJsx from "@vitejs/plugin-vue-jsx";
import viteCompression from "vite-plugin-compression"; import viteCompression from "vite-plugin-compression";
import { svgBuilder } from "./build/svg";
import { cool } from "./build/cool";
import Components from "unplugin-vue-components/vite"; import Components from "unplugin-vue-components/vite";
import Unocss from "unocss/vite"; import Unocss from "unocss/vite";
import { presetUno } from "unocss"; import { presetUno } from "unocss";
import { proxy } from "./src/cool/config/proxy";
import { cool } from "./build/cool";
import { svgBuilder } from "./build/svg";
function resolve(dir: string) { function resolve(dir: string) {
return path.resolve(__dirname, ".", dir); return path.resolve(__dirname, ".", dir);
@ -16,21 +17,6 @@ function resolve(dir: string) {
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default (): UserConfig => { export default (): UserConfig => {
// 请求代理地址
const proxy = {
"/dev": {
target: "http://127.0.0.1:8001",
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/dev/, "")
},
"/pro": {
target: "https://show.cool-admin.com",
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/pro/, "/api")
}
};
return { return {
base: "/", base: "/",
plugins: [ plugins: [
@ -65,9 +51,6 @@ export default (): UserConfig => {
overlay: true overlay: true
} }
}, },
define: {
__PROXY_LIST__: JSON.stringify(proxy)
},
build: { build: {
sourcemap: false, sourcemap: false,
polyfillDynamicImport: false // 必须为false polyfillDynamicImport: false // 必须为false

View File

@ -2124,6 +2124,11 @@ async-validator@^4.0.7:
resolved "https://registry.npmjs.org/async-validator/-/async-validator-4.0.7.tgz#034a0fd2103a6b2ebf010da75183bec299247afe" resolved "https://registry.npmjs.org/async-validator/-/async-validator-4.0.7.tgz#034a0fd2103a6b2ebf010da75183bec299247afe"
integrity sha512-Pj2IR7u8hmUEDOwB++su6baaRi+QvsgajuFB9j95foM1N2gy5HM4z60hfusIO0fBPG5uLAEl6yCJr1jNSVugEQ== integrity sha512-Pj2IR7u8hmUEDOwB++su6baaRi+QvsgajuFB9j95foM1N2gy5HM4z60hfusIO0fBPG5uLAEl6yCJr1jNSVugEQ==
asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
at-least-node@^1.0.0: at-least-node@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" resolved "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
@ -2141,6 +2146,14 @@ axios@^0.26.1:
dependencies: dependencies:
follow-redirects "^1.14.8" follow-redirects "^1.14.8"
axios@^0.27.2:
version "0.27.2"
resolved "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
dependencies:
follow-redirects "^1.14.9"
form-data "^4.0.0"
babel-loader@^8.2.2: babel-loader@^8.2.2:
version "8.2.4" version "8.2.4"
resolved "https://registry.npmjs.org/babel-loader/-/babel-loader-8.2.4.tgz#95f5023c791b2e9e2ca6f67b0984f39c82ff384b" resolved "https://registry.npmjs.org/babel-loader/-/babel-loader-8.2.4.tgz#95f5023c791b2e9e2ca6f67b0984f39c82ff384b"
@ -2532,6 +2545,13 @@ colorette@^2.0.16:
resolved "https://registry.npmjs.org/colorette/-/colorette-2.0.16.tgz#713b9af84fdb000139f04546bd4a93f62a5085da" resolved "https://registry.npmjs.org/colorette/-/colorette-2.0.16.tgz#713b9af84fdb000139f04546bd4a93f62a5085da"
integrity sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g== integrity sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==
combined-stream@^1.0.8:
version "1.0.8"
resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
dependencies:
delayed-stream "~1.0.0"
commander@*: commander@*:
version "9.1.0" version "9.1.0"
resolved "https://registry.npmjs.org/commander/-/commander-9.1.0.tgz#a6b263b2327f2e188c6402c42623327909f2dbec" resolved "https://registry.npmjs.org/commander/-/commander-9.1.0.tgz#a6b263b2327f2e188c6402c42623327909f2dbec"
@ -2815,6 +2835,11 @@ defu@^6.0.0:
resolved "https://registry.npmjs.org/defu/-/defu-6.0.0.tgz#b397a6709a2f3202747a3d9daf9446e41ad0c5fc" resolved "https://registry.npmjs.org/defu/-/defu-6.0.0.tgz#b397a6709a2f3202747a3d9daf9446e41ad0c5fc"
integrity sha512-t2MZGLf1V2rV4VBZbWIaXKdX/mUcYW0n2znQZoADBkGGxYL8EWqCuCZBmJPJ/Yy9fofJkyuuSuo5GSwo0XdEgw== integrity sha512-t2MZGLf1V2rV4VBZbWIaXKdX/mUcYW0n2znQZoADBkGGxYL8EWqCuCZBmJPJ/Yy9fofJkyuuSuo5GSwo0XdEgw==
delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=
dir-glob@^3.0.1: dir-glob@^3.0.1:
version "3.0.1" version "3.0.1"
resolved "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f" resolved "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
@ -3614,6 +3639,11 @@ follow-redirects@^1.14.8:
resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7" resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w== integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==
follow-redirects@^1.14.9:
version "1.15.0"
resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4"
integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ==
for-in@^1.0.2: for-in@^1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" resolved "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
@ -3638,6 +3668,15 @@ fork-ts-checker-webpack-plugin@^6.4.0:
semver "^7.3.2" semver "^7.3.2"
tapable "^1.0.0" tapable "^1.0.0"
form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"
frac@~1.1.2: frac@~1.1.2:
version "1.1.2" version "1.1.2"
resolved "https://registry.npmjs.org/frac/-/frac-1.1.2.tgz#3d74f7f6478c88a1b5020306d747dc6313c74d0b" resolved "https://registry.npmjs.org/frac/-/frac-1.1.2.tgz#3d74f7f6478c88a1b5020306d747dc6313c74d0b"
@ -4669,7 +4708,7 @@ mime-db@1.52.0:
resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
mime-types@^2.1.27: mime-types@^2.1.12, mime-types@^2.1.27:
version "2.1.35" version "2.1.35"
resolved "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" resolved "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==