first commit
This commit is contained in:
56
popup/popup.js
Normal file
56
popup/popup.js
Normal file
@@ -0,0 +1,56 @@
|
||||
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('未设置跳转链接');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
3
popup/popup.json
Normal file
3
popup/popup.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"component": true
|
||||
}
|
||||
23
popup/popup.wxml
Normal file
23
popup/popup.wxml
Normal file
@@ -0,0 +1,23 @@
|
||||
<view wx:if="{{isVisible}}" class="popup-mask" bindtap="onMaskTap">
|
||||
<view class="popup-container" catchtap="preventClose">
|
||||
<view class="popup-content">
|
||||
<!-- 关闭按钮 -->
|
||||
<text class="popup-close" bindtap="closePopup">X</text>
|
||||
|
||||
<!-- 动态标题与内容 -->
|
||||
<block wx:if="{{popupType === 'activity'}}">
|
||||
<view class="popup-title">🎉 活动通知 🎉</view>
|
||||
<text class="popup-text">{{popupContent}}</text>
|
||||
|
||||
</block>
|
||||
<block wx:if="{{popupType === 'announcement'}}">
|
||||
<view class="popup-title">📢 公告通知 📢</view>
|
||||
<text class="popup-text">{{popupContent}}</text>
|
||||
|
||||
</block>
|
||||
|
||||
<!-- 按钮:立即前往 -->
|
||||
<button class="popup-btn" bindtap="onNavigate">{{buttonText}}</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
82
popup/popup.wxss
Normal file
82
popup/popup.wxss
Normal file
@@ -0,0 +1,82 @@
|
||||
/* 背景蒙版模糊 */
|
||||
.popup-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
backdrop-filter: blur(10px); /* 背景模糊 */
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
/* 弹窗容器 */
|
||||
.popup-container {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%) scale(0);
|
||||
background: linear-gradient(135deg, #fff, #f7f7f7);
|
||||
box-shadow: 0 12rpx 28rpx rgba(0, 0, 0, 0.2);
|
||||
border-radius: 20rpx;
|
||||
animation: popup-fade-in 0.3s ease-out forwards;
|
||||
z-index: 1001;
|
||||
padding: 30rpx;
|
||||
width: 80%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* 弹窗显示动画 */
|
||||
@keyframes popup-fade-in {
|
||||
0% {
|
||||
transform: translate(-50%, -50%) scale(0.5);
|
||||
opacity: 0;
|
||||
}
|
||||
100% {
|
||||
transform: translate(-50%, -50%) scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.popup-text {
|
||||
white-space: pre-wrap; /* 支持换行 */
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* 关闭按钮 */
|
||||
.popup-close {
|
||||
position: absolute;
|
||||
top: 10rpx;
|
||||
right: 20rpx;
|
||||
font-size: 40rpx;
|
||||
color: #aaa;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* 标题和内容 */
|
||||
.popup-title {
|
||||
font-size: 40rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.popup-body {
|
||||
font-size: 30rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.popup-btn {
|
||||
width: 260rpx; /* 按钮宽度 */
|
||||
height: 80rpx; /* 按钮高度 */
|
||||
background: linear-gradient(135deg, #6DD5FA, #2980B9); /* 按钮渐变背景 */
|
||||
color: #fff; /* 文字颜色 */
|
||||
text-align: center; /* 文字居中 */
|
||||
line-height: 80rpx; /* 文字垂直居中 */
|
||||
border-radius: 50rpx; /* 圆角 */
|
||||
font-size: 32rpx; /* 字体大小 */
|
||||
font-weight: bold; /* 字体加粗 */
|
||||
box-shadow: 0 8rpx 16rpx rgba(0, 0, 0, 0.2); /* 添加阴影 */
|
||||
transition: all 0.3s ease-in-out; /* 添加过渡动画 */
|
||||
cursor: pointer; /* 鼠标指针样式 */
|
||||
}
|
||||
Reference in New Issue
Block a user