data.ts.vm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #if (${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer")
  34. dictData: 'number',
  35. #else
  36. dictData: 'string',
  37. #end
  38. #end
  39. #if (!$column.createOperation && !$column.updateOperation)
  40. isForm: false,
  41. #elseif(!("" != $column.dictType))
  42. #if ($column.htmlType == "datetime")## 时间框
  43. form: {
  44. show: true,
  45. component: 'DatePicker',
  46. componentProps: {
  47. type: 'datetime',
  48. valueFormat: 'YYYY-MM-DD HH:mm:ss'
  49. }
  50. },
  51. #elseif($column.htmlType == "editor")## 文本编辑器
  52. form: {
  53. show: true,
  54. component: 'Editor',
  55. colProps: {
  56. span: 24
  57. },
  58. componentProps: {
  59. valueHtml: ''
  60. }
  61. },
  62. #elseif($column.htmlType == "textarea")## 文本框
  63. form: {
  64. show: true,
  65. component: 'Input',
  66. componentProps: {
  67. type: 'textarea',
  68. rows: 4
  69. },
  70. colProps: {
  71. span: 24
  72. }
  73. },
  74. #end
  75. #end
  76. #if ($column.listOperationResult)
  77. #if($column.htmlType == "input")
  78. isSearch: true,
  79. #elseif("" != $dictType)
  80. isSearch: true,
  81. #elseif($column.htmlType == "datetime")
  82. search: {
  83. show: true,
  84. itemRender: {
  85. name: 'XDataTimePicker'
  86. }
  87. },
  88. #end
  89. #end
  90. #end
  91. },
  92. #end
  93. #end
  94. ]
  95. })
  96. export const { allSchemas } = useVxeCrudSchemas(crudSchemas)