From 66e606e417fc86e11c26edecd004a1c59fe82762 Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Fri, 5 Apr 2024 14:23:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/pay.vue | 35 ++++++++++++++++++++++++----------- src/utils/audio.js | 5 +++++ src/views/order/index.vue | 19 ++++++++++++++++--- 3 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 src/utils/audio.js diff --git a/src/components/pay.vue b/src/components/pay.vue index 6b0a0ef..9f54b4d 100644 --- a/src/components/pay.vue +++ b/src/components/pay.vue @@ -2,6 +2,7 @@ import { ref, watch, nextTick } from "vue"; import { orderCreateApi, orderStatusApi, orderPayApi } from "@/api/store.js"; import { ElMessage } from "element-plus"; +import { audioplay } from "@/utils/audio.js"; const drawer = ref(false); const active = ref(1); @@ -39,7 +40,7 @@ const emit = defineEmits(["paySuccess"]); const reLoad = ref(false); -let timeout = 0; //刷新间隔 +let timecount = 0; //刷新间隔 const order_id = ref(""); // 支付 @@ -57,18 +58,28 @@ const handleEnter = () => { source: 300, }) .then((res) => { - if (res.status==200&& res.message=='支付成功') { + if (res.status == 200 && res.message == "支付成功") { drawer.value = false; ElMessage({ message: res.message, type: "success", }); + audioplay(res.data.message); beforeClose(); } else { - order_id.value = res.data.group_order_id; - count.value = 0; - timeout = 0; - getOrderStatus(res.data.group_order_sn); + if (!res.data.group_order_sn) { + order_id.value = res.data.result.order_id; + loading.value = false; + return ElMessage({ + message: res.message, + type: "error", + }); + } else { + order_id.value = res.data.group_order_id; + count.value = 0; + timecount = 0; + getOrderStatus(res.data.group_order_sn); + } } }) .catch((err) => { @@ -85,17 +96,18 @@ const orderPay = (id) => { auth_code: input.value, }) .then((res) => { - if (res.data.status == "success") { + if (res.status == 200 && res.message == "支付成功") { drawer.value = false; ElMessage({ message: res.message, type: "success", }); + audioplay(res.data.message); beforeClose(); } else { order_id.value = res.data.group_order_id; count.value = 0; - timeout = 0; + timecount = 0; getOrderStatus(res.data.group_order_sn); } }) @@ -111,7 +123,7 @@ const orderPay = (id) => { const count = ref(0); // 累计请求3次, 如果3次都失败, 则只能重新支付 const getOrderStatus = (id) => { count.value++; - timeout+=5000; + timecount += 5000; orderStatusApi({ order_sn: id, }) @@ -121,6 +133,7 @@ const getOrderStatus = (id) => { message: res.message, type: "success", }); + audioplay(res.data.message); beforeClose(); } else { ElMessage({ @@ -138,7 +151,7 @@ const getOrderStatus = (id) => { if (reLoad.value && count.value < 3) setTimeout(() => { getOrderStatus(id); - }, timeout); + }, 15000 - timecount > 0 ? 15000 - timecount : 0); else { input.value = ""; loading.value = false; @@ -163,7 +176,7 @@ const loading = ref(false); defineExpose({ drawer, setForm, - setRePay + setRePay, }); diff --git a/src/utils/audio.js b/src/utils/audio.js new file mode 100644 index 0000000..8dbdce3 --- /dev/null +++ b/src/utils/audio.js @@ -0,0 +1,5 @@ + +export const audioplay = (text) => { + let ssu = new window.SpeechSynthesisUtterance(text); + window.speechSynthesis.speak(ssu); +} \ No newline at end of file diff --git a/src/views/order/index.vue b/src/views/order/index.vue index 154d0ce..f714567 100644 --- a/src/views/order/index.vue +++ b/src/views/order/index.vue @@ -5,6 +5,7 @@ import { groupOrderListApi, orderStatusApi, orderLadingApi, + cartListApi } from "@/api/store.js"; import { useUserStore } from "@/store/user.js"; import pay from "@/components/pay.vue"; @@ -39,6 +40,17 @@ const getOrderList = () => { getOrderList(); + +const cartCount = ref(0); +const getCartList = () => { + cartListApi({ + source: 300, + }).then((res) => { + cartCount.value = res.data.list?.length; + }); +}; +getCartList(); + const changeTabPosition = (e) => { where.value.page = 1; getOrderList(); @@ -182,10 +194,11 @@ const goHome = ()=>{ 提单前请清空购物车, 避免提单的商品与购物车商品混合, 请确保购物车内无数据后再进行提单