Browse Source

Merge pull request 'Xfy' (#3) from Xfy into Main

Reviewed-on: http://8.137.125.67:4000/SwtTt29/Program-mini/pulls/3
pull/1/head
xfy 3 months ago
parent
commit
f295cc12b2
  1. 0
      pages/buyer/goods-detail.js
  2. 0
      pages/buyer/goods-detail.json
  3. 0
      pages/buyer/goods-detail.wxml
  4. 0
      pages/buyer/goods-detail.wxss
  5. 4
      pages/buyer/index.js
  6. 36
      pages/buyer/index.wxml
  7. 63
      pages/buyer/index.wxss
  8. 40
      pages/index/index.wxml
  9. 50
      pages/index/index.wxss
  10. 48
      pages/seller/index.js
  11. 12
      pages/seller/index.wxml
  12. 47
      pages/seller/index.wxss
  13. 14
      pages/settlement/index.js
  14. 39
      pages/settlement/index.wxml
  15. 63
      pages/settlement/index.wxss
  16. 76
      utils/api.js

0
pages/buyer/goods-detail.js

0
pages/buyer/goods-detail.json

0
pages/buyer/goods-detail.wxml

0
pages/buyer/goods-detail.wxss

4
pages/buyer/index.js

@ -132,6 +132,10 @@ Page({
return;
}
// 点击"我想要"后,将用户类型设置为buyer
const API = require('../../utils/api.js');
API.updateUserType('buyer');
// 1. 前置验证
if (!goodsId) {
console.error('商品ID为空,无法预约');

36
pages/buyer/index.wxml

@ -137,33 +137,25 @@
</view>
<!-- 未授权登录提示弹窗 -->
<view wx:if="{{showAuthModal}}" class="modal-overlay" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); display: flex; justify-content: center; align-items: center; z-index: 9999;">
<view class="modal-container" style="background: white; padding: 40rpx; border-radius: 16rpx; width: 80%; max-width: 500rpx; text-align: center;">
<view class="modal-title" style="font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #333;">
<text>提示</text>
</view>
<view class="modal-content" style="font-size: 28rpx; color: #666; margin-bottom: 40rpx; line-height: 1.5;">
<text>请先登录后再预约商品</text>
</view>
<view class="modal-buttons">
<button class="primary-button" style="background-color: #1677ff; color: white; font-size: 28rpx; line-height: 80rpx; border-radius: 8rpx; margin-bottom: 20rpx;" bindtap="showOneKeyLogin">一键登录</button>
<button class="cancel-button" style="background-color: #f5f5f5; color: #333; font-size: 28rpx; line-height: 80rpx; border-radius: 8rpx;" bindtap="closeAuthModal">取消</button>
<view wx:if="{{showAuthModal}}" class="auth-modal-overlay">
<view class="auth-modal-container">
<view class="auth-modal-title">提示</view>
<view class="auth-modal-content">请先登录后再操作</view>
<view class="auth-modal-buttons">
<button class="auth-primary-button" bindtap="showOneKeyLogin">一键登录</button>
<button class="auth-cancel-button" bindtap="closeAuthModal">取消</button>
</view>
</view>
</view>
<!-- 一键登录弹窗 -->
<view wx:if="{{showOneKeyLoginModal}}" class="modal-overlay" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); display: flex; justify-content: center; align-items: center; z-index: 9999;">
<view class="modal-container" style="background: white; padding: 40rpx; border-radius: 16rpx; width: 80%; max-width: 500rpx; text-align: center;">
<view class="modal-title" style="font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #333;">
<text>授权登录</text>
</view>
<view class="modal-content" style="font-size: 28rpx; color: #666; margin-bottom: 40rpx; line-height: 1.5;">
<text>请授权获取您的手机号用于登录</text>
</view>
<view class="modal-buttons">
<button class="primary-button" open-type="getPhoneNumber" bind:getphonenumber="onGetPhoneNumber" style="background-color: #1677ff; color: white; font-size: 28rpx; line-height: 80rpx; border-radius: 8rpx; margin-bottom: 20rpx;">授权获取手机号</button>
<button class="cancel-button" style="background-color: #f5f5f5; color: #333; font-size: 28rpx; line-height: 80rpx; border-radius: 8rpx;" bindtap="closeOneKeyLoginModal">取消</button>
<view wx:if="{{showOneKeyLoginModal}}" class="auth-modal-overlay">
<view class="auth-modal-container">
<view class="auth-modal-title">授权登录</view>
<view class="auth-modal-content">请授权获取您的手机号用于登录</view>
<view class="auth-modal-buttons">
<button class="auth-primary-button" open-type="getPhoneNumber" bind:getphonenumber="onGetPhoneNumber">授权获取手机号</button>
<button class="auth-cancel-button" bindtap="closeOneKeyLoginModal">取消</button>
</view>
</view>
</view>

63
pages/buyer/index.wxss

@ -475,4 +475,67 @@ button:after {
height: 32vh;
width: 100%;
box-sizing: border-box;
}
/* 统一登录授权弹窗样式 */
.auth-modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 1002;
}
.auth-modal-container {
background-color: #fff;
border-radius: 20rpx;
width: 80%;
max-width: 500rpx;
padding: 40rpx;
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.15);
}
.auth-modal-title {
font-size: 36rpx;
font-weight: bold;
color: #333;
text-align: center;
margin-bottom: 30rpx;
}
.auth-modal-content {
font-size: 32rpx;
line-height: 1.5;
color: #666;
text-align: center;
margin-bottom: 40rpx;
}
.auth-modal-buttons {
display: flex;
flex-direction: column;
gap: 20rpx;
}
.auth-primary-button {
background-color: #1677ff;
color: #fff;
font-size: 32rpx;
line-height: 1.5;
border-radius: 8rpx;
padding: 20rpx 0;
}
.auth-cancel-button {
background-color: #f5f5f5;
color: #666;
font-size: 32rpx;
line-height: 1.5;
border-radius: 8rpx;
padding: 20rpx 0;
}

