Skip to content

Commit 8c42790

Browse files
style: add labelMessage attribute to Form component
1 parent bf83d3e commit 8c42790

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/components/Form/src/Form.vue

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="tsx">
22
import { PropType, defineComponent, ref, computed, unref, watch, onMounted } from 'vue'
3-
import { ElForm, ElFormItem, ElRow, ElCol } from 'element-plus'
3+
import { ElForm, ElFormItem, ElRow, ElCol, ElTooltip } from 'element-plus'
44
import { componentMap } from './componentMap'
55
import { propTypes } from '@/utils/propTypes'
66
import { getSlot } from '@/utils/tsxHelper'
@@ -19,6 +19,7 @@ import { useDesign } from '@/hooks/web/useDesign'
1919
import { findIndex } from '@/utils'
2020
import { set } from 'lodash-es'
2121
import { FormProps } from './types'
22+
import { Icon } from '@/components/Icon'
2223
2324
const { getPrefixCls } = useDesign()
2425
@@ -181,10 +182,35 @@ export default defineComponent({
181182
) {
182183
slotsMap.default = () => renderOptions(item)
183184
}
185+
186+
const formItemSlots: Recordable = setFormItemSlots(slots, item.field)
187+
// 如果有 labelMessage,自动使用插槽渲染
188+
if (item?.labelMessage) {
189+
formItemSlots.label = () => {
190+
return (
191+
<>
192+
<span>{item.label}</span>
193+
<ElTooltip placement="right" raw-content>
194+
{{
195+
content: () => <span v-html={item.labelMessage}></span>,
196+
default: () => (
197+
<Icon
198+
icon="ep:warning"
199+
size={16}
200+
color="var(--el-color-primary)"
201+
class="ml-2px relative top-1px"
202+
></Icon>
203+
)
204+
}}
205+
</ElTooltip>
206+
</>
207+
)
208+
}
209+
}
184210
return (
185211
<ElFormItem {...(item.formItemProps || {})} prop={item.field} label={item.label || ''}>
186212
{{
187-
...setFormItemSlots(slots, item.field),
213+
...formItemSlots,
188214
default: () => {
189215
const Com = componentMap[item.component as string] as ReturnType<
190216
typeof defineComponent

types/componentType/form.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ declare global {
7171
field: string
7272
// 标题
7373
label?: string
74+
// 提示
75+
labelMessage?: string
7476
// col组件属性
7577
colProps?: ColProps
7678
// 表单组件属性,slots对应的是表单组件的插槽,规则:${field}-xxx,具体可以查看element-plus文档

0 commit comments

Comments
 (0)