弹出框业务组件
基础用法
基础用法
根据配置生成弹出框弹出框
<template>
<div>
<a-button @click="open">打开</a-button>
<su-modal
class="vp-raw"
ref="modalRef"
:formParam="formParam"
:formList="formList"
:title="modal.title"
:visible="modal.show"
:edit="modal.edit"
@cancel="handleCancel"
@submit="handleSubmit"
></su-modal>
</div>
</template>
<script setup lang="ts">
import { reactive } from 'vue'
const modal = reactive({
title: '弹出框',
show: false,
edit: true,
})
const handleCancel = () => {
modal.show = false;
};
const handleSubmit = () => {
modal.show = false;
};
let formList:any = reactive([
{
name: 'input',
key: 'input',
title: '用户名',
labelCol: {span:4}
},
])
let formParam: any = reactive({});
// 初始化数据
const initSearch = () => {
formList.forEach((item: any) => {
formParam[item.key] = item.value || '';
});
};
const open = () => {
modal.show = true
initSearch()
}
</script>
仅查看
查看数据不进行编辑
仅查看
<template>
<div>
<a-button @click="open">打开</a-button>
<su-modal
class="vp-raw"
ref="modalRef"
:formParam="formParam"
:formList="formList"
:title="modal.title"
:visible="modal.show"
:edit="modal.edit"
@cancel="handleCancel"
@submit="handleSubmit"
></su-modal>
</div>
</template>
<script setup lang="ts">
import { reactive } from 'vue'
const modal = reactive({
title: '弹出框',
show: false,
edit: false,
})
const handleCancel = () => {
modal.show = false;
};
const handleSubmit = () => {
modal.show = false;
};
let formList: any = reactive([
{
name: 'input',
key: 'input',
title: '用户名',
labelCol: {span:4},
value: '张三'
},
])
let formParam: any = reactive({});
// 初始化数据
const initSearch = () => {
formList.forEach((item: any) => {
formParam[item.key] = item.value || '';
});
};
const open = () => {
modal.show = true
initSearch()
}
</script>
动态配置弹出框
动态配置弹出框
动态修改弹出框
<template>
<div>
<a-button @click="open">打开</a-button>
<su-modal
class="vp-raw"
ref="modalRef"
:formParam="formParam"
:formList="formList"
:title="modal.title"
:visible="modal.show"
:edit="modal.edit"
@cancel="handleCancel"
@submit="handleSubmit"
>
<template #add>
<a-button @click="addItem">添加</a-button>
</template>
</su-modal>
</div>
</template>
<script setup lang="ts">
import { reactive,ref } from 'vue'
const modal = reactive({
title: '弹出框',
show: false,
edit: true,
})
const handleCancel = () => {
modal.show = false;
};
const handleSubmit = () => {
console.log(formParam)
modal.show = false;
};
let formList:any = reactive([
{
name: 'slot',
slotName: 'add',
key: 'add',
title: '添加',
labelCol: {span:4}
},
{
name: 'input',
key: 'input',
title: '用户名',
labelCol: {span:4}
},
])
let formParam: any = reactive({});
// 初始化数据
const initSearch = () => {
formList.forEach((item: any) => {
formParam[item.key] = item.value || '';
});
};
const open = () => {
modal.show = true
initSearch()
}
let modalRef = ref()
const addItem = () => {
formList.push({
name: 'input',
key: 'input' + (Math.random() * 100).toFixed(0),
title: '用户名',
labelCol: {span:4}
})
initSearch()
modalRef.value.updateForm()
}
</script>
弹出框赋值
弹出框赋值
弹出框赋值
<template>
<div>
<a-button @click="open">打开</a-button>
<su-modal
class="vp-raw"
ref="modalRefSetData"
:formParam="formParam"
:formList="formList"
:title="modal.title"
:visible="modal.show"
:edit="modal.edit"
@cancel="handleCancel"
@submit="handleSubmit"
>
<template #add>
<a-button @click="changeValue">随机值</a-button>
</template>
</su-modal>
</div>
</template>
<script setup lang="ts">
import { reactive,ref } from 'vue'
const modal = reactive({
title: '弹出框',
show: false,
edit: true,
})
const handleCancel = () => {
modal.show = false;
};
const handleSubmit = () => {
console.log(formParam)
modal.show = false;
};
let formList:any = reactive([
{
name: 'slot',
slotName: 'add',
key: 'add',
title: '修改',
value: '',
labelCol: {span:4}
},
{
name: 'input',
key: 'input',
title: '用户名',
value: '',
labelCol: {span:4}
},
])
let formParam: any = reactive({});
// 初始化数据
const initSearch = () => {
formList.forEach((item: any) => {
formParam[item.key] = item.value || '';
});
};
const open = () => {
modal.show = true
initSearch()
}
let modalRefSetData = ref()
const changeValue = () => {
modalRefSetData.value.updateData({input: (Math.random() * 100).toFixed(0)})
}
</script>
弹出框组件参数配置
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
formList | 弹出框配置 | itemType[] | 配置请查看下方FormList弹出框配置 |
formParam | 弹出框数据 | string、number、string[]、number[]、boolean | 数值需要根据formList去生成,请查看下方FormParam生成方法 |
title | 弹出框标题 | string | -- |
visible | 弹出框显隐状态 | boolean | false |
edit | 弹出框编辑状态 | boolean | false |
width | 弹出框宽度 | string | '540px' |
submitText | 提交按钮文案 | string | '保存修改' |
cancelText | 取消按钮文案 | string | '取消' |
subLoading | 确认按钮的加载状态 | boolean | false |
maskClosable | 点击蒙层是否允许关闭 | boolean | false |
弹出框内部暴露方法或变量
参数 | 说明 | 类型 | 示例 |
---|---|---|---|
updateData | 更新弹出框值 | function | -- |
updateForm | 更新弹出框配置 | function | -- |
itemChange | 组件值改变时触发的回调 | function | -- |
弹出框单项配置
参数 | 说明 | 类型 | 示例 |
---|---|---|---|
key | 弹出框组件键值 | string | 唯一的key值 |
name | 弹出框组件类别 | string | input 、InputNumber 、select 、timePicker 、 timeRangePicker 、datePicker 、dateRangePicker 、cascader、switch、radio、checkbox、slot |
slotName | 自定义组件 | -- | 当name值为slot时可使用 |
value | 弹出框组件初始值 | -- | string、number、string[]、number[]、boolean |
enum | select组件搜索项 | array | 下拉列表数据,默认取value、label |
labelName | 自定义枚举文字 | string | 更改下拉数据取值 |
valueName | 自定义枚举值 | string | 更改下拉数据取值 |
api | 动态枚举 | function | 获取接口返回的下拉数据 |
params | 动态获取枚举的参数 | object | {} |
style | 组件左侧文字样式 | string | 设置文字行内样式 |
format | 时间类选项输出的格式 | string | 使用dayjs格式化时间格式:'YYYY MM DD hh:mm:ss' |
optionType | 组合式radio | string | 沿用自antd |
width | 表格列宽度 | number | 沿用自antd |
min | inputNumber组件最小值 | number | 沿用自antd |
max | inputNumber组件最大值 | number | 沿用自antd |
placeholder | 组件无值时显示的文字 | string | 沿用自antd |
labelCol | 组件左侧文件宽度 | string | 沿用自antd |
labelAlign | 组件左侧文件定位 | string | 沿用自antd |
wrapperCol | 组件宽度 | string | 沿用自antd |
picker | 日期选项样式 | string | 沿用自antd |
rules | 数据校验 | object[] | 沿用自antd |
FormParam生成方法
let formParam: any = reactive({});
// 初始化搜索值
const initSearch = () => {
formData.forEach((item: itemType) => {
formParam[item.key] = item.value || '';
});
};
initSearch();