select.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import uniqueId from '@form-create/utils/lib/unique'
  2. import { localeProps, makeOptionsRule, makeRequiredRule } from '../../utils/formCreateIndex'
  3. const label = '选择器'
  4. const name = 'select'
  5. export default {
  6. icon: 'icon-select',
  7. label,
  8. name,
  9. rule({ t }) {
  10. const opt = t('props.option')
  11. return {
  12. type: name,
  13. field: uniqueId(),
  14. title: t('components.select.name'),
  15. info: '',
  16. effect: {
  17. fetch: ''
  18. },
  19. $required: false,
  20. props: {},
  21. options: [1, 2].map(value => {
  22. return {
  23. label: opt + value,
  24. value
  25. }
  26. })
  27. }
  28. },
  29. watch: {
  30. multiple({ rule }) {
  31. rule.key = uniqueId()
  32. }
  33. },
  34. props(_, { t }) {
  35. return localeProps(t, name + '.props', [
  36. makeRequiredRule(),
  37. makeOptionsRule(t, 'options'),
  38. { type: 'switch', field: 'multiple', title: '是否多选' },
  39. {
  40. type: 'switch',
  41. field: 'disabled',
  42. title: '是否禁用'
  43. },
  44. { type: 'switch', field: 'clearable', title: '是否可以清空选项' },
  45. {
  46. type: 'switch',
  47. field: 'collapseTags',
  48. title: '多选时是否将选中值按文字的形式展示'
  49. },
  50. { type: 'inputNumber', field: 'multipleLimit', title: '多选时用户最多可以选择的项目数,为 0 则不限制', props: { min: 0 } },
  51. {
  52. type: 'input',
  53. field: 'autocomplete',
  54. title: 'autocomplete 属性'
  55. },
  56. { type: 'input', field: 'placeholder', title: '占位符' },
  57. {
  58. type: 'switch',
  59. field: 'filterable',
  60. title: '是否可搜索'
  61. },
  62. { type: 'switch', field: 'allowCreate', title: '是否允许用户创建新条目' },
  63. {
  64. type: 'input',
  65. field: 'noMatchText',
  66. title: '搜索条件无匹配时显示的文字'
  67. },
  68. {
  69. type: 'switch',
  70. field: 'remote',
  71. title: '其中的选项是否从服务器远程加载'
  72. },
  73. {
  74. type: 'Struct',
  75. field: 'remoteMethod',
  76. title: '自定义远程搜索方法'
  77. },
  78. { type: 'input', field: 'noDataText', title: '选项为空时显示的文字' },
  79. {
  80. type: 'switch',
  81. field: 'reserveKeyword',
  82. title: '多选且可搜索时,是否在选中一个选项后保留当前的搜索关键词'
  83. },
  84. { type: 'switch', field: 'defaultFirstOption', title: '在输入框按下回车,选择第一个匹配项' },
  85. {
  86. type: 'switch',
  87. field: 'popperAppendToBody',
  88. title: '是否将弹出框插入至 body 元素',
  89. value: true
  90. },
  91. { type: 'switch', field: 'automaticDropdown', title: '对于不可搜索的 Select,是否在输入框获得焦点后自动弹出选项菜单' }
  92. ])
  93. }
  94. }