From 26be228f0aacd38f9fae1e90402d8065f576c920 Mon Sep 17 00:00:00 2001 From: Lufaneng Date: Wed, 15 Oct 2025 09:44:41 +0800 Subject: [PATCH] 1 --- pages.json | 12 +- pages/consumption/consumption.vue | 11 +- pages/login/login.vue | 253 +++--- pages/mine/mine.vue | 3 +- pages/order/order.vue | 92 +- pagesA/edit-profile/edit-profile.vue | 1207 +++++++++++++++----------- utils/request.js | 7 +- 7 files changed, 916 insertions(+), 669 deletions(-) diff --git a/pages.json b/pages.json index 6bb8f4b..32146a9 100644 --- a/pages.json +++ b/pages.json @@ -129,12 +129,12 @@ "selectedIconPath": "static/tabbar/order_HL.png", "text": "订单" }, - { - "pagePath": "pages/consumption/consumption", - "iconPath": "static/tabbar/xiaofei.png", - "selectedIconPath": "static/tabbar/xiaofei_HL.png", - "text": "消费" - }, + // { + // "pagePath": "pages/consumption/consumption", + // "iconPath": "static/tabbar/xiaofei.png", + // "selectedIconPath": "static/tabbar/xiaofei_HL.png", + // "text": "消费" + // }, { "pagePath": "pages/mine/mine", "iconPath": "static/tabbar/mine.png", diff --git a/pages/consumption/consumption.vue b/pages/consumption/consumption.vue index 8906570..bc83a6a 100644 --- a/pages/consumption/consumption.vue +++ b/pages/consumption/consumption.vue @@ -1,7 +1,7 @@ @@ -146,8 +147,8 @@ message: "请输入验证码", trigger: ["blur", "change"], }, - }); - + }); + const ToLoginRef = ref(null) const tips = ref("获取验证码"); @@ -156,9 +157,17 @@ }; const codeRef = ref(null); const getCode = () => { - if (!userInfo.phone) { + if (!userInfo.value.phone) { uni.showToast({ - title: "请填写手机号", + title: "请输入手机号", + icon: "none", + }); + return; + } + + if (!/^1[3-9]\d{9}$/.test(userInfo.value.phone)) { + uni.showToast({ + title: "请输入正确的手机号", icon: "none", }); return; @@ -168,16 +177,22 @@ uni.showLoading({ title: "正在获取验证码", }); - setTimeout(() => { - uni.hideLoading(); - // 这里此提示会被this.start()方法中的提示覆盖 + RPC.post('/login/phone/send_code', { + phone: userInfo.value.phone, + }).then(() => { + uni.hideLoading() uni.showToast({ - title: "验证码已发送", - icon: "none", - }); - // 通知验证码组件内部开始倒计时 - codeRef.value.start(); - }, 2000); + title: '验证码已发送', + icon: 'success' + }) + codeRef.value.start() + }).catch(() => { + uni.hideLoading() + uni.showToast({ + title: '发送失败,请重试', + icon: 'none' + }) + }) } else { uni.showToast({ title: "倒计时结束后再发送", @@ -211,11 +226,12 @@ }); let redirect = HOME_PATH; onLoad((options) => { - if (options.redirect && removeQueryString(options.redirect) !== LOGIN_PATH) { + if (options.redirect && removeQueryString(options.redirect) !== LOGIN_PATH) { + if(decodeURIComponent(options.redirect) && decodeURIComponent(options.redirect) != 'undefined') redirect = decodeURIComponent(options.redirect); - } - if(options.from && options.from === 'h5ToWechat') { - XcxLogin() + } + if (options.from && options.from === 'h5ToWechat') { + XcxLogin() } }); @@ -228,9 +244,9 @@ // #ifdef H5 // H5环境,检查是否在微信内 - const ua = navigator.userAgent.toLowerCase(); - const isWechat = ua.indexOf("micromessenger") !== -1; - showWechatLogin.value = isWechat; + // const ua = navigator.userAgent.toLowerCase(); + // const isWechat = ua.indexOf("micromessenger") !== -1; + // showWechatLogin.value = isWechat; // #endif // #ifdef APP-PLUS @@ -250,19 +266,23 @@ js_code: loginRes.code }).then(res => { console.log('phonelogin', res) - authStore.setAccessToken(res.token) - userStore.setUserInfo(res.user) - if(!res.user.phone) { - uni.showToast({ - title: "登录成功", - icon: "success", - }); - uni.$uv.route({ - type: isTabBarPath(redirect) ? "switchTab" : "redirectTo", - url: redirect, - }); - } else { - popup.value.open() + if (res.user.phone) { + authStore.setAccessToken(res.token) + userStore.setUserInfo(res.user) + uni.showToast({ + title: "登录成功", + icon: "success", + }); + uni.$uv.route({ + type: isTabBarPath(redirect || HOME_PATH) ? "switchTab" : + "redirectTo", + url: redirect || HOME_PATH, + }); + } else { + accessToken.value = res.token + accessUserInfo.value = res.user + uni.hideLoading() + popup.value.open() } }).catch(() => { uni.showToast({ @@ -291,7 +311,7 @@ // H5微信登录 if (typeof WeixinJSBridge !== "undefined") { // 在微信内,使用微信JS-SDK进行授权登录 - // wechatH5Login(); + // wechatH5Login(); ToLoginRef.value.click() } else { uni.showToast({ @@ -324,35 +344,28 @@ uni.showLoading({ title: "正在获取验证码", }); - // 调用发送验证码API - // RPC.post('/api/sms/send', { - // phone: bindPhoneInfo.value.phone, - // type: 'bind' - // }).then(() => { - // uni.hideLoading() - // uni.showToast({ - // title: '验证码已发送', - // icon: 'success' - // }) - // bindCodeRef.value.start() - // }).catch(() => { - // uni.hideLoading() - // uni.showToast({ - // title: '发送失败,请重试', - // icon: 'none' - // }) - // }) - - // 模拟发送验证码 - setTimeout(() => { - uni.hideLoading(); + RPC.post('/user/bind_phone/send_code', { + phone: bindPhoneInfo.value.phone, + token: accessToken.value + }, { + custom: { + customToken: accessToken.value + } + }).then(() => { + uni.hideLoading() uni.showToast({ - title: "验证码已发送", - icon: "success", - }); - bindCodeRef.value.start(); - }, 1500); + title: '验证码已发送', + icon: 'success' + }) + bindCodeRef.value.start() + }).catch(() => { + uni.hideLoading() + uni.showToast({ + title: '发送失败,请重试', + icon: 'none' + }) + }) } else { uni.showToast({ title: "倒计时结束后再发送", @@ -399,6 +412,9 @@ // #endif }; + const accessToken = ref('') + const accessUserInfo = ref({}) + // 处理微信H5授权回调 const handleWechatH5Callback = async (code) => { // #ifdef H5 @@ -410,30 +426,32 @@ // 调用后端接口,通过code获取用户信息 // const result = await RPC.post('/api/wechat/h5-login', { // code: code - // }); - RPC.post('/login/wechat_mini', { - js_code: loginRes.code - }).then(res => { - console.log('phonelogin', res) - authStore.setAccessToken(res.token) - userStore.setUserInfo(res.user) - if(!res.user.phone) { - uni.showToast({ - title: "登录成功", - icon: "success", - }); - uni.$uv.route({ - type: isTabBarPath(redirect) ? "switchTab" : "redirectTo", - url: redirect, - }); - } else { - popup.value.open() - } - }).catch(() => { - uni.showToast({ - title: "登录失败", - icon: "error", - }); + // }); + RPC.post('/login/wechat_mini', { + js_code: loginRes.code + }).then(res => { + console.log('phonelogin', res) + if (res.user.phone) { + authStore.setAccessToken(res.token) + userStore.setUserInfo(res.user) + uni.showToast({ + title: "登录成功", + icon: "success", + }); + uni.$uv.route({ + type: isTabBarPath(redirect || HOME_PATH) ? "switchTab" : "redirectTo", + url: redirect || HOME_PATH, + }); + } else { + accessToken.value = res.token + accessUserInfo.value = res.user + popup.value.open() + } + }).catch(() => { + uni.showToast({ + title: "登录失败", + icon: "error", + }); }) // 模拟获取用户信息 @@ -507,35 +525,32 @@ bindingPhone.value = true; // 调用绑定手机号API - // const result = await RPC.post('/api/wechat/bind-phone', { - // phone: bindPhoneInfo.value.phone, - // code: bindPhoneInfo.value.code, - // wechatCode: wechatLoginCode // 微信登录返回的code - // }) - - // 模拟绑定过程 - setTimeout(() => { + RPC.post('/user/bind_phone', { + phone: bindPhoneInfo.value.phone, + code: bindPhoneInfo.value.code, + token: accessToken.value + },{ + custom: { + customToken: accessToken.value + } + }).then((res) => { + console.log('bind_phone', res) bindingPhone.value = false; - + authStore.setAccessToken(accessToken.value) + userStore.setUserInfo(accessUserInfo.value) uni.showToast({ title: "绑定成功", icon: "success", }); - - // 设置登录状态 - authStore.setAccessToken("wechat_access_token"); - // userStore.setUserInfo(result.userInfo) - - closeBindPhoneModal(); - - // 跳转到首页 setTimeout(() => { + closeBindPhoneModal() uni.$uv.route({ - type: isTabBarPath(redirect) ? "switchTab" : "redirectTo", - url: redirect, + type: isTabBarPath(redirect || HOME_PATH) ? "switchTab" : + "redirectTo", + url: redirect || HOME_PATH, }); - }, 1000); - }, 2000); + }, 500); + }) } catch (error) { console.error("绑定手机号失败:", error); bindingPhone.value = false; @@ -571,9 +586,9 @@ // url: redirect, // }); // }) - RPC.post('/login', { - username: userInfo.value.phone, - password: userInfo.value.password, + RPC.post('/login/phone', { + phone: userInfo.value.phone, + code: userInfo.value.password, }, { custom: { loading: true, @@ -588,8 +603,8 @@ .then((res) => { userStore.setUserInfo(res) uni.$uv.route({ - type: isTabBarPath(redirect) ? "switchTab" : "redirectTo", - url: redirect, + type: isTabBarPath(redirect || HOME_PATH) ? "switchTab" : "redirectTo", + url: redirect || HOME_PATH, }); }) .finally(() => { @@ -607,8 +622,8 @@ // // #ifdef MP-WEIXIN // // 检查是否是微信授权回调 // const urlParams = new URLSearchParams(window.location.search); - // const code = urlParams.get("code"); - // const from = urlParams.get("from"); + // const code = urlParams.get("code"); + // const from = urlParams.get("from"); // console.log('from',from) // if (from && from === 'h5') { // handleWechatH5Callback(code); diff --git a/pages/mine/mine.vue b/pages/mine/mine.vue index 2bb1433..b1134cd 100644 --- a/pages/mine/mine.vue +++ b/pages/mine/mine.vue @@ -545,7 +545,8 @@ onPullDownRefresh(() => { getPlanList() // getBalance() - getMemberInfo() + getMemberInfo() + uni.stopPullDownRefresh(); }); diff --git a/pages/order/order.vue b/pages/order/order.vue index 78638be..6d4318b 100644 --- a/pages/order/order.vue +++ b/pages/order/order.vue @@ -1,8 +1,9 @@ - - - - + + + - - - 用户名 - - {{ userStore.userInfo.username }} - - - + + + 用户名 + + {{ userStore.userInfo.username }} + + + - - - 邮箱 - - {{ userStore.userInfo.email }} - - - - - - - 手机号 - - {{ userStore.userInfo.phone }} - - - - - - - - - + + 邮箱 + + {{ userStore.userInfo.email }} + + + + + + + 手机号 + + {{ userStore.userInfo.phone }} + + + + + + + + + + - - - 用户协议 - - - - + + + 用户协议 + + + + - - - 关于我们 - - - - - - - - - - 退出登录 - - - - - - - - 编辑{{ + + + 关于我们 + + + + + + + + + + 退出登录 + + + + + + + + 编辑{{ editType === "username" ? "用户名" : editType === "phone" @@ -96,445 +92,658 @@ ? "邮箱" : "" }} - - - - 取消 - 保存 - - - - - - - - - 选择头像 - - - - - 拍照 - - - - 从相册选择 - - - - - 取消 - - - - - + " border="bottom" clearable> + + 取消 + 保存 + + + + + + + + + 选择头像 + + + + + 拍照 + + + + 从相册选择 + + + + + 取消 + + + + + + + + + 换绑手机号 + 请输入换绑手机号信息 + + + + + + + + + + + + + + + + + + 取消 + + + 确认绑定 + + + + + \ No newline at end of file diff --git a/utils/request.js b/utils/request.js index 13d383d..a084709 100644 --- a/utils/request.js +++ b/utils/request.js @@ -129,14 +129,15 @@ $uv.http.interceptors.request.use( config.url = '/jsonrpc' // #endif // config.url = useUserStore().adressIp + '/jsonrpc' - const params = config.data + const params = config.data + console.log('config',config) + const customToken = config.custom.customToken config.data = { id: guid(), jsonrpc: '2.0', method, params, - session: useAuthStore().accessToken, - // session:'8ef0a67e75d4ebbcbc5bc897024ea160', + session:customToken || useAuthStore().accessToken, timestampin: Date.now().toString() }