feat(design,element-plus-adapter): 新增获取浮层zIndex的方法

This commit is contained in:
roymondchen 2024-01-08 16:42:45 +08:00
parent eeb4566a69
commit 81e3d0a18e
3 changed files with 38 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import { App } from 'vue'; import type { App, Ref } from 'vue';
import { computed, ref, unref } from 'vue';
import { setConfig } from './config'; import { setConfig } from './config';
import { PluginOptions, TMagicMessage, TMagicMessageBox } from './types'; import { PluginOptions, TMagicMessage, TMagicMessageBox } from './types';
@ -81,6 +82,30 @@ export const tMagicMessageBox = {
}, },
} as unknown as TMagicMessageBox; } as unknown as TMagicMessageBox;
const zIndex = ref(0);
export const DEFAULT_INITIAL_Z_INDEX = 2000;
// eslint-disable-next-line import/no-mutable-exports
export let useZIndex = (zIndexOverrides?: Ref<number>) => {
const zIndexInjection = zIndexOverrides;
const initialZIndex = computed(() => {
const zIndexFromInjection = unref(zIndexInjection);
return zIndexFromInjection ?? DEFAULT_INITIAL_Z_INDEX;
});
const currentZIndex = computed(() => initialZIndex.value + zIndex.value);
const nextZIndex = () => {
zIndex.value += 1;
return currentZIndex.value;
};
return {
initialZIndex,
currentZIndex,
nextZIndex,
};
};
export default { export default {
install(app: App, options: PluginOptions) { install(app: App, options: PluginOptions) {
if (options.message) { if (options.message) {
@ -102,6 +127,10 @@ export default {
app.directive('loading', options.loading); app.directive('loading', options.loading);
} }
if (options.useZIndex) {
useZIndex = options.useZIndex;
}
app.config.globalProperties.$MAGIC_DESIGN = options; app.config.globalProperties.$MAGIC_DESIGN = options;
setConfig(options); setConfig(options);
}, },

View File

@ -1,4 +1,4 @@
import { DefineComponent, Directive } from 'vue'; import { ComputedRef, DefineComponent, Directive, Ref } from 'vue';
export type FieldSize = 'large' | 'default' | 'small'; export type FieldSize = 'large' | 'default' | 'small';
@ -704,5 +704,10 @@ export interface PluginOptions {
messageBox?: TMagicMessageBox; messageBox?: TMagicMessageBox;
components?: Components; components?: Components;
loading?: Directive<ElementLoading, LoadingBinding>; loading?: Directive<ElementLoading, LoadingBinding>;
useZIndex?: (zIndexOverrides?: Ref<number>) => {
initialZIndex: ComputedRef<number>;
currentZIndex: ComputedRef<number>;
nextZIndex: () => number;
};
[key: string]: any; [key: string]: any;
} }

View File

@ -46,6 +46,7 @@ import {
ElTooltip, ElTooltip,
ElTree, ElTree,
ElUpload, ElUpload,
useZIndex,
} from 'element-plus'; } from 'element-plus';
import type { import type {
@ -94,6 +95,7 @@ import type {
} from '@tmagic/design'; } from '@tmagic/design';
const adapter: PluginOptions = { const adapter: PluginOptions = {
useZIndex,
message: ElMessage, message: ElMessage,
messageBox: ElMessageBox, messageBox: ElMessageBox,
components: { components: {