91 lines
2.5 KiB
Plaintext
Raw Normal View History

2022-07-25 18:46:04 +08:00
import { reactive } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { DICT_TYPE } from '@/utils/dict'
2022-11-16 18:01:36 +08:00
import { required } from '@/utils/formRules'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
2022-07-25 18:46:04 +08:00
const { t } = useI18n() // 国际化
// 表单校验
export const rules = reactive({
#foreach ($column in $columns)
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
#set($comment=$column.columnComment)
2022-11-16 18:01:36 +08:00
$column.javaField: [required],
2022-07-25 18:46:04 +08:00
#end
#end
})
// CrudSchema
2022-11-16 18:01:36 +08:00
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id', // 默认的主键ID
primaryTitle: t('common.index'), // 默认显示的值
primaryType: 'seq', // 默认为seq序号模式
action: true,
actionWidth: '200', // 3个按钮默认200如有删减对应增减即可
columns: [
2022-07-25 18:46:04 +08:00
#foreach($column in $columns)
#if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation)
#set ($dictType = $column.dictType)
2022-11-16 18:01:36 +08:00
#if(!$column.primaryKey)
{
2022-11-16 18:01:36 +08:00
title: '${column.columnComment}',
field: '${column.javaField}',
#if ("" != $dictType)## 有数据字典
dictType: DICT_TYPE.$dictType.toUpperCase(),
#end
#if (!$column.createOperation && !$column.updateOperation)
2022-11-16 18:01:36 +08:00
isForm: false
#elseif(!("" != $column.dictType))
2022-11-16 18:01:36 +08:00
#if ($column.htmlType == "datetime")## 时间框
form: {
show: true,
component: 'DatePicker',
componentProps: {
type: 'datetime',
valueFormat: 'YYYY-MM-DD HH:mm:ss'
2022-07-25 18:46:04 +08:00
}
2022-11-16 18:01:36 +08:00
}
#elseif($column.htmlType == "editor")## 文本编辑器
form: {
show: true,
component: 'Editor',
colProps: {
span: 24
2022-07-25 18:46:04 +08:00
},
componentProps: {
valueHtml: ''
}
2022-11-16 18:01:36 +08:00
}
#elseif($column.htmlType == "textarea")## 文本框
form: {
show: true,
component: 'Input',
componentProps: {
type: 'textarea',
rows: 4
2022-07-25 18:46:04 +08:00
},
colProps: {
span: 24
}
2022-11-16 18:01:36 +08:00
}
#end
#end
#if ($column.listOperationResult)
2022-11-16 18:01:36 +08:00
#if($column.htmlType == "input")
isSearch: true
#elseif("" != $dictType)
isSearch: true
#elseif($column.htmlType == "datetime")
search: {
show: true,
2022-11-16 18:01:36 +08:00
itemRender: {
name: 'XDataTimePicker'
2022-07-25 18:46:04 +08:00
}
}
2022-07-25 18:46:04 +08:00
#end
#end
2022-11-16 18:01:36 +08:00
#end
},
#end
2022-07-25 18:46:04 +08:00
#end
2022-11-16 18:01:36 +08:00
]
})
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)