data.ts.vm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { reactive } from 'vue'
  2. import { useI18n } from '@/hooks/web/useI18n'
  3. import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
  4. import { DICT_TYPE } from '@/utils/dict'
  5. const { t } = useI18n() // 国际化
  6. // 表单校验
  7. export const rules = reactive({
  8. #foreach ($column in $columns)
  9. #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
  10. #set($comment=$column.columnComment)
  11. $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == "select")'change'#else'blur'#end }],
  12. #end
  13. #end
  14. })
  15. // CrudSchema
  16. const crudSchemas = reactive<CrudSchema[]>([
  17. #foreach($column in $columns)
  18. #if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation)
  19. #set ($dictType = $column.dictType)
  20. {
  21. label: '${column.columnComment}',
  22. field: '${column.javaField}',
  23. #if ("" != $dictType)## 有数据字典
  24. dictType: DICT_TYPE.$dictType.toUpperCase(),
  25. #end
  26. #if($column.primaryKey)
  27. type: 'index',
  28. form: {
  29. show: false
  30. },
  31. detail: {
  32. show: false
  33. }
  34. #else
  35. #if (!$column.createOperation && !$column.updateOperation)
  36. form: {
  37. show: false
  38. },
  39. #elseif(!("" != $column.dictType))
  40. form: {
  41. show: true,
  42. #if ($column.htmlType == "datetime")## 时间框
  43. component: 'DatePicker',
  44. componentProps: {
  45. type: 'datetime',
  46. valueFormat: 'YYYY-MM-DD HH:mm:ss'
  47. }
  48. #elseif($column.htmlType == "editor")## 文本编辑器
  49. component: 'Editor',
  50. colProps: {
  51. span: 24
  52. },
  53. componentProps: {
  54. valueHtml: ''
  55. }
  56. #elseif($column.htmlType == "textarea")## 文本框
  57. component: 'Input',
  58. componentProps: {
  59. type: 'textarea',
  60. rows: 4
  61. },
  62. colProps: {
  63. span: 24
  64. }
  65. #end
  66. },
  67. #end
  68. #if ($column.listOperationResult)
  69. search: {
  70. #if($column.htmlType == "input")
  71. show: true
  72. #else
  73. #if($column.htmlType == "datetime")
  74. show: true,
  75. component: 'DatePicker',
  76. componentProps: {
  77. type: 'datetimerange',
  78. valueFormat: 'YYYY-MM-DD HH:mm:ss'
  79. }
  80. #elseif($column.htmlType == "select" || $column.htmlType == "radio")
  81. #if ("" == $dictType)## 没有数据字典
  82. show: true,
  83. component: 'Select',
  84. componentProps: {
  85. option: [{'','请选择字典生成'}]
  86. }
  87. #else
  88. show: true
  89. #end
  90. #end
  91. #end
  92. }
  93. #end
  94. #end
  95. },
  96. #end
  97. #end
  98. {
  99. label: t('table.action'),
  100. field: 'action',
  101. width: '240px',
  102. form: {
  103. show: false
  104. },
  105. detail: {
  106. show: false
  107. }
  108. }
  109. ])
  110. export const { allSchemas } = useCrudSchemas(crudSchemas)