template.data.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
  2. import { dateFormatter } from '@/utils/formatTime'
  3. import { TableColumn } from '@/types/table'
  4. import { DictTag } from '@/components/DictTag'
  5. import * as MailAccountApi from '@/api/system/mail/account'
  6. const accounts = 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. colProps: {
  39. span: 24
  40. },
  41. componentProps: {
  42. valueHtml: '',
  43. height: 200
  44. }
  45. }
  46. },
  47. {
  48. label: '邮箱账号',
  49. field: 'accountId',
  50. width: '200px',
  51. formatter: (_: Recordable, __: TableColumn, cellValue: number) => {
  52. return accounts.find((account) => account.id === cellValue)?.mail
  53. },
  54. search: {
  55. show: true,
  56. component: 'Select',
  57. api: () => accounts,
  58. componentProps: {
  59. optionsAlias: {
  60. labelField: 'mail',
  61. valueField: 'id'
  62. }
  63. }
  64. },
  65. form: {
  66. component: 'Select',
  67. api: () => accounts,
  68. componentProps: {
  69. optionsAlias: {
  70. labelField: 'mail',
  71. valueField: 'id'
  72. }
  73. }
  74. }
  75. },
  76. {
  77. label: '发送人名称',
  78. field: 'nickname'
  79. },
  80. {
  81. label: '开启状态',
  82. field: 'status',
  83. isSearch: true,
  84. formatter: (_: Recordable, __: TableColumn, cellValue: number) => {
  85. return h(DictTag, {
  86. type: DICT_TYPE.COMMON_STATUS,
  87. value: cellValue
  88. })
  89. },
  90. dictType: DICT_TYPE.COMMON_STATUS,
  91. dictClass: 'number'
  92. },
  93. {
  94. label: '备注',
  95. field: 'remark',
  96. isTable: false
  97. },
  98. {
  99. label: '创建时间',
  100. field: 'createTime',
  101. isForm: false,
  102. formatter: dateFormatter,
  103. search: {
  104. show: true,
  105. component: 'DatePicker',
  106. componentProps: {
  107. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  108. type: 'daterange',
  109. defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
  110. }
  111. }
  112. },
  113. {
  114. label: '操作',
  115. field: 'action',
  116. isForm: false
  117. }
  118. ])
  119. export const { allSchemas } = useCrudSchemas(crudSchemas)