40
pages/index/index.wxml

@ -19,37 +19,25 @@
</view>
<!-- 未授权登录提示弹窗 -->
<view wx:if="{{showAuthModal}}" class="modal-overlay">
<view class="modal-container">
<view class="modal-title">
<text>提示</text>
</view>
<view class="modal-content">
<text>您还没有授权登录</text>
</view>
<view class="modal-buttons">
<button class="primary-button" bindtap="showOneKeyLogin">
一键登录
</button>
<button class="cancel-button" bindtap="closeAuthModal">取消</button>
<view wx:if="{{showAuthModal}}" class="auth-modal-overlay">
<view class="auth-modal-container">
<view class="auth-modal-title">提示</view>
<view class="auth-modal-content">请先登录后再操作</view>
<view class="auth-modal-buttons">
<button class="auth-primary-button" bindtap="showOneKeyLogin">一键登录</button>
<button class="auth-cancel-button" bindtap="closeAuthModal">取消</button>
</view>
</view>
</view>
<!-- 一键登录弹窗 -->
<view wx:if="{{showOneKeyLoginModal}}" class="modal-overlay">
<view class="modal-container">
<view class="modal-title">
<text>授权登录</text>
</view>
<view class="modal-content">
<text>请授权获取您的手机号用于登录</text>
</view>
<view class="modal-buttons">
<button class="primary-button" open-type="getPhoneNumber" bind:getphonenumber="onGetPhoneNumber">
授权获取手机号
</button>
<button class="cancel-button" bindtap="closeOneKeyLoginModal">取消</button>
<view wx:if="{{showOneKeyLoginModal}}" class="auth-modal-overlay">
<view class="auth-modal-container">
<view class="auth-modal-title">授权登录</view>
<view class="auth-modal-content">请授权获取您的手机号用于登录</view>
<view class="auth-modal-buttons">
<button class="auth-primary-button" open-type="getPhoneNumber" bind:getphonenumber="onGetPhoneNumber">授权获取手机号</button>
<button class="auth-cancel-button" bindtap="closeOneKeyLoginModal">取消</button>
</view>
</view>
</view>

50
pages/index/index.wxss

