From e66d64d83e65d7c8b3531146cb66da8b3379d55b Mon Sep 17 00:00:00 2001 From: icssoa <615206459@qq.com> Date: Sat, 30 Aug 2025 14:52:23 +0800 Subject: [PATCH] =?UTF-8?q?clean=20=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vite-plugin/dist/index.js | 87 +++++++++++------------ packages/vite-plugin/package.json | 2 +- packages/vite-plugin/src/eps/index.ts | 51 +++++-------- packages/vite-plugin/src/index.ts | 17 +++-- packages/vite-plugin/src/uniapp-x/code.ts | 22 +++--- packages/vite-plugin/types/index.d.ts | 2 +- 6 files changed, 86 insertions(+), 95 deletions(-) diff --git a/packages/vite-plugin/dist/index.js b/packages/vite-plugin/dist/index.js index 6e4731e..876e8b1 100644 --- a/packages/vite-plugin/dist/index.js +++ b/packages/vite-plugin/dist/index.js @@ -1112,12 +1112,22 @@ break; } // 方法描述 - t += ` - /** - * ${a.summary || n} - */ - ${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")}): Promise<${res}>; - `; + if (config.type == "uniapp-x") { + t += ` + /** + * ${a.summary || n} + */ + ${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")}): Promise; + `; + } + else { + t += ` + /** + * ${a.summary || n} + */ + ${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")}): Promise<${res}>; + `; + } if (!permission.includes(n)) { permission.push(n); } @@ -1159,6 +1169,8 @@ return ` type json = any; + ${await createDict()} + interface PagePagination { size: number; page: number; @@ -1188,8 +1200,6 @@ ${noUniappX("type Request = (options: RequestOptions) => Promise;")} - ${await createDict()} - type Service = { ${noUniappX("request: Request;")} @@ -1354,32 +1364,13 @@ if (item.name) { types.push(item.name); } - // 返回类型 - let res = ""; - // 实体名 - const en = item.name || "any"; - switch (a.path) { - case "/page": - res = `${name}PageResponse`; - types.push(res); - break; - case "/list": - res = `${en}[]`; - break; - case "/info": - res = en; - break; - default: - res = "any"; - break; - } // 方法描述 t += ` /** * ${a.summary || n} */ - ${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")})${noUniappX(`: Promise<${res}>`)} { - return request<${res}>({ + ${n}(data?: any): Promise { + return request({ url: "/${d[i].namespace}${a.path}", method: "${(a.method || "get").toLocaleUpperCase()}", data, @@ -2370,17 +2361,17 @@ if (typeof window !== 'undefined') { } code = code.replace("const ctx = {}", `const ctx = ${JSON.stringify(ctx, null, 4)}`); } - if (id.includes("/cool/service/index.ts")) { - const eps = await createEps(); - if (eps.serviceCode) { - const { content, types } = eps.serviceCode; - const typeCode = `import type { ${lodash.uniq(types).join(", ")} } from '../types';`; - code = - typeCode + - "\n\n" + - code.replace("const service = {}", `const service = ${content}`); - } - } + // if (id.includes("/cool/service/index.ts")) { + // const eps = await createEps(); + // if (eps.serviceCode) { + // const { content, types } = eps.serviceCode; + // const typeCode = `import type { ${uniq(types).join(", ")} } from '../types';`; + // code = + // typeCode + + // "\n\n" + + // code.replace("const service = {}", `const service = ${content}`); + // } + // } if (id.endsWith(".json")) { const d = JSON.parse(code); for (let i in d) { @@ -2446,11 +2437,13 @@ if (typeof window !== 'undefined') { config.type = options.type; // 请求地址 config.reqUrl = getProxyTarget(options.proxy); - // 是否纯净版 - config.clean = options.clean; - if (config.clean) { - // 默认设置为测试地址 - config.reqUrl = "https://show.cool-admin.com/api"; + if (config.type == "uniapp-x") { + // 是否纯净版 + config.clean = options.clean ?? true; + if (config.clean) { + // 默认设置为测试地址 + config.reqUrl = "https://show.cool-admin.com/api"; + } } // 是否开启名称标签 config.nameTag = options.nameTag ?? true; @@ -2476,6 +2469,10 @@ if (typeof window !== 'undefined') { lodash.merge(config.eps.mapping, mapping); } } + // 如果类型为 uniapp-x,则关闭 eps + if (config.type == "uniapp-x") { + config.eps.enable = false; + } // tailwind if (options.tailwind) { lodash.assign(config.tailwind, options.tailwind); diff --git a/packages/vite-plugin/package.json b/packages/vite-plugin/package.json index 0d044d8..bca33fb 100644 --- a/packages/vite-plugin/package.json +++ b/packages/vite-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@cool-vue/vite-plugin", - "version": "8.2.8", + "version": "8.2.10", "description": "cool-admin、cool-uni builder", "types": "./dist/index.d.ts", "main": "/dist/index.js", diff --git a/packages/vite-plugin/src/eps/index.ts b/packages/vite-plugin/src/eps/index.ts index d8d13a0..1ad2393 100644 --- a/packages/vite-plugin/src/eps/index.ts +++ b/packages/vite-plugin/src/eps/index.ts @@ -382,12 +382,21 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service: } // 方法描述 - t += ` - /** - * ${a.summary || n} - */ - ${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")}): Promise<${res}>; - `; + if (config.type == "uniapp-x") { + t += ` + /** + * ${a.summary || n} + */ + ${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")}): Promise; + `; + } else { + t += ` + /** + * ${a.summary || n} + */ + ${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")}): Promise<${res}>; + `; + } if (!permission.includes(n)) { permission.push(n); @@ -436,6 +445,8 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service: return ` type json = any; + ${await createDict()} + interface PagePagination { size: number; page: number; @@ -465,8 +476,6 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service: ${noUniappX("type Request = (options: RequestOptions) => Promise;")} - ${await createDict()} - type Service = { ${noUniappX("request: Request;")} @@ -661,35 +670,13 @@ function createServiceCode(): { content: string; types: string[] } { types.push(item.name); } - // 返回类型 - let res = ""; - - // 实体名 - const en = item.name || "any"; - - switch (a.path) { - case "/page": - res = `${name}PageResponse`; - types.push(res); - break; - case "/list": - res = `${en}[]`; - break; - case "/info": - res = en; - break; - default: - res = "any"; - break; - } - // 方法描述 t += ` /** * ${a.summary || n} */ - ${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")})${noUniappX(`: Promise<${res}>`)} { - return request<${res}>({ + ${n}(data?: any): Promise { + return request({ url: "/${d[i].namespace}${a.path}", method: "${(a.method || "get").toLocaleUpperCase()}", data, diff --git a/packages/vite-plugin/src/index.ts b/packages/vite-plugin/src/index.ts index 33cd0bf..b1fecb0 100644 --- a/packages/vite-plugin/src/index.ts +++ b/packages/vite-plugin/src/index.ts @@ -14,12 +14,14 @@ export function cool(options: Config.Options) { // 请求地址 config.reqUrl = getProxyTarget(options.proxy); - // 是否纯净版 - config.clean = options.clean; + if (config.type == "uniapp-x") { + // 是否纯净版 + config.clean = options.clean ?? true; - if (config.clean) { - // 默认设置为测试地址 - config.reqUrl = "https://show.cool-admin.com/api"; + if (config.clean) { + // 默认设置为测试地址 + config.reqUrl = "https://show.cool-admin.com/api"; + } } // 是否开启名称标签 @@ -53,6 +55,11 @@ export function cool(options: Config.Options) { } } + // 如果类型为 uniapp-x,则关闭 eps + if (config.type == "uniapp-x") { + config.eps.enable = false; + } + // tailwind if (options.tailwind) { assign(config.tailwind, options.tailwind); diff --git a/packages/vite-plugin/src/uniapp-x/code.ts b/packages/vite-plugin/src/uniapp-x/code.ts index fa74b3f..5c95568 100644 --- a/packages/vite-plugin/src/uniapp-x/code.ts +++ b/packages/vite-plugin/src/uniapp-x/code.ts @@ -126,19 +126,19 @@ export function codePlugin(): Plugin[] { ); } - if (id.includes("/cool/service/index.ts")) { - const eps = await createEps(); + // if (id.includes("/cool/service/index.ts")) { + // const eps = await createEps(); - if (eps.serviceCode) { - const { content, types } = eps.serviceCode; - const typeCode = `import type { ${uniq(types).join(", ")} } from '../types';`; + // if (eps.serviceCode) { + // const { content, types } = eps.serviceCode; + // const typeCode = `import type { ${uniq(types).join(", ")} } from '../types';`; - code = - typeCode + - "\n\n" + - code.replace("const service = {}", `const service = ${content}`); - } - } + // code = + // typeCode + + // "\n\n" + + // code.replace("const service = {}", `const service = ${content}`); + // } + // } if (id.endsWith(".json")) { const d = JSON.parse(code); diff --git a/packages/vite-plugin/types/index.d.ts b/packages/vite-plugin/types/index.d.ts index da2cff7..335e68b 100644 --- a/packages/vite-plugin/types/index.d.ts +++ b/packages/vite-plugin/types/index.d.ts @@ -120,6 +120,6 @@ export declare namespace Config { darkTextClass?: string; }; // 是否纯净版 - clean: boolean; + clean?: boolean; } }