From cc93fb03b0d4634edc46acaf92309011ac2aa301 Mon Sep 17 00:00:00 2001
From: limqhz <540344226@qq.com>
Date: Thu, 9 Apr 2026 16:18:27 +0800
Subject: [PATCH] refactor: remove registration page and update login UI with
agreement checkbox
---
app.json | 1 -
pages/login/index.js | 133 ++++++++--------
pages/login/index.wxml | 23 ++-
pages/login/index.wxss | 66 ++++----
pages/register/index.js | 315 --------------------------------------
pages/register/index.json | 6 -
pages/register/index.wxml | 46 ------
pages/register/index.wxss | 67 --------
pages/userInfo/index.js | 102 ++++++++----
pages/userInfo/index.wxml | 29 ++--
pages/userInfo/index.wxss | 18 +++
11 files changed, 211 insertions(+), 595 deletions(-)
delete mode 100644 pages/register/index.js
delete mode 100644 pages/register/index.json
delete mode 100644 pages/register/index.wxml
delete mode 100644 pages/register/index.wxss
diff --git a/app.json b/app.json
index 7b935af..ef8dfb0 100644
--- a/app.json
+++ b/app.json
@@ -21,7 +21,6 @@
"pages/myMembershipCard/index",
"pages/notice/index",
"pages/questions/index",
- "pages/register/index",
"pages/sportsGroundList/index",
"pages/userInfo/index",
"pages/loginIndex/index",
diff --git a/pages/login/index.js b/pages/login/index.js
index 0bd8035..4cc306b 100644
--- a/pages/login/index.js
+++ b/pages/login/index.js
@@ -8,20 +8,20 @@ Page({
data: {
showUnclickMask: false,
isGoHome: false,
- isLogin: false,
+ isAgree: false
},
/**
* 生命周期函数--监听页面加载
*/
- onLoad: function(options) {
+ onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
- onReady: function() {
+ onReady: function () {
let pages = getCurrentPages();
this.setData({
isGoHome: pages.length == 1
@@ -31,7 +31,7 @@ Page({
/**
* 生命周期函数--监听页面显示
*/
- onShow: function() {
+ onShow: function () {
if (this.data.isLogin) {
this.pushRoute()
return;
@@ -64,109 +64,106 @@ Page({
/**
* 生命周期函数--监听页面隐藏
*/
- onHide: function() {
+ onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
- onUnload: function() {
+ onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
- onPullDownRefresh: function() {
+ onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
- onReachBottom: function() {
+ onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
- onShareAppMessage: function() {
+ onShareAppMessage: function () {
return {
title: '智慧云馆'
}
},
- // 登录
- loginClick() {
+ // 跳转到协议
+ pushAgreement() {
wx.navigateTo({
- url: '/pages/loginIndex/index',
+ url: '/pages/agreement/index',
})
},
- // 注册
- registerClick(e) {
- wx.redirectTo({
- url: '/pages/register/index?codeType=' + 2,
+ checkboxChange(e) {
+ this.setData({
+ isAgree: e.detail.value.length > 0
})
},
- // 微信登录
- wxLogin(e) {
- if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
+
+
+ // 手机号一键登录/注册
+ onGetPhoneNumber(e) {
+ if (!this.data.isAgree) {
+ wx.showToast({
+ title: '请阅读并同意服务条款及隐私政策',
+ icon: 'none',
+ duration: 2000
+ })
return;
}
- this.setData({
- showUnclickMask: true
- })
+
+ if (e.detail.errMsg === 'getPhoneNumber:fail user deny') {
+ return;
+ }
+
+ this.setData({ showUnclickMask: true });
let that = this;
- wx.getUserProfile({
- desc: '用于完善会员资料',
- success: (res) => {
- wx.login({
- success: function(r){
- app.$api.memberLoginWX({
- avatar: res.userInfo.avatarUrl,
- code: r.code,
- nickname: res.userInfo.nickName
- }).then(res => {
- wx.setStorageSync('information', res.information);
- if (!res.authorization) {
- wx.redirectTo({
- url: '/pages/register/index?codeType=' + 1,
- })
- return;
- }
- wx.setStorageSync('accessToken', res.authorization.accessToken);
- let route = wx.getStorageSync('history');
- wx.removeStorageSync('history');
- if (!route || route == '/pages/login/index') {
- return wx.redirectTo({
- url: '/pages/mine/index',
- })
- }
- wx.redirectTo({
- url: route,
- })
- }, err => {
- that.setData({
- showUnclickMask: false
- })
- });
- },
- fail: function(res) {
- that.setData({
- showUnclickMask: false
- })
- },
- })
- },
- fail: (res) => {
- that.setData({
- showUnclickMask: false
- })
+
+ // 前端获取到手机号授权 code 后,再去获取 wx.login 的 code
+ wx.login({
+ success: function (r) {
+ // 调用后端接口。
+ // 注意:这里复用了 memberLoginWXPhone。请让后端把接收参数改为 phoneCode 和 loginCode,
+ // 或者您自己在 api.js 里新建一个专属的一键登录接口。后端收到 phoneCode 后去微信服换取真实手机号并完成注册登录。
+ app.$api.memberLoginWXPhone({
+ loginCode: r.code,
+ phoneCode: e.detail.code
+ }).then(res => {
+ if (!res.authorization) {
+ that.setData({ showUnclickMask: false });
+ wx.showToast({ title: '登录失败,未返回Token', icon: 'none' });
+ return;
+ }
+ wx.setStorageSync('information', res.information);
+ wx.setStorageSync('accessToken', res.authorization.accessToken);
+
+
+ that.setData({ showUnclickMask: false });
+ let route = wx.getStorageSync('history');
+ wx.removeStorageSync('history');
+ if (!route || route == '/pages/login/index') {
+ return wx.redirectTo({ url: '/pages/mine/index' })
+ }
+ wx.redirectTo({ url: route })
+ }).catch(err => {
+ that.setData({ showUnclickMask: false });
+ });
},
+ fail: function (res) {
+ that.setData({ showUnclickMask: false });
+ }
})
- },
+ }
})
diff --git a/pages/login/index.wxml b/pages/login/index.wxml
index b36e663..cb33f42 100644
--- a/pages/login/index.wxml
+++ b/pages/login/index.wxml
@@ -1,14 +1,25 @@
+
-
-
-
- 快速微信登录
+
+
+ 欢迎登录智慧云馆
-
-
+
+
+
+
+
+
+ 我已阅读并同意《智慧云馆服务条款》及《隐私政策》
+
+
+
+
+
+
diff --git a/pages/login/index.wxss b/pages/login/index.wxss
index c248a86..4a871e2 100644
--- a/pages/login/index.wxss
+++ b/pages/login/index.wxss
@@ -15,57 +15,43 @@
line-height: 80rpx;
}
-.register-btn {
- margin-top: 38rpx;
- height: 80rpx;
- border-radius: 40rpx;
- background: none;
- border: 2rpx solid #6e602f;
- font-size: 26rpx;
- line-height: 80rpx;
- color: #cdb02e;
+.auth-box {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ margin-top: 50rpx;
}
-.line-between {
- position: relative;
- height: 4rpx;
- margin-top: 190rpx;
- margin-bottom: 70rpx;
- background: #3f3e49;
+.app-logo {
+ width: 600rpx;
+ height: 150rpx;
}
-.line-between .line-between-text {
- position: absolute;
- top: 0;
- left: 50%;
- transform: translate(-50%, -50%);
- padding: 0 40rpx;
- background: #252330;
- font-size: 24rpx;
+.auth-tip {
+ margin-top: 30rpx;
+ font-size: 28rpx;
+ color: #fff;
+}
+
+.agreement {
+ display: flex;
+ align-items: flex-start;
+ margin-top: 40rpx;
+ font-size: 22rpx;
color: rgba(255, 255, 255, 0.6);
}
-.wechat-btn {
- position: relative;
- width: 100rpx;
- height: 100rpx;
- margin: 0 auto;
+.agreement-text {
+ flex: 1;
+ line-height: 1.6;
}
-.wechat-btn>button {
- position: absolute;
- background: none;
- width: 100%;
- height: 100%;
+.agreement .protocol {
+ color: #b1992f;
}
-.wechat-btn>button::after {
- border: none;
-}
-
-.wechat-btn>image {
- width: 100%;
- height: 100%;
+.agreement checkbox {
+ transform: scale(0.6);
}
.unclick-mask{
diff --git a/pages/register/index.js b/pages/register/index.js
deleted file mode 100644
index 6d604cf..0000000
--- a/pages/register/index.js
+++ /dev/null
@@ -1,315 +0,0 @@
-// pages/register/index.js
-const app = getApp();
-let timer = '';
-let codeType = 0;
-let changeType = '';
-Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- isFocus: '',
- body: {},
- code: "获取验证码",
- isGetCode: false,
- ageList: [{
- label: '男',
- value: 0
- }, {
- label: '女',
- value: 1
- }, {
- label: '不选择',
- value: 2
- }],
- isShowSexPopup: false,
- sexLabel: '选择性别(选填)',
- changeFrom: {},
- unClick: false,
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- let that = this;
- changeType = options.changeType ? options.changeType : '';
- codeType = options.codeType;
- this.setData({
- changeFrom: options
- })
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- return {
- title: '智慧云馆'
- }
- },
-
- // 输入框获取聚焦时
- inputFocus(event) {
- let key = event.currentTarget.dataset.type;
- this.setData({
- isFocus: key
- })
- },
-
- // 输入框输入时
- inputChange(event) {
- let key = event.currentTarget.dataset.type;
- this.data.body[key] = event.detail.value;
- },
-
- // 输入框失去焦点时
- inputBlur(event) {
- let key = event.currentTarget.dataset.type;
- this.setData({
- isFocus: ''
- })
- },
-
- // 获取验证码
- getCode() {
- if (this.data.isGetCode) {
- return;
- }
- if (!this.data.body.phone) {
- wx.showToast({
- title: '请输入手机号',
- icon: 'none',
- })
- return;
- }
- this.data.isGetCode = true;
-
- if (this.data.changeFrom.codeType != 3) {
- app.$api.smsRegister({
- mobile: this.data.body.phone,
- 'type': codeType
- }).then(res => {
- clearTimeout(timer);
- this.countdown(60);
- }, err => {
- this.data.isGetCode = false;
- })
- }
- if (this.data.changeFrom.codeType == 3) {
- app.$api.memberSmsUpdate({
- mobile: this.data.body.phone,
- }).then(res => {}, err => {})
- }
- },
-
- // 倒计时
- countdown(val) {
- if (val == 0) {
- this.data.isGetCode = false;
- clearTimeout(timer);
- return;
- }
- let that = this;
- timer = setTimeout(function() {
- val--
- that.countdown(val);
- that.setData({
- code: val == 0 ? '获取验证码' : val + ' s'
- })
- }, 1000)
- },
-
- // 点击选择性别
- changeSex() {
- this.setData({
- isShowSexPopup: true
- })
- },
-
- // 取消选择性别
- cancelSex() {
- this.setData({
- isShowSexPopup: false
- })
- },
-
- // 选择性别
- selectedSex(e) {
- this.data.body.sex = e.detail.value;
- this.setData({
- isShowSexPopup: false,
- sexLabel: e.detail.label == '不选择' ? "选择性别(选填)" : e.detail.label
- })
- },
-
- // 注册
- registerClick(e) {
- if (this.data.unClick) {
- return;
- }
- if (!this.data.body.phone) {
- wx.showToast({
- title: '请输入手机号',
- icon: 'none',
- })
- return;
- }
- if (!this.data.body.code) {
- wx.showToast({
- title: '请输入验证码',
- icon: 'none',
- })
- return;
- }
- if (this.data.body.age > 100) {
- wx.showToast({
- title: '输入年龄不得超过100',
- icon: 'none',
- })
- return;
- }
- this.data.unClick = true;
- if (codeType == 2) {
- app.$api.memberRegister({
- address: this.data.body.address ? this.data.body.address : '',
- age: this.data.body.age ? this.data.body.age : '',
- captcha: this.data.body.code ? this.data.body.code : '',
- mobile: this.data.body.phone ? this.data.body.phone : '',
- name: this.data.body.name ? this.data.body.name : '',
- sex: this.data.body.sex ? this.data.body.sex : '',
- }).then(res => {
- this.data.unClick = false;
- wx.setStorageSync('accessToken', res.authorization.accessToken);
- // if (wx.getStorageSync('history').indexOf("basketballGym") > -1) {
- wx.redirectTo({
- url: '/pages/myAccount/index?isPass=' + 1,
- })
- // } else {
- // wx.redirectTo({
- // url: '/pages/facialCapturing/index?isPass=' + 1,
- // })
- // }
-
- }, err => {
- this.data.unClick = false;
- })
- } else if (codeType == 1) {
- app.$api.memberLoginWXPhone({
- avatar: wx.getStorageSync('information').avatar,
- nickname: wx.getStorageSync('information').nickname,
- openId: wx.getStorageSync('information').openId,
- address: this.data.body.address ? this.data.body.address : '',
- age: this.data.body.age ? this.data.body.age : '',
- captcha: this.data.body.code ? this.data.body.code : '',
- mobile: this.data.body.phone ? this.data.body.phone : '',
- name: this.data.body.name ? this.data.body.name : '',
- sex: this.data.body.sex ? this.data.body.sex : '',
- }).then(res => {
- this.data.unClick = false;
- wx.setStorageSync('accessToken', res.authorization.accessToken);
- // if (wx.getStorageSync('history').indexOf("basketballGym") > -1) {
- wx.redirectTo({
- url: '/pages/myAccount/index?isPass=' + 1,
- })
- // } else {
- // wx.redirectTo({
- // url: '/pages/facialCapturing/index?isPass=' + 1,
- // })
- // }
- }, err => {
- this.data.unClick = false;
- })
- }
- },
-
- // 保存修改
- saveClick() {
- let body = {};
- if (this.data.changeFrom.label == "phone") {
- if (!this.data.body.code) {
- wx.showToast({
- title: '请输入验证码',
- icon: 'none',
- })
- return;
- }
- body.mobile = this.data.body.phone ? this.data.body.phone : this.data.changeFrom.value;
- body.captcha = this.data.body.code;
- } else {
- if (this.data.changeFrom.label == 'age' && this.data.body.age > 100) {
- wx.showToast({
- title: '输入年龄不得超过100',
- icon: 'none',
- })
- return;
- }
- if (this.data.changeFrom.label == 'nickname' && this.data.body.nickname === '') {
- wx.showToast({
- title: '请输入昵称',
- icon: 'none',
- })
- return;
- }
- body[this.data.changeFrom.label] = this.data.body[this.data.changeFrom.label] != undefined ? this.data.body[this.data.changeFrom.label] : this.data.changeFrom.value
- }
-
- app.$api.memberUpdateInformation(body).then(res => {
- wx.showToast({
- title: '保存成功',
- duration: 2000
- });
- setTimeout(function() {
- wx.navigateBack({
- delta: 1,
- })
- }, 2000);
-
- }, err => {
-
- })
- }
-})
\ No newline at end of file
diff --git a/pages/register/index.json b/pages/register/index.json
deleted file mode 100644
index 773af37..0000000
--- a/pages/register/index.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "usingComponents": {
- "action-sheet": "/component/actionSheet/actionSheet",
- "header": "/component/header/header"
- }
-}
\ No newline at end of file
diff --git a/pages/register/index.wxml b/pages/register/index.wxml
deleted file mode 100644
index 94e6a2e..0000000
--- a/pages/register/index.wxml
+++ /dev/null
@@ -1,46 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{sexLabel}}
- {{sexLabel}}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pages/register/index.wxss b/pages/register/index.wxss
deleted file mode 100644
index 5fcb5e7..0000000
--- a/pages/register/index.wxss
+++ /dev/null
@@ -1,67 +0,0 @@
-/* pages/register/index.wxss */
-page {
- position: relative;
-}
-
-.container {
- min-height: calc(100vh - 230rpx);
- padding: 230rpx 124rpx 0 124rpx;
-}
-
-.input-box {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-top: 30rpx;
- border-bottom: 2rpx solid #3f3e49;
-}
-
-.input-box>input {
- /* flex: 1; */
- margin: 20rpx 0;
- font-size: 24rpx;
- font-weight: bold;
- color: #fff;
-}
-
-.input-box>text {
- margin: 30rpx 0;
- color: rgba(255, 255, 255, 0.6);
- font-size: 24rpx;
-}
-
-.input-box>image {
- width: 12rpx;
- height: 22rpx;
-}
-
-.input-box.isActive {
- border-bottom: 2rpx solid #6e602f;
-}
-
-.input-box .placeholder {
- color: rgba(255, 255, 255, 0.6);
-}
-
-.input-box>button {
- padding: 0;
- width: 200rpx;
- background: none;
- font-size: 24rpx;
- color: rgba(255, 255, 255, 0.6);
- text-align: center;
-}
-
-.input-box>button::after {
- border: none;
-}
-
-.register-btn {
- margin-top: 200rpx;
- height: 80rpx;
- border-radius: 40rpx;
- background: #ffda2e;
- color: #252330;
- font-size: 26rpx;
- line-height: 80rpx;
-}
\ No newline at end of file
diff --git a/pages/userInfo/index.js b/pages/userInfo/index.js
index a5f9a94..7888180 100644
--- a/pages/userInfo/index.js
+++ b/pages/userInfo/index.js
@@ -71,29 +71,53 @@ Page({
},
// 切换头像
- changeAvatar() {
+ onChooseAvatar(e) {
let that = this;
- wx.chooseImage({
- count: 1,
- success: function (e) {
- wx.showLoading({
- title: '正在上传...',
- mask: true,
- })
- app.$api.uploadAvatar({
- filePath: e.tempFilePaths[0]
- }).then(res => {
- wx.showToast({
- title: '上传成功',
- icon: 'success',
- })
- that.getData();
- }, err => {});
- },
- fail: function (res) {
- console.log(res);
- },
+ const { avatarUrl } = e.detail;
+ if (!avatarUrl) return;
+
+ wx.showLoading({
+ title: '正在上传...',
+ mask: true,
})
+ app.$api.uploadAvatar({
+ filePath: avatarUrl
+ }).then(res => {
+ wx.showToast({
+ title: '上传成功',
+ icon: 'success',
+ })
+ that.getData();
+ }, err => {
+ wx.hideLoading();
+ });
+ },
+
+ // 修改昵称
+ onNicknameChange(e) {
+ let newName = e.detail.value;
+ // 防止重复触发
+ if (!newName || newName === this.data.members.nickname) return;
+
+ // 乐观反显更新
+ this.setData({
+ 'members.nickname': newName
+ });
+
+ wx.showLoading({ title: '保存中...', mask: true });
+ app.$api.memberUpdateInformation({
+ nickname: newName
+ }).then(res => {
+ wx.hideLoading();
+ wx.showToast({
+ title: '修改成功',
+ icon: 'success',
+ });
+ // 这里的静默获取能确保和数据库端同步
+ this.getData();
+ }, err => {
+ wx.hideLoading();
+ });
},
// 修改性别
@@ -153,14 +177,34 @@ Page({
})
},
- // 修改信息
- changeMessage(e) {
- let label = e.currentTarget.dataset.label;
- let value = e.currentTarget.dataset.value ? e.currentTarget.dataset.value : "";
- wx.removeStorageSync('history');
- wx.navigateTo({
- url: `/pages/register/index?label=${label}&value=${value}&codeType=3`,
- })
+ // 在当前页直接修改文本类别的信息(姓名、年龄、地址)
+ onInfoChange(e) {
+ let type = e.currentTarget.dataset.type;
+ let newValue = e.detail.value;
+
+ if (newValue === undefined || newValue === this.data.members[type]) return;
+
+ let updateData = {};
+ updateData[type] = newValue;
+
+ // 乐观反显
+ let key = 'members.' + type;
+ this.setData({
+ [key]: newValue
+ });
+
+ wx.showLoading({ title: '保存中...', mask: true });
+ app.$api.memberUpdateInformation(updateData).then(res => {
+ wx.hideLoading();
+ wx.showToast({
+ title: '修改成功',
+ icon: 'success',
+ });
+ // 静默获取同步服务器
+ this.getData();
+ }, err => {
+ wx.hideLoading();
+ });
},
// 获取数据
diff --git a/pages/userInfo/index.wxml b/pages/userInfo/index.wxml
index 7365419..30f3578 100644
--- a/pages/userInfo/index.wxml
+++ b/pages/userInfo/index.wxml
@@ -3,46 +3,41 @@
-
+
-
+
+
昵称
- {{members.nickname}}
-
+
-
+
手机号
{{members.mobile}}
-
-
+
姓名
- {{members.name}}
-
+
性别
{{members.sex == 0 ? "男" : (members.sex == 1 ? "女" : "")}}
-
+
年龄
- {{members.age}}
-
+
-
+
地址
- {{members.address}}
-
+
diff --git a/pages/userInfo/index.wxss b/pages/userInfo/index.wxss
index 10680eb..07cd4e7 100644
--- a/pages/userInfo/index.wxss
+++ b/pages/userInfo/index.wxss
@@ -24,6 +24,19 @@
height: 120rpx;
}
+.list .cell-btn {
+ background: transparent;
+ padding: 0 30rpx;
+ margin: 0;
+ width: 100%;
+ text-align: left;
+ line-height: normal;
+}
+
+.list .cell-btn::after {
+ border: none;
+}
+
.list .cell.unLine {
border-bottom: none;
}
@@ -58,4 +71,9 @@
color: #FFF;
font-size: 24rpx;
line-height: 30rpx;
+}
+
+.list .cell .nickname-input {
+ text-align: right;
+ width: 100%;
}
\ No newline at end of file