This commit is contained in:
icssoa 2025-05-29 22:50:12 +08:00 committed by icssoa
parent 3f90cac389
commit a89ef3f0ef
2 changed files with 58 additions and 45 deletions

View File

@ -509,9 +509,9 @@
/**
* 不支持 uniapp-x 平台显示
*/
function noUniappX(text) {
function noUniappX(text, defaultText = "") {
if (config.type == "uniapp-x") {
return "";
return defaultText;
}
else {
return text;
@ -672,6 +672,7 @@
async function createController() {
let controller = "";
let chain = "";
let pageResponse = "";
/**
* 递归处理 service 生成接口定义
* @param d 当前节点
@ -729,24 +730,25 @@
let res = "";
// 实体名
const en = item.name || "any";
if (config.type == "uniapp-x") {
res = "any";
}
else {
switch (a.path) {
case "/page":
res = `PageResponse<${en}>`;
break;
case "/list":
res = `${en} []`;
break;
case "/info":
res = en;
break;
default:
res = "any";
break;
}
switch (a.path) {
case "/page":
res = `${name}PageResponse`;
pageResponse += `
interface ${name}PageResponse {
pagination: PagePagination;
list: ${en}[];
}
`;
break;
case "/list":
res = `${en} []`;
break;
case "/info":
res = en;
break;
default:
res = "any";
break;
}
// 方法描述
t += `
@ -809,6 +811,8 @@
[key: string]: any;
};
${pageResponse}
${controller}
${noUniappX(`interface RequestOptions {
@ -995,10 +999,11 @@
const en = item.name || "any";
switch (a.path) {
case "/page":
res = `PageResponse<${en}>`;
res = `${name}PageResponse`;
types.push(res);
break;
case "/list":
res = `${en} []`;
res = `${en}[]`;
break;
case "/info":
res = en;
@ -1013,7 +1018,7 @@
* ${a.summary || n}
*/
${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")})${noUniappX(`: Promise<${res}>`)} {
return request({
return request<${res}>({
url: "/${d[i].namespace}${a.path}",
method: "${(a.method || "get").toLocaleUpperCase()}",
data,

View File

@ -92,9 +92,9 @@ function checkName(name: string) {
/**
* uniapp-x
*/
function noUniappX(text: string) {
function noUniappX(text: string, defaultText: string = "") {
if (config.type == "uniapp-x") {
return "";
return defaultText;
} else {
return text;
}
@ -275,6 +275,7 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service:
async function createController() {
let controller = "";
let chain = "";
let pageResponse = "";
/**
* service
@ -346,23 +347,27 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service:
// 实体名
const en = item.name || "any";
if (config.type == "uniapp-x") {
res = "any";
} else {
switch (a.path) {
case "/page":
res = `PageResponse<${en}>`;
break;
case "/list":
res = `${en} []`;
break;
case "/info":
res = en;
break;
default:
res = "any";
break;
}
switch (a.path) {
case "/page":
res = `${name}PageResponse`;
pageResponse += `
interface ${name}PageResponse {
pagination: PagePagination;
list: ${en}[];
}
`;
break;
case "/list":
res = `${en} []`;
break;
case "/info":
res = en;
break;
default:
res = "any";
break;
}
// 方法描述
@ -433,6 +438,8 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service:
[key: string]: any;
};
${pageResponse}
${controller}
${noUniappX(`interface RequestOptions {
@ -651,10 +658,11 @@ function createServiceCode(): { content: string; types: string[] } {
switch (a.path) {
case "/page":
res = `PageResponse<${en}>`;
res = `${name}PageResponse`;
types.push(res);
break;
case "/list":
res = `${en} []`;
res = `${en}[]`;
break;
case "/info":
res = en;
@ -670,7 +678,7 @@ function createServiceCode(): { content: string; types: string[] } {
* ${a.summary || n}
*/
${n}(data${q.length == 1 ? "?" : ""}: ${q.join("")})${noUniappX(`: Promise<${res}>`)} {
return request({
return request<${res}>({
url: "/${d[i].namespace}${a.path}",
method: "${(a.method || "get").toLocaleUpperCase()}",
data,