refactor: ♻️ 增删改查的示例中状态更改为switch组件

增删改查的示例中状态更改为switch组件

closed #I9QEFC
This commit is contained in:
胡少翔
2024-08-02 10:51:19 +08:00
parent 0e85cb2dd5
commit af34b28016
4 changed files with 53 additions and 12 deletions

View File

@@ -66,6 +66,14 @@
</template> </template>
</el-radio-group> </el-radio-group>
</template> </template>
<!-- switch 开关 -->
<template v-else-if="item.type === 'switch'">
<el-switch
inline-prompt
v-model="formData[item.prop]"
v-bind="item.attrs"
/>
</template>
<!-- Checkbox 多选框 --> <!-- Checkbox 多选框 -->
<template v-else-if="item.type === 'checkbox'"> <template v-else-if="item.type === 'checkbox'">
<el-checkbox-group <el-checkbox-group
@@ -209,6 +217,14 @@
</template> </template>
</el-radio-group> </el-radio-group>
</template> </template>
<!-- switch 开关 -->
<template v-else-if="item.type === 'switch'">
<el-switch
inline-prompt
v-model="formData[item.prop]"
v-bind="item.attrs"
/>
</template>
<!-- Checkbox 多选框 --> <!-- Checkbox 多选框 -->
<template v-else-if="item.type === 'checkbox'"> <template v-else-if="item.type === 'checkbox'">
<el-checkbox-group <el-checkbox-group
@@ -334,7 +350,7 @@ prepareFuncs.forEach((func) => func());
// 获取表单数据 // 获取表单数据
function getFormData(key?: string) { function getFormData(key?: string) {
return key === undefined ? formData : formData[key] ?? undefined; return key === undefined ? formData : (formData[key] ?? undefined);
} }
// 设置表单值 // 设置表单值

View File

@@ -220,6 +220,7 @@ export type IFormItems<T = any> = Array<{
| "input" | "input"
| "select" | "select"
| "radio" | "radio"
| "switch"
| "checkbox" | "checkbox"
| "tree-select" | "tree-select"
| "date-picker" | "date-picker"

View File

@@ -103,14 +103,26 @@ const modalConfig: IModalConfig<UserForm> = {
maxlength: 50, maxlength: 50,
}, },
}, },
// {
// label: "状态",
// prop: "status",
// type: "radio",
// options: [
// { label: "正常", value: 1 },
// { label: "禁用", value: 0 },
// ],
// initialValue: 1,
// },
{ {
label: "状态", label: "状态",
prop: "status", prop: "status",
type: "radio", type: "switch",
options: [ attrs: {
{ label: "正常", value: 1 }, activeText: "正常",
{ label: "禁用", value: 0 }, inactiveText: "禁用",
], activeValue: 1,
inactiveValue: 0,
},
initialValue: 1, initialValue: 1,
}, },
], ],

View File

@@ -107,14 +107,26 @@ const modalConfig: IModalConfig<UserForm> = {
maxlength: 50, maxlength: 50,
}, },
}, },
// {
// label: "状态",
// prop: "status",
// type: "radio",
// options: [
// { label: "正常", value: 1 },
// { label: "禁用", value: 0 },
// ],
// initialValue: 1,
// },
{ {
label: "状态", label: "状态123",
prop: "status", prop: "status",
type: "radio", type: "switch",
options: [ attrs: {
{ label: "正常", value: 1 }, activeText: "正常",
{ label: "禁用", value: 0 }, inactiveText: "禁用",
], activeValue: 1,
inactiveValue: 0,
},
}, },
], ],
}; };