template.data.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
  2. import { dateFormatter } from '@/utils/formatTime'
  3. import { TableColumn } from '@/types/table'
  4. import * as MailAccountApi from '@/api/system/mail/account'
  5. const accounts = await MailAccountApi.getSimpleMailAccountList()
  6. // 表单校验
  7. export const rules = reactive({
  8. name: [required],
  9. code: [required],
  10. accountId: [required],
  11. label: [required],
  12. content: [required],
  13. params: [required],
  14. status: [required]
  15. })
  16. // CrudSchema:https://kailong110120130.gitee.io/vue-element-plus-admin-doc/hooks/useCrudSchemas.html
  17. const crudSchemas = reactive<CrudSchema[]>([
  18. {
  19. label: '模板编码',
  20. field: 'code',
  21. isSearch: true
  22. },
  23. {
  24. label: '模板名称',
  25. field: 'name',
  26. isSearch: true
  27. },
  28. {
  29. label: '模板标题',
  30. field: 'title'
  31. },
  32. {
  33. label: '模板内容',
  34. field: 'content',
  35. form: {
  36. component: 'Editor',
  37. componentProps: {
  38. valueHtml: '',
  39. height: 200
  40. }
  41. }
  42. },
  43. {
  44. label: '邮箱账号',
  45. field: 'accountId',
  46. width: '200px',
  47. formatter: (_: Recordable, __: TableColumn, cellValue: number) => {
  48. return accounts.find((account) => account.id === cellValue)?.mail
  49. },
  50. search: {
  51. show: true,
  52. component: 'Select',
  53. api: () => accounts,
  54. componentProps: {
  55. optionsAlias: {
  56. labelField: 'mail',
  57. valueField: 'id'
  58. }
  59. }
  60. },
  61. form: {
  62. component: 'Select',
  63. api: () => accounts,
  64. componentProps: {
  65. optionsAlias: {
  66. labelField: 'mail',
  67. valueField: 'id'
  68. }
  69. }
  70. }
  71. },
  72. {
  73. label: '发送人名称',
  74. field: 'nickname'
  75. },
  76. {
  77. label: '开启状态',
  78. field: 'status',
  79. isSearch: true,
  80. dictType: DICT_TYPE.COMMON_STATUS,
  81. dictClass: 'number'
  82. },
  83. {
  84. label: '备注',
  85. field: 'remark',
  86. isTable: false
  87. },
  88. {
  89. label: '创建时间',
  90. field: 'createTime',
  91. isForm: false,
  92. formatter: dateFormatter,
  93. search: {
  94. show: true,
  95. component: 'DatePicker',
  96. componentProps: {
  97. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  98. type: 'daterange',
  99. defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
  100. }
  101. }
  102. },
  103. {
  104. label: '操作',
  105. field: 'action',
  106. isForm: false
  107. }
  108. ])
  109. export const { allSchemas } = useCrudSchemas(crudSchemas)