Commit 488c97d8 authored by spc's avatar spc

user

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