mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-08 01:17:23 +08:00
feat: 函数式弹框添加updateDialog
更改弹框自身属性值方法
This commit is contained in:
parent
a4a691de3e
commit
e65faa5ef8
@ -12,6 +12,7 @@ import type {
|
|||||||
|
|
||||||
const dialogStore = ref<Array<DialogOptions>>([]);
|
const dialogStore = ref<Array<DialogOptions>>([]);
|
||||||
|
|
||||||
|
/** 打开弹框 */
|
||||||
const addDialog = (options: DialogOptions) => {
|
const addDialog = (options: DialogOptions) => {
|
||||||
const open = () =>
|
const open = () =>
|
||||||
dialogStore.value.push(Object.assign(options, { visible: true }));
|
dialogStore.value.push(Object.assign(options, { visible: true }));
|
||||||
@ -24,16 +25,40 @@ const addDialog = (options: DialogOptions) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 关闭弹框 */
|
||||||
const closeDialog = (options: DialogOptions, index: number, args?: any) => {
|
const closeDialog = (options: DialogOptions, index: number, args?: any) => {
|
||||||
dialogStore.value.splice(index, 1);
|
dialogStore.value.splice(index, 1);
|
||||||
options.closeCallBack && options.closeCallBack({ options, index, args });
|
options.closeCallBack && options.closeCallBack({ options, index, args });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 更改弹框自身属性值
|
||||||
|
* @param value 属性值
|
||||||
|
* @param key 属性,默认`title`
|
||||||
|
* @param index 弹框索引(默认`0`,代表只有一个弹框,对于嵌套弹框要改哪个弹框的属性值就把该弹框索引赋给`index`)
|
||||||
|
*/
|
||||||
|
const updateDialog = (value: any, key = "title", index = 0) => {
|
||||||
|
dialogStore.value[index][key] = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 关闭所有弹框 */
|
||||||
const closeAllDialog = () => {
|
const closeAllDialog = () => {
|
||||||
dialogStore.value = [];
|
dialogStore.value = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 千万别忘了在下面这三处引入并注册下,放心注册,不使用`addDialog`调用就不会被挂载
|
||||||
|
* https://github.com/pure-admin/vue-pure-admin/blob/main/src/App.vue#L4
|
||||||
|
* https://github.com/pure-admin/vue-pure-admin/blob/main/src/App.vue#L13
|
||||||
|
* https://github.com/pure-admin/vue-pure-admin/blob/main/src/App.vue#L18
|
||||||
|
*/
|
||||||
const ReDialog = withInstall(reDialog);
|
const ReDialog = withInstall(reDialog);
|
||||||
|
|
||||||
export type { EventType, ArgsType, DialogProps, ButtonProps, DialogOptions };
|
export type { EventType, ArgsType, DialogProps, ButtonProps, DialogOptions };
|
||||||
export { ReDialog, dialogStore, addDialog, closeDialog, closeAllDialog };
|
export {
|
||||||
|
ReDialog,
|
||||||
|
dialogStore,
|
||||||
|
addDialog,
|
||||||
|
closeDialog,
|
||||||
|
updateDialog,
|
||||||
|
closeAllDialog
|
||||||
|
};
|
||||||
|
@ -2,9 +2,14 @@
|
|||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
import { h, createVNode, ref } from "vue";
|
import { h, createVNode, ref } from "vue";
|
||||||
import { message } from "@/utils/message";
|
import { message } from "@/utils/message";
|
||||||
import { cloneDeep } from "@pureadmin/utils";
|
|
||||||
import forms, { type FormProps } from "./form.vue";
|
import forms, { type FormProps } from "./form.vue";
|
||||||
import { addDialog, closeDialog, closeAllDialog } from "@/components/ReDialog";
|
import { cloneDeep, debounce } from "@pureadmin/utils";
|
||||||
|
import {
|
||||||
|
addDialog,
|
||||||
|
closeDialog,
|
||||||
|
updateDialog,
|
||||||
|
closeAllDialog
|
||||||
|
} from "@/components/ReDialog";
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "DialogPage"
|
name: "DialogPage"
|
||||||
@ -60,13 +65,16 @@ function onStyleClick() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onoOpenDelayClick() {
|
// 添加 600ms 防抖
|
||||||
addDialog({
|
const onoOpenDelayClick = debounce(
|
||||||
title: "延时2秒打开弹框",
|
() =>
|
||||||
openDelay: 2000,
|
addDialog({
|
||||||
contentRenderer: () => <p>弹框内容-延时2秒打开弹框</p>
|
title: "延时2秒打开弹框",
|
||||||
});
|
openDelay: 2000 - 600,
|
||||||
}
|
contentRenderer: () => <p>弹框内容-延时2秒打开弹框</p>
|
||||||
|
}),
|
||||||
|
600
|
||||||
|
);
|
||||||
|
|
||||||
function onCloseDelayClick() {
|
function onCloseDelayClick() {
|
||||||
addDialog({
|
addDialog({
|
||||||
@ -240,6 +248,35 @@ function onNestingClick() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 满足在 contentRenderer 内容区更改弹框自身属性值的场景
|
||||||
|
function onUpdateClick() {
|
||||||
|
const curPage = ref(1);
|
||||||
|
addDialog({
|
||||||
|
title: `第${curPage.value}页`,
|
||||||
|
contentRenderer: () => (
|
||||||
|
<>
|
||||||
|
<el-button
|
||||||
|
disabled={curPage.value > 1 ? false : true}
|
||||||
|
onClick={() => {
|
||||||
|
curPage.value -= 1;
|
||||||
|
updateDialog(`第${curPage.value}页`);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
上一页
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
onClick={() => {
|
||||||
|
curPage.value += 1;
|
||||||
|
updateDialog(`第${curPage.value}页`);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
下一页
|
||||||
|
</el-button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 结合Form表单(第一种方式,弹框关闭立刻恢复初始值)通过 props 属性接收子组件的 prop 并赋值
|
// 结合Form表单(第一种方式,弹框关闭立刻恢复初始值)通过 props 属性接收子组件的 prop 并赋值
|
||||||
function onFormOneClick() {
|
function onFormOneClick() {
|
||||||
addDialog({
|
addDialog({
|
||||||
@ -421,6 +458,7 @@ function onBeforeSureClick() {
|
|||||||
<el-button @click="onOpenClick"> 打开后的回调 </el-button>
|
<el-button @click="onOpenClick"> 打开后的回调 </el-button>
|
||||||
<el-button @click="onCloseCallBackClick"> 关闭后的回调 </el-button>
|
<el-button @click="onCloseCallBackClick"> 关闭后的回调 </el-button>
|
||||||
<el-button @click="onNestingClick"> 嵌套的弹框 </el-button>
|
<el-button @click="onNestingClick"> 嵌套的弹框 </el-button>
|
||||||
|
<el-button @click="onUpdateClick"> 更改弹框自身属性值 </el-button>
|
||||||
</el-space>
|
</el-space>
|
||||||
<el-divider />
|
<el-divider />
|
||||||
<el-space wrap>
|
<el-space wrap>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user