wip: Form升级中

This commit is contained in:
kailong321200875 2023-04-27 09:42:22 +08:00
parent 28d1654b20
commit 89844e441d
4 changed files with 39 additions and 33 deletions

View File

@ -174,7 +174,7 @@ export default defineComponent({
// options
const notRenderOptions = ['SelectV2', 'Cascader', 'Transfer']
const slotsMap: Recordable = {
...setItemComponentSlots(slots, item?.componentProps?.slots, item.field)
...setItemComponentSlots(unref(formModel), item?.componentProps?.slots)
}
if (
item?.component !== 'SelectV2' &&

View File

@ -4,6 +4,7 @@ import { getSlot } from '@/utils/tsxHelper'
import { PlaceholderMoel } from './types'
import { FormSchema } from '@/types/form'
import { ColProps } from '@/types/components'
import { isFunction } from '@/utils/is'
const { t } = useI18n()
@ -84,21 +85,21 @@ export const setComponentProps = (item: FormSchema): Recordable => {
/**
*
* @param slots
* @param formModel
* @param slotsProps
* @param field
*/
export const setItemComponentSlots = (
slots: Slots,
slotsProps: Recordable = {},
field: string
): Recordable => {
export const setItemComponentSlots = (formModel: any, slotsProps: Recordable = {}): Recordable => {
const slotObj: Recordable = {}
for (const key in slotsProps) {
if (slotsProps[key]) {
// 由于组件有可能重复,需要有一个唯一的前缀
slotObj[key] = (data: Recordable) => {
return getSlot(slots, `${field}-${key}`, data)
if (isFunction(slotsProps[key])) {
slotObj[key] = () => {
return slotsProps[key]?.(formModel)
}
} else {
slotObj[key] = () => {
return slotsProps[key]
}
}
}
}

View File

@ -39,6 +39,7 @@ export interface InputComponentProps {
size?: InputProps['size']
prefixIcon?: 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
autosize?: boolean | { Pows?: numer; maxRows?: number }
autocomplete?: string

View File

@ -378,34 +378,38 @@ const schema = reactive<FormSchema[]>([
component: 'Input',
componentProps: {
slots: {
suffix: () => {
return unref(toggle) ? useIcon({ icon: 'ep:calendar' }) : useIcon({ icon: 'ep:share' })
suffix: (data: any) => {
return unref(toggle) && data.field4
? useIcon({ icon: 'ep:calendar' })
: useIcon({ icon: 'ep:share' })
},
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',
// label: t('formDemo.autocomplete'),
// component: 'Divider'