mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2025-12-11 21:12:50 +00:00
优化
This commit is contained in:
parent
d2c8f554e9
commit
733a1faef1
43
packages/vite-plugin/dist/index.js
vendored
43
packages/vite-plugin/dist/index.js
vendored
@ -7,6 +7,7 @@
|
||||
const config = {
|
||||
type: "admin",
|
||||
reqUrl: "",
|
||||
demo: false,
|
||||
nameTag: true,
|
||||
eps: {
|
||||
enable: true,
|
||||
@ -432,7 +433,7 @@
|
||||
_permission: { ${permission.map((e) => `${e}: boolean;`).join("\n")} };
|
||||
`;
|
||||
t += `
|
||||
request: Service['request']
|
||||
request: Request
|
||||
`;
|
||||
}
|
||||
t += "}\n\n";
|
||||
@ -454,20 +455,25 @@
|
||||
|
||||
${controller}
|
||||
|
||||
interface RequestOptions {
|
||||
url: string;
|
||||
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
||||
data?: any;
|
||||
params?: any;
|
||||
header?: any;
|
||||
timeout?: number;
|
||||
withCredentials?: boolean;
|
||||
firstIpv4?: boolean;
|
||||
enableChunked?: boolean;
|
||||
}
|
||||
|
||||
type Request = (options: RequestOptions) => Promise<any>;
|
||||
|
||||
interface Service {
|
||||
/**
|
||||
* 基础请求
|
||||
*/
|
||||
request(options?: {
|
||||
url: string;
|
||||
method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
|
||||
data?: any;
|
||||
params?: any;
|
||||
headers?: any,
|
||||
timeout?: number;
|
||||
proxy?: boolean;
|
||||
[key: string]: any;
|
||||
}): Promise<any>;
|
||||
request: Request;
|
||||
|
||||
${chain}
|
||||
}
|
||||
@ -483,10 +489,10 @@
|
||||
// 文件名
|
||||
let name = "eps.d.ts";
|
||||
if (config.type == "uniapp-x") {
|
||||
name = "eps.uts";
|
||||
name = "eps.ts";
|
||||
text = text
|
||||
.replaceAll("interface ", "export interface ")
|
||||
.replaceAll("type Dict", "export type Dict")
|
||||
.replaceAll("type ", "export type ")
|
||||
.replaceAll("[key: string]: any;", "");
|
||||
}
|
||||
else {
|
||||
@ -670,8 +676,13 @@
|
||||
if (match) {
|
||||
const value = match[1];
|
||||
try {
|
||||
const { target, rewrite } = proxy[`/${value}/`];
|
||||
return target + rewrite(`/${value}`);
|
||||
if (config.type == "uniapp-x") {
|
||||
return proxy[value].target;
|
||||
}
|
||||
else {
|
||||
const { target, rewrite } = proxy[`/${value}/`];
|
||||
return target + rewrite(`/${value}`);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
error(`[cool-proxy] Error:${value} → ` + getPath());
|
||||
@ -1551,7 +1562,7 @@ if (typeof window !== 'undefined') {
|
||||
name: "vite-cool-uniappx-code-pre",
|
||||
enforce: "pre",
|
||||
async transform(code, id) {
|
||||
if (id.includes("/cool/virtual.ts")) {
|
||||
if (id.includes("/cool/ctx.ts")) {
|
||||
const ctx = await createCtx();
|
||||
ctx["SAFE_CHAR_MAP"] = [];
|
||||
for (const i in SAFE_CHAR_MAP) {
|
||||
|
||||
@ -363,7 +363,7 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service:
|
||||
`;
|
||||
|
||||
t += `
|
||||
request: Service['request']
|
||||
request: Request
|
||||
`;
|
||||
}
|
||||
|
||||
@ -388,20 +388,25 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service:
|
||||
|
||||
${controller}
|
||||
|
||||
interface RequestOptions {
|
||||
url: string;
|
||||
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
||||
data?: any;
|
||||
params?: any;
|
||||
header?: any;
|
||||
timeout?: number;
|
||||
withCredentials?: boolean;
|
||||
firstIpv4?: boolean;
|
||||
enableChunked?: boolean;
|
||||
}
|
||||
|
||||
type Request = (options: RequestOptions) => Promise<any>;
|
||||
|
||||
interface Service {
|
||||
/**
|
||||
* 基础请求
|
||||
*/
|
||||
request(options?: {
|
||||
url: string;
|
||||
method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
|
||||
data?: any;
|
||||
params?: any;
|
||||
headers?: any,
|
||||
timeout?: number;
|
||||
proxy?: boolean;
|
||||
[key: string]: any;
|
||||
}): Promise<any>;
|
||||
request: Request;
|
||||
|
||||
${chain}
|
||||
}
|
||||
@ -420,10 +425,11 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service:
|
||||
let name = "eps.d.ts";
|
||||
|
||||
if (config.type == "uniapp-x") {
|
||||
name = "eps.uts";
|
||||
name = "eps.ts";
|
||||
|
||||
text = text
|
||||
.replaceAll("interface ", "export interface ")
|
||||
.replaceAll("type Dict", "export type Dict")
|
||||
.replaceAll("type ", "export type ")
|
||||
.replaceAll("[key: string]: any;", "");
|
||||
} else {
|
||||
text = `
|
||||
|
||||
@ -26,8 +26,12 @@ export function getProxyTarget(proxy: any) {
|
||||
const value = match[1];
|
||||
|
||||
try {
|
||||
const { target, rewrite } = proxy[`/${value}/`];
|
||||
return target + rewrite(`/${value}`);
|
||||
if (config.type == "uniapp-x") {
|
||||
return proxy[value].target;
|
||||
} else {
|
||||
const { target, rewrite } = proxy[`/${value}/`];
|
||||
return target + rewrite(`/${value}`);
|
||||
}
|
||||
} catch (err) {
|
||||
error(`[cool-proxy] Error:${value} → ` + getPath());
|
||||
return "";
|
||||
|
||||
@ -9,7 +9,7 @@ export function codePlugin(): Plugin[] {
|
||||
name: "vite-cool-uniappx-code-pre",
|
||||
enforce: "pre",
|
||||
async transform(code, id) {
|
||||
if (id.includes("/cool/virtual.ts")) {
|
||||
if (id.includes("/cool/ctx.ts")) {
|
||||
const ctx = await createCtx();
|
||||
|
||||
ctx["SAFE_CHAR_MAP"] = [];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user