57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
![]() |
Component({
|
||
|
properties: {
|
||
|
popupType: { type: String, value: 'announcement' }, // 弹窗类型
|
||
|
popupContent: { type: String, value: '' }, // 弹窗内容
|
||
|
buttonText: { type: String, value: '立即前往' }, // 按钮文字
|
||
|
targetUrl: { type: String, value: '' }, // 按钮跳转链接
|
||
|
debugMode: { type: Boolean, value: false } // 开关:调试模式
|
||
|
},
|
||
|
data: {
|
||
|
isVisible: false // 默认不显示弹窗
|
||
|
},
|
||
|
lifetimes: {
|
||
|
attached() {
|
||
|
this.checkPopupStatus();
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
// 检查是否需要显示弹窗
|
||
|
checkPopupStatus() {
|
||
|
const debugMode = this.properties.debugMode; // 获取调试模式开关
|
||
|
const lastShownDate = wx.getStorageSync('popup_last_date'); // 读取本地存储的日期
|
||
|
const today = new Date().toDateString(); // 获取当前日期字符串
|
||
|
|
||
|
if (debugMode || lastShownDate !== today) {
|
||
|
// 调试模式或未弹出过,则显示弹窗
|
||
|
this.setData({ isVisible: true });
|
||
|
wx.setStorageSync('popup_last_date', today); // 更新本地存储的日期
|
||
|
} else {
|
||
|
console.log('弹窗今日已显示,不再重复弹出');
|
||
|
}
|
||
|
},
|
||
|
|
||
|
// 关闭弹窗
|
||
|
closePopup() {
|
||
|
this.setData({ isVisible: false });
|
||
|
},
|
||
|
|
||
|
onMaskTap() {
|
||
|
this.closePopup();
|
||
|
},
|
||
|
|
||
|
preventClose() {
|
||
|
// 防止点击弹窗内部关闭
|
||
|
},
|
||
|
|
||
|
onNavigate() {
|
||
|
if (this.properties.targetUrl) {
|
||
|
wx.navigateTo({
|
||
|
url: this.properties.targetUrl
|
||
|
});
|
||
|
} else {
|
||
|
console.warn('未设置跳转链接');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|