|
|
@@ -11,12 +11,16 @@ const _sfc_main = {
|
|
|
return {
|
|
|
showOneClickLogin: true,
|
|
|
// 是否显示一键登录按钮
|
|
|
+ showPhoneAuth: false,
|
|
|
+ // 是否显示手机号授权按钮(新用户第二步)
|
|
|
agreedToTerms: false,
|
|
|
// 是否同意协议
|
|
|
loginCode: "",
|
|
|
// 微信登录code
|
|
|
- tempUserData: null
|
|
|
- // 临时存储的用户数据
|
|
|
+ tempUserData: null,
|
|
|
+ // 临时存储的用户数据(openid, unionid等)
|
|
|
+ tempUserProfile: null
|
|
|
+ // 临时存储的用户头像昵称信息
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -56,8 +60,9 @@ const _sfc_main = {
|
|
|
console.log("[登录] 老用户登录成功");
|
|
|
this.handleLoginSuccess();
|
|
|
} else if (result && result.isSign === "false") {
|
|
|
- console.log("[登录] 新用户,需要授权手机号");
|
|
|
+ console.log("[登录] 新用户,需要先获取头像昵称");
|
|
|
this.showOneClickLogin = false;
|
|
|
+ this.showPhoneAuth = false;
|
|
|
} else if (result && result.code === 103) {
|
|
|
common_vendor.index.showModal({
|
|
|
title: "账号异常",
|
|
|
@@ -78,7 +83,39 @@ const _sfc_main = {
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
- * 第二步:获取手机号授权(新用户)
|
|
|
+ * 第二步:获取用户头像昵称(新用户)
|
|
|
+ */
|
|
|
+ handleGetUserProfile() {
|
|
|
+ if (!this.agreedToTerms) {
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "请先阅读并同意用户协议",
|
|
|
+ icon: "none",
|
|
|
+ duration: 2e3
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log("[登录] 打开用户信息弹窗");
|
|
|
+ this.$refs.userInfoPopup.open();
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 用户信息弹窗确认回调(新用户第二步完成后)
|
|
|
+ */
|
|
|
+ handleUserInfoConfirm(userInfo) {
|
|
|
+ console.log("[登录] 用户信息已获取:", userInfo);
|
|
|
+ this.tempUserProfile = {
|
|
|
+ nickname: userInfo.nickname,
|
|
|
+ avatarUrl: userInfo.avatarUrl,
|
|
|
+ tempAvatarPath: userInfo.tempAvatarPath
|
|
|
+ };
|
|
|
+ this.showPhoneAuth = true;
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "请继续授权手机号",
|
|
|
+ icon: "none",
|
|
|
+ duration: 2e3
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 第三步:获取手机号授权(新用户)
|
|
|
*/
|
|
|
async handleGetPhoneNumber(e) {
|
|
|
console.log("[登录] 手机号授权回调:", e);
|
|
|
@@ -86,7 +123,7 @@ const _sfc_main = {
|
|
|
if (e.detail.errMsg.includes("no permission")) {
|
|
|
common_vendor.index.showModal({
|
|
|
title: "权限不足",
|
|
|
- content: '获取手机号功能需要:\n1. 小程序企业认证\n2. 开通"手机号快速验证组件"权限\n3. 在真机上测试',
|
|
|
+ content: '获取手机号功能需要:\n1. 小程序企业认证"权限 \n2. 在真机上测试',
|
|
|
showCancel: false
|
|
|
});
|
|
|
} else {
|
|
|
@@ -111,9 +148,13 @@ const _sfc_main = {
|
|
|
const result = await utils_auth.wxPhoneLogin(params);
|
|
|
common_vendor.index.hideLoading();
|
|
|
if (result && result.isSign === "false") {
|
|
|
- console.log("[登录] 需要完善用户信息");
|
|
|
- this.tempUserData = result;
|
|
|
- this.$refs.userInfoPopup.open(result);
|
|
|
+ console.log("[登录] 需要完成注册");
|
|
|
+ this.tempUserData = {
|
|
|
+ openid: result.openid,
|
|
|
+ unionid: result.unionid,
|
|
|
+ phoneNumber: result.phoneNumber
|
|
|
+ };
|
|
|
+ await this.submitRegistration();
|
|
|
} else if (result && result.isSign === "true") {
|
|
|
console.log("[登录] 已注册用户,登录成功");
|
|
|
this.handleLoginSuccess();
|
|
|
@@ -150,28 +191,26 @@ const _sfc_main = {
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
- * 第三步:完善用户信息(首次登录)
|
|
|
+ * 第四步:提交注册(新用户完成所有授权后)
|
|
|
*/
|
|
|
- async handleUserInfoConfirm(userInfo) {
|
|
|
+ async submitRegistration() {
|
|
|
try {
|
|
|
common_vendor.index.showLoading({ title: "注册中..." });
|
|
|
const completeInfo = {
|
|
|
openid: this.tempUserData.openid,
|
|
|
unionid: this.tempUserData.unionid,
|
|
|
phoneNumber: this.tempUserData.phoneNumber,
|
|
|
- nickname: userInfo.nickname,
|
|
|
- avatarUrl: userInfo.avatarUrl
|
|
|
- // 微信临时URL,先存着
|
|
|
+ nickname: this.tempUserProfile.nickname,
|
|
|
+ avatarUrl: this.tempUserProfile.avatarUrl
|
|
|
};
|
|
|
console.log("[登录] 提交用户信息");
|
|
|
await utils_auth.wxCompleteUserInfo(completeInfo);
|
|
|
- if (userInfo.tempAvatarPath) {
|
|
|
- console.log("[登录] 开始上传头像到服务器, tempAvatarPath:", userInfo.tempAvatarPath);
|
|
|
+ if (this.tempUserProfile.tempAvatarPath) {
|
|
|
+ console.log("[登录] 开始上传头像到服务器");
|
|
|
try {
|
|
|
- const uploadedUrl = await this.uploadAvatarWithToken(userInfo.tempAvatarPath);
|
|
|
- console.log("[登录] 头像上传成功, uploadedUrl:", uploadedUrl);
|
|
|
+ const uploadedUrl = await this.uploadAvatarWithToken(this.tempUserProfile.tempAvatarPath);
|
|
|
+ console.log("[登录] 头像上传成功:", uploadedUrl);
|
|
|
if (uploadedUrl) {
|
|
|
- console.log("[登录] 调用updateUserProfile更新头像");
|
|
|
const updateResult = await utils_api.updateUserProfile({ avatar: uploadedUrl });
|
|
|
console.log("[登录] updateUserProfile返回:", updateResult);
|
|
|
const userInfoLocal = common_vendor.index.getStorageSync("user_info");
|
|
|
@@ -180,7 +219,6 @@ const _sfc_main = {
|
|
|
parsed.avatar = uploadedUrl;
|
|
|
common_vendor.index.setStorageSync("user_info", JSON.stringify(parsed));
|
|
|
}
|
|
|
- console.log("[登录] 头像上传成功:", uploadedUrl);
|
|
|
}
|
|
|
} catch (uploadErr) {
|
|
|
console.warn("[登录] 头像上传失败:", uploadErr);
|
|
|
@@ -290,15 +328,18 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
b: $data.showOneClickLogin
|
|
|
}, $data.showOneClickLogin ? {
|
|
|
c: common_vendor.o((...args) => $options.handleWxLogin && $options.handleWxLogin(...args))
|
|
|
+ } : $data.showPhoneAuth ? {
|
|
|
+ e: common_vendor.o((...args) => $options.handleGetPhoneNumber && $options.handleGetPhoneNumber(...args))
|
|
|
} : {
|
|
|
- d: common_vendor.o((...args) => $options.handleGetPhoneNumber && $options.handleGetPhoneNumber(...args))
|
|
|
+ f: common_vendor.o((...args) => $options.handleGetUserProfile && $options.handleGetUserProfile(...args))
|
|
|
}, {
|
|
|
- e: $data.agreedToTerms,
|
|
|
- f: common_vendor.o(($event) => $options.showAgreement("user")),
|
|
|
- g: common_vendor.o(($event) => $options.showAgreement("privacy")),
|
|
|
- h: common_vendor.o((...args) => $options.handleAgreementChange && $options.handleAgreementChange(...args)),
|
|
|
- i: common_vendor.sr("userInfoPopup", "cdfe2409-0"),
|
|
|
- j: common_vendor.o($options.handleUserInfoConfirm)
|
|
|
+ d: $data.showPhoneAuth,
|
|
|
+ g: $data.agreedToTerms,
|
|
|
+ h: common_vendor.o(($event) => $options.showAgreement("user")),
|
|
|
+ i: common_vendor.o(($event) => $options.showAgreement("privacy")),
|
|
|
+ j: common_vendor.o((...args) => $options.handleAgreementChange && $options.handleAgreementChange(...args)),
|
|
|
+ k: common_vendor.sr("userInfoPopup", "cdfe2409-0"),
|
|
|
+ l: common_vendor.o($options.handleUserInfoConfirm)
|
|
|
});
|
|
|
}
|
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-cdfe2409"], ["__file", "D:/program/gupiao-wx/src/pages/login/login.vue"]]);
|