data.ts.vm 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { reactive } from 'vue'
  2. import { useI18n } from '@/hooks/web/useI18n'
  3. import { DICT_TYPE } from '@/utils/dict'
  4. import { required } from '@/utils/formRules'
  5. import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
  6. const { t } = useI18n() // 国际化
  7. // 表单校验
  8. export const rules = reactive({
  9. #foreach ($column in $columns)
  10. #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
  11. #set($comment=$column.columnComment)
  12. $column.javaField: [required],
  13. #end
  14. #end
  15. })
  16. // CrudSchema
  17. const crudSchemas = reactive<VxeCrudSchema>({
  18. primaryKey: 'id', // 默认的主键ID
  19. primaryTitle: t('common.index'), // 默认显示的值
  20. primaryType: 'seq', // 默认为seq,序号模式
  21. action: true,
  22. actionWidth: '200', // 3个按钮默认200,如有删减对应增减即可
  23. columns: [
  24. #foreach($column in $columns)
  25. #if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation)
  26. #set ($dictType = $column.dictType)
  27. #if(!$column.primaryKey)
  28. {
  29. title: '${column.columnComment}',
  30. field: '${column.javaField}',
  31. #if ("" != $dictType)## 有数据字典
  32. dictType: DICT_TYPE.$dictType.toUpperCase(),
  33. #end
  34. #if (!$column.createOperation && !$column.updateOperation)
  35. isForm: false
  36. #elseif(!("" != $column.dictType))
  37. #if ($column.htmlType == "datetime")## 时间框
  38. form: {
  39. show: true,
  40. component: 'DatePicker',
  41. componentProps: {
  42. type: 'datetime',
  43. valueFormat: 'YYYY-MM-DD HH:mm:ss'
  44. }
  45. }
  46. #elseif($column.htmlType == "editor")## 文本编辑器
  47. form: {
  48. show: true,
  49. component: 'Editor',
  50. colProps: {
  51. span: 24
  52. },
  53. componentProps: {
  54. valueHtml: ''
  55. }
  56. }
  57. #elseif($column.htmlType == "textarea")## 文本框
  58. form: {
  59. show: true,
  60. component: 'Input',
  61. componentProps: {
  62. type: 'textarea',
  63. rows: 4
  64. },
  65. colProps: {
  66. span: 24
  67. }
  68. }
  69. #end
  70. #end
  71. #if ($column.listOperationResult)
  72. #if($column.htmlType == "input")
  73. isSearch: true
  74. #elseif("" != $dictType)
  75. isSearch: true
  76. #elseif($column.htmlType == "datetime")
  77. search: {
  78. show: true,
  79. itemRender: {
  80. name: 'XDataTimePicker'
  81. }
  82. }
  83. #end
  84. #end
  85. #end
  86. },
  87. #end
  88. #end
  89. ]
  90. })
  91. export const { allSchemas } = useVxeCrudSchemas(crudSchemas)