feat: 函数式弹框添加updateDialog更改弹框自身属性值方法

This commit is contained in:
xiaoxian521 2023-05-23 21:56:24 +08:00
parent a4a691de3e
commit e65faa5ef8
2 changed files with 73 additions and 10 deletions

View File

@ -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
};

View File

@ -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
const onoOpenDelayClick = debounce(
() =>
addDialog({ addDialog({
title: "延时2秒打开弹框", title: "延时2秒打开弹框",
openDelay: 2000, openDelay: 2000 - 600,
contentRenderer: () => <p>弹框内容-延时2秒打开弹框</p> 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>