data.config.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import type {
  2. OnActionClickFn,
  3. VbenFormSchema,
  4. VxeTableGridOptions,
  5. } from '#/adapter';
  6. import type { BasicOptionResult } from '#/api/model';
  7. import type { ParamsApi } from '#/api/shop';
  8. import { h } from 'vue';
  9. import { z } from '#/adapter';
  10. export const paramsTypeOptions: BasicOptionResult[] = [
  11. { label: '文本框', value: 0, color: 'success' },
  12. { label: '复选框', value: 1, color: 'error' },
  13. { label: '单选框', value: 2, color: 'warning' },
  14. ];
  15. export const useSearchSchema = (): VbenFormSchema[] => {
  16. return [
  17. {
  18. component: 'Input',
  19. fieldName: 'name',
  20. label: '名称',
  21. },
  22. {
  23. component: 'Select',
  24. fieldName: 'paramsType',
  25. label: '类型',
  26. componentProps: {
  27. options: paramsTypeOptions,
  28. },
  29. },
  30. ];
  31. };
  32. export function useColumns(
  33. onActionClick?: OnActionClickFn<ParamsApi.RecordItem>,
  34. ): VxeTableGridOptions<ParamsApi.RecordItem>['columns'] {
  35. return [
  36. { title: '序号', type: 'seq', width: 50 },
  37. {
  38. align: 'left',
  39. field: 'name',
  40. title: '名称',
  41. width: 82,
  42. },
  43. {
  44. field: 'paramsType',
  45. title: '类型',
  46. width: 100,
  47. cellRender: { name: 'CellTag', options: paramsTypeOptions },
  48. },
  49. {
  50. align: 'left',
  51. field: 'value',
  52. title: '参数值',
  53. slots: { default: 'value' },
  54. },
  55. {
  56. align: 'right',
  57. cellRender: {
  58. attrs: {
  59. nameField: 'name',
  60. nameTitle: '名称',
  61. onClick: onActionClick,
  62. },
  63. name: 'CellAction',
  64. options: [
  65. {
  66. code: 'edit',
  67. auth: ['params:edit'],
  68. },
  69. {
  70. code: 'delete',
  71. auth: ['params:delete'],
  72. },
  73. ],
  74. },
  75. field: 'operation',
  76. fixed: 'right',
  77. headerAlign: 'center',
  78. showOverflow: false,
  79. title: '操作',
  80. width: 100,
  81. },
  82. ];
  83. }
  84. export const useSchema = (): VbenFormSchema[] => {
  85. return [
  86. {
  87. component: 'Input',
  88. componentProps: {
  89. placeholder: '请输入',
  90. },
  91. fieldName: 'name',
  92. label: '名称',
  93. rules: 'required',
  94. },
  95. {
  96. component: 'Select',
  97. componentProps: {
  98. options: paramsTypeOptions,
  99. },
  100. defaultValue: 0,
  101. fieldName: 'paramsType',
  102. label: '类型',
  103. rules: 'required',
  104. },
  105. {
  106. component: 'Input',
  107. componentProps: {
  108. placeholder: '请输入',
  109. },
  110. fieldName: 'value',
  111. label: '参数值',
  112. dependencies: {
  113. triggerFields: ['paramsType'],
  114. rules(values) {
  115. return [1, 2].includes(values.paramsType)
  116. ? z.string()
  117. : z.string().optional();
  118. },
  119. },
  120. },
  121. {
  122. component: h('div', { class: 'text-sm font-thin' }, [
  123. h(
  124. 'div',
  125. null,
  126. '如果选择的是【单选】或者【复选框】,则多个参数值之间使用小写逗号(,)分隔。',
  127. ),
  128. ]),
  129. formItemClass: 'items-start',
  130. fieldName: 'remark',
  131. label: '说明',
  132. },
  133. ];
  134. };