worsoft-frontend-codegen-local-mcp 0.1.17 → 0.1.18
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.
|
@@ -10,7 +10,7 @@ export function fetchList(query?: object) {
|
|
|
10
10
|
|
|
11
11
|
export function addObj(obj?: object) {
|
|
12
12
|
return request({
|
|
13
|
-
url: '/{{API_PATH}}',
|
|
13
|
+
url: '/{{API_PATH}}/save',
|
|
14
14
|
method: 'post',
|
|
15
15
|
data: obj,
|
|
16
16
|
});
|
|
@@ -18,7 +18,7 @@ export function addObj(obj?: object) {
|
|
|
18
18
|
|
|
19
19
|
export function getObj(obj?: object) {
|
|
20
20
|
return request({
|
|
21
|
-
url: '/{{API_PATH}}/
|
|
21
|
+
url: '/{{API_PATH}}/getById',
|
|
22
22
|
method: 'get',
|
|
23
23
|
params: obj,
|
|
24
24
|
});
|
|
@@ -26,24 +26,16 @@ export function getObj(obj?: object) {
|
|
|
26
26
|
|
|
27
27
|
export function delObjs(ids?: object) {
|
|
28
28
|
return request({
|
|
29
|
-
url: '/{{API_PATH}}',
|
|
30
|
-
method: '
|
|
29
|
+
url: '/{{API_PATH}}/removeByIds',
|
|
30
|
+
method: 'post',
|
|
31
31
|
data: ids,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function putObj(obj?: object) {
|
|
36
36
|
return request({
|
|
37
|
-
url: '/{{API_PATH}}',
|
|
38
|
-
method: '
|
|
37
|
+
url: '/{{API_PATH}}/updateById',
|
|
38
|
+
method: 'post',
|
|
39
39
|
data: obj,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
export function delChildObj(ids?: object, childTableName?: string) {
|
|
44
|
-
return request({
|
|
45
|
-
url: '/{{API_PATH}}/child',
|
|
46
|
-
method: 'delete',
|
|
47
|
-
data: childTableName ? { ids, childTableName } : ids,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
<script setup lang="ts" name="{{CLASS_NAME}}Form">
|
|
32
32
|
import mittBus from '/@/utils/mitt';
|
|
33
33
|
import { useMessage } from '/@/hooks/message';
|
|
34
|
-
import { getObj, addObj, putObj
|
|
34
|
+
import { getObj, addObj, putObj } from '/@/api/{{API_MODULE_PATH}}';
|
|
35
35
|
import { useDict } from '/@/hooks/dict';
|
|
36
36
|
import { useCrudPageMeta } from '/@/hooks/useCrudPageMeta';
|
|
37
37
|
import { useI18n } from 'vue-i18n';
|
|
@@ -49,36 +49,30 @@ const dataFormRef = ref();
|
|
|
49
49
|
const loading = ref(false);
|
|
50
50
|
const detail = ref(false);
|
|
51
51
|
|
|
52
|
-
//
|
|
53
|
-
const getChildFieldMeta = (groupName: string, prop: string) => childFieldGroups[groupName]?.[prop];
|
|
54
|
-
const resolveLabel = (labelKey?: string, fallback = '') => {
|
|
55
|
-
if (!labelKey) return fallback;
|
|
56
|
-
const translated = t(labelKey);
|
|
57
|
-
return translated === labelKey ? fallback : translated;
|
|
58
|
-
};
|
|
59
|
-
const getChildFieldLabel = (groupName: string, prop: string) => {
|
|
60
|
-
const config = getChildFieldMeta(groupName, prop);
|
|
61
|
-
return resolveLabel(config?.labelKey, config?.label || prop);
|
|
62
|
-
};
|
|
52
|
+
// 主表和子表字段的双语、字典和校验提示统一由公共 hook 提供
|
|
63
53
|
const {
|
|
64
54
|
getFieldMeta: getMasterFieldMeta,
|
|
65
55
|
getFieldLabel: getMasterFieldLabel,
|
|
56
|
+
getChildFieldLabel,
|
|
66
57
|
getDictOptions,
|
|
67
58
|
inputPlaceholder,
|
|
68
59
|
selectPlaceholder,
|
|
69
60
|
fieldRequiredMessage,
|
|
70
61
|
commonActionLabel,
|
|
71
|
-
} = useCrudPageMeta(dataMasterEntity, dictRefs);
|
|
62
|
+
} = useCrudPageMeta(dataMasterEntity, dictRefs, childFieldGroups);
|
|
72
63
|
|
|
73
64
|
// 子表分组标题从功能级词条中读取
|
|
74
65
|
const childSectionTitle = (groupName: string) => t(`${pageI18nKey}.children.${groupName}.title`);
|
|
75
66
|
|
|
76
|
-
//
|
|
77
|
-
const
|
|
67
|
+
// 统一维护表单默认值,初始化和重置都复用这一份
|
|
68
|
+
const createDefaultFormState = () => ({
|
|
78
69
|
{{FORM_DEFAULTS}}
|
|
79
70
|
{{CHILD_FORM_LIST_DEFAULTS}}
|
|
80
71
|
});
|
|
81
72
|
|
|
73
|
+
// 表单数据模型,包含主表字段和多个子表列表
|
|
74
|
+
const form = reactive(createDefaultFormState());
|
|
75
|
+
|
|
82
76
|
// 各子表新增行时使用的临时对象
|
|
83
77
|
{{CHILD_TEMP_DECLARATIONS}}
|
|
84
78
|
|
|
@@ -92,7 +86,7 @@ const get{{CLASS_NAME}}Data = async (id: string) => {
|
|
|
92
86
|
try {
|
|
93
87
|
loading.value = true;
|
|
94
88
|
const { data } = await getObj({ {{PK_ATTR}}: id });
|
|
95
|
-
Object.assign(form, data[0] || {});
|
|
89
|
+
Object.assign(form, Array.isArray(data) ? data[0] || {} : data || {});
|
|
96
90
|
} catch (error) {
|
|
97
91
|
useMessage().error(t('common.messages.fetchError'));
|
|
98
92
|
} finally {
|
|
@@ -102,10 +96,7 @@ const get{{CLASS_NAME}}Data = async (id: string) => {
|
|
|
102
96
|
|
|
103
97
|
// 回到初始表单状态,供新增和页面切换时复用
|
|
104
98
|
const resetFormState = () => {
|
|
105
|
-
Object.assign(form,
|
|
106
|
-
{{FORM_DEFAULTS}}
|
|
107
|
-
{{CHILD_FORM_LIST_DEFAULTS}}
|
|
108
|
-
});
|
|
99
|
+
Object.assign(form, createDefaultFormState());
|
|
109
100
|
nextTick(() => {
|
|
110
101
|
dataFormRef.value?.resetFields();
|
|
111
102
|
{{CHILD_RESET_LISTS}}
|
|
@@ -162,16 +153,9 @@ const onSubmit = async (actionType?: string) => {
|
|
|
162
153
|
}
|
|
163
154
|
};
|
|
164
155
|
|
|
165
|
-
//
|
|
166
|
-
const deleteChild =
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
await delChildObj([obj[childPkAttr]], childTableName);
|
|
170
|
-
useMessage().success(t('common.delSuccessText'));
|
|
171
|
-
} catch (err: any) {
|
|
172
|
-
useMessage().error(err.msg || t('common.delBtn'));
|
|
173
|
-
}
|
|
174
|
-
}
|
|
156
|
+
// 子表删除只处理前端行状态,统一随主表保存时提交
|
|
157
|
+
const deleteChild = (_obj: Record<string, any>, _childPkAttr: string) => {
|
|
158
|
+
return true;
|
|
175
159
|
};
|
|
176
160
|
|
|
177
161
|
onMounted(() => {
|
|
@@ -41,10 +41,12 @@ const {
|
|
|
41
41
|
} = useCrudPageMeta(dataMasterEntity, dictRefs);
|
|
42
42
|
|
|
43
43
|
// 表单数据模型
|
|
44
|
-
const
|
|
44
|
+
const createDefaultFormState = () => ({
|
|
45
45
|
{{FORM_DEFAULTS}}
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
+
const form = reactive(createDefaultFormState());
|
|
49
|
+
|
|
48
50
|
// 表单校验规则,仅保留当前需求中明确必填的字段
|
|
49
51
|
const dataRules = ref({
|
|
50
52
|
{{FORM_RULES}}
|
|
@@ -55,7 +57,7 @@ const get{{CLASS_NAME}}Data = async (id: string) => {
|
|
|
55
57
|
try {
|
|
56
58
|
loading.value = true;
|
|
57
59
|
const { data } = await getObj({ {{PK_ATTR}}: id });
|
|
58
|
-
Object.assign(form, data[0] || {});
|
|
60
|
+
Object.assign(form, Array.isArray(data) ? data[0] || {} : data || {});
|
|
59
61
|
} catch (error) {
|
|
60
62
|
useMessage().error(t('common.messages.fetchError'));
|
|
61
63
|
} finally {
|
|
@@ -65,9 +67,7 @@ const get{{CLASS_NAME}}Data = async (id: string) => {
|
|
|
65
67
|
|
|
66
68
|
// 回到初始表单状态,供新增和弹窗切换时复用
|
|
67
69
|
const resetFormState = () => {
|
|
68
|
-
Object.assign(form,
|
|
69
|
-
{{FORM_DEFAULTS}}
|
|
70
|
-
});
|
|
70
|
+
Object.assign(form, createDefaultFormState());
|
|
71
71
|
nextTick(() => {
|
|
72
72
|
dataFormRef.value?.resetFields();
|
|
73
73
|
});
|
|
@@ -55,10 +55,12 @@ const {
|
|
|
55
55
|
} = useCrudPageMeta(dataMasterEntity, dictRefs);
|
|
56
56
|
|
|
57
57
|
// 表单数据模型
|
|
58
|
-
const
|
|
58
|
+
const createDefaultFormState = () => ({
|
|
59
59
|
{{FORM_DEFAULTS}}
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
+
const form = reactive(createDefaultFormState());
|
|
63
|
+
|
|
62
64
|
// 表单校验规则,仅保留当前需求中明确必填的字段
|
|
63
65
|
const dataRules = ref({
|
|
64
66
|
{{FORM_RULES}}
|
|
@@ -69,7 +71,7 @@ const get{{CLASS_NAME}}Data = async (id: string) => {
|
|
|
69
71
|
try {
|
|
70
72
|
loading.value = true;
|
|
71
73
|
const { data } = await getObj({ {{PK_ATTR}}: id });
|
|
72
|
-
Object.assign(form, data[0] || {});
|
|
74
|
+
Object.assign(form, Array.isArray(data) ? data[0] || {} : data || {});
|
|
73
75
|
} catch (error) {
|
|
74
76
|
useMessage().error(t('common.messages.fetchError'));
|
|
75
77
|
} finally {
|
|
@@ -79,9 +81,7 @@ const get{{CLASS_NAME}}Data = async (id: string) => {
|
|
|
79
81
|
|
|
80
82
|
// 回到初始表单状态,供新增和页面切换时复用
|
|
81
83
|
const resetFormState = () => {
|
|
82
|
-
Object.assign(form,
|
|
83
|
-
{{FORM_DEFAULTS}}
|
|
84
|
-
});
|
|
84
|
+
Object.assign(form, createDefaultFormState());
|
|
85
85
|
nextTick(() => {
|
|
86
86
|
dataFormRef.value?.resetFields();
|
|
87
87
|
});
|
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.18';
|
|
9
9
|
const PROTOCOL_VERSION = '2024-11-05';
|
|
10
10
|
const TOOL_NAME = 'worsoft_codegen_local_generate_frontend';
|
|
11
11
|
const TEMPLATE_LIBRARY_ROOT = path.resolve(__dirname, '..', 'template');
|
|
@@ -1306,12 +1306,9 @@ function renderChildTempDeclaration(childModel) {
|
|
|
1306
1306
|
].join('\n');
|
|
1307
1307
|
}
|
|
1308
1308
|
|
|
1309
|
-
function renderChildSection(childModel, childCount) {
|
|
1310
|
-
const title = childModel.tableComment.replace(/'/g, "\\'");
|
|
1311
|
-
const deleteExpression =
|
|
1312
|
-
childCount > 1
|
|
1313
|
-
? `deleteChild(obj, '${childModel.pk.attrName}', '${childModel.tableName}')`
|
|
1314
|
-
: `deleteChild(obj, '${childModel.pk.attrName}')`;
|
|
1309
|
+
function renderChildSection(childModel, childCount) {
|
|
1310
|
+
const title = childModel.tableComment.replace(/'/g, "\\'");
|
|
1311
|
+
const deleteExpression = `deleteChild(obj, '${childModel.pk.attrName}')`;
|
|
1315
1312
|
|
|
1316
1313
|
return [
|
|
1317
1314
|
' <el-col :span="24" class="mb20">',
|
|
@@ -1562,11 +1559,8 @@ function renderChildTableColumnV2(field, childListName) {
|
|
|
1562
1559
|
].join('\n');
|
|
1563
1560
|
}
|
|
1564
1561
|
|
|
1565
|
-
function renderChildSectionV2(childModel, childCount) {
|
|
1566
|
-
const deleteExpression =
|
|
1567
|
-
childCount > 1
|
|
1568
|
-
? `deleteChild(obj, '${childModel.pk.attrName}', '${childModel.tableName}')`
|
|
1569
|
-
: `deleteChild(obj, '${childModel.pk.attrName}')`;
|
|
1562
|
+
function renderChildSectionV2(childModel, childCount) {
|
|
1563
|
+
const deleteExpression = `deleteChild(obj, '${childModel.pk.attrName}')`;
|
|
1570
1564
|
|
|
1571
1565
|
return [
|
|
1572
1566
|
' <el-col :span="24" class="mb20">',
|
package/package.json
CHANGED