修改websocket为全局只有一个

This commit is contained in:
2025-05-19 09:07:35 +08:00
parent ac28ee855f
commit c7e4e5e26b
8 changed files with 3780 additions and 269 deletions

View File

@@ -27,7 +27,7 @@ export const useCartsStore = defineStore('cart',
const goodsMap = reactive({})
//获取商品数据
async function goodsInit() {
goodsIsloading.value=true;
goodsIsloading.value = true;
//获取招牌菜商品
const hotres = await productminiApphotsquery();
for (let product of hotres) {
@@ -102,12 +102,10 @@ export const useCartsStore = defineStore('cart',
return getProductDetails(v)
}).filter(v => v)
}
//收到socket消息时对购物车进行处理
async function onMessage(Message) {
console.log('Message');
console.log(Message);
if (Message) {
// 心跳返回 过滤
if (Message.type == "ping_interval" || Message.msg_id == "ping_interval") {
@@ -184,8 +182,8 @@ export const useCartsStore = defineStore('cart',
}
}
//购物车数据
const carts = ref([])
@@ -219,13 +217,13 @@ export const useCartsStore = defineStore('cart',
//是否使用会员价
const useVipPrice = computed(() => {
const isUse=(orderVIP.value.isVip && shopInfo.value.isMemberPrice)?true:false
console.log('useVipPrice',isUse);
const isUse = (orderVIP.value.isVip && shopInfo.value.isMemberPrice) ? true : false
return isUse
})
function currentCalcMpneyNumber(item){
const n=item.number-(item.returnNum||0)
return n<=0?0:n
function currentCalcMpneyNumber(item) {
const n = item.number - (item.returnNum || 0)
return n <= 0 ? 0 : n
}
//历史订单商品价格总和
const oldOrderMoney = computed(() => {
@@ -239,7 +237,7 @@ export const useCartsStore = defineStore('cart',
const memberPrice = cur.skuData ? (cur.skuData.memberPrice || cur.skuData
.salePrice) : 0
const price = (discount_sale_amount || cur.salePrice || 0)
const number =currentCalcMpneyNumber(cur)
const number = currentCalcMpneyNumber(cur)
return prve + (number <= 0 ? 0 : number) * (discount_sale_amount || (useVipPrice
.value ? memberPrice : price))
}, 0)
@@ -252,7 +250,7 @@ export const useCartsStore = defineStore('cart',
const money = carts.value.reduce((prve, cur) => {
const memberPrice = cur.memberPrice || cur.salePrice
const price = useVipPrice.value ? memberPrice : cur.salePrice;
const curMoney = price * currentCalcMpneyNumber(cur)
const curMoney = price * currentCalcMpneyNumber(cur)
return prve + curMoney
}, 0)
return money
@@ -260,7 +258,7 @@ export const useCartsStore = defineStore('cart',
// 霸王餐购物车原价,不享受任何优惠
const totalOriginPrice = computed(() => {
const money = carts.value.reduce((prve, cur) => {
const curMoney = cur.salePrice * currentCalcMpneyNumber(cur)
const curMoney = cur.salePrice * currentCalcMpneyNumber(cur)
return prve + curMoney
}, 0)
return money
@@ -274,7 +272,7 @@ export const useCartsStore = defineStore('cart',
// return pre + returnProDiscount(cur, index) * 1;
// }, 0);
// });
//返回打包数量称重商品打包数量最大为1
function returnCartPackNumber(cur) {
@@ -285,17 +283,17 @@ export const useCartsStore = defineStore('cart',
pack_number = pack_number <= 0 ? 0 : pack_number
return pack_number * 1
}
//当前购物车打包费
const totalPackFee = computed(() => {
const money = carts.value.reduce((prve, cur) => {
const curMoney = (cur.packFee || 0) * currentCalcMpneyNumber(cur)
const curMoney = (cur.packFee || 0) * currentCalcMpneyNumber(cur)
return prve + curMoney
}, 0)
return money
})
//打包费
const packFee = computed(() => {
const nowPackFee = carts.value.reduce((acc, cur) => {
@@ -351,7 +349,7 @@ export const useCartsStore = defineStore('cart',
console.log('isBwc');
console.log(isBwc);
let cart = matchedProducts.reduce((total, item) => {
if(isBwc===true){
if (isBwc === true) {
return total + (parseFloat(item.price) * parseFloat(item.num - item.returnNum));
}
// 是否启用会员价 0否1是
@@ -447,7 +445,8 @@ export const useCartsStore = defineStore('cart',
totalPrice,
totalPackFee,
updateData,
useVipPrice,totalOriginPrice
useVipPrice,
totalOriginPrice
};
}
);