Commit 4fd99654 authored by chenkai@duiba.com.cn's avatar chenkai@duiba.com.cn

Merge branch '20251014-dev-checkLogin' into dev

# Conflicts:
#	.DS_Store
parents 0def7942 8fa819d3
......@@ -37,6 +37,8 @@ async function onRegisterCancel() {
userStore.loadUserInfo(),
])
//用户信息更新,抛出事件
uni.$emit("updateUserInfo");
uni.navigateBack({
delta: 1
})
......
......@@ -21,31 +21,31 @@ import md from "../md.js";
const globalStore = useGlobalStore();
export const useUserStore = defineStore("userInfo", {
state: () => {
return {
userInfo: null,
babyInfo: null,
memberInfo: null,
babyNickCache: [],
cepingjieguoInfo: null,
};
},
state: () => {
return {
userInfo: null,
babyInfo: null,
memberInfo: null,
babyNickCache: [],
cepingjieguoInfo: null,
};
},
getters: {
isLogin: (state) => {
return state.userInfo?.memberId !== "not_login"
}
},
actions: {
/**
* 更新用户信息
* @param {Object} userInfo
*/
setUserInfo(userInfo) {
this.userInfo = userInfo;
},
setMemberInfo(memberInfo) {
this.memberInfo = memberInfo;
},
isLogin: (state) => {
return state.userInfo?.memberId !== "not_login"
}
},
actions: {
/**
* 更新用户信息
* @param {Object} userInfo
*/
setUserInfo(userInfo) {
this.userInfo = userInfo;
},
setMemberInfo(memberInfo) {
this.memberInfo = memberInfo;
},
/**
* 更新宝宝信息
......@@ -76,8 +76,7 @@ export const useUserStore = defineStore("userInfo", {
* @param {Object} data : {encryptedData, iv, code}
* @returns
*/
async phoneCallback(data, onOpenRegisterFn = () => {
}, cb = null, cb2 = null, invitationInfo = null) {
async phoneCallback(data, onOpenRegisterFn = () => {}, cb = null, cb2 = null, invitationInfo = null) {
uni.login({
provider: "weixin",
success: async (res) => {
......@@ -85,7 +84,9 @@ export const useUserStore = defineStore("userInfo", {
if (res.errMsg === "login:ok") {
// 用户手机授权F
const {
data: {babyExistence}
data: {
babyExistence
}
} = await fetchAutoPhone({
phoneEncryptedData: data.encryptedData,
phoneIv: data.iv,
......@@ -126,6 +127,7 @@ export const useUserStore = defineStore("userInfo", {
// 缓存用户memberId
uni.setStorageSync('memberId', data?.memberId)
}
uni.setStorageSync('loginStatus', data?.memberId == "not_login" ? 0 : 1)
this.userInfo = data;
},
......@@ -171,7 +173,9 @@ export const useUserStore = defineStore("userInfo", {
const RETRY_DELAY = 1000; // 1 second
try {
const {data} = await fetchBabyInfo();
const {
data
} = await fetchBabyInfo();
console.log("babyInfo-宝宝信息", data);
if (data?.memberId !== "not_login") {
......@@ -299,7 +303,9 @@ export const useUserStore = defineStore("userInfo", {
provider: "weixin",
success: async (res) => {
if (res.errMsg === "login:ok") {
const {data} = await autoLoginByCode(res.code);
const {
data
} = await autoLoginByCode(res.code);
// 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用
if (data && data.cuk) {
globalStore.setCuk(data.cuk, data.openId, data.unionId);
......@@ -329,7 +335,9 @@ export const useUserStore = defineStore("userInfo", {
provider: "weixin",
success: async (res) => {
if (res.errMsg === "login:ok") {
const {data} = await autoLoginByCode(res.code);
const {
data
} = await autoLoginByCode(res.code);
// 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用
if (data && data.cuk) {
globalStore.setCuk(data.cuk, data.openId, data.unionId);
......
import {
JumpType,
jump
} from ".";
import {
useUserStore
} from "../stores/user";
export function checkLogin(back) {
const userStore = useUserStore();
const memberInfo = userStore.memberInfo;
if (!memberInfo?.memberId || memberInfo?.memberId == "not_login") { //未登录
jump({
type: JumpType.INNER,
url: "/pages/activity/register"
})
// 监听用户信息更新
uni.$once('updateUserInfo', () => {
if (back) {
back();
}
})
return
}
if (back) {
back();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment