From 6e89b2ef98749c92ef47e714c9905a4ed3caff8b Mon Sep 17 00:00:00 2001 From: Default User Date: Tue, 9 Dec 2025 13:34:34 +0800 Subject: [PATCH] Update nickName to name fields in frontend code --- page.html | 480 +++++++++++++++++++++++++++++++++ pages/buyer/index.js | 16 +- pages/buyer/index.wxml | 2 +- pages/create-supply/index.js | 4 +- pages/index/index.js | 16 +- pages/index/index.wxml | 2 +- pages/profile/index.js | 16 +- pages/publish/index.js | 2 +- pages/seller/index.js | 10 +- pages/seller/index.wxml | 2 +- pages/settlement/index.js | 4 +- server-example/server-mysql.js | 53 ++-- 12 files changed, 544 insertions(+), 63 deletions(-) create mode 100644 page.html diff --git a/page.html b/page.html new file mode 100644 index 0000000..db31592 --- /dev/null +++ b/page.html @@ -0,0 +1,480 @@ + + + + + + + 国内新闻_新闻中心_新浪网 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+ + + + + +
+ + + +
+ +
+
+ +
+
+
    +
    +
    + + +
    +
    +
    +
    + + + + +
    + + + +
    +
    + + + icon关闭 + + + + + + + + + + + + + + + + +
    + +
    +
    + + + + + + +
    +
    + +
    + + + + + + + 下载新浪新闻 + + + + + 新浪新闻App + + + + +
    +

    意见反馈

    +
    + + +
    +

    返回顶部

    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pages/buyer/index.js b/pages/buyer/index.js index 7d5d0df..8b1cc66 100644 --- a/pages/buyer/index.js +++ b/pages/buyer/index.js @@ -640,7 +640,7 @@ Page({ region: product.region || '', // 【新增】添加地区字段 grossWeight: grossWeightValue, // 确保不为null displayGrossWeight: formatGrossWeight(grossWeightValue, product.weight), - seller: product.seller && product.seller.nickName ? product.seller.nickName : '未知卖家', + seller: product.seller && (product.seller.name || product.seller.nickName) ? (product.seller.name || product.seller.nickName) : '未知卖家', status: product.status || 'published', imageUrls: product.imageUrls || [], reservedCount: reservedCount, @@ -838,7 +838,7 @@ Page({ region: product.region || '', // 【新增】添加地区字段 grossWeight: grossWeightValue, displayGrossWeight: formatGrossWeight(grossWeightValue, product.weight), - seller: product.seller && product.seller.nickName ? product.seller.nickName : '未知卖家', + seller: product.seller && (product.seller.name || product.seller.nickName) ? (product.seller.name || product.seller.nickName) : '未知卖家', status: product.status || 'published', imageUrls: product.imageUrls || [], createdAt: product.created_at || product.createTime || null, @@ -1517,7 +1517,7 @@ Page({ const userInfo = { userId: res.data.id, openid: openid, - nickname: res.data.nickname || '', + name: res.data.name || res.data.nickname || '', avatarUrl: res.data.avatar || '', type: res.data.type }; @@ -1618,9 +1618,9 @@ Page({ // 获取用户名 getUserName: function (e) { console.log('获取用户名:', e); - const { nickname } = e.detail.value; + const { name } = e.detail.value; - if (!nickname || nickname.trim() === '') { + if (!name || name.trim() === '') { wx.showToast({ title: '昵称不能为空', icon: 'none' @@ -1629,7 +1629,7 @@ Page({ } const userInfo = { - nickname: nickname.trim(), + name: name.trim(), avatarUrl: this.data.avatarUrl }; @@ -1727,7 +1727,7 @@ Page({ const userInfo = { openid: res.data.openid, userId: res.data.userId, - nickname: userProfile.userInfo.nickName, + name: userProfile.userInfo.name || userProfile.userInfo.nickName, avatarUrl: userProfile.userInfo.avatarUrl, type: this.data.pendingUserType }; @@ -1767,7 +1767,7 @@ Page({ const userInfo = { openid: res.data.openid, userId: res.data.userId, - nickname: '微信用户', + name: '微信用户', avatarUrl: '/images/default-avatar.png', type: this.data.pendingUserType }; diff --git a/pages/buyer/index.wxml b/pages/buyer/index.wxml index e0aec79..3120189 100644 --- a/pages/buyer/index.wxml +++ b/pages/buyer/index.wxml @@ -173,7 +173,7 @@
    - + diff --git a/pages/create-supply/index.js b/pages/create-supply/index.js index e17aa49..7365a8b 100644 --- a/pages/create-supply/index.js +++ b/pages/create-supply/index.js @@ -240,8 +240,8 @@ Page({ // 获取卖家信息 const users = wx.getStorageSync('users') || {}; - const sellerName = users[userId] && users[userId].info && users[userId].info.nickName - ? users[userId].info.nickName + const sellerName = users[userId] && users[userId].info && (users[userId].info.name || users[userId].info.nickName) + ? (users[userId].info.name || users[userId].info.nickName) : '未知卖家'; // 获取当前已有的货源列表 diff --git a/pages/index/index.js b/pages/index/index.js index 1456b7a..bce806b 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -5,7 +5,7 @@ Page({ currentUserType: null, showUserInfoForm: false, avatarUrl: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0', - nickname: '', + name: '', showAuthModal: false, showOneKeyLoginModal: false, // 测试模式开关,用于在未完成微信认证时进行测试 @@ -295,7 +295,7 @@ Page({ // 6. 创建用户信息 const tempUserInfo = { - nickName: userProfile ? userProfile.userInfo.nickName : '微信用户', + name: userProfile ? (userProfile.userInfo.name || userProfile.userInfo.nickName) : '微信用户', // 获取微信头像失败时使用微信默认头像,而不是本地头像 avatarUrl: userProfile ? userProfile.userInfo.avatarUrl : 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0', gender: userProfile ? userProfile.userInfo.gender : 0, @@ -425,7 +425,7 @@ Page({ // 5. 创建模拟用户信息 const mockUserInfo = { - nickName: '测试用户', + name: '测试用户', avatarUrl: this.data.avatarUrl, gender: 0, country: '测试国家', @@ -659,7 +659,7 @@ Page({ // 创建临时用户信息 const tempUserInfo = { - nickName: '微信用户', + name: '微信用户', avatarUrl: this.data.avatarUrl, gender: 0, country: '', @@ -739,7 +739,7 @@ Page({ const completeUserInfo = { ...userInfo, // 确保包含服务器需要的必要字段 - nickName: userInfo.nickName || '测试用户' + name: userInfo.name || '测试用户' } try { @@ -772,10 +772,10 @@ Page({ // 处理昵称提交 getUserName(e) { - const { nickname } = e.detail.value + const { name } = e.detail.value const type = this.data.currentUserType - if (!nickname) { + if (!name) { wx.showToast({ title: '请输入昵称', icon: 'none', @@ -786,7 +786,7 @@ Page({ // 创建用户信息对象 const userInfo = { - nickName: nickname, + name: name, avatarUrl: this.data.avatarUrl, // 其他可能需要的字段 gender: 0, diff --git a/pages/index/index.wxml b/pages/index/index.wxml index a07ec97..c5f92ea 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -60,7 +60,7 @@ 昵称 - + diff --git a/pages/profile/index.js b/pages/profile/index.js index c7d7ee4..d42f19a 100644 --- a/pages/profile/index.js +++ b/pages/profile/index.js @@ -147,7 +147,7 @@ Page({ this.syncUserTypeFromServer(userId, serverUserInfo.type) } - console.log('用户信息已更新,昵称:', updatedUserInfo.nickName, '手机号:', updatedUserInfo.phoneNumber, '身份:', serverUserInfo.type) + console.log('用户信息已更新,昵称:', updatedUserInfo.name, '手机号:', updatedUserInfo.phoneNumber, '身份:', serverUserInfo.type) } }).catch(err => { console.error('从服务器获取用户信息失败:', err) @@ -450,7 +450,7 @@ Page({ const existingUserInfo = app.globalData.userInfo || wx.getStorageSync('userInfo') || {} const userInfo = { // 优先使用最新获取的微信头像和昵称,如果没有获取到则使用本地存储的 - nickName: (userProfile ? userProfile.userInfo.nickName : existingUserInfo.nickName) || '微信用户', + name: (userProfile ? (userProfile.userInfo.name || userProfile.userInfo.nickName) : existingUserInfo.name) || '微信用户', avatarUrl: (userProfile ? userProfile.userInfo.avatarUrl : existingUserInfo.avatarUrl) || 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0', gender: (userProfile ? userProfile.userInfo.gender : existingUserInfo.gender) || 0, country: (userProfile ? userProfile.userInfo.country : existingUserInfo.country) || '', @@ -560,7 +560,7 @@ Page({ const uploadData = { userId: userId, openid: openid, - nickName: userInfo.nickName, + name: userInfo.name, avatarUrl: userInfo.avatarUrl, // 添加头像URL字段 phoneNumber: userInfo.phoneNumber, // 添加phoneNumber字段,满足服务器要求 type: type, @@ -583,8 +583,8 @@ Page({ }, // 修改用户名称 - onEditNickName() { - const currentName = this.data.userInfo.nickName || '未登录'; + onEditName() { + const currentName = this.data.userInfo.name || '未登录'; wx.showModal({ title: '修改用户名称', @@ -635,7 +635,7 @@ Page({ }); // 更新用户信息 - this.updateNickName(newName).finally(() => { + this.updateName(newName).finally(() => { // 无论成功失败,都隐藏加载提示 wx.hideLoading(); }); @@ -645,14 +645,14 @@ Page({ }, // 更新用户名称 - updateNickName(newName) { + updateName(newName) { return new Promise((resolve, reject) => { try { // 更新本地和全局用户信息 const app = getApp(); const updatedUserInfo = { ...this.data.userInfo, - nickName: newName + name: newName }; // 保存到本地存储和全局状态 diff --git a/pages/publish/index.js b/pages/publish/index.js index d3aec9d..43e5058 100644 --- a/pages/publish/index.js +++ b/pages/publish/index.js @@ -397,7 +397,7 @@ Page({ // 获取卖家信息 const users = wx.getStorageSync('users') || {}; - const sellerName = users[userId] && users[userId].info && users[userId].info.nickName ? users[userId].info.nickName : '未知卖家'; + const sellerName = users[userId] && users[userId].info && (users[userId].info.name || users[userId].info.nickName) ? (users[userId].info.name || users[userId].info.nickName) : '未知卖家'; // 保存到本地存储 setTimeout(() => { diff --git a/pages/seller/index.js b/pages/seller/index.js index e5275fd..dd6fc85 100644 --- a/pages/seller/index.js +++ b/pages/seller/index.js @@ -2189,10 +2189,10 @@ Page({ // 处理昵称提交 getUserName(e) { - const { nickname } = e.detail.value + const { name } = e.detail.value const type = 'seller' // 卖家页面固定为卖家类型 - if (!nickname) { + if (!name) { wx.showToast({ title: '请输入昵称', icon: 'none', @@ -2203,7 +2203,7 @@ Page({ // 创建用户信息对象 const userInfo = { - nickName: nickname, + name: name, avatarUrl: this.data.avatarUrl, gender: 0, country: '', @@ -2376,7 +2376,7 @@ Page({ // 5. 获取用户微信头像和昵称 let userProfile = null; let tempUserInfo = { - nickName: '微信用户', + name: '微信用户', avatarUrl: this.data.avatarUrl, gender: 0, country: '', @@ -2398,7 +2398,7 @@ Page({ // 更新临时用户信息 tempUserInfo = { - nickName: userProfile.userInfo.nickName, + name: userProfile.userInfo.name || userProfile.userInfo.nickName, avatarUrl: userProfile.userInfo.avatarUrl, gender: userProfile.userInfo.gender, country: userProfile.userInfo.country, diff --git a/pages/seller/index.wxml b/pages/seller/index.wxml index c1309f2..b4440d2 100644 --- a/pages/seller/index.wxml +++ b/pages/seller/index.wxml @@ -827,7 +827,7 @@ 昵称 - + diff --git a/pages/settlement/index.js b/pages/settlement/index.js index 5d9e427..4482887 100644 --- a/pages/settlement/index.js +++ b/pages/settlement/index.js @@ -979,7 +979,7 @@ Page({ if (result && result.success) { // 保存用户信息到全局和本地存储 const userInfo = { - nickName: '微信用户', + name: '微信用户', avatarUrl: '/images/default-avatar.png', phoneNumber: result.phoneNumber || '未绑定', gender: 0, @@ -1052,7 +1052,7 @@ Page({ // 保存用户信息到全局和本地存储 const userInfo = { - nickName: '微信用户', + name: '微信用户', avatarUrl: '/images/default-avatar.png', phoneNumber: '未绑定', gender: 0, diff --git a/server-example/server-mysql.js b/server-example/server-mysql.js index 9e60762..0e577cd 100644 --- a/server-example/server-mysql.js +++ b/server-example/server-mysql.js @@ -310,9 +310,10 @@ User.init({ allowNull: false, unique: true }, - nickName: { - type: DataTypes.STRING(100), - allowNull: false // 微信名,必填 + name: { + type: DataTypes.STRING(255), + allowNull: true, // 昵称,可选 + comment: '昵称' }, avatarUrl: { type: DataTypes.TEXT @@ -593,9 +594,10 @@ Contact.init({ allowNull: false, unique: true }, - nickName: { + name: { type: DataTypes.STRING(100), - allowNull: false // 联系人 + allowNull: false, // 联系人 + comment: '联系人' }, phoneNumber: { type: DataTypes.STRING(20), @@ -839,14 +841,14 @@ async function createUserAssociations(user) { await sequelize.transaction(async (transaction) => { // 1. 处理联系人记录 - 使用INSERT ... ON DUPLICATE KEY UPDATE确保无论如何都只保留一条记录 await sequelize.query( - `INSERT INTO contacts (userId, nickName, phoneNumber, created_at, updated_at) + `INSERT INTO contacts (userId, name, phoneNumber, created_at, updated_at) VALUES (?, ?, ?, NOW(), NOW()) ON DUPLICATE KEY UPDATE - nickName = VALUES(nickName), + name = VALUES(name), phoneNumber = VALUES(phoneNumber), updated_at = NOW()`, { - replacements: [user.userId, user.nickName || '默认联系人', user.phoneNumber || ''], + replacements: [user.userId, user.name || '默认联系人', user.phoneNumber || ''], transaction: transaction } ); @@ -1098,7 +1100,7 @@ app.post('/api/wechat/getOpenid', async (req, res) => { openid, userId, session_key, - nickName: '微信用户', // 临时占位,等待用户授权 + name: '微信用户', // 临时占位,等待用户授权 phoneNumber: '', // 使用空字符串代替临时手机号,后续由微信小程序拉取的真实手机号更新 type: userType, // 使用客户端传入的类型或默认买家身份 province: '', // 默认空字符串 @@ -1114,7 +1116,7 @@ app.post('/api/wechat/getOpenid', async (req, res) => { }); // 为新创建的用户创建关联记录 - const newUser = { userId, openid, nickName: '微信用户', phoneNumber: '' }; + const newUser = { userId, openid, name: '微信用户', phoneNumber: '' }; await createUserAssociations(newUser); } @@ -1159,7 +1161,7 @@ app.post('/api/user/validate', async (req, res) => { // 查找用户 const user = await User.findOne({ where: { openid }, - attributes: ['openid', 'userId', 'nickName', 'avatarUrl', 'phoneNumber', 'type'] + attributes: ['openid', 'userId', 'name', 'avatarUrl', 'phoneNumber', 'type'] }); if (!user) { @@ -1204,10 +1206,9 @@ app.post('/api/user/get', async (req, res) => { const user = await User.findOne({ where: { openid }, include: [ - { - model: Contact, + { model: Contact, as: 'contacts', - attributes: ['id', 'nickName', 'phoneNumber', 'wechat', 'account', 'accountNumber', 'bank', 'address'] + attributes: ['id', 'name', 'phoneNumber', 'wechat', 'account', 'accountNumber', 'bank', 'address'] }, { model: UserManagement, @@ -1407,12 +1408,12 @@ app.post('/api/product/list', async (req, res) => { const { count, rows: products } = await Product.findAndCountAll({ where, include: [ - { - model: User, - as: 'seller', - attributes: ['userId', 'nickName', 'avatarUrl'] - } - ], + { + model: User, + as: 'seller', + attributes: ['userId', 'name', 'avatarUrl'] + } + ], attributes: { include: [ 'region' // 【新增】确保返回地区字段 @@ -2713,7 +2714,7 @@ try { { model: User, as: 'seller', - attributes: ['userId', 'nickName', 'avatarUrl'] + attributes: ['userId', 'name', 'avatarUrl'] } ] }); @@ -3060,7 +3061,7 @@ app.post('/api/products/detail', async (req, res) => { { model: User, as: 'seller', - attributes: ['userId', 'nickName', 'avatarUrl'] + attributes: ['userId', 'name', 'avatarUrl'] } ] }); @@ -4195,7 +4196,7 @@ app.post('/api/user/debug', async (req, res) => { // 查询用户信息 const user = await User.findOne({ where: { openid }, - attributes: ['openid', 'userId', 'nickName', 'phoneNumber', 'type'] + attributes: ['openid', 'userId', 'name', 'phoneNumber', 'type'] }); if (!user) { @@ -4320,7 +4321,7 @@ app.post('/api/product/hide', async (req, res) => { }); } - console.log('找到用户信息:', { userId: user.userId, nickName: user.nickName }); + console.log('找到用户信息:', { userId: user.userId, name: user.name }); // 查找商品并验证所有权 - 直接使用userId,因为商品创建时使用的就是userId const product = await Product.findOne({ @@ -4561,7 +4562,7 @@ app.post('/api/product/publish', async (req, res) => { }); } - console.log('找到用户:', { userId: user.userId, nickName: user.nickName, type: user.type }); + console.log('找到用户:', { userId: user.userId, name: user.name, type: user.type }); // 验证用户类型 console.log(`验证用户类型: 用户ID=${user.userId}, 类型=${user.type}`); @@ -4625,7 +4626,7 @@ app.post('/api/product/publish', async (req, res) => { { model: User, as: 'seller', - attributes: ['userId', 'nickName', 'avatarUrl'] + attributes: ['userId', 'name', 'avatarUrl'] } ] });