useDictSelectRule.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { generateUUID } from '@/utils'
  2. import * as DictDataApi from '@/api/system/dict/dict.type'
  3. import { localeProps, makeRequiredRule } from '@/components/FormCreate/src/utils'
  4. export const useDictSelectRule = () => {
  5. const label = '字典选择器'
  6. const name = 'DictSelect'
  7. const dictOptions = ref<{ label: string; value: string }[]>([]) // 字典类型下拉数据
  8. onMounted(async () => {
  9. const data = await DictDataApi.getSimpleDictTypeList()
  10. if (!data || data.length === 0) {
  11. return
  12. }
  13. dictOptions.value =
  14. data?.map((item: DictDataApi.DictTypeVO) => ({
  15. label: item.name,
  16. value: item.type
  17. })) ?? []
  18. })
  19. return {
  20. icon: 'icon-select',
  21. label,
  22. name,
  23. rule() {
  24. return {
  25. type: name,
  26. field: generateUUID(),
  27. title: label,
  28. info: '',
  29. $required: false
  30. }
  31. },
  32. props(_, { t }) {
  33. return localeProps(t, name + '.props', [
  34. makeRequiredRule(),
  35. {
  36. type: 'select',
  37. field: 'dictType',
  38. title: '字典类型',
  39. value: '',
  40. options: dictOptions.value
  41. },
  42. {
  43. type: 'select',
  44. field: 'valueType',
  45. title: '字典值类型',
  46. value: 'str',
  47. options: [
  48. { label: '数字', value: 'int' },
  49. { label: '字符串', value: 'str' },
  50. { label: '布尔值', value: 'bool' }
  51. ]
  52. },
  53. { type: 'switch', field: 'multiple', title: '是否多选' },
  54. {
  55. type: 'switch',
  56. field: 'disabled',
  57. title: '是否禁用'
  58. },
  59. { type: 'switch', field: 'clearable', title: '是否可以清空选项' },
  60. {
  61. type: 'switch',
  62. field: 'collapseTags',
  63. title: '多选时是否将选中值按文字的形式展示'
  64. },
  65. {
  66. type: 'inputNumber',
  67. field: 'multipleLimit',
  68. title: '多选时用户最多可以选择的项目数,为 0 则不限制',
  69. props: { min: 0 }
  70. },
  71. {
  72. type: 'input',
  73. field: 'autocomplete',
  74. title: 'autocomplete 属性'
  75. },
  76. { type: 'input', field: 'placeholder', title: '占位符' },
  77. {
  78. type: 'switch',
  79. field: 'filterable',
  80. title: '是否可搜索'
  81. },
  82. { type: 'switch', field: 'allowCreate', title: '是否允许用户创建新条目' },
  83. {
  84. type: 'input',
  85. field: 'noMatchText',
  86. title: '搜索条件无匹配时显示的文字'
  87. },
  88. {
  89. type: 'switch',
  90. field: 'remote',
  91. title: '其中的选项是否从服务器远程加载'
  92. },
  93. {
  94. type: 'Struct',
  95. field: 'remoteMethod',
  96. title: '自定义远程搜索方法'
  97. },
  98. { type: 'input', field: 'noDataText', title: '选项为空时显示的文字' },
  99. {
  100. type: 'switch',
  101. field: 'reserveKeyword',
  102. title: '多选且可搜索时,是否在选中一个选项后保留当前的搜索关键词'
  103. },
  104. {
  105. type: 'switch',
  106. field: 'defaultFirstOption',
  107. title: '在输入框按下回车,选择第一个匹配项'
  108. },
  109. {
  110. type: 'switch',
  111. field: 'popperAppendToBody',
  112. title: '是否将弹出框插入至 body 元素',
  113. value: true
  114. },
  115. {
  116. type: 'switch',
  117. field: 'automaticDropdown',
  118. title: '对于不可搜索的 Select,是否在输入框获得焦点后自动弹出选项菜单'
  119. }
  120. ])
  121. }
  122. }
  123. }