修复切换页面nan问题

This commit is contained in:
2025-05-08 16:24:39 +08:00
parent 1f59082bcb
commit ac28ee855f
6 changed files with 115 additions and 69 deletions

View File

@@ -9,7 +9,8 @@ import {
APIuser
} from '@/common/api/api.js'
import {
APIproductqueryShop,APIusershopInfodetail,
APIproductqueryShop,
APIusershopInfodetail,
APIshopUserInfo
} from '@/common/api/member.js'
export const Storelogin = defineStore('login', {
@@ -17,11 +18,13 @@ export const Storelogin = defineStore('login', {
token: '',
miniAppOpenId: '',
userInfo: '',
shopInfo:{}
shopInfo: {}
}),
actions: {
async getShopInfo(shopId){
const shopRes=await APIusershopInfodetail({shopId})
async getShopInfo(shopId) {
const shopRes = await APIusershopInfodetail({
shopId
})
console.log(shopRes);
},
actionslogin() {
@@ -104,15 +107,15 @@ export const productStore = defineStore('product', {
return new Promise(async (resolve, reject) => {
if (q) {
console.log(q)
let tableCode =""
let tableCode = ""
// #ifdef MP-WEIXIN
tableCode = this.getQueryString(decodeURIComponent(q), 'code')
tableCode = this.getQueryString(decodeURIComponent(q), 'code')
// #endif
// #ifdef MP-ALIPAY
tableCode = q
tableCode = q
// #endif
// #ifdef H5
tableCode= q.tableCode
tableCode = q.tableCode
// #endif
console.log(tableCode);
// 储存卓玛
@@ -120,6 +123,8 @@ export const productStore = defineStore('product', {
if (tableCode) {
console.log(uni.cache.get('tableCode'));
let data = await this.actionsproductqueryShop(tableCode)
console.log('data', data)
// -4请求登录
if (data.code == '500') {
if (await this.actionslogin()) {
@@ -149,6 +154,13 @@ export const productStore = defineStore('product', {
uni.cache.set('tableCode', tableCode)
if (tableCode) {
let data = await this.actionsproductqueryShop()
if (!data) {
uni.showToast({
title: '店铺已过期或其他问题,请联系商家',
icon:'none'
})
return
}
// -4请求登录
const store = Storelogin()
if (data.code == '-4') {
@@ -176,7 +188,7 @@ export const productStore = defineStore('product', {
});
// #endif
}
})
},
@@ -184,21 +196,33 @@ export const productStore = defineStore('product', {
actionsproductqueryShop(tableCode) {
return new Promise(async (resolve, reject) => {
// try {
let res = await APIproductqueryShop({
tableCode: tableCode?tableCode:uni.cache.get('tableCode'),
})
res.shopInfo.isVip = res.vip ? '1' : '0'
res.shopTable.shopExtendMap = res.shopExtendMap
// 店铺信息
uni.cache.set('shopTable', res.shopTable)
// 台桌信息
uni.cache.set('shopInfo', res.shopInfo)
uni.cache.set('shopId', res.shopTable.shopId, 30)
// 当前用户距离店铺的米数
uni.cache.set('distance', res.distance)
try {
let res = await APIproductqueryShop({
tableCode: tableCode ? tableCode : uni.cache.get('tableCode'),
})
if (res) {
res.shopInfo.isVip = res.vip ? '1' : '0'
res.shopTable.shopExtendMap = res.shopExtendMap
// 店铺信息
uni.cache.set('shopTable', res.shopTable)
// 台桌信息
uni.cache.set('shopInfo', res.shopInfo)
uni.cache.set('shopId', res.shopTable.shopId, 30)
// 当前用户距离店铺的米数
uni.cache.set('distance', res.distance)
resolve(res)
} else {
console.log(res)
reject()
}
} catch (error) {
console.log(error);
reject()
//TODO handle the exception
}
resolve(res)
// } catch (e) {
// reject(false)
// }
@@ -214,7 +238,7 @@ export const productStore = defineStore('product', {
uni.cache.set('shopUserInfo', res);
uni.cache.set('orderVIP', res)
uni.cache.set('ordershopUserInfo', res.shopInfo)
resolve(true)
resolve(res)
} catch (e) {
reject(false)
}
@@ -226,14 +250,16 @@ export const productStore = defineStore('product', {
actionsAPIuser() {
return new Promise(async (resolve, reject) => {
try {
let res = null
// 获取店铺用户会员信息
if (uni.cache.get('shopId')) {
this.actionsproductqueryProduct()
res = await this.actionsproductqueryProduct()
} else {
let res = await APIuser()
res = await APIuser()
uni.cache.set('userInfo', res);
}
resolve(true)
console.log('actionsAPIuser res', res);
resolve(res)
} catch (e) {
reject(false)
}