(dropdown): 修改 context-menu 弹出策略, 仅更改触发不方式, 不影响弹出方案

This commit is contained in:
就眠儀式 2022-06-07 20:26:03 +08:00
parent 4d2d7105de
commit 1718e32735
6 changed files with 48 additions and 37 deletions

View File

@ -6,8 +6,6 @@
.layui-dropdown dl { .layui-dropdown dl {
display: none; display: none;
position: absolute; position: absolute;
left: var(--layui-dropdown-left);
top: var(--layui-dropdown-top);
margin-top: 2px; margin-top: 2px;
z-index: 899; z-index: 899;
min-width: 100%; min-width: 100%;
@ -26,7 +24,6 @@
display: block; display: block;
} }
.layui-dropdown .layui-menu { .layui-dropdown .layui-menu {
position: relative; position: relative;
background-color: #fff; background-color: #fff;

View File

@ -21,27 +21,18 @@ const props = withDefaults(defineProps<LayDropdownProps>(), {
}); });
const openState = ref(false); const openState = ref(false);
const dropdownRef = ref<null | HTMLElement>(null); const dropdownRef = ref<null | HTMLElement>();
const dropdownX = ref<number | string>(0); const dropdownX = ref<number | string>(0);
const dropdownY = ref<number | string>("auto"); const dropdownY = ref<number | string>("auto");
const emit = defineEmits(["open", "hide"]); const emit = defineEmits(["open", "hide"]);
// @ts-ignore
onClickOutside(dropdownRef, (event) => { onClickOutside(dropdownRef, () => {
openState.value = false; openState.value = false;
}); });
const open = function (event?: Event): void { const open = function (event?: Event): void {
if (props.disabled === false) { if (props.disabled === false) {
if (event) {
const el = event.currentTarget;
// @ts-ignore
const rect = el.getBoundingClientRect();
// @ts-ignore
dropdownX.value = event.clientX - rect.left + "px";
// @ts-ignore
dropdownY.value = event.clientY - rect.top + "px";
}
openState.value = true; openState.value = true;
emit("open"); emit("open");
} }
@ -61,11 +52,6 @@ const toggle = function (event?: Event): void {
} }
}; };
const dropdownStyle = computed(() => ({
"--layui-dropdown-left": dropdownX.value,
"--layui-dropdown-top": dropdownY.value,
}));
provide("openState", openState); provide("openState", openState);
defineExpose({ open, hide, toggle }); defineExpose({ open, hide, toggle });
@ -78,7 +64,6 @@ defineExpose({ open, hide, toggle });
@mouseenter="trigger === 'hover' && open()" @mouseenter="trigger === 'hover' && open()"
@mouseleave="trigger === 'hover' && hide()" @mouseleave="trigger === 'hover' && hide()"
:class="{ 'layui-dropdown-up': openState }" :class="{ 'layui-dropdown-up': openState }"
:style="dropdownStyle"
> >
<div <div
@click="trigger === 'click' && toggle()" @click="trigger === 'click' && toggle()"

View File

@ -158,6 +158,34 @@ export default {
::: :::
::: title 位置优化
:::
::: demo
<template>
<lay-dropdown>
<lay-button type="primary">下拉菜单</lay-button>
<template #content>
<div style="width:300px;height:200px;"></div>
</template>
</lay-dropdown>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
return {
}
}
}
</script>
:::
::: title Dropdown 属性 ::: title Dropdown 属性
::: :::

View File

@ -76,27 +76,27 @@
</lay-icon> </lay-icon>
</a> </a>
<template #content> <template #content>
<div style="width: 380px; padding: 0px 10px 10px 10px"> <div class="theme-panel">
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-primary-color']" v-model="appStore.themeVariable['--global-primary-color']"
></lay-color-picker ></lay-color-picker
>&nbsp; >
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-normal-color']" v-model="appStore.themeVariable['--global-normal-color']"
></lay-color-picker ></lay-color-picker
>&nbsp; >
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-warm-color']" v-model="appStore.themeVariable['--global-warm-color']"
></lay-color-picker ></lay-color-picker
>&nbsp; >
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-danger-color']" v-model="appStore.themeVariable['--global-danger-color']"
></lay-color-picker ></lay-color-picker
>&nbsp; >
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-checked-color']" v-model="appStore.themeVariable['--global-checked-color']"
></lay-color-picker ></lay-color-picker
>&nbsp; >
<lay-input <lay-input
v-model="appStore.themeVariable['--global-border-radius']" v-model="appStore.themeVariable['--global-border-radius']"
style="display: inline-block; width: 130px" style="display: inline-block; width: 130px"
@ -104,31 +104,24 @@
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-neutral-color-1']" v-model="appStore.themeVariable['--global-neutral-color-1']"
></lay-color-picker> ></lay-color-picker>
&nbsp;
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-neutral-color-2']" v-model="appStore.themeVariable['--global-neutral-color-2']"
></lay-color-picker> ></lay-color-picker>
&nbsp;
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-neutral-color-3']" v-model="appStore.themeVariable['--global-neutral-color-3']"
></lay-color-picker> ></lay-color-picker>
&nbsp;
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-neutral-color-4']" v-model="appStore.themeVariable['--global-neutral-color-4']"
></lay-color-picker> ></lay-color-picker>
&nbsp;
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-neutral-color-5']" v-model="appStore.themeVariable['--global-neutral-color-5']"
></lay-color-picker> ></lay-color-picker>
&nbsp;
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-neutral-color-6']" v-model="appStore.themeVariable['--global-neutral-color-6']"
></lay-color-picker> ></lay-color-picker>
&nbsp;
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-neutral-color-7']" v-model="appStore.themeVariable['--global-neutral-color-7']"
></lay-color-picker> ></lay-color-picker>
&nbsp;
<lay-color-picker <lay-color-picker
v-model="appStore.themeVariable['--global-neutral-color-8']" v-model="appStore.themeVariable['--global-neutral-color-8']"
></lay-color-picker> ></lay-color-picker>
@ -394,4 +387,13 @@ export default {
top: 3px; top: 3px;
left: 3px; left: 3px;
} }
.theme-panel {
width: 380px;
padding: 0px 10px 10px 10px
}
.theme-panel > * {
margin-right: 9px;
}
</style> </style>

View File

@ -41,4 +41,4 @@ export default (str: string, lang: string): string => {
return wrap(code, rawLang); return wrap(code, rawLang);
} }
return wrap(str, "text"); return wrap(str, "text");
}; };

View File

@ -1,6 +1,5 @@
import { import {
createRouter as _createRouter, createRouter as _createRouter,
createWebHashHistory,
createWebHistory, createWebHistory,
Router, Router,
} from "vue-router"; } from "vue-router";