Browse Source

Merge remote-tracking branch 'origin/dev_czc' into dev

master
congzc 1 year ago
parent
commit
28ff1f9da7
3 changed files with 35 additions and 14 deletions
  1. +8
    -6
      src/App.vue
  2. +26
    -8
      src/pages/index/index.vue
  3. +1
    -0
      src/store/modules/userInfo.js

+ 8
- 6
src/App.vue View File

@@ -56,16 +56,18 @@ onLaunch(() => {
code: res.code, code: res.code,
}; };
const res2 = await loginApi(data); 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(); uni.hideLoading();
if (res2.code == 200) {
if (res2.token) {
uni.redirectTo({ uni.redirectTo({
url: "pages/home/index",
url: "/pages/home/index",
}); });
} else { } else {
// uni.redirectTo({
// url: "pages/index/index",
// });
uni.redirectTo({
url: "/pages/index/index",
});
uni.showToast({ uni.showToast({
title: "登录失败,请重试", title: "登录失败,请重试",
icon: "none", icon: "none",


+ 26
- 8
src/pages/index/index.vue View File

@@ -38,12 +38,13 @@
//#region 导入 //#region 导入
import { ref, reactive } from "vue"; import { ref, reactive } from "vue";
import { voiceTotalApi, loginPhoneApi } from "../../api/login.js"; import { voiceTotalApi, loginPhoneApi } from "../../api/login.js";
import { userInfoModules } from "@/store/modules/userInfo";
//#endregion //#endregion
const userInfoModulesPinia = userInfoModules();
//#region 勾选 //#region 勾选
const checkboxValue1 = ref([]); const checkboxValue1 = ref([]);
const checkboxList1 = reactive([
const checkboxList1 = ref([
{ {
name: "同意智像相机用户使用协议", name: "同意智像相机用户使用协议",
disabled: false, disabled: false,
@@ -58,6 +59,7 @@ async function toCreate() {
content: "同意慧图相机用户使用协议?", content: "同意慧图相机用户使用协议?",
success: function (res) { success: function (res) {
if (res.confirm) { if (res.confirm) {
checkboxList1.value[0].disabled = true;
handleLogin(); handleLogin();
} else if (res.cancel) { } else if (res.cancel) {
} }
@@ -70,13 +72,29 @@ async function handleLogin() {
// uni.getUserInfo({}); // uni.getUserInfo({});
uni.getUserProfile({ uni.getUserProfile({
desc: "用于完善用户信息", desc: "用于完善用户信息",
success: (res1) => {
success: async (res1) => {
userInfo.value = res1.userInfo; 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) => { fail: (err) => {
console.log(err); console.log(err);


+ 1
- 0
src/store/modules/userInfo.js View File

@@ -4,6 +4,7 @@ export const userInfoModules = defineStore("userInfoStore", () => {
// state // state
const userInfo = ref(null) const userInfo = ref(null)
const openId = ref(null) const openId = ref(null)
const token = ref(null)
/** /**
* @description:依托平台:(web、mp-weixin、mp-toutiao) * @description:依托平台:(web、mp-weixin、mp-toutiao)
* @example 平台名:"web-H5",枚举值:1 * @example 平台名:"web-H5",枚举值:1


Loading…
Cancel
Save