diff --git a/src/locales/en.ts b/src/locales/en.ts
index 26a9a02..5d44df3 100644
--- a/src/locales/en.ts
+++ b/src/locales/en.ts
@@ -221,6 +221,7 @@ export default {
position: 'Position',
autocomplete: 'Autocomplete',
select: 'Select',
+ optionSlot: 'Option Slot',
selectGroup: 'Select Group',
selectV2: 'SelectV2',
cascader: 'Cascader',
diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts
index 165e268..6e8e4a5 100644
--- a/src/locales/zh-CN.ts
+++ b/src/locales/zh-CN.ts
@@ -221,6 +221,7 @@ export default {
position: '位置',
autocomplete: '自动补全',
select: '选择器',
+ optionSlot: '选项插槽',
selectGroup: '选项分组',
selectV2: '虚拟列表选择器',
cascader: '级联选择器',
diff --git a/src/types/components.d.ts b/src/types/components.d.ts
index e132fad..7c93506 100644
--- a/src/types/components.d.ts
+++ b/src/types/components.d.ts
@@ -47,8 +47,8 @@ export interface InputComponentProps {
showPassword?: boolean
disabled?: boolean
size?: InputProps['size']
- prefixIcon?: string | JSX.Element | ((item: any, data: any) => string | JSX.Element)
- suffixIcon?: string | JSX.Element | ((item: any, data: any) => string | JSX.Element)
+ prefixIcon?: string | JSX.Element | ((formData: any) => string | JSX.Element)
+ suffixIcon?: string | JSX.Element | ((formData: any) => string | JSX.Element)
type?: InputProps['type']
rows?: number
autosize?: boolean | { Pows?: numer; maxRows?: number }
@@ -73,10 +73,10 @@ export interface InputComponentProps {
input?: (value: string | number) => void
}
slots?: {
- prefix?: JSX.Element | ((item: any, data: any) => JSX.Element)
- suffix?: JSX.Element | ((item: any, data: any) => JSX.Element)
- prepend?: JSX.Element | ((item: any, data: any) => JSX.Element)
- append?: JSX.Element | ((item: any, data: any) => JSX.Element)
+ prefix?: JSX.Element | null | ((formData: any) => JSX.Element | null)
+ suffix?: JSX.Element | null | ((formData: any) => JSX.Element | null)
+ prepend?: JSX.Element | null | ((formData: any) => JSX.Element | null)
+ append?: JSX.Element | null | ((formData: any) => JSX.Element | null)
}
style?: CSSProperties
}
@@ -105,11 +105,11 @@ export interface AutocompleteComponentProps {
change?: (value: string | number) => void
}
slots?: {
- default?: JSX.Element | ((item: any, data: any) => JSX.Element)
- prefix?: JSX.Element | ((item: any, data: any) => JSX.Element)
- suffix?: JSX.Element | ((item: any, data: any) => JSX.Element)
- prepend?: JSX.Element | ((item: any, data: any) => JSX.Element)
- append?: JSX.Element | ((item: any, data: any) => JSX.Element)
+ default?: JSX.Element | null | ((formData: any) => JSX.Element | null)
+ prefix?: JSX.Element | null | ((formData: any) => JSX.Element | null)
+ suffix?: JSX.Element | null | ((formData: any) => JSX.Element | null)
+ prepend?: JSX.Element | null | ((formData: any) => JSX.Element | null)
+ append?: JSX.Element | null | ((formData: any) => JSX.Element | null)
}
style?: CSSProperties
}
@@ -180,9 +180,9 @@ export interface SelectComponentProps {
teleported?: boolean
persistent?: boolean
automaticDropdown?: boolean
- clearIcon?: string | JSX.Element | ((item: any, data: any) => string | JSX.Element)
+ clearIcon?: string | JSX.Element | ((formData: any) => string | JSX.Element)
fitInputWidth?: boolean
- suffixIcon?: string | JSX.Element | ((item: any, data: any) => string | JSX.Element)
+ suffixIcon?: string | JSX.Element | ((formData: any) => string | JSX.Element)
tagType?: 'success' | 'info' | 'warning' | 'danger'
validateEvent?: boolean
placement?:
@@ -213,11 +213,6 @@ export interface SelectComponentProps {
* key别名
*/
keyAlias?: string
-
- /**
- * option是否禁用的统一拦截
- */
- optionDisabled?: (optin: any, data: any) => boolean
on?: {
change?: (value: string | number | boolean | Object) => void
visibleChange?: (visible: boolean) => void
@@ -227,9 +222,11 @@ export interface SelectComponentProps {
focus?: (event: FocusEvent) => void
}
slots?: {
- default?: (item: any) => JSX.Element
- prefix?: JSX.Element | ((item: any, data: any) => JSX.Element)
- empty?: JSX.Element | ((item: any, data: any) => JSX.Element)
+ default?: (options: SelectOption[]) => JSX.Element[] | null
+ optionGroupDefault?: (item: SelectOption) => JSX.Element
+ optionDefault?: (option: SelectOption) => JSX.Element | null
+ prefix?: JSX.Element | null | ((formData: any) => JSX.Element | null)
+ empty?: JSX.Element | null | ((formData: any) => JSX.Element | null)
}
options?: SelectOption[]
style?: CSSProperties
diff --git a/src/views/Components/Form/DefaultForm.vue b/src/views/Components/Form/DefaultForm.vue
index 3902705..503400d 100644
--- a/src/views/Components/Form/DefaultForm.vue
+++ b/src/views/Components/Form/DefaultForm.vue
@@ -6,8 +6,9 @@ import { useIcon } from '@/hooks/web/useIcon'
import { ContentWrap } from '@/components/ContentWrap'
import { useAppStore } from '@/store/modules/app'
import { FormSchema } from '@/types/form'
-import { ComponentOptions } from '@/types/components'
+import { ComponentOptions, SelectOption, SelectComponentProps } from '@/types/components'
import { useForm } from '@/hooks/web/useForm'
+import { ElOption, ElOptionGroup } from 'element-plus'
const appStore = useAppStore()
@@ -393,7 +394,7 @@ const schema = reactive([
component: 'Input',
componentProps: {
slots: {
- suffix: (_, data: any) => {
+ suffix: (data: any) => {
return unref(toggle) && data.field4
? useIcon({ icon: 'ep:calendar' })
: useIcon({ icon: 'ep:share' })
@@ -409,7 +410,7 @@ const schema = reactive([
componentProps: {
slots: {
prepend: useIcon({ icon: 'ep:calendar' }),
- append: (_, data: any) => {
+ append: (data: any) => {
return data.field5 ? useIcon({ icon: 'ep:calendar' }) : useIcon({ icon: 'ep:share' })
}
}
@@ -510,10 +511,6 @@ const schema = reactive([
label: t('formDemo.default'),
component: 'Select',
componentProps: {
- optionDisabled: (item: any, data: any) => {
- console.log(item, data)
- return false
- },
options: [
{
disabled: true,
@@ -543,94 +540,157 @@ const schema = reactive([
}
],
slots: {
- default: (item) => {
- console.log(item)
+ default: (options: SelectOption[]) => {
+ if (options.length) {
+ return options?.map((v) => {
+ return
+ })
+ } else {
+ return null
+ }
+ },
+ prefix: useIcon({ icon: 'ep:calendar' }),
+ empty: (data: any) => {
+ return data.field5 ? useIcon({ icon: 'ep:calendar' }) : useIcon({ icon: 'ep:share' })
+ }
+ }
+ }
+ },
+ {
+ field: 'select-field18',
+ label: t('formDemo.optionSlot'),
+ component: 'Select',
+ componentProps: {
+ options: [
+ {
+ value: 'Beijing',
+ label: 'Beijing'
+ },
+ {
+ value: 'Shanghai',
+ label: 'Shanghai'
+ },
+ {
+ value: 'Nanjing',
+ label: 'Nanjing'
+ },
+ {
+ value: 'Chengdu',
+ label: 'Chengdu'
+ },
+ {
+ value: 'Shenzhen',
+ label: 'Shenzhen'
+ },
+ {
+ value: 'Guangzhou',
+ label: 'Guangzhou'
+ }
+ ],
+ slots: {
+ optionDefault: (option: SelectOption) => {
return (
<>
- {item.label}
-
- {item.value}
+ {option.label}
+
+ {option.value}
>
)
}
}
}
+ },
+ {
+ field: 'field16',
+ label: t('formDemo.selectGroup'),
+ component: 'Select',
+ componentProps: {
+ options: [
+ {
+ label: 'option1',
+ options: [
+ {
+ disabled: true,
+ label: 'option1-1',
+ value: '1-1'
+ },
+ {
+ label: 'option1-2',
+ value: '1-2'
+ }
+ ]
+ },
+ {
+ label: 'option2',
+ options: [
+ {
+ label: 'option2-1',
+ value: '2-1'
+ },
+ {
+ label: 'option2-2',
+ value: '2-2'
+ }
+ ]
+ }
+ ]
+ }
+ },
+ {
+ field: 'field17',
+ label: `${t('formDemo.selectGroup')}${t('formDemo.slot')}`,
+ component: 'Select',
+ componentProps: {
+ options: [
+ {
+ label: 'option1',
+ options: [
+ {
+ label: 'option1-1',
+ value: '1-1'
+ },
+ {
+ label: 'option1-2',
+ value: '1-2'
+ }
+ ]
+ },
+ {
+ label: 'option2',
+ options: [
+ {
+ label: 'option2-1',
+ value: '2-1'
+ },
+ {
+ label: 'option2-2',
+ value: '2-2'
+ }
+ ]
+ }
+ ],
+ slots: {
+ optionGroupDefault: (option: SelectOption) => {
+ return (
+
+ {option?.options?.map((v) => {
+ return (
+
+ )
+ })}
+
+ )
+ }
+ }
+ }
}
// {
- // field: 'field16',
- // label: t('formDemo.selectGroup'),
- // component: 'Select',
- // componentProps: {
- // options: [
- // {
- // label: 'option1',
- // options: [
- // {
- // disabled: true,
- // label: 'option1-1',
- // value: '1-1'
- // },
- // {
- // label: 'option1-2',
- // value: '1-2'
- // }
- // ]
- // },
- // {
- // label: 'option2',
- // options: [
- // {
- // label: 'option2-1',
- // value: '2-1'
- // },
- // {
- // label: 'option2-2',
- // value: '2-2'
- // }
- // ]
- // }
- // ]
- // }
- // },
- // {
- // field: 'field17',
- // label: `${t('formDemo.selectGroup')}${t('formDemo.slot')}`,
- // component: 'Select',
- // componentProps: {
- // options: [
- // {
- // label: 'option1',
- // options: [
- // {
- // label: 'option1-1',
- // value: '1-1',
- // disabled: true
- // },
- // {
- // label: 'option1-2',
- // value: '1-2'
- // }
- // ]
- // },
- // {
- // label: 'option2',
- // options: [
- // {
- // label: 'option2-1',
- // value: '2-1'
- // },
- // {
- // label: 'option2-2',
- // value: '2-2'
- // }
- // ]
- // }
- // ],
- // optionsSlot: true
- // }
- // },
- // {
// field: 'field18',
// label: `${t('formDemo.selectV2')}`,
// component: 'Divider'