template.data.ts 2.4 KB

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