✨(component): 根据 id 保证弹层实例唯一
This commit is contained in:
parent
95ca7b8165
commit
afbfeb0c18
@ -16,11 +16,11 @@
|
|||||||
import { layer } from "../../../../layer/src/index"
|
import { layer } from "../../../../layer/src/index"
|
||||||
|
|
||||||
const msg = function() {
|
const msg = function() {
|
||||||
layer.msg("普通消息", { time: 1000 })
|
layer.msg("普通消息", { time: 3000, id: "1" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const success = function() {
|
const success = function() {
|
||||||
layer.msg("成功消息", { time: 1000, icon: 1})
|
layer.msg("成功消息", { time: 3000, id: "1" ,icon: 1})
|
||||||
}
|
}
|
||||||
|
|
||||||
const failure = function() {
|
const failure = function() {
|
||||||
@ -86,7 +86,7 @@ const openConfirm2 = function() {
|
|||||||
import { layer } from "../../../../layer/src/index"
|
import { layer } from "../../../../layer/src/index"
|
||||||
|
|
||||||
const load1 = function() {
|
const load1 = function() {
|
||||||
layer.load(0, {time: 2000})
|
layer.load(0, {id:"1", time: 3000})
|
||||||
}
|
}
|
||||||
|
|
||||||
const load2 = function() {
|
const load2 = function() {
|
||||||
|
@ -55,9 +55,9 @@ const mergeOption = (option: any, defaultOption: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 创建 modal 容器
|
// 创建 modal 容器
|
||||||
const createContainer = () => {
|
const createContainer = (options: any) => {
|
||||||
const modalContainer = document.createElement("div");
|
const modalContainer = document.createElement("div");
|
||||||
modalContainer.id = nextId();
|
modalContainer.id = options.id;
|
||||||
document.body.appendChild(modalContainer);
|
document.body.appendChild(modalContainer);
|
||||||
return modalContainer;
|
return modalContainer;
|
||||||
};
|
};
|
||||||
@ -71,8 +71,8 @@ const modalChildrenVNode = (content: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const layer = {
|
const layer = {
|
||||||
// 上下文
|
|
||||||
_context: <AppContext | null>null,
|
_context: <AppContext | null> null,
|
||||||
|
|
||||||
// 页面
|
// 页面
|
||||||
open: (option: any, callback?: Function) => {
|
open: (option: any, callback?: Function) => {
|
||||||
@ -155,10 +155,16 @@ const layer = {
|
|||||||
let timer: NodeJS.Timeout;
|
let timer: NodeJS.Timeout;
|
||||||
// 聚合配置 Opt
|
// 聚合配置 Opt
|
||||||
const options = mergeOption(option, defaultOption);
|
const options = mergeOption(option, defaultOption);
|
||||||
|
// 生成唯一标识
|
||||||
|
if(options.hasOwnProperty("id")) {
|
||||||
|
// 判断 id 存在, 并销毁窗体
|
||||||
|
layer.close(options.id);
|
||||||
|
} else {
|
||||||
|
// 生成新的唯一标识
|
||||||
|
options.id = nextId();
|
||||||
|
}
|
||||||
// 创建容器 Dom
|
// 创建容器 Dom
|
||||||
const modalContainer = createContainer();
|
const modalContainer = createContainer(options);
|
||||||
|
|
||||||
options.id = modalContainer.id;
|
|
||||||
// 创建虚拟 Dom
|
// 创建虚拟 Dom
|
||||||
const modalInstance = h(
|
const modalInstance = h(
|
||||||
LayLayer,
|
LayLayer,
|
||||||
@ -261,4 +267,5 @@ export { layer, LayLayer };
|
|||||||
|
|
||||||
export default { install };
|
export default { install };
|
||||||
|
|
||||||
import "./theme/index.css";
|
import "./theme/index.css";import { getSystemErrorMap } from "util";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user