diff --git a/pages/consumption/consumption.vue b/pages/consumption/consumption.vue
index b6ad248..3ea124d 100644
--- a/pages/consumption/consumption.vue
+++ b/pages/consumption/consumption.vue
@@ -107,7 +107,6 @@
import { computed, onMounted, ref } from "vue";
import { onShow } from "@dcloudio/uni-app";
import { useAuthStore, useUserStore } from "@/store";
-import { regions } from "/static/json/regions.js";
import HeaderCustom from "/components/HeaderCustom/HeaderCustom.vue";
import RPC from "@/utils/request";
diff --git a/pages/login/login.vue b/pages/login/login.vue
index 9ae5fd2..3d9f53a 100644
--- a/pages/login/login.vue
+++ b/pages/login/login.vue
@@ -84,7 +84,10 @@
-
+
+
+ 打开小程序并登录
+
@@ -133,9 +136,9 @@
trigger: ["blur", "change"],
},
{
- pattern: /^1[3-9]\d{9}$/,
- message: "请输入正确的手机号",
- trigger: ["blur", "change"],
+ pattern: /^1[3-9]\d{9}$/,
+ message: "请输入正确的手机号",
+ trigger: ["blur", "change"],
},
],
code: {
@@ -143,7 +146,9 @@
message: "请输入验证码",
trigger: ["blur", "change"],
},
- });
+ });
+
+ const ToLoginRef = ref(null)
const tips = ref("获取验证码");
const codeChange = (text) => {
@@ -208,6 +213,9 @@
onLoad((options) => {
if (options.redirect && removeQueryString(options.redirect) !== LOGIN_PATH) {
redirect = decodeURIComponent(options.redirect);
+ }
+ if(options.from && options.from === 'h5ToWechat') {
+ XcxLogin()
}
});
@@ -231,47 +239,60 @@
// #endif
};
+ const XcxLogin = () => {
+ uni.showLoading({
+ title: "登录中...",
+ });
+ uni.login({
+ success: function(loginRes) {
+ console.log('loginRes', loginRes);
+ 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",
+ });
+ })
+ },
+ fail: () => {
+ uni.hideLoading();
+ }
+ })
+ }
+
+
+
// 微信登录
const wechatLogin = () => {
// #ifdef MP-WEIXIN
// 微信小程序登录
- // uni.login({
- // provider: "weixin",
- // success: (loginRes) => {
- // console.log("微信登录成功:", loginRes);
- // // 获取用户信息
- // uni.getUserProfile({
- // desc: "用于完善用户资料",
- // success: (userRes) => {
- // console.log("获取用户信息成功:", userRes);
- // // 显示绑定手机号弹窗
- // showBindPhoneModal.value = true;
- // },
- // fail: (err) => {
- // console.error("获取用户信息失败:", err);
- // uni.showToast({
- // title: "获取用户信息失败",
- // icon: "none",
- // });
- // },
- // });
- // },
- // fail: (err) => {
- // console.error("微信登录失败:", err);
- // uni.showToast({
- // title: "微信登录失败",
- // icon: "none",
- // });
- // },
- // });
- popup.value.open();
+ XcxLogin()
+ // popup.value.open();
// #endif
// #ifdef H5
// H5微信登录
if (typeof WeixinJSBridge !== "undefined") {
// 在微信内,使用微信JS-SDK进行授权登录
- wechatH5Login();
+ // wechatH5Login();
+ ToLoginRef.value.click()
} else {
uni.showToast({
title: "请在微信中打开",
@@ -349,7 +370,7 @@
const wechatH5Login = () => {
// #ifdef H5
// 构建微信授权URL
- const appId = "YOUR_WECHAT_APP_ID"; // 替换为你的微信公众号AppID
+ const appId = "wxc504638e03981812"; // 替换为你的微信公众号AppID
const redirectUri = encodeURIComponent(
window.location.origin + "/pages/login/login"
); // 授权回调地址
@@ -389,33 +410,57 @@
// 调用后端接口,通过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",
+ });
+ })
// 模拟获取用户信息
- setTimeout(() => {
- uni.hideLoading();
-
- // 模拟获取到的用户信息
- const userInfo = {
- openid: "mock_openid_" + Date.now(),
- nickname: "微信用户",
- headimgurl: "/static/imgs/avatar.png",
- };
-
- console.log("微信H5登录成功,用户信息:", userInfo);
-
- // 显示绑定手机号弹窗
- popup.value.open();
-
- // 清除URL中的code参数
- const url = new URL(window.location);
- url.searchParams.delete("code");
- url.searchParams.delete("state");
- window.history.replaceState({},
- document.title,
- url.pathname + url.search
- );
- }, 1500);
+ // setTimeout(() => {
+ // uni.hideLoading();
+
+ // // 模拟获取到的用户信息
+ // const userInfo = {
+ // openid: "mock_openid_" + Date.now(),
+ // nickname: "微信用户",
+ // headimgurl: "/static/imgs/avatar.png",
+ // };
+
+ // console.log("微信H5登录成功,用户信息:", userInfo);
+
+ // // 显示绑定手机号弹窗
+ // popup.value.open();
+
+ // // 清除URL中的code参数
+ // const url = new URL(window.location);
+ // url.searchParams.delete("code");
+ // url.searchParams.delete("state");
+ // window.history.replaceState({},
+ // document.title,
+ // url.pathname + url.search
+ // );
+ // }, 1500);
} catch (error) {
uni.hideLoading();
console.error("微信H5登录失败:", error);
@@ -559,11 +604,13 @@
onMounted(() => {
checkEnvironment();
- // #ifdef H5
+ // #ifdef MP-WEIXIN
// 检查是否是微信授权回调
const urlParams = new URLSearchParams(window.location.search);
- const code = urlParams.get("code");
- if (code && showWechatLogin.value) {
+ const code = urlParams.get("code");
+ const from = urlParams.get("from");
+ console.log('from',from)
+ if (from && from === 'h5') {
handleWechatH5Callback(code);
}
diff --git a/pages/order/order.vue b/pages/order/order.vue
index 09839e6..ec8f576 100644
--- a/pages/order/order.vue
+++ b/pages/order/order.vue
@@ -138,9 +138,6 @@
useAuthStore,
useUserStore
} from "@/store";
- import {
- regions
- } from '/static/json/regions.js'
import HeaderCustom from '/components/HeaderCustom/HeaderCustom.vue'
import RPC from "@/utils/request";
diff --git a/pagesA/edit-profile/edit-profile.vue b/pagesA/edit-profile/edit-profile.vue
index d805753..e7b175c 100644
--- a/pagesA/edit-profile/edit-profile.vue
+++ b/pagesA/edit-profile/edit-profile.vue
@@ -19,29 +19,29 @@
用户名
- {{ userInfo.username }}
+ {{ userStore.userInfo.username }}
-
-
-
邮箱
- {{ userInfo.email }}
+ {{ userStore.userInfo.email }}
-
-
+
+
+
+
+ 手机号
+
+ {{ userStore.userInfo.phone }}
+
+
+
+
@@ -151,7 +151,8 @@