diff --git a/src/App.vue b/src/App.vue index e5b6ee4..628ec32 100644 --- a/src/App.vue +++ b/src/App.vue @@ -56,16 +56,18 @@ onLaunch(() => { code: res.code, }; const res2 = await loginApi(data); - userInfoModulesPinia.openId = res2.openId; + userInfoModulesPinia.openId = res2.data.openId; + userInfoModulesPinia.token = res2.token; + console.log(userInfoModulesPinia.openId, "获取openid"); uni.hideLoading(); - if (res2.code == 200) { + if (res2.token) { uni.redirectTo({ - url: "pages/home/index", + url: "/pages/home/index", }); } else { - // uni.redirectTo({ - // url: "pages/index/index", - // }); + uni.redirectTo({ + url: "/pages/index/index", + }); uni.showToast({ title: "登录失败,请重试", icon: "none", diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index b13f462..d92034f 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -38,12 +38,13 @@ //#region 导入 import { ref, reactive } from "vue"; import { voiceTotalApi, loginPhoneApi } from "../../api/login.js"; - +import { userInfoModules } from "@/store/modules/userInfo"; //#endregion +const userInfoModulesPinia = userInfoModules(); //#region 勾选 const checkboxValue1 = ref([]); -const checkboxList1 = reactive([ +const checkboxList1 = ref([ { name: "同意智像相机用户使用协议", disabled: false, @@ -58,6 +59,7 @@ async function toCreate() { content: "同意慧图相机用户使用协议?", success: function (res) { if (res.confirm) { + checkboxList1.value[0].disabled = true; handleLogin(); } else if (res.cancel) { } @@ -70,13 +72,29 @@ async function handleLogin() { // uni.getUserInfo({}); uni.getUserProfile({ desc: "用于完善用户信息", - success: (res1) => { + success: async (res1) => { userInfo.value = res1.userInfo; - console.log(res1); - uni.showToast({ - icon: "none", - title: "获取成功", - }); + userInfoModulesPinia.userInfo = res1.userInfo; + console.log(userInfoModulesPinia.openId, "拿出openid"); + + const data = { + appId: "wx75cf14e3a0d45821", + openId: userInfoModulesPinia.openId, + encryptedData: res1.encryptedData, + iv: res1.iv, + }; + try { + const res2 = await loginPhoneApi(data); + uni.showToast({ + icon: "none", + title: "获取成功", + }); + } catch (error) { + uni.showToast({ + icon: "none", + title: "获取失败", + }); + } }, fail: (err) => { console.log(err); diff --git a/src/store/modules/userInfo.js b/src/store/modules/userInfo.js index ed1cf04..4a95363 100644 --- a/src/store/modules/userInfo.js +++ b/src/store/modules/userInfo.js @@ -4,6 +4,7 @@ export const userInfoModules = defineStore("userInfoStore", () => { // state const userInfo = ref(null) const openId = ref(null) + const token = ref(null) /** * @description:依托平台:(web、mp-weixin、mp-toutiao) * @example 平台名:"web-H5",枚举值:1