Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions uview-ui/components/u-mask/u-mask.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@
maskStyle() {
let style = {};
style.backgroundColor = "rgba(0, 0, 0, 0.6)";
if(this.show) style.zIndex = this.zIndex ? this.zIndex : this.$u.zIndex.mask;
else style.zIndex = -1;
if(this.show) {
// 如果传入了zIndex(包括0),使用传入的值;否则使用默认值
// 使用 !== '' 和 !== null 和 !== undefined 来判断是否传入了值
style.zIndex = (this.zIndex !== '' && this.zIndex !== null && this.zIndex !== undefined)
? Number(this.zIndex)
: this.$u.zIndex.mask;
} else {
style.zIndex = -1;
}
style.transition = `all ${this.duration / 1000}s ease-in-out`;
// 判断用户传递的对象是否为空,不为空就进行合并
if (Object.keys(this.customStyle).length) style = {
Expand Down
15 changes: 13 additions & 2 deletions uview-ui/components/u-popup/u-popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<view v-if="visibleSync" :style="[customStyle, {
zIndex: uZindex - 1
}]" class="u-drawer" hover-stop-propagation>
<u-mask :duration="duration" :custom-style="maskCustomStyle" :maskClickAble="maskCloseAble" :z-index="uZindex - 2" :show="showDrawer && mask" @click="maskClick"></u-mask>
<u-mask :duration="duration" :custom-style="maskCustomStyle" :maskClickAble="maskCloseAble" :z-index="maskZIndex" :show="showDrawer && mask" @click="maskClick"></u-mask>
<view
class="u-drawer-content"
@tap="modeCenterClose(mode)"
Expand Down Expand Up @@ -262,7 +262,18 @@ export default {
},
// 计算整理后的z-index值
uZindex() {
return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
if (!this.zIndex) {
return this.$u.zIndex.popup;
}
const zIndex = Number(this.zIndex);
// 如果转换失败(NaN),使用默认值
return isNaN(zIndex) ? this.$u.zIndex.popup : zIndex;
},
// 计算遮罩层的z-index值,确保始终比内容层低,且基于内容层的zIndex计算
maskZIndex() {
const contentZIndex = this.uZindex;
// 确保遮罩层比内容层至少低2,但至少为1
return Math.max(1, contentZIndex - 2);
}
},
watch: {
Expand Down