style: add labelMessage attribute to Form component
This commit is contained in:
parent
bf83d3efba
commit
8c42790784
|
@ -1,6 +1,6 @@
|
||||||
<script lang="tsx">
|
<script lang="tsx">
|
||||||
import { PropType, defineComponent, ref, computed, unref, watch, onMounted } from 'vue'
|
import { PropType, defineComponent, ref, computed, unref, watch, onMounted } from 'vue'
|
||||||
import { ElForm, ElFormItem, ElRow, ElCol } from 'element-plus'
|
import { ElForm, ElFormItem, ElRow, ElCol, ElTooltip } 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'
|
||||||
|
@ -19,6 +19,7 @@ import { useDesign } from '@/hooks/web/useDesign'
|
||||||
import { findIndex } from '@/utils'
|
import { findIndex } from '@/utils'
|
||||||
import { set } from 'lodash-es'
|
import { set } from 'lodash-es'
|
||||||
import { FormProps } from './types'
|
import { FormProps } from './types'
|
||||||
|
import { Icon } from '@/components/Icon'
|
||||||
|
|
||||||
const { getPrefixCls } = useDesign()
|
const { getPrefixCls } = useDesign()
|
||||||
|
|
||||||
|
@ -181,10 +182,35 @@ export default defineComponent({
|
||||||
) {
|
) {
|
||||||
slotsMap.default = () => renderOptions(item)
|
slotsMap.default = () => renderOptions(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formItemSlots: Recordable = setFormItemSlots(slots, item.field)
|
||||||
|
// 如果有 labelMessage,自动使用插槽渲染
|
||||||
|
if (item?.labelMessage) {
|
||||||
|
formItemSlots.label = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<span>{item.label}</span>
|
||||||
|
<ElTooltip placement="right" raw-content>
|
||||||
|
{{
|
||||||
|
content: () => <span v-html={item.labelMessage}></span>,
|
||||||
|
default: () => (
|
||||||
|
<Icon
|
||||||
|
icon="ep:warning"
|
||||||
|
size={16}
|
||||||
|
color="var(--el-color-primary)"
|
||||||
|
class="ml-2px relative top-1px"
|
||||||
|
></Icon>
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
</ElTooltip>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<ElFormItem {...(item.formItemProps || {})} prop={item.field} label={item.label || ''}>
|
<ElFormItem {...(item.formItemProps || {})} prop={item.field} label={item.label || ''}>
|
||||||
{{
|
{{
|
||||||
...setFormItemSlots(slots, item.field),
|
...formItemSlots,
|
||||||
default: () => {
|
default: () => {
|
||||||
const Com = componentMap[item.component as string] as ReturnType<
|
const Com = componentMap[item.component as string] as ReturnType<
|
||||||
typeof defineComponent
|
typeof defineComponent
|
||||||
|
|
|
@ -71,6 +71,8 @@ declare global {
|
||||||
field: string
|
field: string
|
||||||
// 标题
|
// 标题
|
||||||
label?: string
|
label?: string
|
||||||
|
// 提示
|
||||||
|
labelMessage?: string
|
||||||
// col组件属性
|
// col组件属性
|
||||||
colProps?: ColProps
|
colProps?: ColProps
|
||||||
// 表单组件属性,slots对应的是表单组件的插槽,规则:${field}-xxx,具体可以查看element-plus文档
|
// 表单组件属性,slots对应的是表单组件的插槽,规则:${field}-xxx,具体可以查看element-plus文档
|
||||||
|
|
Loading…
Reference in New Issue