diff --git a/src/component/index.vue b/src/component/index.vue index bd0d716b8d5cab1741c42d39b569a6134e1f360d..1be72e7240fceac20818a712b41bc8c6660f587b 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 cd102489e4f7a6266d1f79a1b90eb58e60e9c8d5..df9de7c3a8836f1da3791593b18eadb328d014af 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 0000000000000000000000000000000000000000..6990b21a148f63cc3f6c733136f98bb3e3545fc9 --- /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 45bda30aa57cf6ea13e18a705c656d1d05e6ff7c..5efc8b68b9dac45592f1c83f256b64da3e76b35a 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