Commit 488c97d8 authored by spc's avatar spc

user

parent 53739a2f
......@@ -21,7 +21,7 @@ export const useUserStore = defineStore("userInfo", {
babyInfo: null,
memberInfo: null,
babyNickCache: [],
cepingjieguoInfo:null,
cepingjieguoInfo: null,
};
},
actions: {
......@@ -63,7 +63,7 @@ export const useUserStore = defineStore("userInfo", {
* @param {Object} data : {encryptedData, iv, code}
* @returns
*/
async phoneCallback(data, onOpenRegisterFn = () => {}) {
async phoneCallback(data, onOpenRegisterFn = () => { }) {
uni.login({
provider: "weixin",
success: async (res) => {
......@@ -140,65 +140,65 @@ export const useUserStore = defineStore("userInfo", {
// }
// }
// },
async loadBabyInfo(retryCount = 0) {
const MAX_RETRIES = 3;
const RETRY_DELAY = 1000; // 1 second
try {
const { data } = await fetchBabyInfo();
console.log("babyInfo-宝宝信息", data);
if (data?.memberId !== "not_login") {
async loadBabyInfo(retryCount = 0) {
const MAX_RETRIES = 3;
const RETRY_DELAY = 1000; // 1 second
try {
const { data } = await fetchBabyInfo();
console.log("babyInfo-宝宝信息", data);
if (data?.memberId !== "not_login") {
this.babyInfo = data;
if (data.allBabyBaseInfo) {
if (data.allBabyBaseInfo) {
if (this.babyInfo.babyAge == "0月龄") {
this.babyInfo.babyAge = "1月龄";
}
console.log("this.11111", this.babyNickCache, data?.content?.id);
const findItem = this.babyNickCache.find(
(item) => item.id == data?.content?.id
);
if (data?.content?.id && findItem) {
this.babyInfo.babyName = findItem.name;
this.babyInfo.allBabyBaseInfo.forEach((item) => {
if (item.id == data?.content?.id) {
item.babyName = findItem.name;
}
});
}
return; // Success case, exit the function
} else {
console.log("this.babyInfo", '重新请求接口');
if (retryCount < MAX_RETRIES - 1) {
await new Promise(resolve => setTimeout(resolve, RETRY_DELAY));
return this.loadBabyInfo(retryCount + 1);
} else {
console.log("Max retries reached, giving up");
// Show user notification when max retries reached
// uni.showToast({
// title: "系统繁忙,请稍后再试",
// icon: "none",
// });
}
}
}
} catch (error) {
console.log("🚀 ~ loadBabyInfo ~ error:", error);
if (retryCount >= MAX_RETRIES - 1) {
// Show user notification when max retries reached with error
uni.showToast({
title: "系统繁忙,请稍后再试",
icon: "none",
});
}
}
},
console.log("this.11111", this.babyNickCache, data?.content?.id);
const findItem = this.babyNickCache.find(
(item) => item.id == data?.content?.id
);
if (data?.content?.id && findItem) {
this.babyInfo.babyName = findItem.name;
this.babyInfo.allBabyBaseInfo.forEach((item) => {
if (item.id == data?.content?.id) {
item.babyName = findItem.name;
}
});
}
return; // Success case, exit the function
} else {
console.log("this.babyInfo", '重新请求接口');
if (retryCount < MAX_RETRIES - 1) {
await new Promise(resolve => setTimeout(resolve, RETRY_DELAY));
return this.loadBabyInfo(retryCount + 1);
} else {
console.log("Max retries reached, giving up");
// Show user notification when max retries reached
// uni.showToast({
// title: "系统繁忙,请稍后再试",
// icon: "none",
// });
}
}
}
} catch (error) {
console.log("🚀 ~ loadBabyInfo ~ error:", error);
if (retryCount >= MAX_RETRIES - 1) {
// Show user notification when max retries reached with error
uni.showToast({
title: "系统繁忙,请稍后再试",
icon: "none",
});
}
}
},
/**
* 获取用户积分信息
*/
......@@ -228,7 +228,7 @@ export const useUserStore = defineStore("userInfo", {
console.log("autoLoginByCode", data);
// 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用
if (data && data.cuk) {
globalStore.setCuk(data.cuk,data.openId,data.unionId);
globalStore.setCuk(data.cuk, data.openId, data.unionId);
await this.loadUserInfo();
await this.loadBabyInfo();
......@@ -236,10 +236,10 @@ export const useUserStore = defineStore("userInfo", {
}
},
/**
* 用户自动登录
*/
async wxAutoLogin(cb=null) {
/**
* 用户自动登录
*/
async wxAutoLogin(cb = null) {
uni.login({
provider: "weixin",
success: async (res) => {
......@@ -264,19 +264,17 @@ export const useUserStore = defineStore("userInfo", {
* @param {sy使用}
* @returns
*/
async syWxAutoLogin(cb=null) {
async syWxAutoLogin(cb = null) {
uni.login({
provider: "weixin",
success: async (res) => {
console.log("wxAutoLogin", res);
if (res.errMsg === "login:ok") {
const { data } = await autoLoginByCode(code);
console.log("autoLoginByCode", data);
// 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用
if (data && data.cuk) {
globalStore.setCuk(data.cuk,data.openId,data.unionId);
cb && cb();
}
const { data } = await autoLoginByCode(res.code);
// 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用
if (data && data.cuk) {
globalStore.setCuk(data.cuk, data.openId, data.unionId);
cb && cb();
}
} else {
uni.showToast({
title: res.errMsg,
......
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