@ -109,7 +109,7 @@ page {
}
/* 弹窗样式 */
.modal-overlay {
.auth-modal-overlay {
position: fixed;
top: 0;
left: 0;
@ -119,38 +119,56 @@ page {
display: flex;
justify-content: center;
align-items: center;
z-index: 999;
z-index: 1002;
}
.modal-container {
background-color: white;
border-radius: 16rpx;
.auth-modal-container {
background-color: #fff;
border-radius: 20rpx;
width: 80%;
max-width: 500rpx;
padding: 40rpx;
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.15);
}
.modal-title {
text-align: center;
margin-bottom: 30rpx;
}
.modal-title text {
.auth-modal-title {
font-size: 36rpx;
font-weight: bold;
color: #333;
text-align: center;
margin-bottom: 30rpx;
}
.modal-content {
.auth-modal-content {
font-size: 32rpx;
line-height: 1.5;
color: #666;
text-align: center;
margin-bottom: 40rpx;
color: #666;
}
.modal-content text {
.auth-modal-buttons {
display: flex;
flex-direction: column;
gap: 20rpx;
}
.auth-primary-button {
background-color: #1677ff;
color: #fff;
font-size: 32rpx;
line-height: 1.5;
border-radius: 8rpx;
padding: 20rpx 0;
}
.modal-buttons {
text-align: center;
.auth-cancel-button {
background-color: #f5f5f5;
color: #666;
font-size: 32rpx;
line-height: 1.5;
border-radius: 8rpx;
padding: 20rpx 0;
}
.primary-button {

48
pages/seller/index.js

@ -1165,6 +1165,10 @@ Page({
try {
const res = await API.uploadUserInfo(uploadData)
console.log('用户信息上传成功:', res)
// 入驻成功后,将用户类型设置为seller
API.updateUserType('seller');
return res
} catch (err) {
console.error('用户信息上传失败:', err)
@ -1207,10 +1211,12 @@ Page({
wx.switchTab({ url: '/pages/buyer/index' })
} else {
// 卖家登录成功后,重新显示创建货源弹窗
// 从本地存储加载保存的表单数据
const savedSupply = wx.getStorageSync('newSupplyDraft') || { name: '', price: '', minOrder: '', yolk: '', spec: '', imageUrls: [] };
this.setData({
showImagePreview: false,
showModal: true,
newSupply: { name: '', price: '', minOrder: '', yolk: '', spec: '', imageUrls: [] }
newSupply: savedSupply
});
this.disablePageScroll();
}
@ -1397,6 +1403,8 @@ Page({
if (!userId || !openid || !userInfo) {
console.log('用户未登录,显示登录提示');
// 登录前保存当前表单数据到本地存储
wx.setStorageSync('newSupplyDraft', this.data.newSupply);
// 用户未登录,显示未授权提示弹窗
wx.showModal({
title: '登录提示',
@ -2895,6 +2903,29 @@ Page({
});
},
// 双击检测变量
lastTapTime: {},
tapCount: {},
// 通用双击检测函数
handleDoubleTap: function(e, type, callback) {
const currentTime = Date.now();
const tapKey = `${type}-${e.currentTarget.dataset.index}`;
const lastTap = this.lastTapTime[tapKey] || 0;
const tapInterval = currentTime - lastTap;
if (tapInterval < 300 && tapInterval > 0) {
// 双击事件触发,执行确认选择
callback();
} else {
// 单击事件触发,执行选择操作
this.lastTapTime[tapKey] = currentTime;
setTimeout(() => {
delete this.lastTapTime[tapKey];
}, 300);
}
},
// 弹窗中选择规格
onModalSpecSelect: function (e) {
const index = e.currentTarget.dataset.index;
@ -2903,6 +2934,11 @@ Page({
selectedModalSpecIndex: index,
modalSpecSearchKeyword: selectedSpec // 自动填充搜索框为当前选择的规格
});
// 检测双击
this.handleDoubleTap(e, 'spec', () => {
this.confirmSpecSelection();
});
},
// 确认规格选择
@ -3393,6 +3429,11 @@ Page({
this.setData({
selectedNameIndex: index
});
// 检测双击
this.handleDoubleTap(e, 'name', () => {
this.confirmNameSelection();
});
},
confirmNameSelection() {
@ -3469,6 +3510,11 @@ Page({
this.setData({
selectedYolkIndex: index
});
// 检测双击
this.handleDoubleTap(e, 'yolk', () => {
this.confirmYolkSelection();
});
},
confirmYolkSelection() {

12
pages/seller/index.wxml

@ -803,16 +803,10 @@
<!-- 未授权登录提示弹窗 -->
<view wx:if="{{showAuthModal}}" class="auth-modal-overlay">
<view class="auth-modal-container">
<view class="auth-modal-title">
<text>提示</text>
</view>
<view class="auth-modal-content">
<text>您还没有授权登录</text>
</view>
<view class="auth-modal-title">提示</view>
<view class="auth-modal-content">请先登录后再操作</view>
<view class="auth-modal-buttons">
<button class="auth-primary-button" bindtap="showOneKeyLogin">
一键登录
</button>
<button class="auth-primary-button" bindtap="showOneKeyLogin">一键登录</button>
<button class="auth-cancel-button" bindtap="closeAuthModal">取消</button>
</view>
</view>

47
pages/seller/index.wxss

@ -529,38 +529,35 @@ button {
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
background: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 999;
z-index: 9999;
}
.auth-modal-container {
background-color: white;
background: white;
padding: 40rpx;
border-radius: 16rpx;
width: 80%;
padding: 40rpx;
}
.auth-modal-title {
max-width: 500rpx;
text-align: center;
margin-bottom: 30rpx;
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.1);
}
.auth-modal-title text {
font-size: 36rpx;
.auth-modal-title {
font-size: 32rpx;
font-weight: bold;
margin-bottom: 30rpx;
color: #333;
}
.auth-modal-content {
text-align: center;
margin-bottom: 40rpx;
font-size: 28rpx;
color: #666;
}
.auth-modal-content text {
font-size: 32rpx;
margin-bottom: 40rpx;
line-height: 1.5;
}
.auth-modal-buttons {
@ -570,22 +567,18 @@ button {
.auth-primary-button {
background-color: #1677ff;
color: white;
width: 100%;
font-size: 28rpx;
line-height: 80rpx;
border-radius: 8rpx;
margin-bottom: 20rpx;
border: none;
font-size: 32rpx;
font-weight: 600;
text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.2);
}
.auth-cancel-button {
background: none;
color: #666;
border: none;
font-size: 32rpx;
font-weight: 600;
text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
background-color: #f5f5f5;
color: #333;
font-size: 28rpx;
line-height: 80rpx;
border-radius: 8rpx;
}
/* 头像选择样式 */

14
pages/settlement/index.js

@ -37,6 +37,7 @@ Page({
// 登录弹窗相关
showAuthModal: false,
showOneKeyLoginModal: false,
loginModalTitle: '请先登录',
loginModalContent: '为了您的账户安全,请先完成手机号登录',
showLoginButton: true
@ -825,6 +826,19 @@ Page({
});
},
// 显示一键登录弹窗
showOneKeyLogin() {
this.setData({
showAuthModal: false,
showOneKeyLoginModal: true
})
},
// 关闭一键登录弹窗
closeOneKeyLoginModal() {
this.setData({ showOneKeyLoginModal: false })
},
// 处理手机号授权
async onGetPhoneNumber(e) {
console.log('用户点击了手机号授权按钮', e.detail);

39
pages/settlement/index.wxml

@ -341,27 +341,26 @@
<!-- 登录授权弹窗 -->
<view class="auth-modal" wx:if="{{showAuthModal}}">
<view class="auth-content">
<view class="auth-header">
<view class="auth-title">登录授权</view>
<view class="auth-close" bindtap="closeAuthModal">×</view>
<!-- 未授权登录提示弹窗 -->
<view wx:if="{{showAuthModal}}" class="auth-modal-overlay">
<view class="auth-modal-container">
<view class="auth-modal-title">提示</view>
<view class="auth-modal-content">请先登录后再操作</view>
<view class="auth-modal-buttons">
<button class="auth-primary-button" bindtap="showOneKeyLogin">一键登录</button>
<button class="auth-cancel-button" bindtap="closeAuthModal">取消</button>
</view>
<view class="auth-body">
<view class="auth-icon">📱</view>
<view class="auth-text">为了提供更好的服务,需要获取您的手机号进行身份验证</view>
<!-- 手机号授权按钮 -->
<button
class="auth-btn"
open-type="getPhoneNumber"
bindgetphonenumber="onGetPhoneNumber"
>
授权手机号
</button>
<view class="auth-tip">授权后即可完成入驻申请</view>
</view>
</view>
<!-- 一键登录弹窗 -->
<view wx:if="{{showOneKeyLoginModal}}" class="auth-modal-overlay">
<view class="auth-modal-container">
<view class="auth-modal-title">授权登录</view>
<view class="auth-modal-content">请授权获取您的手机号用于登录</view>
<view class="auth-modal-buttons">
<button class="auth-primary-button" open-type="getPhoneNumber" bind:getphonenumber="onGetPhoneNumber">授权获取手机号</button>
<button class="auth-cancel-button" bindtap="closeOneKeyLoginModal">取消</button>
</view>
</view>
</view>

63
pages/settlement/index.wxss

@ -1552,28 +1552,63 @@ picker {
}
/* 登录授权弹窗 */
.auth-modal {
/* 统一的授权登录弹窗样式 */
.auth-modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1002;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 9999;
}
.auth-content {
background-color: white;
border-radius: 20rpx;
width: 85%;
max-width: 520rpx;
overflow: hidden;
display: flex;
flex-direction: column;
animation: modalSlideIn 0.3s ease-out;
.auth-modal-container {
background: white;
padding: 40rpx;
border-radius: 16rpx;
width: 80%;
max-width: 500rpx;
text-align: center;
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.1);
}
.auth-modal-title {
font-size: 32rpx;
font-weight: bold;
margin-bottom: 30rpx;
color: #333;
}
.auth-modal-content {
font-size: 28rpx;
color: #666;
margin-bottom: 40rpx;
line-height: 1.5;
}
.auth-modal-buttons {
text-align: center;
}
.auth-primary-button {
background-color: #1677ff;
color: white;
font-size: 28rpx;
line-height: 80rpx;
border-radius: 8rpx;
margin-bottom: 20rpx;
}
.auth-cancel-button {
background-color: #f5f5f5;
color: #333;
font-size: 28rpx;
line-height: 80rpx;
border-radius: 8rpx;
}
@keyframes modalSlideIn {

76
utils/api.js

@ -1570,6 +1570,82 @@ module.exports = {
return request('/api/user/upload', 'POST', data);
},
// 更新用户类型
updateUserType: async (typeToAdd) => {
try {
const userId = wx.getStorageSync('userId');
const openid = wx.getStorageSync('openid');
const userInfo = wx.getStorageSync('userInfo');
if (!userId || !openid) {
console.log('用户未登录,无法更新用户类型');
return;
}
// 获取当前用户类型
let users = wx.getStorageSync('users') || {};
let currentType = users[userId] && users[userId].type ? users[userId].type : '';
// 计算新的用户类型
let newType = currentType;
// 如果要添加的类型与当前类型相同,则不改变
if (newType === typeToAdd) {
return;
}
// 如果当前类型为空,则直接设置为要添加的类型
if (!newType) {
newType = typeToAdd;
} else {
// 如果当前类型是buyer,要添加seller,则变为both
if (newType === 'buyer' && typeToAdd === 'seller') {
newType = 'both';
}
// 如果当前类型是seller,要添加buyer,则变为both
else if (newType === 'seller' && typeToAdd === 'buyer') {
newType = 'both';
}
}
// 如果类型没有变化,不需要更新
if (newType === currentType) {
return;
}
// 更新本地存储
if (!users[userId]) {
users[userId] = {};
}
users[userId].type = newType;
wx.setStorageSync('users', users);
// 更新全局数据
const app = getApp();
app.globalData.userType = newType;
// 上传到服务器
const uploadData = {
userId,
openid,
...userInfo,
type: newType,
timestamp: Date.now()
};
// 调用用户信息更新API
return API.request({
url: '/api/user/update',
method: 'POST',
data: uploadData
});
} catch (error) {
console.error('更新用户类型失败:', error);
throw error;
}
},
// 获取用户信息用于调试
getUserInfoForDebug: function () {
const openid = wx.getStorageSync('openid');

Loading…
Cancel
Save