wip: Form改造中
This commit is contained in:
parent
deeee73bcb
commit
e34b5cb613
|
@ -25,7 +25,8 @@ import {
|
||||||
ComponentNameEnum,
|
ComponentNameEnum,
|
||||||
SelectComponentProps,
|
SelectComponentProps,
|
||||||
SelectOption,
|
SelectOption,
|
||||||
RadioComponentProps
|
RadioComponentProps,
|
||||||
|
CheckboxComponentProps
|
||||||
} from '@/types/components.d'
|
} from '@/types/components.d'
|
||||||
|
|
||||||
const { renderSelectOptions } = useRenderSelect()
|
const { renderSelectOptions } = useRenderSelect()
|
||||||
|
@ -230,16 +231,17 @@ export default defineComponent({
|
||||||
const { autoSetPlaceholder } = unref(getProps)
|
const { autoSetPlaceholder } = unref(getProps)
|
||||||
|
|
||||||
// 需要特殊处理的组件
|
// 需要特殊处理的组件
|
||||||
const specialComponents = [ComponentNameEnum.RADIO]
|
const specialComponents = [ComponentNameEnum.RADIO, ComponentNameEnum.CHECKBOX]
|
||||||
|
|
||||||
if (specialComponents.findIndex((v) => v === item.component) !== -1) {
|
if (specialComponents.findIndex((v) => v === item.component) !== -1) {
|
||||||
switch (item.component) {
|
const componentProps =
|
||||||
case ComponentNameEnum.RADIO:
|
item.component === ComponentNameEnum.RADIO
|
||||||
const componentProps = item.componentProps as RadioComponentProps
|
? (item.componentProps as RadioComponentProps)
|
||||||
|
: (item.componentProps as CheckboxComponentProps)
|
||||||
|
|
||||||
const valueAlias = componentProps?.props?.value || 'value'
|
const valueAlias = componentProps?.props?.value || 'value'
|
||||||
const labelAlias = componentProps?.props?.label || 'label'
|
const labelAlias = componentProps?.props?.label || 'label'
|
||||||
const disabledAlias = componentProps?.props?.disabled || 'disabled'
|
const disabledAlias = componentProps?.props?.disabled || 'disabled'
|
||||||
|
|
||||||
return componentProps?.options?.map((v) => {
|
return componentProps?.options?.map((v) => {
|
||||||
return (
|
return (
|
||||||
<Com
|
<Com
|
||||||
|
@ -257,7 +259,6 @@ export default defineComponent({
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const componentSlots = (item?.componentProps as any)?.slots || {}
|
const componentSlots = (item?.componentProps as any)?.slots || {}
|
||||||
const slotsMap: Recordable = {
|
const slotsMap: Recordable = {
|
||||||
|
|
|
@ -17,7 +17,8 @@ import {
|
||||||
ElTransfer,
|
ElTransfer,
|
||||||
ElAutocomplete,
|
ElAutocomplete,
|
||||||
ElDivider,
|
ElDivider,
|
||||||
ElRadio
|
ElRadio,
|
||||||
|
ElCheckbox
|
||||||
} from 'element-plus'
|
} from 'element-plus'
|
||||||
import { InputPassword } from '@/components/InputPassword'
|
import { InputPassword } from '@/components/InputPassword'
|
||||||
import { Editor } from '@/components/Editor'
|
import { Editor } from '@/components/Editor'
|
||||||
|
@ -27,7 +28,8 @@ const componentMap: Recordable<Component, ComponentName> = {
|
||||||
Radio: ElRadio,
|
Radio: ElRadio,
|
||||||
RadioGroup: ElRadioGroup,
|
RadioGroup: ElRadioGroup,
|
||||||
RadioButton: ElRadioGroup,
|
RadioButton: ElRadioGroup,
|
||||||
Checkbox: ElCheckboxGroup,
|
Checkbox: ElCheckbox,
|
||||||
|
CheckboxGroup: ElCheckboxGroup,
|
||||||
CheckboxButton: ElCheckboxGroup,
|
CheckboxButton: ElCheckboxGroup,
|
||||||
Input: ElInput,
|
Input: ElInput,
|
||||||
Autocomplete: ElAutocomplete,
|
Autocomplete: ElAutocomplete,
|
||||||
|
|
|
@ -244,6 +244,8 @@ export default {
|
||||||
radioGroup: 'Radio Group',
|
radioGroup: 'Radio Group',
|
||||||
button: 'Button',
|
button: 'Button',
|
||||||
checkbox: 'Checkbox',
|
checkbox: 'Checkbox',
|
||||||
|
checkboxButton: 'Checkbox Button',
|
||||||
|
checkboxGroup: 'Checkbox Group',
|
||||||
slider: 'Slider',
|
slider: 'Slider',
|
||||||
datePicker: 'Date Picker',
|
datePicker: 'Date Picker',
|
||||||
shortcuts: 'Shortcuts',
|
shortcuts: 'Shortcuts',
|
||||||
|
|
|
@ -244,6 +244,8 @@ export default {
|
||||||
radioGroup: '单选框组',
|
radioGroup: '单选框组',
|
||||||
button: '按钮',
|
button: '按钮',
|
||||||
checkbox: '多选框',
|
checkbox: '多选框',
|
||||||
|
checkboxButton: '多选框按钮',
|
||||||
|
checkboxGroup: '多选框组',
|
||||||
slider: '滑块',
|
slider: '滑块',
|
||||||
datePicker: '日期选择器',
|
datePicker: '日期选择器',
|
||||||
shortcuts: '快捷选项',
|
shortcuts: '快捷选项',
|
||||||
|
|
|
@ -14,6 +14,7 @@ export enum ComponentNameEnum {
|
||||||
RADIO_GROUP = 'RadioGroup',
|
RADIO_GROUP = 'RadioGroup',
|
||||||
RADIO_BUTTON = 'RadioButton',
|
RADIO_BUTTON = 'RadioButton',
|
||||||
CHECKBOX = 'Checkbox',
|
CHECKBOX = 'Checkbox',
|
||||||
|
CHECKBOX_GROUP = 'CheckboxGroup',
|
||||||
CHECKBOX_BUTTON = 'CheckboxButton',
|
CHECKBOX_BUTTON = 'CheckboxButton',
|
||||||
INPUT = 'Input',
|
INPUT = 'Input',
|
||||||
AUTOCOMPLETE = 'Autocomplete',
|
AUTOCOMPLETE = 'Autocomplete',
|
||||||
|
@ -432,6 +433,7 @@ export interface RadioOption {
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RadioComponentProps {
|
export interface RadioComponentProps {
|
||||||
value?: string | number | boolean
|
value?: string | number | boolean
|
||||||
label?: string | number | boolean
|
label?: string | number | boolean
|
||||||
|
@ -513,6 +515,50 @@ export interface RadioButtonComponentProps {
|
||||||
style?: CSSProperties
|
style?: CSSProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CheckboxOption {
|
||||||
|
label?: string
|
||||||
|
value?: string | number | boolean
|
||||||
|
disabled?: boolean
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CheckboxComponentProps {
|
||||||
|
value?: string | number | boolean
|
||||||
|
label?: string | number | boolean | any
|
||||||
|
trueLabel?: string | number
|
||||||
|
falseLabel?: string | number
|
||||||
|
disabled?: boolean
|
||||||
|
border?: boolean
|
||||||
|
size?: ElementPlusSize
|
||||||
|
name?: string
|
||||||
|
checked?: boolean
|
||||||
|
indeterminate?: boolean
|
||||||
|
validateEvent?: boolean
|
||||||
|
tabindex?: number | string
|
||||||
|
id?: string
|
||||||
|
controls?: boolean
|
||||||
|
on?: {
|
||||||
|
change?: (value: string | number | boolean) => void
|
||||||
|
}
|
||||||
|
slots?: {
|
||||||
|
default?: (...args: any[]) => JSX.Element | null
|
||||||
|
}
|
||||||
|
options: CheckboxOption[]
|
||||||
|
/**
|
||||||
|
* 数据源的字段别名
|
||||||
|
*/
|
||||||
|
props: {
|
||||||
|
label?: string
|
||||||
|
value?: string
|
||||||
|
disabled?: string
|
||||||
|
}
|
||||||
|
style?: CSSProperties
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CheckboxGroupComponentProps {
|
||||||
|
value?: string[] | number[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface ColProps {
|
export interface ColProps {
|
||||||
span?: number
|
span?: number
|
||||||
xs?: number
|
xs?: number
|
||||||
|
|
|
@ -15,7 +15,8 @@ import {
|
||||||
TransferComponentProps,
|
TransferComponentProps,
|
||||||
RadioComponentProps,
|
RadioComponentProps,
|
||||||
RadioGroupComponentProps,
|
RadioGroupComponentProps,
|
||||||
RadioButtonComponentProps
|
RadioButtonComponentProps,
|
||||||
|
CheckboxComponentProps
|
||||||
} from '@/types/components'
|
} from '@/types/components'
|
||||||
import { FormValueType, FormValueType } from '@/types/form'
|
import { FormValueType, FormValueType } from '@/types/form'
|
||||||
import type { AxiosPromise } from 'axios'
|
import type { AxiosPromise } from 'axios'
|
||||||
|
@ -76,6 +77,7 @@ export interface FormSchema {
|
||||||
| RadioComponentProps
|
| RadioComponentProps
|
||||||
| RadioGroupComponentProps
|
| RadioGroupComponentProps
|
||||||
| RadioButtonComponentProps
|
| RadioButtonComponentProps
|
||||||
|
| CheckboxComponentProps
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* formItem组件属性,具体可以查看element-plus文档
|
* formItem组件属性,具体可以查看element-plus文档
|
||||||
|
|
|
@ -1048,7 +1048,7 @@ const schema = reactive<FormSchema[]>([
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'field40',
|
field: 'field40-1',
|
||||||
label: `${t('formDemo.button')} ${t('formDemo.slot')}`,
|
label: `${t('formDemo.button')} ${t('formDemo.slot')}`,
|
||||||
component: 'RadioButton',
|
component: 'RadioButton',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
|
@ -1079,16 +1079,68 @@ const schema = reactive<FormSchema[]>([
|
||||||
field: 'field41',
|
field: 'field41',
|
||||||
label: t('formDemo.checkbox'),
|
label: t('formDemo.checkbox'),
|
||||||
component: 'Divider'
|
component: 'Divider'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'field42',
|
||||||
|
label: t('formDemo.default'),
|
||||||
|
component: 'Checkbox',
|
||||||
|
componentProps: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
disabled: true,
|
||||||
|
label: 'option-1',
|
||||||
|
value: '1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'option-2',
|
||||||
|
value: '2'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'option-3',
|
||||||
|
value: '3'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'field42-1',
|
||||||
|
label: t('formDemo.slot'),
|
||||||
|
component: 'Checkbox',
|
||||||
|
componentProps: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'option-1',
|
||||||
|
value: '1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'option-2',
|
||||||
|
value: '2'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'option-3',
|
||||||
|
value: '3'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
slots: {
|
||||||
|
default: ({ option }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<span>{option.label}</span>
|
||||||
|
<span> ({option.value}) </span>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// {
|
// {
|
||||||
// field: 'field42',
|
// field: 'field42-2',
|
||||||
// label: t('formDemo.default'),
|
// label: t('formDemo.checkboxGroup'),
|
||||||
// component: 'Checkbox',
|
// component: 'CheckboxGroup',
|
||||||
// value: [],
|
// value: [],
|
||||||
// componentProps: {
|
// componentProps: {
|
||||||
// options: [
|
// options: [
|
||||||
// {
|
// {
|
||||||
// disabled: true,
|
|
||||||
// label: 'option-1',
|
// label: 'option-1',
|
||||||
// value: '1'
|
// value: '1'
|
||||||
// },
|
// },
|
||||||
|
@ -1098,11 +1150,11 @@ const schema = reactive<FormSchema[]>([
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// label: 'option-3',
|
// label: 'option-3',
|
||||||
// value: '23'
|
// value: '3'
|
||||||
// }
|
// }
|
||||||
// ]
|
// ]
|
||||||
// }
|
// }
|
||||||
// },
|
// }
|
||||||
// {
|
// {
|
||||||
// field: 'field43',
|
// field: 'field43',
|
||||||
// label: t('formDemo.button'),
|
// label: t('formDemo.button'),
|
||||||
|
|
Loading…
Reference in New Issue