wip: Form升级中
This commit is contained in:
parent
28d1654b20
commit
89844e441d
|
@ -174,7 +174,7 @@ export default defineComponent({
|
||||||
// 单独给只有options属性的组件做判断
|
// 单独给只有options属性的组件做判断
|
||||||
const notRenderOptions = ['SelectV2', 'Cascader', 'Transfer']
|
const notRenderOptions = ['SelectV2', 'Cascader', 'Transfer']
|
||||||
const slotsMap: Recordable = {
|
const slotsMap: Recordable = {
|
||||||
...setItemComponentSlots(slots, item?.componentProps?.slots, item.field)
|
...setItemComponentSlots(unref(formModel), item?.componentProps?.slots)
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
item?.component !== 'SelectV2' &&
|
item?.component !== 'SelectV2' &&
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { getSlot } from '@/utils/tsxHelper'
|
||||||
import { PlaceholderMoel } from './types'
|
import { PlaceholderMoel } from './types'
|
||||||
import { FormSchema } from '@/types/form'
|
import { FormSchema } from '@/types/form'
|
||||||
import { ColProps } from '@/types/components'
|
import { ColProps } from '@/types/components'
|
||||||
|
import { isFunction } from '@/utils/is'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
@ -84,21 +85,21 @@ export const setComponentProps = (item: FormSchema): Recordable => {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param slots 插槽
|
* @param formModel 表单数据
|
||||||
* @param slotsProps 插槽属性
|
* @param slotsProps 插槽属性
|
||||||
* @param field 字段名
|
|
||||||
*/
|
*/
|
||||||
export const setItemComponentSlots = (
|
export const setItemComponentSlots = (formModel: any, slotsProps: Recordable = {}): Recordable => {
|
||||||
slots: Slots,
|
|
||||||
slotsProps: Recordable = {},
|
|
||||||
field: string
|
|
||||||
): Recordable => {
|
|
||||||
const slotObj: Recordable = {}
|
const slotObj: Recordable = {}
|
||||||
for (const key in slotsProps) {
|
for (const key in slotsProps) {
|
||||||
if (slotsProps[key]) {
|
if (slotsProps[key]) {
|
||||||
// 由于组件有可能重复,需要有一个唯一的前缀
|
if (isFunction(slotsProps[key])) {
|
||||||
slotObj[key] = (data: Recordable) => {
|
slotObj[key] = () => {
|
||||||
return getSlot(slots, `${field}-${key}`, data)
|
return slotsProps[key]?.(formModel)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slotObj[key] = () => {
|
||||||
|
return slotsProps[key]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ export interface InputComponentProps {
|
||||||
size?: InputProps['size']
|
size?: InputProps['size']
|
||||||
prefixIcon?: string | JSX.Element | (<T>(data: T | any) => string | JSX.Element)
|
prefixIcon?: string | JSX.Element | (<T>(data: T | any) => string | JSX.Element)
|
||||||
suffixIcon?: string | JSX.Element | (<T>(data: T | any) => string | JSX.Element)
|
suffixIcon?: string | JSX.Element | (<T>(data: T | any) => string | JSX.Element)
|
||||||
|
type?: InputProps['type']
|
||||||
rows?: number
|
rows?: number
|
||||||
autosize?: boolean | { Pows?: numer; maxRows?: number }
|
autosize?: boolean | { Pows?: numer; maxRows?: number }
|
||||||
autocomplete?: string
|
autocomplete?: string
|
||||||
|
|
|
@ -378,34 +378,38 @@ const schema = reactive<FormSchema[]>([
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
slots: {
|
slots: {
|
||||||
suffix: () => {
|
suffix: (data: any) => {
|
||||||
return unref(toggle) ? useIcon({ icon: 'ep:calendar' }) : useIcon({ icon: 'ep:share' })
|
return unref(toggle) && data.field4
|
||||||
|
? useIcon({ icon: 'ep:calendar' })
|
||||||
|
: useIcon({ icon: 'ep:share' })
|
||||||
},
|
},
|
||||||
prefix: useIcon({ icon: 'ep:calendar' })
|
prefix: useIcon({ icon: 'ep:calendar' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'field5',
|
||||||
|
label: t('formDemo.mixed'),
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
slots: {
|
||||||
|
prepend: useIcon({ icon: 'ep:calendar' }),
|
||||||
|
append: (data: any) => {
|
||||||
|
return data.field5 ? useIcon({ icon: 'ep:calendar' }) : useIcon({ icon: 'ep:share' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'field6',
|
||||||
|
label: t('formDemo.textarea'),
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
type: 'textarea',
|
||||||
|
rows: 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// {
|
// {
|
||||||
// field: 'field5',
|
|
||||||
// label: t('formDemo.mixed'),
|
|
||||||
// component: 'Input',
|
|
||||||
// componentProps: {
|
|
||||||
// slots: {
|
|
||||||
// prepend: true,
|
|
||||||
// append: true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'field6',
|
|
||||||
// label: t('formDemo.textarea'),
|
|
||||||
// component: 'Input',
|
|
||||||
// componentProps: {
|
|
||||||
// type: 'textarea',
|
|
||||||
// rows: 1
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'field7',
|
// field: 'field7',
|
||||||
// label: t('formDemo.autocomplete'),
|
// label: t('formDemo.autocomplete'),
|
||||||
// component: 'Divider'
|
// component: 'Divider'
|
||||||
|
|
Loading…
Reference in New Issue