Browse Source

Merge branch 'Xfy' of http://8.137.125.67:4000/SwtTt29/Program-mini into Xfy

pull/1/head
Default User 3 months ago
parent
commit
ab2e1f5ed1
  1. 10
      custom-tab-bar/index.js
  2. BIN
      images/轮播图3.jpg
  3. 7
      pages/buyer/index.js
  4. 17
      pages/index/index.js
  5. 5
      pages/index/index.wxml
  6. 6
      pages/index/index.wxss
  7. 380
      pages/settlement/index.js
  8. 2
      pages/settlement/index.wxml

10
custom-tab-bar/index.js

@ -199,7 +199,15 @@ Component({
// 检查全局数据中是否有控制tab-bar显示的状态 // 检查全局数据中是否有控制tab-bar显示的状态
let showTabBar = true let showTabBar = true
if (app && app.globalData && typeof app.globalData.showTabBar !== 'undefined') { // 如果是tabBar页面,默认显示tab-bar
const tabBarPages = this.data.tabBarItems.map(item => item.route)
if (tabBarPages.includes(currentRoute)) {
showTabBar = true
// 同时更新全局状态,确保一致性
if (app && app.globalData) {
app.globalData.showTabBar = true
}
} else if (app && app.globalData && typeof app.globalData.showTabBar !== 'undefined') {
showTabBar = app.globalData.showTabBar showTabBar = app.globalData.showTabBar
} }

BIN
images/轮播图3.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

7
pages/buyer/index.js

@ -493,12 +493,17 @@ Page({
// 更新自定义tabBar状态 // 更新自定义tabBar状态
if (typeof this.getTabBar === 'function' && this.getTabBar()) { if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({ this.getTabBar().setData({
selected: 1 selected: 1,
show: true // 确保导航栏显示
}); });
} }
// 更新全局tab状态 // 更新全局tab状态
const app = getApp(); const app = getApp();
app.updateCurrentTab('buyer'); app.updateCurrentTab('buyer');
// 确保全局tabBar显示状态为true
if (app.globalData) {
app.globalData.showTabBar = true;
}
}, },
// 带分页的本地存储回退函数 // 带分页的本地存储回退函数

17
pages/index/index.js

@ -11,7 +11,8 @@ Page({
userInfo: {}, userInfo: {},
needPhoneAuth: false, needPhoneAuth: false,
// 测试模式开关,用于在未完成微信认证时进行测试 // 测试模式开关,用于在未完成微信认证时进行测试
testMode: true testMode: true,
partnerstatus: '' // 用户入驻状态,用于显示入驻/未入驻
}, },
// 跳转到聊天页面 // 跳转到聊天页面
@ -952,7 +953,12 @@ Page({
app.globalData.userInfo = updatedUserInfo app.globalData.userInfo = updatedUserInfo
wx.setStorageSync('userInfo', updatedUserInfo) wx.setStorageSync('userInfo', updatedUserInfo)
this.setData({ userInfo: updatedUserInfo })
// 设置用户入驻状态
this.setData({
userInfo: updatedUserInfo,
partnerstatus: serverUserInfo.partnerstatus || ''
})
// 同步更新用户身份信息(当前身份由数据库决定) // 同步更新用户身份信息(当前身份由数据库决定)
if (serverUserInfo.type) { if (serverUserInfo.type) {
@ -979,7 +985,12 @@ Page({
app.globalData.userInfo = updatedUserInfo app.globalData.userInfo = updatedUserInfo
wx.setStorageSync('userInfo', updatedUserInfo) wx.setStorageSync('userInfo', updatedUserInfo)
this.setData({ userInfo: updatedUserInfo })
// 设置用户入驻状态
this.setData({
userInfo: updatedUserInfo,
partnerstatus: serverUserInfo.partnerstatus || ''
})
// 同步更新用户身份信息(当前身份由数据库决定) // 同步更新用户身份信息(当前身份由数据库决定)
if (serverUserInfo.type) { if (serverUserInfo.type) {

5
pages/index/index.wxml

@ -23,7 +23,10 @@
<!-- 第一行 --> <!-- 第一行 -->
<view class="btn-row"> <view class="btn-row">
<button class="btn message-btn" bindtap="navigateToChat">消息中心</button> <button class="btn message-btn" bindtap="navigateToChat">消息中心</button>
<button class="btn settlement-btn" bindtap="navigateToSettlement">立即入驻</button> <button
class="btn settlement-btn {{partnerstatus !== 'approved' ? 'not-approved' : ''}}"
bindtap="navigateToSettlement"
>{{partnerstatus === 'approved' ? '已入驻' : '立即入驻'}}</button>
</view> </view>
<!-- 第二行 --> <!-- 第二行 -->
<view class="btn-row full-width"> <view class="btn-row full-width">

6
pages/index/index.wxss

@ -119,6 +119,12 @@ page {
width: 100%; width: 100%;
} }
/* 未入驻按钮样式 */
.settlement-btn.not-approved {
background: rgba(255, 77, 79, 0.15);
color: #ff4d4f;
}
/* 按钮点击效果 */ /* 按钮点击效果 */
.btn:active { .btn:active {
transform: scale(0.98); transform: scale(0.98);

380
pages/settlement/index.js

@ -523,47 +523,47 @@ Page({
const openid = wx.getStorageSync('openid'); const openid = wx.getStorageSync('openid');
const userId = wx.getStorageSync('userId'); const userId = wx.getStorageSync('userId');
// 如果本地有openid,查询数据库验证用户是否真的存在 // 如果本地没有openid或用户信息,直接显示一键登录弹窗
if (openid) { if (!openid || !userId) {
try { console.log('本地没有用户信息,显示一键登录弹窗');
const API = require('../../utils/api');
console.log('查询数据库验证用户是否存在...');
const userRes = await API.getUserInfo(openid);
// 如果用户存在,继续提交申请
if (userRes && userRes.success && userRes.data) {
console.log('用户已在数据库中存在,跳过登录验证');
// 更新本地存储的用户信息
wx.setStorageSync('userInfo', userRes.data);
// 继续执行后续逻辑
} else {
// 用户不存在,需要登录
console.log('用户不存在于数据库中,需要登录');
// 保存当前表单数据
this.saveSettlementProgress();
// 显示登录弹窗
this.setData({
showAuthModal: true
});
return; // 取消提交申请
}
} catch (error) {
console.error('查询用户信息失败:', error);
// 查询失败,可能是网络问题或其他原因,继续使用本地存储的信息
console.log('查询失败,继续使用本地存储的用户信息:', openid, userId);
}
} else if (!openid || !userId) {
// 本地没有openid或userId,显示登录弹窗
console.log('本地没有用户信息,显示授权弹窗');
// 保存当前表单数据 // 保存当前表单数据
this.saveSettlementProgress(); this.saveSettlementProgress();
// 显示登录弹窗 // 直接显示一键登录弹窗
this.setData({ this.setData({
showAuthModal: true showOneKeyLoginModal: true
}); });
return; // 取消提交申请 return; // 取消提交申请
} }
// 如果本地有openid,查询数据库验证用户是否真的存在
try {
const API = require('../../utils/api');
console.log('查询数据库验证用户是否存在...');
const userRes = await API.getUserInfo(openid);
// 如果用户存在,继续提交申请
if (userRes && userRes.success && userRes.data) {
console.log('用户已在数据库中存在,跳过登录验证');
// 更新本地存储的用户信息
wx.setStorageSync('userInfo', userRes.data);
// 继续执行后续逻辑
} else {
// 用户不存在,需要登录
console.log('用户不存在于数据库中,需要登录');
// 保存当前表单数据
this.saveSettlementProgress();
// 直接显示一键登录弹窗
this.setData({
showOneKeyLoginModal: true
});
return; // 取消提交申请
}
} catch (error) {
console.error('查询用户信息失败:', error);
// 查询失败,可能是网络问题或其他原因,继续使用本地存储的信息
console.log('查询失败,继续使用本地存储的用户信息:', openid, userId);
}
console.log('使用用户信息提交申请:', openid, userId); console.log('使用用户信息提交申请:', openid, userId);
// 先上传所有文件 // 先上传所有文件
@ -697,27 +697,7 @@ Page({
return; return;
} }
// 检查用户是否已经获取手机号 // 先检查所有必填表单字段
let userInfo = wx.getStorageSync('userInfo');
if (!userInfo || !userInfo.phoneNumber || userInfo.phoneNumber === '未绑定') {
wx.showToast({
title: '请先授权手机号',
icon: 'none'
});
// 显示登录弹窗,引导用户授权手机号
this.setData({
showAuthModal: true
});
return;
}
// 如果用户已经获取手机号,确保手机号字段正确赋值
if (userInfo.phoneNumber && userInfo.phoneNumber !== '未绑定') {
submitData.phoneNumber = userInfo.phoneNumber;
contactPhone = userInfo.phoneNumber;
console.log('使用登录获取的手机号:', contactPhone);
}
if (!this.data.collaborationid) { if (!this.data.collaborationid) {
wx.showToast({ wx.showToast({
title: '请选择合作商身份', title: '请选择合作商身份',
@ -742,6 +722,21 @@ Page({
return; return;
} }
// 检查用户是否已经获取手机号
let userInfo = wx.getStorageSync('userInfo');
if (!userInfo || !userInfo.phoneNumber || userInfo.phoneNumber === '未绑定') {
// 直接显示一键登录弹窗,引导用户授权手机号
this.setData({
showOneKeyLoginModal: true
});
return;
}
// 如果用户已经获取手机号,确保手机号字段正确赋值
submitData.phoneNumber = userInfo.phoneNumber;
contactPhone = userInfo.phoneNumber;
console.log('使用登录获取的手机号:', contactPhone);
// 强制要求手机号 // 强制要求手机号
if (!contactPhone) { if (!contactPhone) {
wx.showToast({ wx.showToast({
@ -751,10 +746,6 @@ Page({
return; return;
} }
// 更新submitData中的手机号
submitData.phoneNumber = contactPhone;
console.log('使用的手机号:', contactPhone);
// 验证省市区字段是否填写完整(用于构建region字段) // 验证省市区字段是否填写完整(用于构建region字段)
if (!this.data.province || !this.data.city || !this.data.district) { if (!this.data.province || !this.data.city || !this.data.district) {
wx.showToast({ wx.showToast({
@ -764,6 +755,10 @@ Page({
return; return;
} }
// 更新submitData中的手机号
submitData.phoneNumber = contactPhone;
console.log('使用的手机号:', contactPhone);
// 记录省市区字段内容 // 记录省市区字段内容
console.log('省市区字段内容:', this.data.province, this.data.city, this.data.district); console.log('省市区字段内容:', this.data.province, this.data.city, this.data.district);
@ -873,14 +868,26 @@ Page({
console.log('用户完整数据:', userRes.data); console.log('用户完整数据:', userRes.data);
// 更新用户的申请状态 // 更新用户的申请状态
if (userRes.data && userRes.data.partnerstatus) { if (userRes.data && userRes.data.partnerstatus) {
this.setData({ // 构建要更新的数据对象,确保只设置存在的值
partnerstatus: userRes.data.partnerstatus, const updateData = {
applicationId: userRes.data.applicationId partnerstatus: userRes.data.partnerstatus
}); };
// 只有当applicationId存在且不为undefined时才设置
if (userRes.data.applicationId) {
updateData.applicationId = userRes.data.applicationId;
} else {
updateData.applicationId = null; // 设置为null而不是undefined
}
this.setData(updateData);
// 保存最新状态到本地存储 // 保存最新状态到本地存储
wx.setStorageSync('settlementStatus', userRes.data.partnerstatus); wx.setStorageSync('settlementStatus', userRes.data.partnerstatus);
if (userRes.data.applicationId) { if (userRes.data.applicationId) {
wx.setStorageSync('applicationId', userRes.data.applicationId); wx.setStorageSync('applicationId', userRes.data.applicationId);
} else {
wx.removeStorageSync('applicationId'); // 如果不存在则移除本地存储
} }
} }
}).catch(err => { }).catch(err => {
@ -960,75 +967,182 @@ Page({
// 关闭登录弹窗 // 关闭登录弹窗
this.setData({ this.setData({
showAuthModal: false showOneKeyLoginModal: false
}); });
if (e.detail.errMsg === 'getPhoneNumber:ok') { // 首先检查用户是否拒绝授权
// 用户同意授权 if (e.detail.errMsg !== 'getPhoneNumber:ok') {
wx.showLoading({ console.log('用户拒绝授权手机号');
title: '登录中...', wx.showToast({
mask: true title: '您已拒绝授权,操作已取消',
icon: 'none'
}); });
return;
}
// 用户同意授权
wx.showLoading({
title: '登录中...',
mask: true
});
try {
// 引入API服务
const API = require('../../utils/api.js');
// 1. 先执行微信登录获取code
const loginRes = await new Promise((resolve, reject) => {
wx.login({
success: resolve,
fail: reject
});
});
if (!loginRes.code) {
throw new Error('获取登录code失败');
}
console.log('获取登录code成功:', loginRes.code);
// 2. 使用code换取openid
const openidRes = await API.getOpenid(loginRes.code);
// 增强版响应处理逻辑,支持多种返回格式
let openid = null;
let userId = null;
let sessionKey = null;
// 优先从data字段获取数据
if (openidRes && openidRes.data && typeof openidRes.data === 'object') {
openid = openidRes.data.openid || openidRes.data.OpenID || null;
userId = openidRes.data.userId || openidRes.data.userid || null;
sessionKey = openidRes.data.session_key || openidRes.data.sessionKey || null;
}
// 如果data为空或不存在,尝试从响应对象直接获取
if (!openid && openidRes && typeof openidRes === 'object') {
console.warn('服务器返回格式可能不符合预期,data字段为空或不存在,但尝试从根对象提取信息:', openidRes);
openid = openidRes.openid || openidRes.OpenID || null;
userId = openidRes.userId || openidRes.userid || null;
sessionKey = openidRes.session_key || openidRes.sessionKey || null;
}
// 检查服务器状态信息
const isSuccess = openidRes && (openidRes.success === true || openidRes.code === 200);
if (!openid) {
throw new Error('获取openid失败: ' + (openidRes && openidRes.message ? openidRes.message : '未知错误'));
}
// 存储openid和session_key
wx.setStorageSync('openid', openid);
if (sessionKey) {
wx.setStorageSync('sessionKey', sessionKey);
}
// 确保始终使用从服务器获取的正式用户ID
if (userId) {
wx.setStorageSync('userId', userId);
}
console.log('获取openid成功并存储:', openid);
// 3. 上传手机号加密数据到服务器解密
const phoneData = {
...e.detail,
openid: openid,
sessionKey: sessionKey || ''
};
console.log('准备上传手机号加密数据到服务器');
const phoneRes = await API.uploadPhoneNumberData(phoneData);
// 改进手机号解密结果的处理逻辑
if (!phoneRes || (!phoneRes.success && !phoneRes.phoneNumber)) {
// 如果服务器返回格式不标准但包含手机号,也接受
if (!(phoneRes && phoneRes.phoneNumber)) {
throw new Error('获取手机号失败: ' + (phoneRes && phoneRes.message ? phoneRes.message : '未知错误'));
}
}
const phoneNumber = phoneRes.phoneNumber || '未绑定';
console.log('获取手机号成功:', phoneNumber);
// 4. 获取用户信息
let userInfo = {
name: '微信用户',
avatarUrl: '/images/default-avatar.png',
phoneNumber: phoneNumber,
gender: 0,
country: '',
province: '',
city: '',
language: 'zh_CN'
};
try { try {
// 调用API解密手机号 // 尝试获取用户微信头像和昵称
const app = getApp(); const userProfileRes = await new Promise((resolve, reject) => {
if (app && app.uploadPhoneNumberData) { wx.getUserProfile({
const result = await app.uploadPhoneNumberData(e.detail); desc: '用于完善会员资料',
success: resolve,
if (result && result.success) { fail: reject
// 保存用户信息到全局和本地存储 });
const userInfo = { });
name: '微信用户',
avatarUrl: '/images/default-avatar.png', if (userProfileRes && userProfileRes.userInfo) {
phoneNumber: result.phoneNumber || '未绑定', userInfo = {
gender: 0, ...userInfo,
country: '', ...userProfileRes.userInfo
province: '', };
city: '',
language: 'zh_CN'
};
// 保存到全局数据
app.globalData.userInfo = userInfo;
// 保存到本地存储
wx.setStorageSync('userInfo', userInfo);
console.log('用户信息已保存:', userInfo);
wx.hideLoading();
wx.showToast({
title: '登录成功',
icon: 'success',
duration: 1500,
complete: () => {
// 登录成功后关闭弹窗,让用户决定是否继续提交
setTimeout(() => {
this.closeOneKeyLoginModal();
this.setData({ showAuthModal: false });
}, 1500);
}
});
} else {
throw new Error(result.message || '登录失败');
}
} else {
// 备用方案:模拟登录
await this.performBackupLogin();
} }
} catch (error) { } catch (err) {
wx.hideLoading(); console.warn('获取用户头像昵称失败:', err);
console.error('手机号授权登录失败:', error); // 不影响主流程,使用默认值
wx.showToast({ }
title: '登录失败,请重试',
icon: 'none' // 5. 更新用户信息到服务器
try {
await API.updateUserInfo({
openid: openid,
phoneNumber: phoneNumber,
...userInfo
}); });
console.log('用户信息已更新到服务器');
} catch (err) {
console.warn('更新用户信息到服务器失败:', err);
// 不影响主流程,继续执行
} }
} else {
// 用户拒绝授权 // 6. 保存用户信息到全局和本地存储
const app = getApp();
if (app) {
app.globalData.userInfo = userInfo;
}
wx.setStorageSync('userInfo', userInfo);
console.log('用户信息已保存到本地存储:', userInfo);
wx.hideLoading();
wx.showToast({ wx.showToast({
title: '需要手机号授权才能继续', title: '登录成功',
icon: 'success',
duration: 1500,
complete: () => {
// 登录成功后关闭弹窗,让用户继续提交申请
setTimeout(() => {
this.closeOneKeyLoginModal();
// 用户登录成功后,可以选择自动提交申请
// 这里保持原逻辑,让用户手动点击提交
}, 1500);
}
});
} catch (error) {
wx.hideLoading();
console.error('手机号授权登录失败:', error);
wx.showToast({
title: '登录失败,请重试',
icon: 'none' icon: 'none'
}); });
} }
@ -1182,15 +1296,15 @@ Page({
}); });
} }
// 跳转到seller页面,不显示提示 // 跳转到index页面,不显示提示
wx.reLaunch({ wx.reLaunch({
url: '/pages/seller/index' url: '/pages/index/index'
}); });
}).catch(err => { }).catch(err => {
console.error('获取用户数据失败:', err); console.error('获取用户数据失败:', err);
// 即使获取失败也跳转到seller页面 // 即使获取失败也跳转到index页面
wx.reLaunch({ wx.reLaunch({
url: '/pages/seller/index' url: '/pages/index/index'
}); });
}); });
}, },
@ -1263,18 +1377,10 @@ Page({
completeApplication() { completeApplication() {
// 更新入驻状态为审核通过 // 更新入驻状态为审核通过
this.updateGlobalSettlementStatus('approved'); this.updateGlobalSettlementStatus('approved');
// 返回首页
wx.showToast({
title: '感谢您的提交,我们将尽快与您联系!',
icon: 'success'
});
// 延迟跳转到seller页面
setTimeout(() => {
wx.reLaunch({ wx.reLaunch({
url: '/pages/seller/index' url: '/pages/index/index'
}); });
}, 1500);
}, },
// 重置申请流程 // 重置申请流程

2
pages/settlement/index.wxml

@ -357,7 +357,7 @@
<view wx:if="{{showOneKeyLoginModal}}" class="auth-modal-overlay"> <view wx:if="{{showOneKeyLoginModal}}" class="auth-modal-overlay">
<view class="auth-modal-container"> <view class="auth-modal-container">
<view class="auth-modal-title">授权登录</view> <view class="auth-modal-title">授权登录</view>
<view class="auth-modal-content">请授权获取您的手机号用于登录</view> <view class="auth-modal-content">授权您的手机号后才能提交申请</view>
<view class="auth-modal-buttons"> <view class="auth-modal-buttons">
<button class="auth-primary-button" open-type="getPhoneNumber" bind:getphonenumber="onGetPhoneNumber">授权获取手机号</button> <button class="auth-primary-button" open-type="getPhoneNumber" bind:getphonenumber="onGetPhoneNumber">授权获取手机号</button>
<button class="auth-cancel-button" bindtap="closeOneKeyLoginModal">取消</button> <button class="auth-cancel-button" bindtap="closeOneKeyLoginModal">取消</button>

Loading…
Cancel
Save