问题修复

This commit is contained in:
2025-11-06 10:42:42 +08:00
parent 0f6c87efc7
commit ab350ccc14
9 changed files with 332 additions and 217 deletions

View File

@@ -1,120 +1,138 @@
export default (params) => {
let url = params.url;
let method = params.method || "get";
let data = params.data || {};
let type = params.type || 1;
let toast = params.toast || true;
let token=uni.cache.get('token') || '';
const shopId=uni.cache.get('shopId')*1;
const userInfo=uni.cache.get('userInfo')||{};
// #ifdef H5
token="21f0a0b10e1d40ce9c6464037fedb792"
// #endif
let header = {
version: uni.conf.version,
type: uni.getSystemInfoSync().platform,
// #ifdef APP-PLUS
platformType: 'APP',
// #endif
// #ifdef H5
platformType: 'H5',
// #endif
// #ifdef MP-WEIXIN
platformType: 'WX',
// #endif
// #ifdef MP-ALIPAY
platformType: 'ALI',
// #endif
token,
id: userInfo.id || '',
shopId:shopId || '',
userId: userInfo.id || '',
}
if (toast) {
uni.showLoading({
title: '加载中',
mask: true
})
}
return new Promise((resolve, reject) => {
const timeoutDuration = params.timeout || 10000; // 可以通过 params 传入超时时间,默认 10 秒
uni.request({
url: uni.conf.baseUrl + url,
method: method,
header: header,
data: data,
timeout: timeoutDuration,
success(response) {
const res = response.data
// 根据返回的状态码做出对应的操作
//获取成功
if (res.code == 200) {
uni.hideLoading();
uni.hideToast();
resolve(res.data ? res.data : true);
} else {
switch (res.code) {
case '501':
uni.cache.remove('shopId')
// uni.showToast({
// title: '',
// icon: "none",
// success: () => {
let url = params.url;
let method = params.method || "get";
let data = params.data || {};
let type = params.type || 1;
let toast = params.toast || true;
let token = uni.cache.get("token") || "";
const shopId = uni.cache.get("shopId") * 1;
const userInfo = uni.cache.get("userInfo") || {};
// #ifdef H5
token = "21f0a0b10e1d40ce9c6464037fedb792";
// #endif
let header = {
version: uni.conf.version,
type: uni.getSystemInfoSync().platform,
// #ifdef APP-PLUS
platformType: "APP",
// #endif
// #ifdef H5
platformType: "H5",
// #endif
// #ifdef MP-WEIXIN
platformType: "WX",
// #endif
// #ifdef MP-ALIPAY
platformType: "ALI",
// #endif
token,
id: userInfo.id || "",
shopId: shopId || "",
userId: userInfo.id || "",
};
if (toast) {
uni.showLoading({
title: "加载中",
mask: true,
});
}
return new Promise((resolve, reject) => {
const timeoutDuration = params.timeout || 10000; // 可以通过 params 传入超时时间,默认 10 秒
uni.request({
url: uni.conf.baseUrl + url,
method: method,
header: header,
data: data,
timeout: timeoutDuration,
success(response) {
const res = response.data;
// 根据返回的状态码做出对应的操作
//获取成功
if (res.code == 200) {
uni.hideLoading();
uni.hideToast();
resolve(res.data ? res.data : true);
} else {
switch (res.code) {
case "501":
uni.cache.remove("shopId");
// uni.showToast({
// title: '',
// icon: "none",
// success: () => {
// }
// })
setTimeout(() => {
uni.reLaunch({
url: "/pages/index/index",
})
}, 1000);
break;
case 404:
uni.showToast({
title: '请求地址不存在...',
duration: 2000,
})
break;
default:
// 是否提示
if (toast) {
uni.showToast({
title: res.message || res.msg || res.error,
icon: "none",
success: () => {
setTimeout(res => {
reject(false);
}, 1000)
}
})
}
break;
}
}
},
fail(err) {
if (err.errMsg.indexOf('request:fail') !== -1) {
if (err.errMsg.indexOf('timeout') !== -1) {
if (toast) {
uni.showToast({
title: `请求超时,请稍后重试`,
icon: "error",
duration: 2000
});
}
}
}
reject(err);
},
complete() {
// 不管成功还是失败都会执行
setTimeout(res => {
uni.hideLoading();
uni.hideToast();
}, 10000)
}
});
}).catch((e) => {
});
};
// }
// })
setTimeout(() => {
uni.reLaunch({
url: "/pages/index/index",
});
}, 1000);
break;
case 404:
uni.showToast({
title: "请求地址不存在...",
duration: 2000,
});
break;
default:
// 是否提示
if (toast) {
uni.showToast({
title: (() => {
// 1. 获取原始提示文本(兜底空字符串避免报错)
const originMsg = res.message || res.msg || res.error || "";
// 2. 定义要匹配的前缀
const exceptionPrefix = "Exception:";
// 3. 判断是否包含目标前缀
if (originMsg.includes(exceptionPrefix)) {
// 截取前缀后的内容 → 去除首尾空格 → 限制最大20个字符
return originMsg
.slice(
originMsg.indexOf(exceptionPrefix) +
exceptionPrefix.length
)
.trim()
.slice(0, 20);
} else {
// 不包含则按原逻辑截取前20个字符
return originMsg.slice(0, 20);
}
})(),
icon: "none",
success: () => {
// 修复:去掉多余的 res 参数(避免覆盖外层 res
setTimeout(() => {
reject(false);
}, 1000);
},
});
}
break;
}
}
},
fail(err) {
if (err.errMsg.indexOf("request:fail") !== -1) {
if (err.errMsg.indexOf("timeout") !== -1) {
if (toast) {
uni.showToast({
title: `请求超时,请稍后重试`,
icon: "error",
duration: 2000,
});
}
}
}
reject(err);
},
complete() {
// 不管成功还是失败都会执行
setTimeout((res) => {
uni.hideLoading();
uni.hideToast();
}, 10000);
},
});
}).catch((e) => {});
};

