123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import { reactive } from 'vue'
- import { useI18n } from '@/hooks/web/useI18n'
- import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
- import { DICT_TYPE } from '@/utils/dict'
- const { t } = useI18n() // 国际化
- // 表单校验
- export const rules = reactive({
- #foreach ($column in $columns)
- #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
- #set($comment=$column.columnComment)
- $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == "select")'change'#else'blur'#end }],
- #end
- #end
- })
- // CrudSchema
- const crudSchemas = reactive<CrudSchema[]>([
- #foreach($column in $columns)
- #if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation)
- #set ($dictType = $column.dictType)
- {
- label: '${column.columnComment}',
- field: '${column.javaField}',
- #if ("" != $dictType)## 有数据字典
- dictType: DICT_TYPE.$dictType.toUpperCase(),
- #end
- #if($column.primaryKey)
- type: 'index',
- form: {
- show: false
- },
- detail: {
- show: false
- }
- #else
- #if (!$column.createOperation && !$column.updateOperation)
- form: {
- show: false
- },
- #elseif(!("" != $column.dictType))
- form: {
- show: true,
- #if ($column.htmlType == "datetime")## 时间框
- component: 'DatePicker',
- componentProps: {
- type: 'datetime',
- valueFormat: 'YYYY-MM-DD HH:mm:ss'
- }
- #elseif($column.htmlType == "editor")## 文本编辑器
- component: 'Editor',
- colProps: {
- span: 24
- },
- componentProps: {
- valueHtml: ''
- }
- #elseif($column.htmlType == "textarea")## 文本框
- component: 'Input',
- componentProps: {
- type: 'textarea',
- rows: 4
- },
- colProps: {
- span: 24
- }
- #end
- },
- #end
- #if ($column.listOperationResult)
- search: {
- #if($column.htmlType == "input")
- show: true
- #else
- #if($column.htmlType == "datetime")
- show: true,
- component: 'DatePicker',
- componentProps: {
- type: 'datetimerange',
- valueFormat: 'YYYY-MM-DD HH:mm:ss'
- }
- #elseif($column.htmlType == "select" || $column.htmlType == "radio")
- #if ("" == $dictType)## 没有数据字典
- show: true,
- component: 'Select',
- componentProps: {
- option: [{'','请选择字典生成'}]
- }
- #else
- show: true
- #end
- #end
- #end
- }
- #end
- #end
- },
- #end
- #end
- {
- label: t('table.action'),
- field: 'action',
- width: '240px',
- form: {
- show: false
- },
- detail: {
- show: false
- }
- }
- ])
- export const { allSchemas } = useCrudSchemas(crudSchemas)
|