From 537cd2f7086e6b8f0cbc098d9ae5cc2e4c1b031d Mon Sep 17 00:00:00 2001 From: icssoa <2570063477@qq.com> Date: Mon, 16 May 2022 02:14:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/default-avatar.png | Bin 3991 -> 0 bytes src/cool/module/index.ts | 5 ++-- src/cool/service/eps.ts | 46 +++++++++++++++---------------- src/cool/service/index.ts | 14 +++++----- src/cool/service/request.ts | 44 ++++++++++++----------------- src/cool/utils/module.ts | 20 +++++++++++++- src/env.d.ts | 3 ++ src/modules/demo/service/test.ts | 6 ++++ src/shims-vue.d.ts | 4 --- 9 files changed, 76 insertions(+), 66 deletions(-) delete mode 100644 src/assets/default-avatar.png diff --git a/src/assets/default-avatar.png b/src/assets/default-avatar.png deleted file mode 100644 index 1ede40f529b013d4e4bbcc06241249d082512971..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3991 zcmY*cc{mha7rrxwVT2hihAe|DBb0q9jD6oG6xj+{vSiny8Cxk!WRSAg&{*adDIulE zP9#aPO*EDy+sHC})1TiTcX^)sJm;SGyyu+z-aB?SraTBC1OR}?+{_5iT8aM#CkJb8 z)xFRI0H3?Lk-kHW`;r@X>M>)%z5T+`g4w8h1r>$%&^Ma)t%h7EB+?-xHy-);`<>H? ze~?m$X$5o}CVy4)Pm+YuAqcxfr(wenD9!xy8P&V_Fr>{%(Vp>$$mQnf=*FJiEJ5YK zsQOAV$8jAE!l#BL%Jw4RhTF!-Vo0KH(9n^VAeWsts{`;Bb>4VgunoSpD?Cf9oLq+d z-*!%iJEpK+1^oK8vj;T_Wb%Lz2yyy195w$|-=cvFsDCmfNJ=o9gn*MI&2l{&39DS( z*sg58R9!d+5lU;PCdXv>IGb8x^-2cKc_nlY!QOo;DJePJ+S-}~H@X0sx;ioaW|?pR z@EWvjUXIwVsv?u_ozHpkev?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index.ts @@ -1,9 +1,8 @@ +import { App } from "vue"; import modules from "/@/modules"; import { router, addViews } from "../router"; -import { filename } from "../utils"; +import { filename, module } from "../utils"; import { isFunction, isObject } from "lodash"; -import { App } from "vue"; -import module from "../utils/module"; // 扫描文件 const files = import.meta.globEager("/src/modules/**/*"); diff --git a/src/cool/service/eps.ts b/src/cool/service/eps.ts index 4deff12..0db0f0a 100644 --- a/src/cool/service/eps.ts +++ b/src/cool/service/eps.ts @@ -66,7 +66,7 @@ export function useEps(service: Service) { // 获取 eps function getEps() { - if (isDev) { + if (isDev && test.eps) { service .request({ url: "/admin/base/open/eps" @@ -183,30 +183,28 @@ export function useEps(service: Service) { } } - // 获取 - if (isDev) { - // 缓存数据 - set(storage.get("eps")); + // 解析 + try { + const eps = + storage.get("eps") || + JSON.parse(__EPS__ || "[]").map(([prefix, api]: any[]) => { + return { + prefix, + api: api.map(([method, path, name]: string[]) => { + return { + method, + path, + name + }; + }) + }; + }); - // 接口数据 - if (test.eps) { - getEps(); - } - } else { - const eps = JSON.parse(__EPS__).map(([prefix, api]: any[]) => { - return { - prefix, - api: api.map(([method, path, name]: string[]) => { - return { - method, - path, - name - }; - }) - }; - }); - - // 文件数据 set({ eps }); + } catch (err) { + console.error("[Eps] 解析失败!", err); } + + // 获取 + getEps(); } diff --git a/src/cool/service/index.ts b/src/cool/service/index.ts index ec25f75..438ef81 100644 --- a/src/cool/service/index.ts +++ b/src/cool/service/index.ts @@ -1,20 +1,20 @@ -import { deepFiles, deepMerge } from "../utils"; +import { deepFiles, deepMerge, module } from "../utils"; import { BaseService } from "./base"; import { useEps } from "./eps"; -// 服务 +// 基础服务 export const service: Service = { request: new BaseService().request }; export function useService() { + // 接口内容 useEps(service); - if (window.__modules__) { - window.__modules__.forEach((e: any) => { - deepMerge(service, deepFiles(e.service || [])); - }); - } + // 模块内容 + module.list.forEach((e) => { + deepMerge(service, deepFiles(e.service || [])); + }); return service; } diff --git a/src/cool/service/request.ts b/src/cool/service/request.ts index 542a1d8..9c52786 100644 --- a/src/cool/service/request.ts +++ b/src/cool/service/request.ts @@ -115,40 +115,30 @@ axios.interceptors.response.use( if (error.response) { const { status, config } = error.response; + const message = `${config.url} ${status}`; - switch (status) { - case 401: - href("/401"); - break; + console.error(message); - case 403: - if (isDev) { - ElMessage.error(`${config.url} 无权限访问!!`); - } else { + if (isDev) { + ElMessage.error(message); + } else { + switch (status) { + case 401: + href("/401"); + break; + + case 403: href("/403"); - } - break; + break; - case 404: - break; - - case 500: - if (!isDev) { + case 500: href("/500"); - } - break; + break; - case 502: - if (isDev) { - ElMessage.error(`${config.url} 服务异常!!`); - } else { + case 502: href("/502"); - } - break; - - default: - console.error(status, config.url); - break; + break; + } } } diff --git a/src/cool/utils/module.ts b/src/cool/utils/module.ts index 5e836b4..4a290e0 100644 --- a/src/cool/utils/module.ts +++ b/src/cool/utils/module.ts @@ -1,7 +1,25 @@ // @ts-nocheck +interface Item { + name: string; + options: { + [key: string]: any; + }; + value: any; + service?: any[]; + pages?: any[]; + views?: any[]; + components?: { + [key: string]: any; + }; +} + const module = { - set(list: any[]) { + get list(): Item[] { + return window.__modules__ || []; + }, + + set(list: Item[]) { window.__modules__ = list; }, diff --git a/src/env.d.ts b/src/env.d.ts index 7ec8820..f8da03d 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1,2 +1,5 @@ /// /// + +declare const __PROXY_LIST__: any[]; +declare const __EPS__: string; diff --git a/src/modules/demo/service/test.ts b/src/modules/demo/service/test.ts index e69de29..5b6aa7b 100644 --- a/src/modules/demo/service/test.ts +++ b/src/modules/demo/service/test.ts @@ -0,0 +1,6 @@ +import { BaseService, Service } from "/@/cool"; + +@Service("test") +class Test extends BaseService {} + +export default Test; diff --git a/src/shims-vue.d.ts b/src/shims-vue.d.ts index 1d84172..39981b8 100644 --- a/src/shims-vue.d.ts +++ b/src/shims-vue.d.ts @@ -7,7 +7,3 @@ declare module "*.vue" { export default component; } - -declare const __PROXY_LIST__: any[]; -declare const __EPS__: string; -declare const __modules__: any[];