文件
NHCshopro/components/shopro-notice-modal/shopro-notice-modal.vue
可乐加冰 9d2488a631 chore: 纳入小程序完整源码
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-23 20:25:01 +08:00

155 行
3.2 KiB
Vue

<template>
<view v-if="visible" class="notice-modal"
style="position:fixed;top:0;left:0;width:100%;height:100%;z-index:10090;"
@touchmove.stop.prevent="() => {}">
<view class="notice-modal__mask"
style="position:absolute;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,0.6);z-index:1;"
@tap="hideModal(currentPopup, popupCurrent)"></view>
<view class="notice-modal__content"
style="position:absolute;top:0;left:0;width:100%;height:100%;z-index:2;display:flex;flex-direction:column;align-items:center;justify-content:center;">
<view class="img-box" style="width:610rpx;" @tap.stop="onPopup(currentPopup.path)">
<image class="modal-img" style="display:block;width:610rpx;" :src="currentPopup.image" mode="widthFix"></image>
</view>
<view class="notice-modal__close" @tap.stop="hideModal(currentPopup, popupCurrent)">
<u-icon size="80" name="close-circle" color="#fff"></u-icon>
</view>
</view>
</view>
</template>
<script>
/**
* 广告模态框。连续弹窗和只弹一次。
*/
import {
mapGetters
} from 'vuex';
let timer = null;
export default {
name: 'shoproNoticeModal',
// #ifdef MP-WEIXIN
options: {
styleIsolation: 'shared',
virtualHost: true
},
// #endif
data() {
return {
popupCurrent: 0,
visible: false
};
},
computed: {
...mapGetters(['popupData', 'isLogin']),
newPopupList() {
if (this.popupData && this.popupData.list) {
return this.popupData.list;
}
return [];
},
currentPopup() {
if (!this.newPopupList.length) {
return null;
}
const popup = this.newPopupList[this.popupCurrent];
return popup && popup.image ? popup : null;
}
},
watch: {
currentPopup: {
handler(val) {
clearTimeout(timer);
if (val) {
this.$nextTick(() => {
this.visible = true;
});
} else {
this.visible = false;
}
},
immediate: true
},
popupData: {
handler() {
if (this.popupCurrent >= this.newPopupList.length) {
this.popupCurrent = 0;
}
},
deep: true
}
},
beforeDestroy() {
clearTimeout(timer);
timer = null;
},
methods: {
hideModal(p, index) {
if (!p) {
return;
}
clearTimeout(timer);
this.visible = false;
if (p.style == 1) {
this.$store.commit('delPopup', index);
}
timer = setTimeout(() => {
const nextIndex = index + 1;
if (nextIndex < this.newPopupList.length) {
this.popupCurrent = nextIndex;
}
}, 300);
},
onPopup(path) {
this.$tools.routerTo(path);
}
}
};
</script>
<style lang="scss">
.notice-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10090;
}
.notice-modal__mask {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
z-index: 1;
}
.notice-modal__content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.img-box {
width: 610rpx;
.modal-img {
display: block;
width: 610rpx;
}
}
.notice-modal__close {
margin-top: 40rpx;
}
</style>