Browse Source

实现添加桌面功能:点击添加桌面按钮弹出引导框,帮助用户将小程序添加到手机桌面

pull/19/head
徐飞洋 2 months ago
parent
commit
2948cc8faf
  1. 20
      pages/index/index.js
  2. 32
      pages/index/index.wxml
  3. 110
      pages/index/index.wxss

20
pages/index/index.js

@ -55,6 +55,7 @@ Page({
name: '', name: '',
showAuthModal: false, showAuthModal: false,
showOneKeyLoginModal: false, showOneKeyLoginModal: false,
showAddToHomeModal: false,
userInfo: {}, userInfo: {},
needPhoneAuth: false, needPhoneAuth: false,
testMode: true, testMode: true,
@ -2277,6 +2278,25 @@ Page({
}) })
}, },
// 显示添加桌面引导框
showAddToHomeModal: function () {
this.setData({
showAddToHomeModal: true
});
},
// 隐藏添加桌面引导框
hideAddToHomeModal: function () {
this.setData({
showAddToHomeModal: false
});
},
// 阻止事件冒泡
stopPropagation: function (e) {
e.stopPropagation();
},
// 跳转到货源管理页面 // 跳转到货源管理页面
navigateToGoods: function () { navigateToGoods: function () {
this.setData({ this.setData({

32
pages/index/index.wxml

@ -183,12 +183,40 @@
<text class="function-btn-icon">🚻</text> <text class="function-btn-icon">🚻</text>
<text class="function-btn-text">我们</text> <text class="function-btn-text">我们</text>
</view> </view>
<view class="function-btn" bindtap="navigateToCooperation"> <view class="function-btn" bindtap="showAddToHomeModal">
<text class="function-btn-icon">🚻</text> <text class="function-btn-icon"></text>
<text class="function-btn-text">添加桌面</text> <text class="function-btn-text">添加桌面</text>
</view> </view>
</view> </view>
<!-- 添加桌面引导框 -->
<view class="add-to-home-modal" wx:if="{{showAddToHomeModal}}" bindtap="hideAddToHomeModal">
<view class="modal-content" bindtap="stopPropagation">
<view class="modal-header">
<text class="modal-title">添加到桌面</text>
<text class="modal-close" bindtap="hideAddToHomeModal">×</text>
</view>
<view class="modal-body">
<text class="modal-text">为了方便您下次使用,请将小程序添加到手机桌面:</text>
<view class="step">
<text class="step-number">1</text>
<text class="step-text">点击右上角的【...】</text>
</view>
<view class="step">
<text class="step-number">2</text>
<text class="step-text">在弹出菜单中选择【添加到桌面】</text>
</view>
<view class="step">
<text class="step-number">3</text>
<text class="step-text">返回桌面即可快速访问</text>
</view>
</view>
<view class="modal-footer">
<button class="modal-button" bindtap="hideAddToHomeModal">我知道了</button>
</view>
</view>
</view>
<!-- 广告走马灯轮播图 --> <!-- 广告走马灯轮播图 -->
<view class="ad-carousel"> <view class="ad-carousel">
<swiper <swiper

110
pages/index/index.wxss

@ -2309,8 +2309,116 @@ video.product-media {
to { transform: translateY(0); } to { transform: translateY(0); }
} }
/* 淡入动画 */ /* 娣″叆鍔ㄧ敾 */
@keyframes fadeIn { @keyframes fadeIn {
from { opacity: 0; } from { opacity: 0; }
to { opacity: 1; } to { opacity: 1; }
} }
/* 添加桌面引导框样式 */
.add-to-home-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
display: flex;
align-items: center;
justify-content: center;
z-index: 999;
}
.modal-content {
background-color: #ffffff;
border-radius: 12rpx;
padding: 40rpx;
width: 80%;
max-width: 500rpx;
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.2);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30rpx;
padding-bottom: 20rpx;
border-bottom: 1rpx solid #f0f0f0;
}
.modal-title {
font-size: 32rpx;
font-weight: 700;
color: #262626;
}
.modal-close {
font-size: 40rpx;
color: #999;
cursor: pointer;
line-height: 1;
}
.modal-body {
margin-bottom: 40rpx;
}
.modal-text {
font-size: 28rpx;
color: #666;
line-height: 1.6;
margin-bottom: 30rpx;
display: block;
}
.step {
display: flex;
align-items: center;
margin-bottom: 24rpx;
}
.step-number {
width: 44rpx;
height: 44rpx;
border-radius: 50%;
background-color: #1890ff;
color: #ffffff;
font-size: 24rpx;
font-weight: 700;
display: flex;
align-items: center;
justify-content: center;
margin-right: 16rpx;
flex-shrink: 0;
}
.step-text {
font-size: 28rpx;
color: #666;
line-height: 1.5;
}
.modal-footer {
display: flex;
justify-content: center;
}
.modal-button {
background-color: #1890ff;
color: #ffffff;
border-radius: 8rpx;
padding: 0 48rpx;
height: 80rpx;
line-height: 80rpx;
font-size: 28rpx;
font-weight: 700;
border: none;
outline: none;
cursor: pointer;
transition: background-color 0.3s;
}
.modal-button:active {
background-color: #40a9ff;
}

Loading…
Cancel
Save