diff --git a/src/pages/uploadPhoto/uploadPhoto.vue b/src/pages/uploadPhoto/uploadPhoto.vue index 76f93c1..9b1a34b 100644 --- a/src/pages/uploadPhoto/uploadPhoto.vue +++ b/src/pages/uploadPhoto/uploadPhoto.vue @@ -332,171 +332,210 @@ async function toCloseStyle() { //#region 页面初始化 onLoad((options) => { - // 获取微信小程序的 AppID - // const appid = uni.getAccountInfoSync().miniProgram.appId; - // 微信登录授权 - if (userInfoModulesPinia.platForm == 2) { - uni.login({ - provider: "weixin", // 使用微信登录授权 - success: async (res) => { - console.log(res, "uni.login"); - if (res.code) { - try { - uni.showLoading({ - title: "加载中...", - mask: true, - }); - const data = { - appId: userInfoModulesPinia.getAppId(), - code: res.code, - }; - const res2 = await loginApi(data); - userInfoModulesPinia.openId = res2.data.openId; - if (res2.data.token) { - userInfoModulesPinia.token = res2.data.token; - uni.setStorageSync("token", userInfoModulesPinia.token); - console.log(userInfoModulesPinia.openId, "获取openid"); - // 获取头像和金币 - const res3 = await findImageApi(); - if (res3.data) { - uni.setStorageSync("userId", res3.data.id); - } - userInfoModulesPinia.myAvatar = - res3.data && res3.data.image ? res3.data.image : ""; - const res4 = await findGlodApi(); - if (res4.data) { - uni.setStorageSync("userId", res4.data.id); - } - if (!res4.data) { - userInfoModulesPinia.myGlod = 0; - } else { - userInfoModulesPinia.myGlod = res4.data.digitalAvatarResidueGlod - ? res4.data.digitalAvatarResidueGlod - : 0; - } + uni.getSystemInfo({ + success: function (res) { + let uniPlatform = ""; + let osName = ""; + if (res.uniPlatform == "web") { + uniPlatform = 1; + } else if (res.uniPlatform == "mp-weixin") { + uni.setStorageSync("plat", 1); + uniPlatform = 2; + } else if (res.uniPlatform == "mp-toutiao") { + uni.setStorageSync("plat", 2); + uniPlatform = 3; + } + if (res.osName == "windows") { + osName = 1; + } else if (res.osName == "ios") { + osName = 2; + } else if (res.osName == "android") { + osName = 3; + } else if (res.osName == "mac") { + osName = 4; + } else if (res.osName == "linux") { + osName = 5; + } - uni.hideLoading(); - if (res2.data.token) { + userInfoModulesPinia.platForm = uniPlatform; // 平台 + userInfoModulesPinia.hostSystem = osName; // 系统 + console.log(res.uniPlatform, uniPlatform, "PlatForm"); + console.log(res.osName, osName, "System"); + }, + complete: function (res) { + // 获取微信小程序的 AppID + // const appid = uni.getAccountInfoSync().miniProgram.appId; + // 微信登录授权 + if (userInfoModulesPinia.platForm == 2) { + uni.login({ + provider: "weixin", // 使用微信登录授权 + success: async (res) => { + console.log(res, "uni.login"); + if (res.code) { + try { + uni.showLoading({ + title: "加载中...", + mask: true, + }); + const data = { + appId: userInfoModulesPinia.getAppId(), + code: res.code, + }; + const res2 = await loginApi(data); + userInfoModulesPinia.openId = res2.data.openId; + if (res2.data.token) { + userInfoModulesPinia.token = res2.data.token; + uni.setStorageSync("token", userInfoModulesPinia.token); + console.log(userInfoModulesPinia.openId, "获取openid"); + // 获取头像和金币 + const res3 = await findImageApi(); + if (res3.data) { + uni.setStorageSync("userId", res3.data.id); + } + userInfoModulesPinia.myAvatar = + res3.data && res3.data.image ? res3.data.image : ""; + const res4 = await findGlodApi(); + if (res4.data) { + uni.setStorageSync("userId", res4.data.id); + } + if (!res4.data) { + userInfoModulesPinia.myGlod = 0; + } else { + userInfoModulesPinia.myGlod = res4.data + .digitalAvatarResidueGlod + ? res4.data.digitalAvatarResidueGlod + : 0; + } + + uni.hideLoading(); + if (res2.data.token) { + // uni.redirectTo({ + // url: "/pages/index/index", + // }); + } else { + uni.redirectTo({ + url: "/pages/login/index", + }); + console.log("error1"); + uni.showToast({ + title: "登录失败,请重试", + icon: "none", + }); + } + } + uni.hideLoading(); + } catch (error) { // uni.redirectTo({ - // url: "/pages/index/index", + // url: "pages/index/index", // }); - } else { - uni.redirectTo({ - url: "/pages/login/index", - }); - console.log("error1"); + console.log(error, "error2"); uni.showToast({ title: "登录失败,请重试", icon: "none", }); } + } else { + // uni.redirectTo({ + // url: "pages/index/index", + // }); + console.log("error3"); + uni.showToast({ + title: "登录失败,请重试", + icon: "none", + }); } - uni.hideLoading(); - } catch (error) { + }, + fail: (err) => { // uni.redirectTo({ // url: "pages/index/index", // }); - console.log(error, "error2"); + console.log("error4"); uni.showToast({ title: "登录失败,请重试", icon: "none", }); - } - } else { - // uni.redirectTo({ - // url: "pages/index/index", - // }); - console.log("error3"); - uni.showToast({ - title: "登录失败,请重试", - icon: "none", - }); - } - }, - fail: (err) => { - // uni.redirectTo({ - // url: "pages/index/index", - // }); - console.log("error4"); - uni.showToast({ - title: "登录失败,请重试", - icon: "none", + }, }); - }, - }); - } - // 抖音头条授权 - else if (userInfoModulesPinia.platForm == 3) { - uni.login({ - provider: "toutiao", // 使用微信登录授权 - success: async (res) => { - if (res.code) { - try { - uni.showLoading({ - title: "加载中...", - mask: true, - }); - const data = { - appId: userInfoModulesPinia.getAppId(), - code: res.code, - }; - const res2 = await loginApi(data); - userInfoModulesPinia.openId = res2.data.openId; - if (res2.data.token) { - userInfoModulesPinia.token = res2.data.token; - uni.setStorageSync("token", userInfoModulesPinia.token); - console.log(userInfoModulesPinia.openId, "获取openid"); - // 获取头像和金币 - const res3 = await findImageApi(); - userInfoModulesPinia.myAvatar = - res3.data && res3.data.image ? res3.data.image : ""; - const res4 = await findGlodApi(); - if (!res4.data) { - userInfoModulesPinia.myGlod = 0; - } else { - userInfoModulesPinia.myGlod = res4.data.digitalAvatarResidueGlod - ? res4.data.digitalAvatarResidueGlod - : 0; + } + // 抖音头条授权 + else if (userInfoModulesPinia.platForm == 3) { + console.log("platForm3"); + uni.login({ + provider: "toutiao", // 使用抖音登录授权 + success: async (res) => { + if (res.code) { + console.log("code"); + try { + uni.showLoading({ + title: "加载中...", + mask: true, + }); + const data = { + appId: userInfoModulesPinia.getAppId(), + code: res.code, + }; + const res2 = await loginApi(data); + userInfoModulesPinia.openId = res2.data.openId; + if (res2.data.token) { + console.log(res2.data.token, "res2.data.token"); + userInfoModulesPinia.token = res2.data.token; + uni.setStorageSync("token", userInfoModulesPinia.token); + console.log(userInfoModulesPinia.openId, "获取openid"); + // 获取头像和金币 + + const res3 = await findImageApi(); + userInfoModulesPinia.myAvatar = + res3.data && res3.data.image ? res3.data.image : ""; + const res4 = await findGlodApi(); + if (!res4.data) { + userInfoModulesPinia.myGlod = 0; + } else { + userInfoModulesPinia.myGlod = res4.data + .digitalAvatarResidueGlod + ? res4.data.digitalAvatarResidueGlod + : 0; + } + getCount(); + uni.hideLoading(); + } else { + uni.hideLoading(); + uni.redirectTo({ + url: "/pages/login/index", + }); + console.log("error1"); + uni.showToast({ + title: "登录失败,请重试", + icon: "none", + }); + } + uni.hideLoading(); + } catch (error) { + uni.hideLoading(); + console.log(error, "error2"); + uni.showToast({ + title: "登录失败,请重试", + icon: "none", + }); } - getCount(); - uni.hideLoading(); } else { - uni.hideLoading(); - uni.redirectTo({ - url: "/pages/login/index", - }); - console.log("error1"); + console.log("error3"); uni.showToast({ title: "登录失败,请重试", icon: "none", }); } - uni.hideLoading(); - } catch (error) { - uni.hideLoading(); - console.log(error, "error2"); + }, + fail: (err) => { + console.log("error4"); uni.showToast({ title: "登录失败,请重试", icon: "none", }); - } - } else { - console.log("error3"); - uni.showToast({ - title: "登录失败,请重试", - icon: "none", - }); - } - }, - fail: (err) => { - console.log("error4"); - uni.showToast({ - title: "登录失败,请重试", - icon: "none", + }, }); - }, - }); - } + } + }, + }); // 如果是从相机页返回 });