|
@@ -1,11 +1,15 @@
|
|
|
+import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
|
|
|
import type { VbenFormSchema } from '#/adapter/form';
|
|
|
-import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
|
|
+import type { OnActionClickFn } from '#/adapter/vxe-table';
|
|
|
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
|
|
|
|
|
import { z } from '#/adapter/form';
|
|
|
-import { CommonStatusEnum } from '#/utils/constants';
|
|
|
+#if(${table.templateType} == 2)## 树表需要导入这些
|
|
|
+import { get${simpleClassName}List } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
|
|
+import { handleTree } from '#/utils/tree';
|
|
|
+#end
|
|
|
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
|
|
-import { getRangePickerDefaultProps } from '#/utils/date';
|
|
|
+import { CommonStatusEnum } from '#/utils/constants';
|
|
|
import { useAccess } from '@vben/access';
|
|
|
|
|
|
const { hasAccessByCodes } = useAccess();
|
|
@@ -21,9 +25,34 @@ export function useFormSchema(): VbenFormSchema[] {
|
|
|
show: () => false,
|
|
|
},
|
|
|
},
|
|
|
+#if(${table.templateType} == 2)## 树表特有字段:上级
|
|
|
+ {
|
|
|
+ fieldName: '${treeParentColumn.javaField}',
|
|
|
+ label: '上级${table.classComment}',
|
|
|
+ component: 'ApiTreeSelect',
|
|
|
+ componentProps: {
|
|
|
+ allowClear: true,
|
|
|
+ api: async () => {
|
|
|
+ const data = await get${simpleClassName}List({});
|
|
|
+ data.unshift({
|
|
|
+ id: 0,
|
|
|
+ ${treeNameColumn.javaField}: '顶级${table.classComment}',
|
|
|
+ });
|
|
|
+ return handleTree(data);
|
|
|
+ },
|
|
|
+ class: 'w-full',
|
|
|
+ labelField: '${treeNameColumn.javaField}',
|
|
|
+ valueField: 'id',
|
|
|
+ childrenField: 'children',
|
|
|
+ placeholder: '请选择上级${table.classComment}',
|
|
|
+ treeDefaultExpandAll: true,
|
|
|
+ },
|
|
|
+ rules: 'selectRequired',
|
|
|
+ },
|
|
|
+#end
|
|
|
#foreach($column in $columns)
|
|
|
#if ($column.createOperation || $column.updateOperation)
|
|
|
-#if (!$column.primaryKey)## 忽略主键,不用在表单里
|
|
|
+#if (!$column.primaryKey && ($table.templateType != 2 || ($table.templateType == 2 && $column.id != $treeParentColumn.id)))## 树表中已经添加了父ID字段,这里排除
|
|
|
#set ($dictType = $column.dictType)
|
|
|
#set ($javaType = $column.javaType)
|
|
|
#set ($javaField = $column.javaField)
|
|
@@ -69,6 +98,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
|
|
options: [],
|
|
|
#end
|
|
|
placeholder: '请选择${comment}',
|
|
|
+ class: 'w-full',
|
|
|
},
|
|
|
#elseif($column.htmlType == "checkbox")## 多选框
|
|
|
component: 'Checkbox',
|
|
@@ -102,6 +132,14 @@ export function useFormSchema(): VbenFormSchema[] {
|
|
|
componentProps: {
|
|
|
placeholder: '请输入${comment}',
|
|
|
},
|
|
|
+ #elseif($column.htmlType == "inputNumber")## 数字输入框
|
|
|
+ component: 'InputNumber',
|
|
|
+ componentProps: {
|
|
|
+ min: 0,
|
|
|
+ class: 'w-full',
|
|
|
+ controlsPosition: 'right',
|
|
|
+ placeholder: '请输入${comment}',
|
|
|
+ },
|
|
|
#end
|
|
|
},
|
|
|
#end
|
|
@@ -159,7 +197,6 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|
|
#elseif($column.htmlType == "datetime")
|
|
|
component: 'RangePicker',
|
|
|
componentProps: {
|
|
|
- ...getRangePickerDefaultProps(),
|
|
|
allowClear: true,
|
|
|
},
|
|
|
#end
|
|
@@ -170,9 +207,9 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|
|
}
|
|
|
|
|
|
/** 列表的字段 */
|
|
|
-export function useGridColumns<T = ${simpleClassName}Api.${simpleClassName}>(
|
|
|
- onActionClick: OnActionClickFn<T>,
|
|
|
-): VxeTableGridOptions['columns'] {
|
|
|
+export function useGridColumns(
|
|
|
+ onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>,
|
|
|
+): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] {
|
|
|
return [
|
|
|
#foreach($column in $columns)
|
|
|
#if ($column.listOperationResult)
|
|
@@ -190,6 +227,9 @@ export function useGridColumns<T = ${simpleClassName}Api.${simpleClassName}>(
|
|
|
name: 'CellDict',
|
|
|
props: { type: DICT_TYPE.$dictType.toUpperCase() },
|
|
|
},
|
|
|
+ #end
|
|
|
+ #if (${table.templateType} == 2 && $column.id == $treeNameColumn.id)## 树表特有:标记树节点列
|
|
|
+ treeNode: true,
|
|
|
#end
|
|
|
},
|
|
|
#end
|
|
@@ -197,9 +237,11 @@ export function useGridColumns<T = ${simpleClassName}Api.${simpleClassName}>(
|
|
|
{
|
|
|
field: 'operation',
|
|
|
title: '操作',
|
|
|
- minWidth: 180,
|
|
|
- align: 'center',
|
|
|
+ minWidth: 200,
|
|
|
+ align: 'right',
|
|
|
fixed: 'right',
|
|
|
+ headerAlign: 'center',
|
|
|
+ showOverflow: false,
|
|
|
cellRender: {
|
|
|
attrs: {
|
|
|
nameField: '${columns[0].javaField}',
|
|
@@ -208,6 +250,13 @@ export function useGridColumns<T = ${simpleClassName}Api.${simpleClassName}>(
|
|
|
},
|
|
|
name: 'CellOperation',
|
|
|
options: [
|
|
|
+#if (${table.templateType} == 2)## 树表特有操作
|
|
|
+ {
|
|
|
+ code: 'add_child',
|
|
|
+ text: '新增下级',
|
|
|
+ show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:create']),
|
|
|
+ },
|
|
|
+#end
|
|
|
{
|
|
|
code: 'edit',
|
|
|
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:update']),
|
|
@@ -215,7 +264,12 @@ export function useGridColumns<T = ${simpleClassName}Api.${simpleClassName}>(
|
|
|
{
|
|
|
code: 'delete',
|
|
|
show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:delete']),
|
|
|
- }
|
|
|
+#if (${table.templateType} == 2)## 树表禁止删除带有子节点的数据
|
|
|
+ disabled: (row: ${simpleClassName}Api.${simpleClassName}) => {
|
|
|
+ return !!(row.children && row.children.length > 0);
|
|
|
+ },
|
|
|
+#end
|
|
|
+ },
|
|
|
],
|
|
|
},
|
|
|
},
|