From a5cb6856c6caa66140152f2c5287fae6d1bbece5 Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Wed, 16 Mar 2022 16:28:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=85=A8=E5=B1=80=20zIndex=20?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/index.vue | 6 +++--- src/index.ts | 2 ++ src/tokens/index.ts | 1 + src/types/index.ts | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 src/tokens/index.ts diff --git a/src/component/index.vue b/src/component/index.vue index bd0d716..1050bc5 100644 --- a/src/component/index.vue +++ b/src/component/index.vue @@ -10,7 +10,7 @@ import Iframe from "./Iframe.vue"; import Title from "./Title.vue"; import CloseBtn from "./CloseBtn.vue"; import Resize from "./Resize.vue"; -import { Ref, ref, watch, computed, useSlots, VNodeTypes, nextTick } from "vue"; +import { Ref, ref, watch, computed, useSlots, VNodeTypes, nextTick, inject } from "vue"; import { nextId, maxArea, @@ -28,6 +28,7 @@ import { } from "../utils"; import useMove from "../composable/useMove"; import useResize from "../composable/useResize"; +import { zIndexKey } from "../tokens"; const slots = useSlots(); const layero = ref(null); @@ -70,7 +71,6 @@ export interface LayModalProps { const props = withDefaults(defineProps(), { title: "信息", - zIndex: 99999, setTop: false, offset: () => ["50%", "50%"], area: "auto", @@ -104,7 +104,7 @@ const type: number = calculateType(props.type); const area: Ref = ref(calculateArea(props.type, props.area, props.offset)); const offset: Ref = ref(calculateOffset(props.offset, area.value, props.type)); const contentHeight = ref(calculateContent(area.value[1], props.btn, type, props.isMessage)); -const index: Ref = ref(props.zIndex); +const index: Ref = ref(props.zIndex ?? inject(zIndexKey, 99999)) ; const visible: Ref = ref(false); const first: Ref = ref(true); diff --git a/src/index.ts b/src/index.ts index cd10248..df9de7c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { render, h, isVNode, getCurrentInstance, AppContext, App } from "vue"; import LayLayer from "./component/index.vue"; import { InstallOptions } from "./types"; +import { zIndexKey } from "./tokens"; import { nextId } from "./utils"; // 实例队列 @@ -201,6 +202,7 @@ const layer = { // 全局安装 const install = (app: App, options: InstallOptions): void => { layer._context = app._context; + app.provide(zIndexKey, options.zIndex) app.component(LayLayer.name, LayLayer); app.config.globalProperties.$layer = layer; }; diff --git a/src/tokens/index.ts b/src/tokens/index.ts new file mode 100644 index 0000000..6990b21 --- /dev/null +++ b/src/tokens/index.ts @@ -0,0 +1 @@ +export const zIndexKey = Symbol("zIndex"); \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index 45bda30..5efc8b6 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,3 @@ export type StringObject = Record; -export interface InstallOptions extends StringObject {} \ No newline at end of file +export interface InstallOptions extends StringObject {}; \ No newline at end of file -- Gitee From 023cedfcc946c263a006c08bb72e04e19852b285 Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Wed, 16 Mar 2022 16:38:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20zIndex=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/index.vue b/src/component/index.vue index 1050bc5..1be72e7 100644 --- a/src/component/index.vue +++ b/src/component/index.vue @@ -104,7 +104,7 @@ const type: number = calculateType(props.type); const area: Ref = ref(calculateArea(props.type, props.area, props.offset)); const offset: Ref = ref(calculateOffset(props.offset, area.value, props.type)); const contentHeight = ref(calculateContent(area.value[1], props.btn, type, props.isMessage)); -const index: Ref = ref(props.zIndex ?? inject(zIndexKey, 99999)) ; +const index: Ref = ref(props.zIndex ?? inject(zIndexKey, 99999)) ; const visible: Ref = ref(false); const first: Ref = ref(true); -- Gitee