【代码优化】INFRA: vue3_vben5_antd schema 单表和树表代码生成模版优化
This commit is contained in:
parent
7c94085499
commit
24aea3e30a
|
@ -9,6 +9,7 @@ import { get${simpleClassName}List } from '#/api/${table.moduleName}/${simpleCla
|
||||||
import { handleTree } from '#/utils/tree';
|
import { handleTree } from '#/utils/tree';
|
||||||
#end
|
#end
|
||||||
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
||||||
|
import { getRangePickerDefaultProps } from '#/utils/date';
|
||||||
import { useAccess } from '@vben/access';
|
import { useAccess } from '@vben/access';
|
||||||
|
|
||||||
const { hasAccessByCodes } = useAccess();
|
const { hasAccessByCodes } = useAccess();
|
||||||
|
@ -196,6 +197,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
#elseif($column.htmlType == "datetime")
|
#elseif($column.htmlType == "datetime")
|
||||||
component: 'RangePicker',
|
component: 'RangePicker',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
|
...getRangePickerDefaultProps(),
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
},
|
},
|
||||||
#end
|
#end
|
||||||
|
@ -237,7 +239,7 @@ export function useGridColumns(
|
||||||
field: 'operation',
|
field: 'operation',
|
||||||
title: '操作',
|
title: '操作',
|
||||||
minWidth: 200,
|
minWidth: 200,
|
||||||
align: 'right',
|
align: 'center',
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
headerAlign: 'center',
|
headerAlign: 'center',
|
||||||
showOverflow: false,
|
showOverflow: false,
|
||||||
|
@ -251,7 +253,7 @@ export function useGridColumns(
|
||||||
options: [
|
options: [
|
||||||
#if (${table.templateType} == 2)## 树表特有操作
|
#if (${table.templateType} == 2)## 树表特有操作
|
||||||
{
|
{
|
||||||
code: 'add_child',
|
code: 'append',
|
||||||
text: '新增下级',
|
text: '新增下级',
|
||||||
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:create']),
|
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:create']),
|
||||||
},
|
},
|
||||||
|
|
|
@ -64,49 +64,25 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载数据
|
// 加载数据
|
||||||
#if (${table.templateType} == 2)## 树表处理传入的父ID
|
|
||||||
let data = modalApi.getData<${simpleClassName}Api.${simpleClassName}>();
|
let data = modalApi.getData<${simpleClassName}Api.${simpleClassName}>();
|
||||||
#else## 标准表直接获取
|
|
||||||
const data = modalApi.getData<${simpleClassName}Api.${simpleClassName}>();
|
|
||||||
#end
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (${table.templateType} == 2)## 树表特有:处理新增下级的情况
|
|
||||||
// 处理新增下级的情况
|
|
||||||
if (!data.id && data.${treeParentColumn.javaField}) {
|
|
||||||
parentId.value = data.${treeParentColumn.javaField};
|
|
||||||
formData.value = { ${treeParentColumn.javaField}: parentId.value } as ${simpleClassName}Api.${simpleClassName};
|
|
||||||
await formApi.setValues(formData.value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#end
|
|
||||||
|
|
||||||
if (data.id) {
|
if (data.id) {
|
||||||
// 编辑
|
// 编辑
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
try {
|
try {
|
||||||
#if (${table.templateType} == 2)## 树表获取数据后重新赋值
|
|
||||||
data = await get${simpleClassName}(data.id);
|
data = await get${simpleClassName}(data.id);
|
||||||
formData.value = data;
|
|
||||||
#else## 标准表设置表单数据
|
|
||||||
formData.value = await get${simpleClassName}(data.id as number);
|
|
||||||
#end
|
|
||||||
await formApi.setValues(formData.value);
|
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.lock(false);
|
modalApi.lock(false);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// 新增
|
|
||||||
#if (${table.templateType} == 2)## 树表特有:设置顶级ID
|
|
||||||
formData.value = { ${treeParentColumn.javaField}: 0 } as ${simpleClassName}Api.${simpleClassName};
|
|
||||||
#else## 标准表:设置空值
|
|
||||||
formData.value = data;
|
|
||||||
#end
|
|
||||||
await formApi.setValues(formData.value || {});
|
|
||||||
}
|
}
|
||||||
|
// 设置到 values
|
||||||
|
formData.value = data;
|
||||||
|
await formApi.setValues(formData.value);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { Button, message } from 'ant-design-vue';
|
||||||
import { Download, Plus } from '@vben/icons';
|
import { Download, Plus } from '@vben/icons';
|
||||||
import Form from './modules/form.vue';
|
import Form from './modules/form.vue';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
import { ref, h } from 'vue';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
#if (${table.templateType} == 2)## 树表接口
|
#if (${table.templateType} == 2)## 树表接口
|
||||||
|
@ -56,7 +56,7 @@ function onEdit(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||||
|
|
||||||
#if (${table.templateType} == 2)## 树表特有:新增下级
|
#if (${table.templateType} == 2)## 树表特有:新增下级
|
||||||
/** 新增下级${table.classComment} */
|
/** 新增下级${table.classComment} */
|
||||||
function onAddChild(row: ${simpleClassName}Api.${simpleClassName}) {
|
function onAppend(row: ${simpleClassName}Api.${simpleClassName}) {
|
||||||
formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open();
|
formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open();
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
@ -86,20 +86,20 @@ function onActionClick({
|
||||||
row,
|
row,
|
||||||
}: OnActionClickParams<${simpleClassName}Api.${simpleClassName}>) {
|
}: OnActionClickParams<${simpleClassName}Api.${simpleClassName}>) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 'edit': {
|
#if (${table.templateType} == 2)## 树表特有:新增下级
|
||||||
onEdit(row);
|
case 'append': {
|
||||||
|
onAppend(row);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#end
|
||||||
case 'delete': {
|
case 'delete': {
|
||||||
onDelete(row);
|
onDelete(row);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if (${table.templateType} == 2)## 树表特有:新增下级
|
case 'edit': {
|
||||||
case 'add_child': {
|
onEdit(row);
|
||||||
onAddChild(row);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#end
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,12 +167,16 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
{{ isExpanded ? '收缩' : '展开' }}
|
{{ isExpanded ? '收缩' : '展开' }}
|
||||||
</Button>
|
</Button>
|
||||||
#end
|
#end
|
||||||
<Button type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']">
|
<Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']">
|
||||||
<Plus class="size-5" />
|
|
||||||
{{ $t('ui.actionTitle.create', ['${table.classComment}']) }}
|
{{ $t('ui.actionTitle.create', ['${table.classComment}']) }}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="primary" class="ml-2" @click="onExport" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:export']">
|
<Button
|
||||||
<Download class="size-5" />
|
:icon="h(Download)"
|
||||||
|
type="primary"
|
||||||
|
class="ml-2"
|
||||||
|
@click="onExport"
|
||||||
|
v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:export']"
|
||||||
|
>
|
||||||
{{ $t('ui.actionTitle.export') }}
|
{{ $t('ui.actionTitle.export') }}
|
||||||
</Button>
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue