worsoft-frontend-codegen-local-mcp 0.1.65 → 0.1.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/templates/master_child_jump/api.tpl +5 -46
- package/assets/templates/master_child_jump/menu.sql.tpl +5 -1
- package/assets/templates/single_table_dialog/api.tpl +5 -46
- package/assets/templates/single_table_jump/api.tpl +5 -46
- package/assets/templates/single_table_jump/menu.sql.tpl +5 -1
- package/mcp_server.js +177 -44
- package/package.json +1 -1
|
@@ -1,48 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
import
|
|
1
|
+
// 通用 CRUD 接口工厂
|
|
2
|
+
import { createCrudApi } from '/@/api/common/crudFactory';
|
|
3
|
+
{{API_REQUEST_IMPORT}}
|
|
3
4
|
|
|
4
|
-
//
|
|
5
|
-
export
|
|
6
|
-
return request({
|
|
7
|
-
url: '/{{API_PATH}}/page',
|
|
8
|
-
method: 'get',
|
|
9
|
-
params: query,
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// 新增数据
|
|
14
|
-
export function addObj(obj?: object) {
|
|
15
|
-
return request({
|
|
16
|
-
url: '/{{API_PATH}}/save',
|
|
17
|
-
method: 'post',
|
|
18
|
-
data: obj,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 查询详情数据
|
|
23
|
-
export function getObj(obj?: object) {
|
|
24
|
-
return request({
|
|
25
|
-
url: '/{{API_PATH}}/getById',
|
|
26
|
-
method: 'get',
|
|
27
|
-
params: obj,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 删除数据
|
|
32
|
-
export function delObjs(ids?: object) {
|
|
33
|
-
return request({
|
|
34
|
-
url: '/{{API_PATH}}/removeByIds',
|
|
35
|
-
method: 'post',
|
|
36
|
-
data: ids,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 更新数据
|
|
41
|
-
export function putObj(obj?: object) {
|
|
42
|
-
return request({
|
|
43
|
-
url: '/{{API_PATH}}/updateById',
|
|
44
|
-
method: 'post',
|
|
45
|
-
data: obj,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
5
|
+
// {{FEATURE_TITLE}} 通用列表、新增、详情、删除、更新接口
|
|
6
|
+
export const { fetchList, addObj, getObj, delObjs, putObj } = createCrudApi('/{{API_PATH}}');
|
|
48
7
|
{{EXTRA_API_FUNCTIONS}}
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
insert into sys_menu (menu_id, parent_id, path, permission, menu_type, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)
|
|
6
6
|
values ({{MENU_BASE_ID}}, '-1', '/{{MENU_ROUTE_PATH}}/index', '', '0', 'icon-bangzhushouji', '0', null, '8', null, '{{TABLE_COMMENT}}管理', 1);
|
|
7
7
|
|
|
8
|
+
-- Form route SQL for jump-based pages. Hidden from sidebar, used by list page add/edit/view navigation.
|
|
9
|
+
insert into sys_menu (menu_id, parent_id, path, permission, menu_type, icon, visible, del_flag, create_time, sort_order, update_time, name, tenant_id)
|
|
10
|
+
values ({{MENU_BASE_ID_PLUS_6}}, {{MENU_BASE_ID}}, '/{{MENU_ROUTE_PATH}}/form', '', '0', 'icon-biaodan', '0', '0', null, '9', null, '{{TABLE_COMMENT}}表单', 1);
|
|
11
|
+
|
|
8
12
|
insert into sys_menu (menu_id, parent_id, permission, menu_type, path, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)
|
|
9
13
|
values ({{MENU_BASE_ID_PLUS_1}}, {{MENU_BASE_ID}}, '{{PERMISSION_PREFIX}}_view', '1', null, '1', '0', null, '0', null, '{{TABLE_COMMENT}}查看', 1);
|
|
10
14
|
|
|
@@ -18,4 +22,4 @@ insert into sys_menu (menu_id, parent_id, permission, menu_type, path, icon, del
|
|
|
18
22
|
values ({{MENU_BASE_ID_PLUS_4}}, {{MENU_BASE_ID}}, '{{PERMISSION_PREFIX}}_del', '1', null, '1', '0', null, '3', null, '{{TABLE_COMMENT}}删除', 1);
|
|
19
23
|
|
|
20
24
|
insert into sys_menu (menu_id, parent_id, permission, menu_type, path, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)
|
|
21
|
-
values ({{MENU_BASE_ID_PLUS_5}}, {{MENU_BASE_ID}}, '{{PERMISSION_PREFIX}}_export', '1', null, '1', '0', null, '4', null, '导入导出', 1);
|
|
25
|
+
values ({{MENU_BASE_ID_PLUS_5}}, {{MENU_BASE_ID}}, '{{PERMISSION_PREFIX}}_export', '1', null, '1', '0', null, '4', null, '导入导出', 1);
|
|
@@ -1,50 +1,9 @@
|
|
|
1
|
-
//
|
|
2
|
-
import
|
|
1
|
+
// 通用 CRUD 接口工厂
|
|
2
|
+
import { createCrudApi } from '/@/api/common/crudFactory';
|
|
3
|
+
{{API_REQUEST_IMPORT}}
|
|
3
4
|
|
|
4
|
-
//
|
|
5
|
-
export
|
|
6
|
-
return request({
|
|
7
|
-
url: '/{{API_PATH}}/page',
|
|
8
|
-
method: 'get',
|
|
9
|
-
params: query,
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// 新增数据
|
|
14
|
-
export function addObj(obj?: object) {
|
|
15
|
-
return request({
|
|
16
|
-
url: '/{{API_PATH}}',
|
|
17
|
-
method: 'post',
|
|
18
|
-
data: obj,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 查询详情数据
|
|
23
|
-
export function getObj(obj?: object) {
|
|
24
|
-
return request({
|
|
25
|
-
url: '/{{API_PATH}}/details',
|
|
26
|
-
method: 'get',
|
|
27
|
-
params: obj,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 删除数据
|
|
32
|
-
export function delObjs(ids?: object) {
|
|
33
|
-
return request({
|
|
34
|
-
url: '/{{API_PATH}}',
|
|
35
|
-
method: 'delete',
|
|
36
|
-
data: ids,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 更新数据
|
|
41
|
-
export function putObj(obj?: object) {
|
|
42
|
-
return request({
|
|
43
|
-
url: '/{{API_PATH}}',
|
|
44
|
-
method: 'put',
|
|
45
|
-
data: obj,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
5
|
+
// {{FEATURE_TITLE}} 通用列表、新增、详情、删除、更新接口
|
|
6
|
+
export const { fetchList, addObj, getObj, delObjs, putObj } = createCrudApi('/{{API_PATH}}');
|
|
48
7
|
|
|
49
8
|
{{DICT_API_FUNCTIONS}}
|
|
50
9
|
{{EXTRA_API_FUNCTIONS}}
|
|
@@ -1,48 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
import
|
|
1
|
+
// 通用 CRUD 接口工厂
|
|
2
|
+
import { createCrudApi } from '/@/api/common/crudFactory';
|
|
3
|
+
{{API_REQUEST_IMPORT}}
|
|
3
4
|
|
|
4
|
-
//
|
|
5
|
-
export
|
|
6
|
-
return request({
|
|
7
|
-
url: '/{{API_PATH}}/page',
|
|
8
|
-
method: 'get',
|
|
9
|
-
params: query,
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// 新增数据
|
|
14
|
-
export function addObj(obj?: object) {
|
|
15
|
-
return request({
|
|
16
|
-
url: '/{{API_PATH}}',
|
|
17
|
-
method: 'post',
|
|
18
|
-
data: obj,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 查询详情数据
|
|
23
|
-
export function getObj(obj?: object) {
|
|
24
|
-
return request({
|
|
25
|
-
url: '/{{API_PATH}}/details',
|
|
26
|
-
method: 'get',
|
|
27
|
-
params: obj,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 删除数据
|
|
32
|
-
export function delObjs(ids?: object) {
|
|
33
|
-
return request({
|
|
34
|
-
url: '/{{API_PATH}}',
|
|
35
|
-
method: 'delete',
|
|
36
|
-
data: ids,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 更新数据
|
|
41
|
-
export function putObj(obj?: object) {
|
|
42
|
-
return request({
|
|
43
|
-
url: '/{{API_PATH}}',
|
|
44
|
-
method: 'put',
|
|
45
|
-
data: obj,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
5
|
+
// {{FEATURE_TITLE}} 通用列表、新增、详情、删除、更新接口
|
|
6
|
+
export const { fetchList, addObj, getObj, delObjs, putObj } = createCrudApi('/{{API_PATH}}');
|
|
48
7
|
{{EXTRA_API_FUNCTIONS}}
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
insert into sys_menu (menu_id, parent_id, path, permission, menu_type, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)
|
|
6
6
|
values ({{MENU_BASE_ID}}, '-1', '/{{MENU_ROUTE_PATH}}/index', '', '0', 'icon-bangzhushouji', '0', null, '8', null, '{{TABLE_COMMENT}}管理', 1);
|
|
7
7
|
|
|
8
|
+
-- Form route SQL for jump-based pages. Hidden from sidebar, used by list page add/edit/view navigation.
|
|
9
|
+
insert into sys_menu (menu_id, parent_id, path, permission, menu_type, icon, visible, del_flag, create_time, sort_order, update_time, name, tenant_id)
|
|
10
|
+
values ({{MENU_BASE_ID_PLUS_6}}, {{MENU_BASE_ID}}, '/{{MENU_ROUTE_PATH}}/form', '', '0', 'icon-biaodan', '0', '0', null, '9', null, '{{TABLE_COMMENT}}表单', 1);
|
|
11
|
+
|
|
8
12
|
insert into sys_menu (menu_id, parent_id, permission, menu_type, path, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)
|
|
9
13
|
values ({{MENU_BASE_ID_PLUS_1}}, {{MENU_BASE_ID}}, '{{PERMISSION_PREFIX}}_view', '1', null, '1', '0', null, '0', null, '{{TABLE_COMMENT}}查看', 1);
|
|
10
14
|
|
|
@@ -18,4 +22,4 @@ insert into sys_menu (menu_id, parent_id, permission, menu_type, path, icon, del
|
|
|
18
22
|
values ({{MENU_BASE_ID_PLUS_4}}, {{MENU_BASE_ID}}, '{{PERMISSION_PREFIX}}_del', '1', null, '1', '0', null, '3', null, '{{TABLE_COMMENT}}删除', 1);
|
|
19
23
|
|
|
20
24
|
insert into sys_menu (menu_id, parent_id, permission, menu_type, path, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)
|
|
21
|
-
values ({{MENU_BASE_ID_PLUS_5}}, {{MENU_BASE_ID}}, '{{PERMISSION_PREFIX}}_export', '1', null, '1', '0', null, '4', null, '导入导出', 1);
|
|
25
|
+
values ({{MENU_BASE_ID_PLUS_5}}, {{MENU_BASE_ID}}, '{{PERMISSION_PREFIX}}_export', '1', null, '1', '0', null, '4', null, '导入导出', 1);
|
package/mcp_server.js
CHANGED
|
@@ -5,7 +5,7 @@ const fs = require('fs');
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
|
|
7
7
|
const SERVER_NAME = 'worsoft-codegen-local';
|
|
8
|
-
const SERVER_VERSION = '0.1.
|
|
8
|
+
const SERVER_VERSION = '0.1.66';
|
|
9
9
|
const PROTOCOL_VERSION = '2024-11-05';
|
|
10
10
|
const TOOL_NAME = 'worsoft_codegen_local_generate_frontend';
|
|
11
11
|
const STYLE_CATALOG_PATH = path.join(__dirname, 'assets', 'style-catalog.json');
|
|
@@ -146,10 +146,65 @@ export function createCrudSchema(
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
return buildSchema(masterOrDefinition as Record<string, FieldMeta>, children);
|
|
149
|
-
}
|
|
150
|
-
`;
|
|
151
|
-
|
|
152
|
-
const
|
|
149
|
+
}
|
|
150
|
+
`;
|
|
151
|
+
|
|
152
|
+
const DEFAULT_CRUD_FACTORY_TEMPLATE = `import request from '/@/utils/request';
|
|
153
|
+
|
|
154
|
+
export interface CrudApiPathOverrides {
|
|
155
|
+
page?: string;
|
|
156
|
+
save?: string;
|
|
157
|
+
detail?: string;
|
|
158
|
+
remove?: string;
|
|
159
|
+
update?: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const joinApiPath = (baseUrl: string, suffix: string) => {
|
|
163
|
+
const normalizedBase = String(baseUrl || '').replace(/\\/+$/, '');
|
|
164
|
+
const normalizedSuffix = String(suffix || '').replace(/^\\/+/, '');
|
|
165
|
+
return normalizedSuffix ? \`\${normalizedBase}/\${normalizedSuffix}\` : normalizedBase;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// 生成标准业务功能 CRUD 接口:分页、新增、详情、删除、更新。
|
|
169
|
+
export const createCrudApi = (baseUrl: string, overrides: CrudApiPathOverrides = {}) => ({
|
|
170
|
+
fetchList: (query?: object) =>
|
|
171
|
+
request({
|
|
172
|
+
url: overrides.page || joinApiPath(baseUrl, 'page'),
|
|
173
|
+
method: 'get',
|
|
174
|
+
params: query,
|
|
175
|
+
}),
|
|
176
|
+
|
|
177
|
+
addObj: (obj?: object) =>
|
|
178
|
+
request({
|
|
179
|
+
url: overrides.save || joinApiPath(baseUrl, 'save'),
|
|
180
|
+
method: 'post',
|
|
181
|
+
data: obj,
|
|
182
|
+
}),
|
|
183
|
+
|
|
184
|
+
getObj: (obj?: object) =>
|
|
185
|
+
request({
|
|
186
|
+
url: overrides.detail || joinApiPath(baseUrl, 'getById'),
|
|
187
|
+
method: 'get',
|
|
188
|
+
params: obj,
|
|
189
|
+
}),
|
|
190
|
+
|
|
191
|
+
delObjs: (ids?: object) =>
|
|
192
|
+
request({
|
|
193
|
+
url: overrides.remove || joinApiPath(baseUrl, 'removeByIds'),
|
|
194
|
+
method: 'post',
|
|
195
|
+
data: ids,
|
|
196
|
+
}),
|
|
197
|
+
|
|
198
|
+
putObj: (obj?: object) =>
|
|
199
|
+
request({
|
|
200
|
+
url: overrides.update || joinApiPath(baseUrl, 'updateById'),
|
|
201
|
+
method: 'post',
|
|
202
|
+
data: obj,
|
|
203
|
+
}),
|
|
204
|
+
});
|
|
205
|
+
`;
|
|
206
|
+
|
|
207
|
+
const TOOL_SCHEMA = {
|
|
153
208
|
type: 'object',
|
|
154
209
|
properties: {
|
|
155
210
|
featureTitle: { type: 'string', description: 'Feature title from pre-parsed structured metadata.' },
|
|
@@ -340,11 +395,11 @@ const TOOL_SCHEMA = {
|
|
|
340
395
|
},
|
|
341
396
|
writeToDisk: { type: 'boolean', default: true, description: 'Whether to write generated files.' },
|
|
342
397
|
overwrite: { type: 'boolean', default: true, description: 'Whether to overwrite existing files. If false, existing files are skipped.' },
|
|
343
|
-
writeSupportFiles: {
|
|
344
|
-
type: 'boolean',
|
|
345
|
-
default: true,
|
|
346
|
-
description: 'Whether to write project support files such as src/enums/dict-registry.ts
|
|
347
|
-
},
|
|
398
|
+
writeSupportFiles: {
|
|
399
|
+
type: 'boolean',
|
|
400
|
+
default: true,
|
|
401
|
+
description: 'Whether to write project support files such as src/enums/dict-registry.ts, src/utils/crudSchema.ts and src/api/common/crudFactory.ts.'
|
|
402
|
+
},
|
|
348
403
|
mergeI18nZh: {
|
|
349
404
|
type: 'boolean',
|
|
350
405
|
default: true,
|
|
@@ -835,7 +890,7 @@ function prepareDictRegistry(frontendPath, dictTypes) {
|
|
|
835
890
|
};
|
|
836
891
|
}
|
|
837
892
|
|
|
838
|
-
function ensureCrudSchemaSupportFile(frontendPath) {
|
|
893
|
+
function ensureCrudSchemaSupportFile(frontendPath) {
|
|
839
894
|
const schemaPath = path.join(frontendPath, 'src', 'utils', 'crudSchema.ts');
|
|
840
895
|
const exists = fs.existsSync(schemaPath);
|
|
841
896
|
const currentContent = exists ? readUtf8File(schemaPath) : '';
|
|
@@ -852,12 +907,27 @@ function ensureCrudSchemaSupportFile(frontendPath) {
|
|
|
852
907
|
exists,
|
|
853
908
|
isCompatible: hasCoreShape && supportsLabelKey,
|
|
854
909
|
needsWrite: !exists || shouldUpgradeLegacy,
|
|
855
|
-
};
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
function
|
|
859
|
-
|
|
860
|
-
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
function ensureCrudFactorySupportFile(frontendPath) {
|
|
914
|
+
const factoryPath = path.join(frontendPath, 'src', 'api', 'common', 'crudFactory.ts');
|
|
915
|
+
const exists = fs.existsSync(factoryPath);
|
|
916
|
+
const currentContent = exists ? readUtf8File(factoryPath) : '';
|
|
917
|
+
const isCompatible = !exists || currentContent.includes('export const createCrudApi');
|
|
918
|
+
|
|
919
|
+
return {
|
|
920
|
+
path: factoryPath,
|
|
921
|
+
content: DEFAULT_CRUD_FACTORY_TEMPLATE,
|
|
922
|
+
exists,
|
|
923
|
+
isCompatible,
|
|
924
|
+
needsWrite: !exists,
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function ensureDirectory(filePath) {
|
|
929
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
930
|
+
}
|
|
861
931
|
|
|
862
932
|
function writeSupportFile(filePath, content) {
|
|
863
933
|
ensureDirectory(filePath);
|
|
@@ -880,30 +950,52 @@ function prepareSharedSupport(frontendPath, dictTypes, writeSupportFiles) {
|
|
|
880
950
|
const normalizedDictTypes = [...new Set((dictTypes || []).filter(Boolean))];
|
|
881
951
|
const dictRegistry = writeSupportFiles ? prepareDictRegistry(frontendPath, normalizedDictTypes) : buildVirtualDictRegistry(normalizedDictTypes);
|
|
882
952
|
const crudSchemaPath = path.join(frontendPath, 'src', 'utils', 'crudSchema.ts');
|
|
883
|
-
const crudSchema = writeSupportFiles
|
|
884
|
-
? ensureCrudSchemaSupportFile(frontendPath)
|
|
885
|
-
: {
|
|
886
|
-
path: crudSchemaPath,
|
|
953
|
+
const crudSchema = writeSupportFiles
|
|
954
|
+
? ensureCrudSchemaSupportFile(frontendPath)
|
|
955
|
+
: {
|
|
956
|
+
path: crudSchemaPath,
|
|
887
957
|
content: DEFAULT_CRUD_SCHEMA_TEMPLATE,
|
|
888
958
|
exists: fs.existsSync(crudSchemaPath),
|
|
889
959
|
isCompatible: true,
|
|
890
|
-
needsWrite: false,
|
|
891
|
-
writeEnabled: false,
|
|
892
|
-
};
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
960
|
+
needsWrite: false,
|
|
961
|
+
writeEnabled: false,
|
|
962
|
+
};
|
|
963
|
+
const crudFactoryPath = path.join(frontendPath, 'src', 'api', 'common', 'crudFactory.ts');
|
|
964
|
+
const crudFactory = writeSupportFiles
|
|
965
|
+
? ensureCrudFactorySupportFile(frontendPath)
|
|
966
|
+
: {
|
|
967
|
+
path: crudFactoryPath,
|
|
968
|
+
content: DEFAULT_CRUD_FACTORY_TEMPLATE,
|
|
969
|
+
exists: fs.existsSync(crudFactoryPath),
|
|
970
|
+
isCompatible: true,
|
|
971
|
+
needsWrite: false,
|
|
972
|
+
writeEnabled: false,
|
|
973
|
+
};
|
|
974
|
+
return {
|
|
975
|
+
dictRegistry,
|
|
976
|
+
crudSchema,
|
|
977
|
+
crudFactory,
|
|
978
|
+
writeEnabled: Boolean(writeSupportFiles),
|
|
979
|
+
};
|
|
980
|
+
}
|
|
899
981
|
|
|
900
982
|
function maybeWriteSharedSupport(sharedSupport, writeToDisk) {
|
|
901
983
|
if (!writeToDisk || !sharedSupport.writeEnabled) return;
|
|
902
984
|
|
|
903
|
-
if (sharedSupport.crudSchema.needsWrite) {
|
|
904
|
-
writeSupportFile(sharedSupport.crudSchema.path, sharedSupport.crudSchema.content);
|
|
905
|
-
}
|
|
906
|
-
|
|
985
|
+
if (sharedSupport.crudSchema.needsWrite) {
|
|
986
|
+
writeSupportFile(sharedSupport.crudSchema.path, sharedSupport.crudSchema.content);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
if (sharedSupport.crudFactory.needsWrite) {
|
|
990
|
+
if (!sharedSupport.crudFactory.isCompatible) {
|
|
991
|
+
throw new Error(
|
|
992
|
+
'Detected an existing src/api/common/crudFactory.ts that MCP could not merge safely. ' +
|
|
993
|
+
'Please align the createCrudApi export manually before enabling writeSupportFiles.'
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
writeSupportFile(sharedSupport.crudFactory.path, sharedSupport.crudFactory.content);
|
|
997
|
+
}
|
|
998
|
+
|
|
907
999
|
if (sharedSupport.dictRegistry.needsWrite) {
|
|
908
1000
|
if (!sharedSupport.dictRegistry.isCompatible) {
|
|
909
1001
|
throw new Error(
|
|
@@ -918,11 +1010,11 @@ function maybeWriteSharedSupport(sharedSupport, writeToDisk) {
|
|
|
918
1010
|
function buildSupportNote(sharedSupport, localeZhSupport) {
|
|
919
1011
|
const notes = [];
|
|
920
1012
|
|
|
921
|
-
if (!sharedSupport.writeEnabled) {
|
|
922
|
-
notes.push(
|
|
923
|
-
'Shared support file writing is disabled. Generated code still references src/utils/crudSchema.ts and may reference src/enums/dict-registry.ts, so those helpers must already exist in the target project.'
|
|
924
|
-
);
|
|
925
|
-
}
|
|
1013
|
+
if (!sharedSupport.writeEnabled) {
|
|
1014
|
+
notes.push(
|
|
1015
|
+
'Shared support file writing is disabled. Generated code still references src/utils/crudSchema.ts, src/api/common/crudFactory.ts and may reference src/enums/dict-registry.ts, so those helpers must already exist in the target project.'
|
|
1016
|
+
);
|
|
1017
|
+
}
|
|
926
1018
|
|
|
927
1019
|
if (sharedSupport.crudSchema.exists && !sharedSupport.crudSchema.isCompatible) {
|
|
928
1020
|
notes.push(
|
|
@@ -931,6 +1023,13 @@ function buildSupportNote(sharedSupport, localeZhSupport) {
|
|
|
931
1023
|
);
|
|
932
1024
|
}
|
|
933
1025
|
|
|
1026
|
+
if (sharedSupport.crudFactory.exists && !sharedSupport.crudFactory.isCompatible) {
|
|
1027
|
+
notes.push(
|
|
1028
|
+
'Detected an existing src/api/common/crudFactory.ts that does not export createCrudApi. ' +
|
|
1029
|
+
'MCP preserved the existing file and did not overwrite it. Generated API modules now depend on that file being manually aligned.'
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
934
1033
|
if (sharedSupport.dictRegistry.exists && !sharedSupport.dictRegistry.isCompatible) {
|
|
935
1034
|
notes.push(
|
|
936
1035
|
'Detected an existing src/enums/dict-registry.ts that MCP could not merge safely. ' +
|
|
@@ -3226,6 +3325,38 @@ function renderExtraApiFunctions(model) {
|
|
|
3226
3325
|
.join('\n');
|
|
3227
3326
|
}
|
|
3228
3327
|
|
|
3328
|
+
function renderApiRequestImport(model) {
|
|
3329
|
+
const hasExtraApis = Array.isArray(model.extraApis) && model.extraApis.length > 0;
|
|
3330
|
+
const hasDictStatusApis = model.pageType === 'dict' && !!model.statusField;
|
|
3331
|
+
return hasExtraApis || hasDictStatusApis ? "import request from '/@/utils/request';" : '';
|
|
3332
|
+
}
|
|
3333
|
+
|
|
3334
|
+
function renderExtraApiFunctionsV2(model) {
|
|
3335
|
+
if (!Array.isArray(model.extraApis) || !model.extraApis.length) return '';
|
|
3336
|
+
return model.extraApis
|
|
3337
|
+
.map((api) => {
|
|
3338
|
+
const requestField = api.requestType === 'data' ? 'data' : 'params';
|
|
3339
|
+
const lines = ['', `// 额外接口:${sanitizeComment(api.description)}`];
|
|
3340
|
+
if (api.usedBy) {
|
|
3341
|
+
lines.push(`// 使用场景:${sanitizeComment(api.usedBy)}`);
|
|
3342
|
+
}
|
|
3343
|
+
if (api.source) {
|
|
3344
|
+
lines.push(`// 来源说明:${sanitizeComment(api.source)}`);
|
|
3345
|
+
}
|
|
3346
|
+
lines.push(
|
|
3347
|
+
`export function ${api.functionName}(payload?: any) {`,
|
|
3348
|
+
' return request({',
|
|
3349
|
+
` url: '${api.url}',`,
|
|
3350
|
+
` method: '${api.method}',`,
|
|
3351
|
+
` ${requestField}: payload,`,
|
|
3352
|
+
' });',
|
|
3353
|
+
'}'
|
|
3354
|
+
);
|
|
3355
|
+
return lines.join('\n');
|
|
3356
|
+
})
|
|
3357
|
+
.join('\n');
|
|
3358
|
+
}
|
|
3359
|
+
|
|
3229
3360
|
function buildReplacements(model, sharedSupport) {
|
|
3230
3361
|
const menuBaseId = Date.now();
|
|
3231
3362
|
const apiModulePath = model.targetApiModule || `${model.moduleName}/${model.functionName}`;
|
|
@@ -3256,16 +3387,18 @@ function buildReplacements(model, sharedSupport) {
|
|
|
3256
3387
|
BUSINESS_STATUS_IMPORTS: renderBusinessStatusImports(model),
|
|
3257
3388
|
BUSINESS_EDIT_IF: hasBusinessBillStateEditControl(model) ? ' v-if="showEditAction(row)"' : '',
|
|
3258
3389
|
BUSINESS_STATUS_HELPERS: renderBusinessStatusHelpers(model),
|
|
3259
|
-
|
|
3390
|
+
API_REQUEST_IMPORT: renderApiRequestImport(model),
|
|
3391
|
+
EXTRA_API_FUNCTIONS: renderExtraApiFunctionsV2(model),
|
|
3260
3392
|
CUSTOM_QUERY_FIELDS_EXPR: model.pageType === 'dict' ? '[]' : 'queryableDictOptions.value',
|
|
3261
3393
|
SHOW_RIGHT_TOOLS: model.pageType === 'dict' ? 'false' : 'true',
|
|
3262
3394
|
MENU_BASE_ID: menuBaseId,
|
|
3263
3395
|
MENU_BASE_ID_PLUS_1: menuBaseId + 1,
|
|
3264
3396
|
MENU_BASE_ID_PLUS_2: menuBaseId + 2,
|
|
3265
|
-
MENU_BASE_ID_PLUS_3: menuBaseId + 3,
|
|
3266
|
-
MENU_BASE_ID_PLUS_4: menuBaseId + 4,
|
|
3267
|
-
MENU_BASE_ID_PLUS_5: menuBaseId + 5,
|
|
3268
|
-
|
|
3397
|
+
MENU_BASE_ID_PLUS_3: menuBaseId + 3,
|
|
3398
|
+
MENU_BASE_ID_PLUS_4: menuBaseId + 4,
|
|
3399
|
+
MENU_BASE_ID_PLUS_5: menuBaseId + 5,
|
|
3400
|
+
MENU_BASE_ID_PLUS_6: menuBaseId + 6,
|
|
3401
|
+
GENERATED_AT: new Date().toISOString(),
|
|
3269
3402
|
FORM_FIELDS: model.visibleFields.map(renderFormFieldV2).join('\n'),
|
|
3270
3403
|
TABLE_COLUMNS: model.gridFields.map((field) => renderTableColumn(field, dictRegistryRefs)).join('\n'),
|
|
3271
3404
|
FORM_DEFAULTS: renderFormDefaults(model),
|
package/package.json
CHANGED