<template>
<view class="u-mask" :style="[maskStyle]" @tap="click" @touchmove.stop.prevent :class="{
'u-mask-zoom': zoom,
'u-mask-show': show
}">
<slot />
</view>
</template>
<script>
export default {
name: "u-mask",
props: {
show: {
type: Boolean,
default: false
},
zIndex: {
type: [Number, String],
default: ''
},
customStyle: {
type: Object,
default () {
return {}
}
},
zoom: {
type: Boolean,
default: true
},
duration: {
type: [Number, String],
default: 300
},
maskClickAble: {
type: Boolean,
default: true
}
},
data() {
return {
zoomStyle: {
transform: ''
},
scale: 'scale(1.2, 1.2)'
}
},
watch: {
show(n) {
if(n && this.zoom) {
if(navigator.userAgent.indexOf("Ultra")>-1 || navigator.userAgent.indexOf("NRD90M")>-1){
this.zoomStyle.transform = 'scale(1, 1)';
}
} else if(!n && this.zoom) {
if(navigator.userAgent.indexOf("Ultra")>-1 || navigator.userAgent.indexOf("NRD90M")>-1){
this.zoomStyle.transform = this.scale;
}
}
}
},
computed: {
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(navigator.userAgent&&navigator.userAgent.indexOf("Ultra")>-1 || navigator.userAgent.indexOf("NRD90M")>-1){
style.transition = `all ${this.duration / 1000}s ease-in-out`;
}
if (Object.keys(this.customStyle).length) style = { ...style,
...this.customStyle
};
return style;
}
},
methods: {
click() {
if (!this.maskClickAble) return;
this.$emit('click');
}
}
}
</script>
<style lang="scss" scoped>
@import "../../libs/css/style.components.scss";
.u-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0;
transition: transform 0.3s;
}
.u-mask-show {
opacity: 1;
}
.u-mask-zoom {
transform: scale(1.2, 1.2);
}
</style>