|
|
@@ -1817,6 +1817,26 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
const upperValue = Vue.ref(""); //上级下拉菜单当前值,在初始化下拉菜单默认值时,和上级下拉菜单的值变化时,修改此upperValue变量
|
|
|
const popupDirection = Vue.ref("bottom");
|
|
|
const popupMaxHeight = Vue.ref("none"); // popup最大高度,用于空间不足时限制高度并出滚动条 by xu 20251212
|
|
|
+ const selectContainerRef = Vue.ref(null);
|
|
|
+ const popupRef = Vue.ref(null);
|
|
|
+ const teleportRootStyle = Vue.ref({
|
|
|
+ position: "fixed",
|
|
|
+ left: "0",
|
|
|
+ top: "0",
|
|
|
+ width: "0",
|
|
|
+ height: "0",
|
|
|
+ zIndex: 9999,
|
|
|
+ pointerEvents: "none",
|
|
|
+ });
|
|
|
+ const popupLayerStyle = Vue.ref({
|
|
|
+ position: "fixed",
|
|
|
+ left: "0",
|
|
|
+ top: "0",
|
|
|
+ bottom: "auto",
|
|
|
+ minWidth: "0",
|
|
|
+ zIndex: 9999,
|
|
|
+ pointerEvents: "auto",
|
|
|
+ });
|
|
|
|
|
|
//有隐藏字段的下拉菜单,加载菜单项并展开事件
|
|
|
// 被上级下拉菜单选中值后,触发本下拉菜单刷新菜单项并弹出显示
|
|
|
@@ -2367,15 +2387,13 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
// 计算弹出方向和最大高度的方法 by xu 20251212
|
|
|
// 当空间不足时限制popup高度并显示滚动条
|
|
|
const calculatePopupDirection = () => {
|
|
|
- // 1. 获取select容器元素
|
|
|
- const selectEl = document.querySelector(
|
|
|
- `[name="${props.name}"]`
|
|
|
- )?.nextElementSibling;
|
|
|
- console.log("selectEl:" + selectEl, props.name);
|
|
|
- if (!selectEl) return;
|
|
|
+ const triggerEl =
|
|
|
+ selectContainerRef.value?.querySelector(".input") ||
|
|
|
+ selectContainerRef.value;
|
|
|
+ if (!triggerEl) return;
|
|
|
|
|
|
// 2. 获取位置信息
|
|
|
- const selectRect = selectEl.getBoundingClientRect();
|
|
|
+ const selectRect = triggerEl.getBoundingClientRect();
|
|
|
const viewportHeight = window.innerHeight;
|
|
|
|
|
|
// 3. 计算上下可用空间 by xu 20251212
|
|
|
@@ -2425,6 +2443,110 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+ const updatePopupPosition = () => {
|
|
|
+ const triggerEl =
|
|
|
+ selectContainerRef.value?.querySelector(".input") ||
|
|
|
+ selectContainerRef.value;
|
|
|
+ if (!triggerEl) return;
|
|
|
+
|
|
|
+ const triggerRect = triggerEl.getBoundingClientRect();
|
|
|
+ const margin = 10;
|
|
|
+ const viewportWidth = window.innerWidth;
|
|
|
+ const viewportHeight = window.innerHeight;
|
|
|
+ const popupGap = 0;
|
|
|
+
|
|
|
+ popupLayerStyle.value = {
|
|
|
+ position: "fixed",
|
|
|
+ left: `${Math.max(margin, triggerRect.left)}px`,
|
|
|
+ top: `${Math.max(margin, triggerRect.bottom + popupGap)}px`,
|
|
|
+ bottom: "auto",
|
|
|
+ minWidth: `${Math.max(0, triggerRect.width)}px`,
|
|
|
+ zIndex: 9999,
|
|
|
+ pointerEvents: "auto",
|
|
|
+ };
|
|
|
+
|
|
|
+ Vue.nextTick(() => {
|
|
|
+ const popupEl = popupRef.value;
|
|
|
+ if (!popupEl) return;
|
|
|
+
|
|
|
+ const popupRect = popupEl.getBoundingClientRect();
|
|
|
+ const maxLeft = viewportWidth - popupRect.width - margin;
|
|
|
+ const left = Math.min(
|
|
|
+ Math.max(margin, triggerRect.left),
|
|
|
+ Math.max(margin, maxLeft)
|
|
|
+ );
|
|
|
+
|
|
|
+ let top;
|
|
|
+ if (popupDirection.value === "top") {
|
|
|
+ top = triggerRect.top - popupRect.height - popupGap;
|
|
|
+ top = Math.max(margin, top);
|
|
|
+ } else {
|
|
|
+ top = triggerRect.bottom + popupGap;
|
|
|
+ if (top + popupRect.height > viewportHeight - margin) {
|
|
|
+ top = Math.max(
|
|
|
+ margin,
|
|
|
+ viewportHeight - popupRect.height - margin
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ popupLayerStyle.value = {
|
|
|
+ ...popupLayerStyle.value,
|
|
|
+ left: `${left}px`,
|
|
|
+ top: `${top}px`,
|
|
|
+ bottom: "auto",
|
|
|
+ };
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const openPopup = () => {
|
|
|
+ if (!popupWinVisible.value) popupWinVisible.value = true;
|
|
|
+ Vue.nextTick(() => {
|
|
|
+ calculatePopupDirection();
|
|
|
+ updatePopupPosition();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleViewportChange = () => {
|
|
|
+ if (!popupWinVisible.value) return;
|
|
|
+ calculatePopupDirection();
|
|
|
+ updatePopupPosition();
|
|
|
+ };
|
|
|
+
|
|
|
+ const onDocPointerDown = (event) => {
|
|
|
+ if (!popupWinVisible.value) return;
|
|
|
+ const target = event.target;
|
|
|
+ if (selectContainerRef.value?.contains(target)) return;
|
|
|
+ if (popupRef.value?.contains(target)) return;
|
|
|
+ hidePopup();
|
|
|
+ };
|
|
|
+
|
|
|
+ let hidePopupTimer = null;
|
|
|
+ let keepPopupTimer = null;
|
|
|
+ const leaveInput = () => {
|
|
|
+ clearTimeout(hidePopupTimer);
|
|
|
+ hidePopupTimer = setTimeout(() => {
|
|
|
+ popupWinVisible.value = false;
|
|
|
+ }, 200);
|
|
|
+ };
|
|
|
+ const enterInput = () => {
|
|
|
+ clearTimeout(hidePopupTimer);
|
|
|
+ if (popupWinVisible.value) {
|
|
|
+ clearTimeout(keepPopupTimer);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const enterPopup = () => {
|
|
|
+ clearTimeout(hidePopupTimer);
|
|
|
+ popupWinVisible.value = true;
|
|
|
+ };
|
|
|
+ const leavePopup = () => {
|
|
|
+ clearTimeout(keepPopupTimer);
|
|
|
+ keepPopupTimer = setTimeout(() => {
|
|
|
+ popupWinVisible.value = false;
|
|
|
+ }, 200);
|
|
|
+ };
|
|
|
+
|
|
|
//级联菜单点击事件
|
|
|
const togglePopup = () => {
|
|
|
if (!popupWinVisible.value) {
|
|
|
@@ -2535,9 +2657,7 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
}
|
|
|
|
|
|
// 无论是否有数据,都显示popup by xu 20251212
|
|
|
- if (!popupWinVisible.value) {
|
|
|
- popupWinVisible.value = true;
|
|
|
- }
|
|
|
+ openPopup();
|
|
|
});
|
|
|
}
|
|
|
} catch (error) {
|
|
|
@@ -2631,9 +2751,7 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
}
|
|
|
|
|
|
// 无论是否有数据,都显示popup by xu 20251212
|
|
|
- if (!popupWinVisible.value) {
|
|
|
- popupWinVisible.value = true;
|
|
|
- }
|
|
|
+ openPopup();
|
|
|
});
|
|
|
}
|
|
|
} catch (error) {
|
|
|
@@ -2654,7 +2772,9 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
|
|
|
// 合并所有的 onMounted 逻辑
|
|
|
Vue.onMounted(() => {
|
|
|
- window.addEventListener("resize", calculatePopupDirection);
|
|
|
+ window.addEventListener("resize", handleViewportChange);
|
|
|
+ window.addEventListener("scroll", handleViewportChange, true);
|
|
|
+ document.addEventListener("pointerdown", onDocPointerDown);
|
|
|
|
|
|
// 1. 监听展开下一级事件
|
|
|
window.addEventListener("open-next-cascader", (event) => {
|
|
|
@@ -2677,7 +2797,11 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
});
|
|
|
});
|
|
|
Vue.onUnmounted(() => {
|
|
|
- window.removeEventListener("resize", calculatePopupDirection);
|
|
|
+ window.removeEventListener("resize", handleViewportChange);
|
|
|
+ window.removeEventListener("scroll", handleViewportChange, true);
|
|
|
+ document.removeEventListener("pointerdown", onDocPointerDown);
|
|
|
+ clearTimeout(hidePopupTimer);
|
|
|
+ clearTimeout(keepPopupTimer);
|
|
|
});
|
|
|
// 监听值变化,处理回显 (mode 2)
|
|
|
Vue.watch(
|
|
|
@@ -2733,13 +2857,21 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
togglePopup,
|
|
|
hidePopup,
|
|
|
doSelectItem,
|
|
|
+ leaveInput,
|
|
|
+ enterInput,
|
|
|
+ leavePopup,
|
|
|
+ enterPopup,
|
|
|
+ selectContainerRef,
|
|
|
+ popupRef,
|
|
|
+ teleportRootStyle,
|
|
|
+ popupLayerStyle,
|
|
|
};
|
|
|
},
|
|
|
|
|
|
template: `
|
|
|
<div class="input ss-ccp-container" style="position: relative" :style="{width: width}">
|
|
|
<input type="hidden" :name="name" :value="modelValue">
|
|
|
- <div class="select-container" @mouseleave="hidePopup">
|
|
|
+ <div class="select-container" ref="selectContainerRef" @mouseleave="leaveInput" @mouseenter="enterInput">
|
|
|
<div class="input" @click="togglePopup">
|
|
|
<input
|
|
|
type="hidden"
|
|
|
@@ -2756,33 +2888,45 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
<ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
|
|
|
</div>
|
|
|
</div>
|
|
|
-
|
|
|
- <!-- popup弹出层,添加maxHeight和overflowY支持空间不足时滚动 by xu 20251212 -->
|
|
|
- <div v-show="popupWinVisible" class="popup-win " :class="popupDirection" :style="{ maxHeight: popupMaxHeight, overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }">
|
|
|
- <div v-if="opt && opt.length > 0" class="popup-content">
|
|
|
- <div class="content-area">
|
|
|
- <div
|
|
|
- v-for="(item, index) in opt"
|
|
|
- :key="index"
|
|
|
- @click="doSelectItem(item)"
|
|
|
- :class="{ active: item.value === selectItem.value }"
|
|
|
- >
|
|
|
- <span class="check-icon">
|
|
|
- <ss-form-icon class="form-icon-select-checked" />
|
|
|
- </span>
|
|
|
- <span>{{ item.label }}</span>
|
|
|
+ </div>
|
|
|
+ <teleport to="body">
|
|
|
+ <div
|
|
|
+ v-show="popupWinVisible"
|
|
|
+ class="select-container ss-ccp-teleport-root"
|
|
|
+ :style="teleportRootStyle"
|
|
|
+ @mouseleave="leavePopup"
|
|
|
+ @mouseenter="enterPopup"
|
|
|
+ >
|
|
|
+ <div
|
|
|
+ ref="popupRef"
|
|
|
+ class="popup-win"
|
|
|
+ :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }]"
|
|
|
+ >
|
|
|
+ <div v-if="opt && opt.length > 0" class="popup-content">
|
|
|
+ <div class="content-area">
|
|
|
+ <div
|
|
|
+ v-for="(item, index) in opt"
|
|
|
+ :key="index"
|
|
|
+ @click="doSelectItem(item)"
|
|
|
+ :class="{ active: item.value === selectItem.value }"
|
|
|
+ >
|
|
|
+ <span class="check-icon">
|
|
|
+ <ss-form-icon class="form-icon-select-checked" />
|
|
|
+ </span>
|
|
|
+ <span>{{ item.label }}</span>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
- <div v-else class="popup-content">
|
|
|
- <div class="content-area">
|
|
|
+ <div v-else class="popup-content">
|
|
|
<div class="content-area">
|
|
|
- <span>无选项</span>
|
|
|
+ <div class="content-area">
|
|
|
+ <span>无选项</span>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </teleport>
|
|
|
</div>
|
|
|
`,
|
|
|
};
|