|
@@ -1,10 +1,11 @@
|
|
<script lang="tsx">
|
|
<script lang="tsx">
|
|
import { PropType, defineComponent, ref, computed, unref } from 'vue'
|
|
import { PropType, defineComponent, ref, computed, unref } from 'vue'
|
|
-import { ElForm, ElFormItem, ElRow, ElCol, ElOption, ElOptionGroup } from 'element-plus'
|
|
|
|
|
|
+import { ElForm, ElFormItem, ElRow, ElCol } from 'element-plus'
|
|
import { componentMap } from './componentMap'
|
|
import { componentMap } from './componentMap'
|
|
import { propTypes } from '@/utils/propTypes'
|
|
import { propTypes } from '@/utils/propTypes'
|
|
import { getSlot } from '@/utils/tsxHelper'
|
|
import { getSlot } from '@/utils/tsxHelper'
|
|
import { setTextPlaceholder, setGridProp, setComponentProps, setItemComponentSlots } from './helper'
|
|
import { setTextPlaceholder, setGridProp, setComponentProps, setItemComponentSlots } from './helper'
|
|
|
|
+import { useRenderSelect } from './components/useRenderSelect'
|
|
|
|
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
name: 'VForm',
|
|
name: 'VForm',
|
|
@@ -74,9 +75,12 @@ export default defineComponent({
|
|
<Com
|
|
<Com
|
|
{...(autoSetPlaceholder && setTextPlaceholder(item))}
|
|
{...(autoSetPlaceholder && setTextPlaceholder(item))}
|
|
{...setComponentProps(item.componentProps)}
|
|
{...setComponentProps(item.componentProps)}
|
|
|
|
+ // 单独给SelectV2做判断
|
|
|
|
+ options={item.component === 'SelectV2' ? item.options || [] : undefined}
|
|
>
|
|
>
|
|
{{
|
|
{{
|
|
- default: () => (item.options ? renderOptions(item) : null),
|
|
|
|
|
|
+ default: () =>
|
|
|
|
+ item.options && item.component !== 'SelectV2' ? renderOptions(item) : undefined,
|
|
...setItemComponentSlots(slots, item?.componentProps?.slots, item.field)
|
|
...setItemComponentSlots(slots, item?.componentProps?.slots, item.field)
|
|
}}
|
|
}}
|
|
</Com>
|
|
</Com>
|
|
@@ -90,52 +94,13 @@ export default defineComponent({
|
|
function renderOptions(item: VFormSchema) {
|
|
function renderOptions(item: VFormSchema) {
|
|
switch (item.component) {
|
|
switch (item.component) {
|
|
case 'Select':
|
|
case 'Select':
|
|
|
|
+ const { renderSelectOptions } = useRenderSelect(slots)
|
|
return renderSelectOptions(item)
|
|
return renderSelectOptions(item)
|
|
default:
|
|
default:
|
|
break
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // 渲染 select options
|
|
|
|
- function renderSelectOptions(item: VFormSchema) {
|
|
|
|
- // 如果有别名,就取别名
|
|
|
|
- const labelAlias = item.optionsField?.labelField
|
|
|
|
- return item.options?.map((option) => {
|
|
|
|
- if (option?.options?.length) {
|
|
|
|
- return (
|
|
|
|
- <ElOptionGroup label={labelAlias ? option[labelAlias] : option['label']}>
|
|
|
|
- {() => {
|
|
|
|
- return option?.options?.map((v) => {
|
|
|
|
- return renderSelectOptionItem(item, v)
|
|
|
|
- })
|
|
|
|
- }}
|
|
|
|
- </ElOptionGroup>
|
|
|
|
- )
|
|
|
|
- } else {
|
|
|
|
- return renderSelectOptionItem(item, option)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 渲染 select option item
|
|
|
|
- function renderSelectOptionItem(item: VFormSchema, option: FormOptions) {
|
|
|
|
- // 如果有别名,就取别名
|
|
|
|
- const labelAlias = item.optionsField?.labelField
|
|
|
|
- const valueAlias = item.optionsField?.valueField
|
|
|
|
- return (
|
|
|
|
- <ElOption
|
|
|
|
- label={labelAlias ? option[labelAlias] : option['label']}
|
|
|
|
- value={valueAlias ? option[valueAlias] : option['value']}
|
|
|
|
- >
|
|
|
|
- {{
|
|
|
|
- default: () =>
|
|
|
|
- // option 插槽名规则,{field}-option
|
|
|
|
- item.optionsSlot ? getSlot(slots, `${item.field}-option`, option) : null
|
|
|
|
- }}
|
|
|
|
- </ElOption>
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// 过滤传入Form组件的属性
|
|
// 过滤传入Form组件的属性
|
|
function getFormBindValue() {
|
|
function getFormBindValue() {
|
|
// 避免在标签上出现多余的属性
|
|
// 避免在标签上出现多余的属性
|