From f39b6ec1fb681daf821fb5d2a04e93551d4ac8f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?=
<15778543+xufeiyang6017@user.noreply.gitee.com>
Date: Mon, 8 Dec 2025 11:52:54 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=88=9B=E5=BB=BA=E6=96=B0?=
=?UTF-8?q?=E8=B4=A7=E6=BA=90=E9=A1=B5=E9=9D=A2=E8=A1=A8=E5=8D=95=E9=A1=BA?=
=?UTF-8?q?=E5=BA=8F=E4=B8=BA=EF=BC=9A=E5=93=81=E7=A7=8D=E8=9B=8B=E9=BB=84?=
=?UTF-8?q?=E8=A7=84=E6=A0=BC=E5=9C=B0=E5=8C=BA=E4=BB=B7=E6=A0=BC=E6=95=B0?=
=?UTF-8?q?=E9=87=8F=E6=AF=9B=E9=87=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pages/create-supply/index.js | 71 ++++++++++++++++++++++++++++++++--
pages/create-supply/index.wxml | 34 +++++++++++-----
pages/create-supply/index.wxss | 34 ++++++++++++++++
pages/settlement/index.js | 45 ++++++++++++++++-----
server-example/server-mysql.js | 36 +++++++++++++++--
日报.md | 50 ------------------------
6 files changed, 193 insertions(+), 77 deletions(-)
delete mode 100644 日报.md
diff --git a/pages/create-supply/index.js b/pages/create-supply/index.js
index 7ed1d6a..e17aa49 100644
--- a/pages/create-supply/index.js
+++ b/pages/create-supply/index.js
@@ -15,24 +15,56 @@ Page({
grossWeight: '',
yolk: '', // 蛋黄
specification: '',
- images: [] // 图片数组
+ images: [], // 图片数组
+ province: '',
+ city: '',
+ district: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
- // 页面加载时的初始化
+ // 页面加载时从本地存储读取地区信息
+ const storedProvince = wx.getStorageSync('createSupplyProvince') || '';
+ const storedCity = wx.getStorageSync('createSupplyCity') || '';
+ const storedDistrict = wx.getStorageSync('createSupplyDistrict') || '';
+
+ // 即使部分数据存在,也加载已有的数据
+ if (storedProvince || storedCity || storedDistrict) {
+ this.setData({
+ province: storedProvince,
+ city: storedCity,
+ district: storedDistrict
+ });
+ }
},
/**
- * 返回上一页
+ * 返回按钮点击事件
*/
onBackTap: function () {
wx.navigateBack({
delta: 1
});
},
+
+ /**
+ * 生命周期函数--监听页面卸载
+ */
+ onUnload: function () {
+ // 页面卸载时不再自动保存地区数据,仅在用户明确点击确定时保存
+ },
+
+ /**
+ * 保存地区数据到本地存储
+ */
+ saveRegionToStorage: function () {
+ const { province, city, district } = this.data;
+ wx.setStorageSync('createSupplyProvince', province);
+ wx.setStorageSync('createSupplyCity', city);
+ wx.setStorageSync('createSupplyDistrict', district);
+ },
/**
* 品种输入处理
@@ -89,6 +121,28 @@ Page({
});
},
+ /**
+ * 地区选择处理
+ */
+ onRegionChange(e) {
+ // 只有当用户点击确定按钮时,code数组才会有值
+ if (e.detail.code && e.detail.code.length > 0) {
+ const value = e.detail.value;
+ const province = value[0] || '';
+ const city = value[1] || '';
+ const district = value[2] || '';
+
+ this.setData({
+ province: province,
+ city: city,
+ district: district
+ });
+
+ // 保存到本地存储,实现记忆功能
+ this.saveRegionToStorage();
+ }
+ },
+
/**
* 表单验证
*/
@@ -132,7 +186,10 @@ Page({
yolk: yolk || '',
specification: specification || '',
images: images,
- imageUrls: images
+ imageUrls: images,
+ province: province || '',
+ city: city || '',
+ district: district || ''
};
console.log('创建货源数据:', productData);
@@ -206,6 +263,9 @@ Page({
yolk: formData.yolk,
spec: formData.specification,
grossWeight: formData.grossWeight || '',
+ province: formData.province || '',
+ city: formData.city || '',
+ district: formData.district || '',
seller: sellerName,
status: apiResponse.product && apiResponse.product.status
? apiResponse.product.status
@@ -232,6 +292,9 @@ Page({
spec: formData.specification,
grossWeight: formData.grossWeight || '',
displayGrossWeight: formData.grossWeight || '',
+ province: formData.province || '',
+ city: formData.city || '',
+ district: formData.district || '',
seller: sellerName,
status: apiResponse.product && apiResponse.product.status
? apiResponse.product.status
diff --git a/pages/create-supply/index.wxml b/pages/create-supply/index.wxml
index 80ef419..9daac0c 100644
--- a/pages/create-supply/index.wxml
+++ b/pages/create-supply/index.wxml
@@ -16,28 +16,42 @@
- 价格 (元/斤) *
-
+ 蛋黄
+
- 数量 (斤) *
-
+ 规格
+
- 毛重 (斤)
-
+ 地区
+
+
+ {{province || city || district ? province + ' ' + city + ' ' + district : '请选择省市区'}}
+
+
- 蛋黄
-
+ 价格 (元/斤) *
+
- 规格
-
+ 数量 (斤) *
+
+
+
+
+ 毛重 (斤)
+
diff --git a/pages/create-supply/index.wxss b/pages/create-supply/index.wxss
index cd045cc..5bd659f 100644
--- a/pages/create-supply/index.wxss
+++ b/pages/create-supply/index.wxss
@@ -87,6 +87,40 @@ page {
outline: none;
}
+/* 地区选择器样式 */
+.region-picker {
+ width: 100%;
+ height: 80rpx;
+ border: 2rpx solid #e5e5e5;
+ border-radius: 12rpx;
+ padding: 0 20rpx;
+ font-size: 28rpx;
+ box-sizing: border-box;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ background-color: #fff;
+}
+
+.region-picker:hover {
+ border-color: #FF6B81;
+}
+
+.picker-content {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ width: 100%;
+}
+
+.picker-content text {
+ flex: 1;
+ color: #333;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
.image-upload-container {
margin-bottom: 30rpx;
}
diff --git a/pages/settlement/index.js b/pages/settlement/index.js
index 3f2f73b..5d9e427 100644
--- a/pages/settlement/index.js
+++ b/pages/settlement/index.js
@@ -523,9 +523,38 @@ Page({
const openid = wx.getStorageSync('openid');
const userId = wx.getStorageSync('userId');
- // 如果未登录,显示登录弹窗
- if (!openid || !userId) {
- console.log('用户未登录,显示授权弹窗');
+ // 如果本地有openid,查询数据库验证用户是否真的存在
+ if (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({
+ showAuthModal: true
+ });
+ return; // 取消提交申请
+ }
+ } catch (error) {
+ console.error('查询用户信息失败:', error);
+ // 查询失败,可能是网络问题或其他原因,继续使用本地存储的信息
+ console.log('查询失败,继续使用本地存储的用户信息:', openid, userId);
+ }
+ } else if (!openid || !userId) {
+ // 本地没有openid或userId,显示登录弹窗
+ console.log('本地没有用户信息,显示授权弹窗');
// 保存当前表单数据
this.saveSettlementProgress();
// 显示登录弹窗
@@ -535,7 +564,7 @@ Page({
return; // 取消提交申请
}
- console.log('使用已登录用户信息提交申请:', openid, userId);
+ console.log('使用用户信息提交申请:', openid, userId);
// 先上传所有文件
wx.showLoading({
@@ -974,12 +1003,10 @@ Page({
icon: 'success',
duration: 1500,
complete: () => {
- // 登录成功后关闭弹窗,并自动提交申请
+ // 登录成功后关闭弹窗,让用户决定是否继续提交
setTimeout(() => {
this.closeOneKeyLoginModal();
this.setData({ showAuthModal: false });
- // 自动提交申请
- this.submitApplication();
}, 1500);
}
});
@@ -1052,12 +1079,10 @@ Page({
icon: 'success',
duration: 1500,
complete: () => {
- // 登录成功后关闭弹窗,并自动提交申请
+ // 登录成功后关闭弹窗,让用户决定是否继续提交
setTimeout(() => {
this.closeOneKeyLoginModal();
this.setData({ showAuthModal: false });
- // 自动提交申请
- this.submitApplication();
}, 1500);
}
});
diff --git a/server-example/server-mysql.js b/server-example/server-mysql.js
index 86e59a4..9e60762 100644
--- a/server-example/server-mysql.js
+++ b/server-example/server-mysql.js
@@ -253,7 +253,7 @@ const sequelize = new Sequelize(
define: {
timestamps: false
},
- timezone: '+08:00' // 设置时区为UTC+8
+ timezone: '+00:00' // 设置时区为UTC
}
);
@@ -3652,11 +3652,17 @@ app.post('/api/cart/add', async (req, res) => {
try {
console.log(`准备创建/更新购物车项: userId=${cartData.userId}, productId=${cartData.productId}`);
if (existingItem) {
+ // 添加详细的时间调试日志
+ const updateCurrentDate = new Date();
+ const updateUtcTime = updateCurrentDate.toISOString();
+ console.log('购物车更新 - 当前时间对象:', updateCurrentDate);
+ console.log('购物车更新 - 转换后UTC时间:', updateUtcTime);
+ console.log('购物车更新 - 时区设置:', sequelize.options.timezone);
// 已存在,更新数量
await CartItem.update(
{
quantity: existingItem.quantity + cartData.quantity,
- updated_at: new Date()
+ updated_at: new Date().toISOString()
},
{
where: {
@@ -3665,9 +3671,24 @@ app.post('/api/cart/add', async (req, res) => {
}
);
console.log(`更新购物车项成功: id=${existingItem.id}, 新数量=${existingItem.quantity + cartData.quantity}`);
+
+ // 同步更新用户表的updated_at为UTC时间
+ const userUtcTime = new Date().toISOString();
+ console.log('用户表更新 - UTC时间:', userUtcTime);
+ await User.update(
+ { updated_at: userUtcTime },
+ { where: { userId: cartData.userId } }
+ );
+ console.log(`用户${cartData.userId}的updated_at已更新为UTC时间: ${userUtcTime}`);
} else {
// 不存在,创建新购物车项
console.log('创建新购物车项,所有字段:');
+ // 添加详细的时间调试日志
+ const currentDate = new Date();
+ const utcTime = currentDate.toISOString();
+ console.log('购物车创建 - 当前时间对象:', currentDate);
+ console.log('购物车创建 - 转换后UTC时间:', utcTime);
+ console.log('购物车创建 - 时区设置:', sequelize.options.timezone);
console.log(' userId:', cartData.userId);
console.log(' productId:', cartData.productId);
console.log(' productName:', cartData.productName);
@@ -3682,9 +3703,18 @@ app.post('/api/cart/add', async (req, res) => {
}
await CartItem.create({
...cartData,
- added_at: new Date()
+ added_at: new Date().toISOString()
});
console.log(`创建购物车项成功: userId=${cartData.userId}, productId=${cartData.productId}`);
+
+ // 同步更新用户表的updated_at为UTC时间
+ const updateUserUtcTime = new Date().toISOString();
+ console.log('用户表更新 - UTC时间:', updateUserUtcTime);
+ await User.update(
+ { updated_at: updateUserUtcTime },
+ { where: { userId: cartData.userId } }
+ );
+ console.log(`用户${cartData.userId}的updated_at已更新为UTC时间: ${updateUserUtcTime}`);
}
} catch (createError) {
console.error('创建/更新购物车项失败,可能是外键约束问题:', createError);
diff --git a/日报.md b/日报.md
deleted file mode 100644
index 019efb6..0000000
--- a/日报.md
+++ /dev/null
@@ -1,50 +0,0 @@
-# 工作日报
-
-## 日期
-2025年12月06日
-
-## 今日完成工作
-修复微信小程序"又鸟蛋平台"中创建/编辑货源页面的双击确定功能失效问题,并将代码提交到远程仓库。
-
-## 工作详情
-
-### 问题分析
-在创建和编辑货源时,双击商品名称、蛋黄和规格选择弹窗中的选项时,双击确定功能失效,用户无法通过双击快速完成选择。
-
-### 解决方案
-1. **定位问题**:检查handleDoubleTap函数实现,发现lastTapTime对象使用时未进行存在性检查
-2. **修复代码**:在`pages/seller/index.js`中修改handleDoubleTap函数:
- - 添加lastTapTime对象存在性检查
- - 优化双击处理逻辑,在触发后清除记录
- - 确保双击功能在商品名称、蛋黄和规格选择弹窗中正常工作
-
-### 代码修改
-**修改文件**:`pages/seller/index.js`
-**修改内容**:
-- 在handleDoubleTap函数中添加lastTapTime对象存在性检查
-- 提取index变量,优化代码结构
-- 在双击触发后添加清除记录逻辑
-
-**修改文件**:`pages/seller/index.wxml`
-**修改内容**:确保商品名称、蛋黄和规格选择弹窗的选项均有正确的data-index属性
-
-### 代码提交
-- 将修改的文件添加到暂存区
-- 提交信息:"修复双击确定功能失效问题"
-- 推送到远程仓库new-origin的Xfy分支
-- 创建PR链接:http://8.137.125.67:4000/SwtTt29/Program-mini/compare/master...Xfy
-
-## 遇到的问题及解决方法
-
-1. **问题**:npm run dev命令失败,提示缺少dev脚本
- **解决方法**:查看package.json文件,发现只有check和start命令,使用npm start命令启动项目
-
-2. **问题**:服务器启动失败,提示端口3003被占用
- **解决方法**:检查后台运行的命令,发现已有服务在运行,无需再次启动
-
-## 明日计划
-无
-
-## 其他
-- 修复后的双击功能已测试,可以正常使用
-- 代码已成功提交到远程仓库,等待合并
\ No newline at end of file