This commit is contained in:
icssoa 2022-05-16 02:14:44 +08:00
parent 13c74533bd
commit 537cd2f708
9 changed files with 76 additions and 66 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -1,9 +1,8 @@
import { App } from "vue";
import modules from "/@/modules"; import modules from "/@/modules";
import { router, addViews } from "../router"; import { router, addViews } from "../router";
import { filename } from "../utils"; import { filename, module } from "../utils";
import { isFunction, isObject } from "lodash"; import { isFunction, isObject } from "lodash";
import { App } from "vue";
import module from "../utils/module";
// 扫描文件 // 扫描文件
const files = import.meta.globEager("/src/modules/**/*"); const files = import.meta.globEager("/src/modules/**/*");

View File

@ -66,7 +66,7 @@ export function useEps(service: Service) {
// 获取 eps // 获取 eps
function getEps() { function getEps() {
if (isDev) { if (isDev && test.eps) {
service service
.request({ .request({
url: "/admin/base/open/eps" url: "/admin/base/open/eps"
@ -183,17 +183,11 @@ export function useEps(service: Service) {
} }
} }
// 获取 // 解析
if (isDev) { try {
// 缓存数据 const eps =
set(storage.get("eps")); storage.get("eps") ||
JSON.parse(__EPS__ || "[]").map(([prefix, api]: any[]) => {
// 接口数据
if (test.eps) {
getEps();
}
} else {
const eps = JSON.parse(__EPS__).map(([prefix, api]: any[]) => {
return { return {
prefix, prefix,
api: api.map(([method, path, name]: string[]) => { api: api.map(([method, path, name]: string[]) => {
@ -206,7 +200,11 @@ export function useEps(service: Service) {
}; };
}); });
// 文件数据
set({ eps }); set({ eps });
} catch (err) {
console.error("[Eps] 解析失败!", err);
} }
// 获取
getEps();
} }

View File

@ -1,20 +1,20 @@
import { deepFiles, deepMerge } from "../utils"; import { deepFiles, deepMerge, module } from "../utils";
import { BaseService } from "./base"; import { BaseService } from "./base";
import { useEps } from "./eps"; import { useEps } from "./eps";
// 服务 // 基础服务
export const service: Service = { export const service: Service = {
request: new BaseService().request request: new BaseService().request
}; };
export function useService() { export function useService() {
// 接口内容
useEps(service); useEps(service);
if (window.__modules__) { // 模块内容
window.__modules__.forEach((e: any) => { module.list.forEach((e) => {
deepMerge(service, deepFiles(e.service || [])); deepMerge(service, deepFiles(e.service || []));
}); });
}
return service; return service;
} }

View File

@ -115,40 +115,30 @@ axios.interceptors.response.use(
if (error.response) { if (error.response) {
const { status, config } = error.response; const { status, config } = error.response;
const message = `${config.url} ${status}`;
console.error(message);
if (isDev) {
ElMessage.error(message);
} else {
switch (status) { switch (status) {
case 401: case 401:
href("/401"); href("/401");
break; break;
case 403: case 403:
if (isDev) {
ElMessage.error(`${config.url} 无权限访问!!`);
} else {
href("/403"); href("/403");
}
break;
case 404:
break; break;
case 500: case 500:
if (!isDev) {
href("/500"); href("/500");
}
break; break;
case 502: case 502:
if (isDev) {
ElMessage.error(`${config.url} 服务异常!!`);
} else {
href("/502"); href("/502");
break;
} }
break;
default:
console.error(status, config.url);
break;
} }
} }

View File

@ -1,7 +1,25 @@
// @ts-nocheck // @ts-nocheck
interface Item {
name: string;
options: {
[key: string]: any;
};
value: any;
service?: any[];
pages?: any[];
views?: any[];
components?: {
[key: string]: any;
};
}
const module = { const module = {
set(list: any[]) { get list(): Item[] {
return window.__modules__ || [];
},
set(list: Item[]) {
window.__modules__ = list; window.__modules__ = list;
}, },

3
src/env.d.ts vendored
View File

@ -1,2 +1,5 @@
/// <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;

View File

@ -0,0 +1,6 @@
import { BaseService, Service } from "/@/cool";
@Service("test")
class Test extends BaseService {}
export default Test;

4
src/shims-vue.d.ts vendored
View File

@ -7,7 +7,3 @@ declare module "*.vue" {
export default component; export default component;
} }
declare const __PROXY_LIST__: any[];
declare const __EPS__: string;
declare const __modules__: any[];