|
@@ -4,7 +4,9 @@ const common_assets = require("../../common/assets.js");
|
|
|
const _sfc_main = {
|
|
|
data() {
|
|
|
return {
|
|
|
- isAgreed: false
|
|
|
+ isAgreed: false,
|
|
|
+ showServiceAgreement: false,
|
|
|
+ showPrivacyPolicy: false
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
@@ -15,45 +17,114 @@ const _sfc_main = {
|
|
|
// 微信登录
|
|
|
async handleWechatLogin() {
|
|
|
if (!this.isAgreed) {
|
|
|
- common_vendor.index.showToast({
|
|
|
- title: "请先同意服务协议和隐私政策",
|
|
|
- icon: "none"
|
|
|
- });
|
|
|
+ common_vendor.index.showToast({ title: "请先同意用户协议和隐私政策", icon: "none" });
|
|
|
return;
|
|
|
}
|
|
|
- common_vendor.wx$1.login({
|
|
|
- success: function(res) {
|
|
|
- if (res.code) {
|
|
|
- common_vendor.index.__f__("log", "at pages/login/index.vue:79", res.code);
|
|
|
- common_vendor.wx$1.request({
|
|
|
- url: "http://localhost:9527/api/wx-login",
|
|
|
- method: "POST",
|
|
|
- // 设置请求头,指定请求体为 JSON 格式
|
|
|
- header: {
|
|
|
- "content-type": "application/json"
|
|
|
- },
|
|
|
- data: {
|
|
|
- code: res.code
|
|
|
- },
|
|
|
- success: function(response) {
|
|
|
- common_vendor.index.__f__("log", "at pages/login/index.vue:92", response.data);
|
|
|
- },
|
|
|
- fail: function(err) {
|
|
|
- common_vendor.index.__f__("error", "at pages/login/index.vue:95", err);
|
|
|
- }
|
|
|
+ try {
|
|
|
+ const loginResult = await new Promise((resolve, reject) => {
|
|
|
+ common_vendor.index.login({
|
|
|
+ provider: "weixin",
|
|
|
+ success: (res) => resolve(res),
|
|
|
+ fail: (err) => reject(err)
|
|
|
+ });
|
|
|
+ });
|
|
|
+ if (!loginResult.code) {
|
|
|
+ common_vendor.index.showToast({ title: "获取登录凭证失败", icon: "none" });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ common_vendor.index.__f__("log", "at pages/login/index.vue:88", "获取到的code:", loginResult.code);
|
|
|
+ const userInfoResult = await new Promise((resolve, reject) => {
|
|
|
+ common_vendor.index.getUserInfo({
|
|
|
+ provider: "weixin",
|
|
|
+ withCredentials: true,
|
|
|
+ success: (res) => resolve(res),
|
|
|
+ fail: (err) => reject(err)
|
|
|
+ });
|
|
|
+ });
|
|
|
+ if (!userInfoResult.userInfo) {
|
|
|
+ common_vendor.index.showToast({ title: "获取用户信息失败", icon: "none" });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const loginRes = await common_vendor.index.request({
|
|
|
+ url: "http://localhost:9527/api/wx-login",
|
|
|
+ method: "POST",
|
|
|
+ data: {
|
|
|
+ code: loginResult.code,
|
|
|
+ nickName: userInfoResult.userInfo.nickName,
|
|
|
+ avatarUrl: userInfoResult.userInfo.avatarUrl,
|
|
|
+ gender: userInfoResult.userInfo.gender.toString(),
|
|
|
+ country: userInfoResult.userInfo.country,
|
|
|
+ province: userInfoResult.userInfo.province,
|
|
|
+ city: userInfoResult.userInfo.city,
|
|
|
+ language: userInfoResult.userInfo.language,
|
|
|
+ rawData: userInfoResult.rawData,
|
|
|
+ signature: userInfoResult.signature,
|
|
|
+ encryptedData: userInfoResult.encryptedData,
|
|
|
+ iv: userInfoResult.iv
|
|
|
+ },
|
|
|
+ header: {
|
|
|
+ "content-type": "application/json"
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (loginRes.data.errcode === 40029) {
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/index.vue:130", "微信登录code无效,尝试重新获取");
|
|
|
+ const newLoginResult = await new Promise((resolve, reject) => {
|
|
|
+ common_vendor.index.login({
|
|
|
+ provider: "weixin",
|
|
|
+ success: (res) => resolve(res),
|
|
|
+ fail: (err) => reject(err)
|
|
|
+ });
|
|
|
+ });
|
|
|
+ if (!newLoginResult.code) {
|
|
|
+ throw new Error("重新获取登录凭证失败");
|
|
|
+ }
|
|
|
+ const retryRes = await common_vendor.index.request({
|
|
|
+ url: "http://localhost:9527/api/wx-login",
|
|
|
+ method: "POST",
|
|
|
+ data: {
|
|
|
+ code: newLoginResult.code,
|
|
|
+ nickName: userInfoResult.userInfo.nickName,
|
|
|
+ avatarUrl: userInfoResult.userInfo.avatarUrl,
|
|
|
+ gender: userInfoResult.userInfo.gender.toString(),
|
|
|
+ country: userInfoResult.userInfo.country,
|
|
|
+ province: userInfoResult.userInfo.province,
|
|
|
+ city: userInfoResult.userInfo.city,
|
|
|
+ language: userInfoResult.userInfo.language,
|
|
|
+ rawData: userInfoResult.rawData,
|
|
|
+ signature: userInfoResult.signature,
|
|
|
+ encryptedData: userInfoResult.encryptedData,
|
|
|
+ iv: userInfoResult.iv
|
|
|
+ },
|
|
|
+ header: {
|
|
|
+ "content-type": "application/json"
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (retryRes.statusCode === 200 && !retryRes.data.errcode) {
|
|
|
+ common_vendor.index.setStorageSync("token", retryRes.data.data.token);
|
|
|
+ common_vendor.index.setStorageSync("userInfo", retryRes.data.data.userInfo);
|
|
|
+ common_vendor.index.switchTab({
|
|
|
+ url: "/pages/discover/index"
|
|
|
});
|
|
|
} else {
|
|
|
- common_vendor.index.__f__("log", "at pages/login/index.vue:99", "获取 code 失败!" + res.errMsg);
|
|
|
+ throw new Error(retryRes.data.errmsg || "登录失败");
|
|
|
}
|
|
|
+ } else if (loginRes.statusCode === 200 && !loginRes.data.errcode) {
|
|
|
+ common_vendor.index.setStorageSync("token", loginRes.data.data.token);
|
|
|
+ common_vendor.index.setStorageSync("userInfo", loginRes.data.data.userInfo);
|
|
|
+ common_vendor.index.switchTab({
|
|
|
+ url: "/pages/discover/index"
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ throw new Error(loginRes.data.errmsg || "登录失败");
|
|
|
}
|
|
|
- });
|
|
|
+ } catch (error) {
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/index.vue:192", "登录过程出错:", error);
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: error.message || "登录失败,请重试",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
- // // 跳转到密码登录页面
|
|
|
- // navigateToPasswordLogin() {
|
|
|
- // uni.navigateTo({
|
|
|
- // url: '/pages/login/password'
|
|
|
- // })
|
|
|
- // },
|
|
|
// 跳转到验证码登录页面
|
|
|
navigateToVerifyCodeLogin() {
|
|
|
common_vendor.index.navigateTo({
|