|
@@ -0,0 +1,277 @@
|
|
|
+import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
|
|
|
+import type { VbenFormSchema } from '#/adapter/form';
|
|
|
+import type { OnActionClickFn } from '#/adapter/vxe-table';
|
|
|
+import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
|
|
|
+
|
|
|
+import { z } from '#/adapter/form';
|
|
|
+#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 { CommonStatusEnum } from '#/utils/constants';
|
|
|
+import { useAccess } from '@vben/access';
|
|
|
+
|
|
|
+const { hasAccessByCodes } = useAccess();
|
|
|
+
|
|
|
+/** 新增/修改的表单 */
|
|
|
+export function useFormSchema(): VbenFormSchema[] {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ fieldName: 'id',
|
|
|
+ component: 'Input',
|
|
|
+ dependencies: {
|
|
|
+ triggerFields: [''],
|
|
|
+ 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 && ($table.templateType != 2 || ($table.templateType == 2 && $column.id != $treeParentColumn.id)))## 树表中已经添加了父ID字段,这里排除
|
|
|
+ #set ($dictType = $column.dictType)
|
|
|
+ #set ($javaType = $column.javaType)
|
|
|
+ #set ($javaField = $column.javaField)
|
|
|
+ #set ($comment = $column.columnComment)
|
|
|
+ #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
|
|
+ #set ($dictMethod = "number")
|
|
|
+ #elseif ($javaType == "String")
|
|
|
+ #set ($dictMethod = "string")
|
|
|
+ #elseif ($javaType == "Boolean")
|
|
|
+ #set ($dictMethod = "boolean")
|
|
|
+ #end
|
|
|
+ {
|
|
|
+ fieldName: '${javaField}',
|
|
|
+ label: '${comment}',
|
|
|
+ #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
|
|
+ rules: 'required',
|
|
|
+ #end
|
|
|
+ #if ($column.htmlType == "input")
|
|
|
+ component: 'Input',
|
|
|
+ componentProps: {
|
|
|
+ placeholder: '请输入${comment}',
|
|
|
+ },
|
|
|
+ #elseif($column.htmlType == "imageUpload")## 图片上传
|
|
|
+ component: 'FileUpload',
|
|
|
+ componentProps: {
|
|
|
+ fileType: 'image',
|
|
|
+ maxCount: 1,
|
|
|
+ },
|
|
|
+ #elseif($column.htmlType == "fileUpload")## 文件上传
|
|
|
+ component: 'FileUpload',
|
|
|
+ componentProps: {
|
|
|
+ fileType: 'file',
|
|
|
+ maxCount: 1,
|
|
|
+ },
|
|
|
+ #elseif($column.htmlType == "editor")## 文本编辑器
|
|
|
+ component: 'Editor',
|
|
|
+ #elseif($column.htmlType == "select")## 下拉框
|
|
|
+ component: 'Select',
|
|
|
+ componentProps: {
|
|
|
+ #if ("" != $dictType)## 有数据字典
|
|
|
+ options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
|
|
+ #else##没数据字典
|
|
|
+ options: [],
|
|
|
+ #end
|
|
|
+ placeholder: '请选择${comment}',
|
|
|
+ class: 'w-full',
|
|
|
+ },
|
|
|
+ #elseif($column.htmlType == "checkbox")## 多选框
|
|
|
+ component: 'Checkbox',
|
|
|
+ componentProps: {
|
|
|
+ #if ("" != $dictType)## 有数据字典
|
|
|
+ options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
|
|
+ #else##没数据字典
|
|
|
+ options: [],
|
|
|
+ #end
|
|
|
+ },
|
|
|
+ #elseif($column.htmlType == "radio")## 单选框
|
|
|
+ component: 'RadioGroup',
|
|
|
+ componentProps: {
|
|
|
+ #if ("" != $dictType)## 有数据字典
|
|
|
+ options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
|
|
+ #else##没数据字典
|
|
|
+ options: [],
|
|
|
+ #end
|
|
|
+ buttonStyle: 'solid',
|
|
|
+ optionType: 'button',
|
|
|
+ },
|
|
|
+ #elseif($column.htmlType == "datetime")## 时间框
|
|
|
+ component: 'DatePicker',
|
|
|
+ componentProps: {
|
|
|
+ showTime: true,
|
|
|
+ format: 'YYYY-MM-DD HH:mm:ss',
|
|
|
+ valueFormat: 'x',
|
|
|
+ },
|
|
|
+ #elseif($column.htmlType == "textarea")## 文本域
|
|
|
+ component: 'Textarea',
|
|
|
+ componentProps: {
|
|
|
+ placeholder: '请输入${comment}',
|
|
|
+ },
|
|
|
+ #elseif($column.htmlType == "inputNumber")## 数字输入框
|
|
|
+ component: 'InputNumber',
|
|
|
+ componentProps: {
|
|
|
+ min: 0,
|
|
|
+ class: 'w-full',
|
|
|
+ controlsPosition: 'right',
|
|
|
+ placeholder: '请输入${comment}',
|
|
|
+ },
|
|
|
+ #end
|
|
|
+ },
|
|
|
+#end
|
|
|
+#end
|
|
|
+#end
|
|
|
+ ];
|
|
|
+}
|
|
|
+
|
|
|
+/** 列表的搜索表单 */
|
|
|
+export function useGridFormSchema(): VbenFormSchema[] {
|
|
|
+ return [
|
|
|
+#foreach($column in $columns)
|
|
|
+#if ($column.listOperation)
|
|
|
+ #set ($dictType = $column.dictType)
|
|
|
+ #set ($javaType = $column.javaType)
|
|
|
+ #set ($javaField = $column.javaField)
|
|
|
+ #set ($comment = $column.columnComment)
|
|
|
+ #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
|
|
+ #set ($dictMethod = "number")
|
|
|
+ #elseif ($javaType == "String")
|
|
|
+ #set ($dictMethod = "string")
|
|
|
+ #elseif ($javaType == "Boolean")
|
|
|
+ #set ($dictMethod = "boolean")
|
|
|
+ #end
|
|
|
+ {
|
|
|
+ fieldName: '${javaField}',
|
|
|
+ label: '${comment}',
|
|
|
+ #if ($column.htmlType == "input")
|
|
|
+ component: 'Input',
|
|
|
+ componentProps: {
|
|
|
+ allowClear: true,
|
|
|
+ placeholder: '请输入${comment}',
|
|
|
+ },
|
|
|
+ #elseif ($column.htmlType == "select")
|
|
|
+ component: 'Select',
|
|
|
+ componentProps: {
|
|
|
+ allowClear: true,
|
|
|
+ #if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
|
|
+ options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
|
|
+ #else## 未设置 dictType 数据字典的情况
|
|
|
+ options: [],
|
|
|
+ #end
|
|
|
+ placeholder: '请选择${comment}',
|
|
|
+ },
|
|
|
+ #elseif ($column.htmlType == "radio")
|
|
|
+ component: 'Select',
|
|
|
+ componentProps: {
|
|
|
+ allowClear: true,
|
|
|
+ #if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
|
|
+ options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
|
|
+ #else## 未设置 dictType 数据字典的情况
|
|
|
+ options: [],
|
|
|
+ #end
|
|
|
+ },
|
|
|
+ #elseif($column.htmlType == "datetime")
|
|
|
+ component: 'RangePicker',
|
|
|
+ componentProps: {
|
|
|
+ allowClear: true,
|
|
|
+ },
|
|
|
+ #end
|
|
|
+ },
|
|
|
+#end
|
|
|
+#end
|
|
|
+ ];
|
|
|
+}
|
|
|
+
|
|
|
+/** 列表的字段 */
|
|
|
+export function useGridColumns(
|
|
|
+ onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>,
|
|
|
+): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] {
|
|
|
+ return [
|
|
|
+#foreach($column in $columns)
|
|
|
+#if ($column.listOperationResult)
|
|
|
+ #set ($dictType = $column.dictType)
|
|
|
+ #set ($javaField = $column.javaField)
|
|
|
+ #set ($comment = $column.columnComment)
|
|
|
+ {
|
|
|
+ field: '${javaField}',
|
|
|
+ title: '${comment}',
|
|
|
+ minWidth: 120,
|
|
|
+ #if ($column.javaType == "LocalDateTime")## 时间类型
|
|
|
+ formatter: 'formatDateTime',
|
|
|
+ #elseif("" != $dictType)## 数据字典
|
|
|
+ cellRender: {
|
|
|
+ name: 'CellDict',
|
|
|
+ props: { type: DICT_TYPE.$dictType.toUpperCase() },
|
|
|
+ },
|
|
|
+ #end
|
|
|
+ #if (${table.templateType} == 2 && $column.id == $treeNameColumn.id)## 树表特有:标记树节点列
|
|
|
+ treeNode: true,
|
|
|
+ #end
|
|
|
+ },
|
|
|
+#end
|
|
|
+#end
|
|
|
+ {
|
|
|
+ field: 'operation',
|
|
|
+ title: '操作',
|
|
|
+ minWidth: 200,
|
|
|
+ align: 'right',
|
|
|
+ fixed: 'right',
|
|
|
+ headerAlign: 'center',
|
|
|
+ showOverflow: false,
|
|
|
+ cellRender: {
|
|
|
+ attrs: {
|
|
|
+ nameField: '${columns[0].javaField}',
|
|
|
+ nameTitle: '${table.classComment}',
|
|
|
+ onClick: onActionClick,
|
|
|
+ },
|
|
|
+ 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']),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 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
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+}
|