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