View File

@@ -8,8 +8,12 @@
backgroundColor: btnColor,
width: `${btnSize}px`,
height: `${btnSize}px`,
transform: `translateX(${currentOffsetX}px) translateY(${currentOffsetY}px)`,
}"
:class="{ active: isPopupVisible }"
@touchstart="touchstart"
@touchmove="touchmove"
@touchend="touchend"
>
<up-icon
name="plus"
@@ -20,7 +24,14 @@
</view>
<!-- 操作弹窗 -->
<view class="popup" v-if="isPopupVisible" :class="{ show: isPopupVisible }">
<view
class="popup"
v-if="isPopupVisible"
:class="{ show: isPopupVisible }"
:style="{
transform: `translateX(${currentOffsetX}px) translateY(${currentOffsetY}px)`,
}"
>
<view class="popup-arrow"></view>
<view class="popup-content">
<view
@@ -40,14 +51,57 @@
</template>
<script setup>
import { ref, defineProps, defineEmits,computed } from "vue";
const show=computed(()=>{
const sysInfo=uni.getAccountInfoSync();
if(sysInfo&&sysInfo.miniProgram && (sysInfo.miniProgram.envVersion == 'release'||sysInfo.miniProgram.envVersion == 'develop')) {
return true;
}
return false
})
import { ref, defineProps, defineEmits, computed } from "vue";
const show = computed(() => {
// trial
const sysInfo = uni.getAccountInfoSync();
if (
sysInfo &&
sysInfo.miniProgram &&
(
sysInfo.miniProgram.envVersion == "develop")
) {
return true;
}
return false;
});
// 核心修改1新增“历史累积偏移量”变量保存上一次拖拽后的最终位置
const lastOffsetX = ref(0); // 历史X偏移累积值
const lastOffsetY = ref(0); // 历史Y偏移累积值
const currentOffsetX = ref(0); // 当前拖拽的实时偏移(基于历史值)
const currentOffsetY = ref(0); // 当前拖拽的实时偏移(基于历史值)
const startX = ref(0);
const startY = ref(0);
// 核心修改2touchstart - 基于历史偏移量初始化当前拖拽起点
function touchstart(e) {
const touch = e.touches[0];
startX.value = touch.clientX;
startY.value = touch.clientY;
// 关键:当前拖拽的起点 = 上一次拖拽的终点(历史累积偏移量)
currentOffsetX.value = lastOffsetX.value;
currentOffsetY.value = lastOffsetY.value;
}
// 核心修改3touchmove - 实时计算“历史偏移量 + 当前拖拽距离”
function touchmove(e) {
const touch = e.touches[0];
// 当前拖拽的相对距离 = 现在触摸点 - 拖拽起点
const moveX = touch.clientX - startX.value;
const moveY = touch.clientY - startY.value;
// 实时偏移 = 历史累积偏移 + 当前相对移动距离(位置连续)
currentOffsetX.value = lastOffsetX.value + moveX;
currentOffsetY.value = lastOffsetY.value + moveY;
}
// 核心修改4touchend - 保存当前拖拽终点为历史偏移量(供下次使用)
function touchend() {
// 关键:将本次拖拽的最终位置保存为历史值
lastOffsetX.value = currentOffsetX.value;
lastOffsetY.value = currentOffsetY.value;
}
// 定义组件属性
const props = defineProps({
@@ -133,45 +187,43 @@ const closePopup = () => {
}
};
async function getWxloginCode(){
return new Promise((resolve, reject) => {
uni.login({
success: (res) => {
if (res.code) {
resolve(res.code);
} else {
console.log("获取登录凭证code失败" + res.errMsg);
reject(res.errMsg);
}
},
});
async function getWxloginCode() {
return new Promise((resolve, reject) => {
uni.login({
success: (res) => {
if (res.code) {
resolve(res.code);
} else {
console.log("获取登录凭证code失败" + res.errMsg);
reject(res.errMsg);
}
},
});
});
}
// 处理操作选择
const handleOperation = async (action) => {
let data='';
let data = "";
if (action == "token") {
data=uni.cache.get("token");
data = uni.cache.get("token");
}
if (action == "userInfo") {
data=JSON.stringify(uni.cache.get("userInfo"));
data = JSON.stringify(uni.cache.get("userInfo"));
}
if(action == "getLoginCode"){
data=await getWxloginCode();
if (action == "getLoginCode") {
data = await getWxloginCode();
}
if(action == "copyStoreInfo"){
data=JSON.stringify(uni.cache.get("shopInfo"));
if (action == "copyStoreInfo") {
data = JSON.stringify(uni.cache.get("shopInfo"));
}
if(action == "copyStoreUserInfo"){
data=JSON.stringify(uni.cache.get("shopUserInfo"));
if (action == "copyStoreUserInfo") {
data = JSON.stringify(uni.cache.get("shopUserInfo"));
}
console.log('data',data)
console.log("data", data);
uni.setClipboardData({
data: data,
success: function () {},
});
data: data,
success: function () {},
});
emit("onOperation", action);
closePopup();
};
@@ -198,7 +250,7 @@ const handleOperation = async (action) => {
linear-gradient(259deg, #fe6d11 50.14%, #ffd1b4 114.93%);
box-shadow: 0 0.4375rem 0.95rem 0 #fe8b435e;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
/*transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); */
z-index: 1001;
}

View File

@@ -1,5 +1,5 @@
// const debug = process.env.NODE_ENV == 'development' ? true : false;
const debug = true
const debug = false
// #ifdef H5
const proxyApi = "/api"
// #endif
@@ -7,9 +7,6 @@ const proxyApi = "/api"
// #ifdef MP-WEIXIN || APP || MP-ALIPAY
const proxyApi = 'http://192.168.1.42' // 调试地址
const proxyApiwws = 'ws://192.168.1.42:2348' // 调试地址
// 测试
// const proxyApi = "https://fv901fw8033.vicp.fun"
// const proxyApiwws = 'wss://sockets.sxczgkj.com/wss'
// #endif
// #ifdef H5
@@ -23,10 +20,6 @@ const baseUrlwws = debug ? proxyApiwws : 'wss://czgeatws.sxczgkj.com/wss' // 线
// #endif
// import VConsole from "./vConsole.js"
// if (debug) {
// new VConsole()
// }
const version = '100'
const autoRemoveCache = {
count: 100000,

View File

@@ -220,7 +220,7 @@
ref="payPasswordref"
:isShow="ispws"
@inputComplete="(e) => accountPayevent(e)"
@close="ispws = false"
@close="pwdClose"
/>
<!-- 私域引流配置 -->
<OrderFinshModal v-model="showDrainage"></OrderFinshModal>
@@ -228,7 +228,7 @@
</template>
<script setup>
import { back } from "@/utils/uniapp.js";
import { onLoad } from "@dcloudio/uni-app";
import { onLoad ,onUnload} from "@dcloudio/uni-app";
import ChargeVue from "./components/charge.vue";
import { pay } from "@/utils/pay.js";
import OrderFinshModal from "@/components/order-finish-modal.vue";
@@ -263,6 +263,19 @@ import {
import { useCartsStore } from "@/stores/carts.js";
import { useWebSocket } from "@/stores/carts-websocket.js";
function pwdClose() {
ispws.value = false;
pay_unlock();
}
onUnload(()=> {
console.log("onUnload");
closeSocket();
})
onBackPress(()=> {
console.log("返回拦截");
closeSocket();
})
function onback() {
closeSocket();
console.log("返回");
@@ -306,18 +319,24 @@ async function onMessage(Message) {
youhuiReset();
}
if (Message.operate_type == "cleanup") {
listinfo.totalCost = 0;
console.log("onMessage:cleanup", Message);
console.log("onMessage:options", options);
console.log("onMessage:listinfo", listinfo);
youhuiReset();
if (listinfo.id) {
let res = await APIgetOrderById({
orderId: listinfo.id,
});
if (listinfo.id || options.tableCode) {
let res = listinfo.id
? await APIgetOrderById({
orderId: listinfo.id,
})
: await APIhistoryOrder({
tableCode: options.tableCode || "",
});
console.log("onMessage:APIgetOrderById", res);
Object.assign(listinfo, res);
if (res) {
orderRemarker.value = res.remark;
// cartStore.carts=[];
// cartStore.setOldOrder(res)
cartStore.setOldOrder(res);
}
if (noPayStatus[res.status]) {
uni.showToast({
@@ -437,14 +456,18 @@ const freeCheck = ref(false);
let backtimer = null;
let historyTotalPrices = 0;
// * 获取订单详情接口
const orderorderInfo = async () => {
const orderorderInfo = async (isNpwGetOrderDetail = false) => {
console.log("listinfo.id", listinfo.id);
if (!listinfo.id && !options.tableCode) {
return;
}
if (isPayBefor() && !listinfo.id) {
return;
if (!isNpwGetOrderDetail) {
if (isPayBefor() && !listinfo.id) {
return;
}
}
let res = listinfo.id
? await APIgetOrderById({
orderId: listinfo.id,
@@ -838,10 +861,36 @@ const istoricalorders = async () => {
}
};
//开始锁单
function start_lock_order() {
clearInterval(payStatusTimer);
pay_lock();
payStatusTimer = setInterval(() => {
pay_lock();
}, 1000);
}
// * 去支付
const goToPay = async (payParams) => {
console.log("goToPay:payParams", payParams);
const canPayRes = await search_pay_lock();
const canPay = canPayRes.status == 1 ? true : false;
if (!canPay) {
uni.showToast({
title: "有人正在付款中!",
icon: "none",
});
const shopUserInfo = uni.cache.get("shopUserInfo");
console.log("shopUserInfo", shopUserInfo);
console.log("listinfo", listinfo);
if (shopUserInfo) {
if (shopUserInfo.userId == listinfo.userId) {
pay_unlock();
}
}
return;
}
// 余额支付
if (payParams.payType == "accountPay") {
if (orderVIP.value.payPwd == "") {
@@ -861,6 +910,7 @@ const goToPay = async (payParams) => {
});
return;
}
start_lock_order();
if (userInfo.usePayPwd) {
ispws.value = true;
return;
@@ -868,30 +918,10 @@ const goToPay = async (payParams) => {
accountPayevent();
return;
}
const canPayRes = await search_pay_lock();
const canPay = canPayRes.status == 1 ? true : false;
if (!canPay) {
uni.showToast({
title: "有人正在付款中!",
icon: "none",
});
const shopUserInfo = uni.cache.get("shopUserInfo");
console.log("shopUserInfo", shopUserInfo);
console.log("listinfo", listinfo);
if (shopUserInfo) {
if (shopUserInfo.userId == listinfo.userId) {
pay_unlock();
}
}
return;
}
console.log("canPay:goToPay:payParams", payParams);
pay_lock();
payStatusTimer = setInterval(() => {
pay_lock();
}, 1000);
start_lock_order();
console.log("霸王餐前payParams", payParams);
if (payParams.isBwc) {
payParams.checkOrderPay.orderId = listinfo.id;
@@ -968,7 +998,7 @@ const accountPayevent = async (pwd) => {
ispws.value = false;
payParams.checkOrderPay.userId = uni.cache.get("userInfo").id;
payParams.checkOrderPay.orderId = listinfo.id;
payParams.pwd = pwd;
try {
const isPaySuccess = await storeMemberpay.balancePayOrder(payParams);
if (isPaySuccess) {
@@ -976,10 +1006,13 @@ const accountPayevent = async (pwd) => {
title: "支付成功",
icon: "none",
});
pay_unlock();
paySucessCallback();
}
} catch (error) {
//TODO handle the exception
pay_unlock();
}
orderorderInfo();
};
@@ -1028,10 +1061,6 @@ let options = {};
function toJiacai() {
console.log("跳转到加菜页面");
back();
return;
uni.navigateTo({
url: "/pages/product/index",
});
}
const packfee = computed(() => {
return cartStore.orderCostSummary.packFee;
@@ -1067,6 +1096,7 @@ const navTitle = computed(() => {
//支付成功后的处理
function paySucessCallback() {
console.log("paySucessCallback");
cartsSocket.closeSocket();
showDrainage.value = true;
}

View File

@@ -847,6 +847,7 @@ import {
onReady,
onShow,
onHide,
onUnload,
onPageScroll,
} from "@dcloudio/uni-app";
@@ -989,8 +990,6 @@ const imageLoaded = (item, index, index1) => {
// 计算左侧位置
const leftIndex = ref(0);
//元素最低端的距离
const lastbottom = ref("");
@@ -1428,7 +1427,7 @@ const submitSelection = async () => {
} else {
selectedGroupSnap.value = [];
}
console.log('specifications.item', specifications.item);
websocketsendMessage({
id: res ? res.cartListId : "",
type: "shopping",
@@ -1446,8 +1445,7 @@ const submitSelection = async () => {
memberPrice: specifications.item.memberPrice,
is_print: 1,
product_type: specifications.item.type,
is_time_discount:specifications.item.is_time_discount
is_time_discount: specifications.item.is_time_discount,
});
// 清空套餐选中
selectedGroupSnap.value = [];
@@ -1487,7 +1485,7 @@ const clickspecifications = async (item, index, indexs, type) => {
// skuBtnText.value = '请选择规格'
// single-单规格商品 sku-多规格商品 package-套餐商品 weight-称重商品 coupon-团购券
let res = await APIminiAppinfo(item.id);
specifications.item = res;
specifications.item = {...res,is_time_discount:item.is_time_discount};
if (specifications.item.type == "package") {
selectedOptions.value = [];
specifications.product_id = res.id;
@@ -1595,7 +1593,7 @@ const singleclick = async (item, i) => {
number: await calculateValue(item.cartNumber, i, suitNum),
is_print: 1,
product_type: item.type,
is_time_discount:item.is_time_discount
is_time_discount: item.is_time_discount,
});
};
@@ -2122,7 +2120,7 @@ const productqueryProduct = async () => {
product.startTime,
product.endTime
);
product.is_time_discount = showLimitDiscount(product)?1:0;
product.is_time_discount = showLimitDiscount(product) ? 1 : 0;
product.limitSalePrice = returnLimitPrice(product);
cartStore.setGoodsMap(product.id, product);
@@ -2135,11 +2133,11 @@ const productqueryProduct = async () => {
i.startTime,
i.endTime
);
i.is_time_discount = showLimitDiscount(i)?1:0;
i.is_time_discount = showLimitDiscount(i) ? 1 : 0;
i.limitSalePrice = returnLimitPrice(i);
cartStore.setGoodsMap(i.id, i);
});
console.log("shopProductList", shopProductList);
cartStore.goodsIsloading = true;
scrollTopSize.value = 0;
topArr.value = [];
@@ -2167,6 +2165,11 @@ provide("shopUserInfo", shopUserInfo);
provide("shopInfo", shopInfo);
onLoad(async (e) => {
console.log("onLoad:e", e);
cartStore.setOldOrder({
detailMap: {},
originAmount: 0,
});
await proxy.$onLaunched;
});
@@ -2215,7 +2218,16 @@ onShow(async () => {
}
});
onHide(() => {});
onHide(() => {
console.log("product index onHide");
useSocket.closeSocket();
useSocket.setOnMessage(()=>{});
});
onUnload(() => {
console.log("product index onUnload");
useSocket.closeSocket();
useSocket.setOnMessage(()=>{});
});
onMounted(async () => {
await proxy.$onLaunched;
@@ -2252,7 +2264,6 @@ onMounted(async () => {
operate_type: "time_discount_save",
data: null,
});
}
await productqueryProduct();

View File

@@ -288,11 +288,15 @@ export const useCartsStore = defineStore("cart", () => {
//购物车商品信息补全初始化
function cartsGoodsInfoInit(arr) {
carts.value = arr
console.log('cartsGoodsInfoInit',arr)
if(arr&&Array.isArray(arr)){
carts.value = arr
.map((v) => {
return getProductDetails(v);
})
.filter((v) => v);
}
}
//收到socket消息时对购物车进行处理
@@ -395,6 +399,7 @@ export const useCartsStore = defineStore("cart", () => {
});
function setOldOrder(data) {
console.log("setOldOrder", data);
oldOrder.value = data;
allGoods.value = getAllGoodsList();
}

View File

@@ -27,6 +27,10 @@
<view class="color-333 font-bold small-title">优惠券</view>
<text class="color-666 u-m-l-38">{{data.couponInfoList.map(item=>item.title+'*'+item.num).join('、')}}</text>
</view>
<view class="u-m-t-32 u-flex u-col-center" v-if="data.amount">
<view class="color-333 font-bold small-title">金额</view>
<text class="color-666 u-m-l-38">{{data.amount}}</text>
</view>
<view class="u-m-t-32 u-flex u-col-center" style="gap: 54rpx">
<view class="cancel" @click="close">取消</view>
<view class="confirm" @click="confirm">确认</view>

View File

@@ -1316,7 +1316,7 @@ function calcVipDiscountAmount(
return truncateToTwoDecimals(
new BigNumber(goodsRealAmount)
.times((100 - (shopUserInfo.discount || 0)) / 100)
.decimalPlaces(2, BigNumber.ROUND_UP)
.decimalPlaces(2, BigNumber.ROUND_DOWN)
.toNumber()
);
}
@@ -1584,7 +1584,8 @@ export function calculateOrderCostSummary(
.minus(fullReductionAmount)
.toNumber(),
shopUserInfo
); // 会员折扣减免金额
);
console.log("vipDiscountAmount", vipDiscountAmount);
// ------------------------------ 6. 最终实付金额计算 ------------------------------
const finalPayAmountBn = new BigNumber(goodsRealAmount)
.minus(newUserDiscount)

View File

@@ -59,6 +59,7 @@ export function returnPrice(args) {
shopUserInfo,
idKey = "product_id",
} = args;
limitTimeDiscountRes=limitTimeDiscountRes||{foods:'',foodType:2}
const canUseFoods = (limitTimeDiscountRes.foods || "").split(",");
const includesGoods =
limitTimeDiscountRes.foodType == 1 ||