From 98ce8b55446563164c6ec629a579f2b942df280b Mon Sep 17 00:00:00 2001
From: wwz <1144797966@qq.com>
Date: Wed, 26 Mar 2025 17:58:52 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BD=91=E7=BB=9C=E6=B3=A2?=
=?UTF-8?q?=E5=8A=A8=E5=8A=A0=E8=BD=BD=E4=B8=AD=EF=BC=8C=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E4=BC=9A=E5=91=98=E4=BF=A1=E6=81=AF=E6=89=AB=E7=A0=81=E5=85=85?=
=?UTF-8?q?=E5=80=BC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
App.vue | 36 +
common/js/websocket.js | 26 +-
components/Loading.vue | 83 +++
pages/index/components/todaylist.vue | 19 +-
pages/index/index.vue | 17 +-
pages/index/indexs.vue | 19 +-
pages/order/components/orderInfoAfter.vue | 11 +-
pages/order/detail.vue | 30 +-
pages/product/choosetable.vue | 15 +-
pages/product/components/confirmorder.vue | 12 +-
pages/product/components/shoppingCartes.vue | 12 +-
pages/product/index.vue | 77 +-
pages/subscribeto/index.vue | 696 ++++++++++++++++++
.../user/member/components/registermember.vue | 11 +-
pages/user/member/index.vue | 56 +-
pages/user/user.vue | 1 -
stores/order.js | 9 +-
stores/user.js | 16 +-
18 files changed, 1018 insertions(+), 128 deletions(-)
create mode 100644 components/Loading.vue
create mode 100644 pages/subscribeto/index.vue
diff --git a/App.vue b/App.vue
index f334f06..d37448c 100644
--- a/App.vue
+++ b/App.vue
@@ -31,6 +31,42 @@
// },
onShow(async () => {
+ try {
+ // #ifdef MP-WEIXIN
+ // 当向小程序后台请求完新版本信息,会进行回调。res: {hasUpdate: true, version: 1.0.0}
+ const updateManager = uni.getUpdateManager();
+ updateManager.onCheckForUpdate((res) => {
+ if (res.hasUpdate) { // 有更新
+ uni.showLoading({
+ title: '更新中...'
+ }); // 开始下载前,显示Loading
+ }
+ });
+ // 当新版本下载完成,会进行回调
+ updateManager.onUpdateReady(() => {
+ uni.hideLoading(); // 关闭 Loading
+ uni.showModal({ // 弹确认框(强制更新)
+ title: '更新提示',
+ content: '更新完毕,是否重启?',
+ success: function(res) {
+ if (res.confirm) {
+ updateManager.applyUpdate(); // 强制小程序重启并使用新版本。
+ }
+ }
+ })
+ });
+ // 当新版本下载失败,会进行回调
+ updateManager.onUpdateFailed(() => {
+ uni.hideLoading(); // 关闭 Loading
+ uni.showToast({
+ title: '更新失败,稍后再试...',
+ icon: "error"
+ });
+ });
+ // #endif
+ } catch (error) {
+ //TODO handle the exception
+ }
// #ifndef H5
// try {
const storelogin = Storelogin();
diff --git a/common/js/websocket.js b/common/js/websocket.js
index ca47168..89c0bdb 100644
--- a/common/js/websocket.js
+++ b/common/js/websocket.js
@@ -94,12 +94,13 @@ const useWebSocket = (options = {}) => {
socketTask.value.onMessage((res) => {
receivedMessages.value = JSON.parse(res.data)
// receivedMessages.value.push(list);
- if (receivedMessages.value == 'ok') {
- console.log('心跳响应正常');
- // 心跳正常,重置重连尝试次数
- reconnectAttempts.value = 0;
+ if (receivedMessages.value == 'ok' || receivedMessages.value.operate_type == 'init') {
+ console.log('初始化正常,心跳响应正常');
+ // 清除重连定时器
clearTimeout(reconnectTimer.value);
+ reconnectTimer.value = null;
}
+
});
socketTask.value.onClose((res) => {
@@ -109,13 +110,13 @@ const useWebSocket = (options = {}) => {
clearTimeout(reconnectTimer.value); // 清除重连定时器
if (res.code == '1006') {
uni.showToast({
- title: '操作异常,请重新扫码',
+ title: '网络异常,请重新扫码',
icon: 'none'
});
autoReconnect.value = false;
setTimeout(() => {
uni.pro.switchTab('index/index');
- }, 1500)
+ }, 1000)
return false;
}
if (autoReconnect.value && !isManuallyClosed.value) {
@@ -179,7 +180,9 @@ const useWebSocket = (options = {}) => {
const handlePong = (res) => {
try {
let data = JSON.parse(res.data);
- if (data.msg === 'ok' && data.msg_id == 'ping_interval') {
+ if (data.operate_type == "init" || (data.msg === 'ok' &&
+ data.msg_id ==
+ 'ping_interval')) {
isPongReceived.value = true;
console.log('收到心跳响应,清除超时定时器');
clearTimeout(pongTimer);
@@ -252,9 +255,7 @@ const useWebSocket = (options = {}) => {
mask: true
})
console.log(`尝试第 ${reconnectAttempts.value} 次重连,重连间隔: ${randomizedInterval}ms...`);
- setTimeout(() => {
- uni.hideLoading();
- }, 1000)
+
reconnectTimer.value = setTimeout(() => {
connect();
}, randomizedInterval);
@@ -266,7 +267,10 @@ const useWebSocket = (options = {}) => {
});
clearInterval(heartbeatTimer.value);
autoReconnect.value = false;
- uni.pro.switchTab('index/index');
+ setTimeout(() => {
+ uni.hideLoading();
+ uni.pro.switchTab('index/index');
+ }, 1000)
}
};
diff --git a/components/Loading.vue b/components/Loading.vue
new file mode 100644
index 0000000..c788fe2
--- /dev/null
+++ b/components/Loading.vue
@@ -0,0 +1,83 @@
+
+
+
+
+ 努力加载中...
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pages/index/components/todaylist.vue b/pages/index/components/todaylist.vue
index 3054d96..3970cce 100644
--- a/pages/index/components/todaylist.vue
+++ b/pages/index/components/todaylist.vue
@@ -1,5 +1,5 @@
-
+
@@ -42,7 +42,7 @@
style="background: url(https://czg-qr-order.oss-cn-beijing.aliyuncs.com/index/towcontent_box2.png) no-repeat; background-size: cover;"
@click="jrtoday(1)">
- {{salesList.name}}
+ {{salesList.name || ''}}
@@ -82,13 +82,20 @@
defineProps
} from 'vue';
const props = defineProps({
- salesList: Object,
+ salesList: {
+ type: Object,
+ default: {
+ name: '',
+ date: '',
+ hotList: [],
+ }
+ },
todayList: {
type: Object,
default: () => ({
- name:'',
- date:'',
- hotList:[]
+ name: '',
+ date: '',
+ hotList: []
}) //
},
});
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 7968a15..5a17a3a 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -127,7 +127,7 @@
-
+
@@ -139,7 +139,8 @@
reactive,
onBeforeUnmount,
watch,
- getCurrentInstance
+ getCurrentInstance,
+ nextTick
} from "vue";
import {
onLoad,
@@ -235,7 +236,7 @@
size: 10, //页容量
status: 'loadmore',
name: '1',
- list:[]
+ list: []
})
// 使用 reactive 创建响应式对象
const timeData = ref({});
@@ -287,7 +288,7 @@
formhomelist.status = 'loading';
}
}
-
+
} catch (e) {}
}
// /筛选数据处理
@@ -307,6 +308,10 @@
onLoadhome()
}
+ const orderVIP = ref({
+ shopExtendList:''
+ })
+
// 弹出层处理
const showproductlist = ref(false);
// 定义方法
@@ -393,7 +398,9 @@
await proxy.$onLaunched;
if (uni.cache.get('shopId')) {
showindex.value = 'shopIndex'
- await storeuser.actionsAPIuser()
+ await storeuser.actionsproductqueryProduct()
+ await nextTick()
+ orderVIP.value = uni.cache.get('orderVIP')
} else {
showindex.value = 'index'
hometop()
diff --git a/pages/index/indexs.vue b/pages/index/indexs.vue
index 4e20c41..00cb5c6 100644
--- a/pages/index/indexs.vue
+++ b/pages/index/indexs.vue
@@ -1,7 +1,7 @@
+ :style="'background:url('+(shopExtend?shopExtend[0].value:'https://czg-qr-order.oss-cn-beijing.aliyuncs.com/indexs/shuangbackground.png')+') no-repeat center center / cover' ">
@@ -36,13 +36,23 @@
\ No newline at end of file
diff --git a/pages/user/member/components/registermember.vue b/pages/user/member/components/registermember.vue
index 7fe16f4..0eb2ed6 100644
--- a/pages/user/member/components/registermember.vue
+++ b/pages/user/member/components/registermember.vue
@@ -113,6 +113,9 @@
},
});
+ // 定义事件发射器
+ const emits = defineEmits(['emitsmemberOpen']);
+
// 定义要触发的事件
const formInfo = reactive({
@@ -304,7 +307,6 @@
const registerMember = async () => {
-
if (formInfo.nickName == "" || formInfo.nickName == null) {
uni.showToast({
title: '请输入会员昵称',
@@ -345,9 +347,10 @@
icon: 'none'
})
// 定义自定义事件
- setTimeout(() => {
- uni.navigateBack()
- }, 1500)
+ // setTimeout(() => {
+ // uni.navigateBack()
+ // }, 1500)
+ emits('emitsmemberOpen');
}
diff --git a/pages/user/member/index.vue b/pages/user/member/index.vue
index e092048..2601dba 100644
--- a/pages/user/member/index.vue
+++ b/pages/user/member/index.vue
@@ -94,7 +94,8 @@
立即充值
-
+
@@ -104,7 +105,8 @@
import {
ref,
reactive,
- onMounted
+ onMounted,
+ getCurrentInstance
} from 'vue';
import registermember from './components/registermember.vue'
@@ -113,6 +115,11 @@
APIshopUserInfo
} from '@/common/api/member.js'
+ // 获取全局属性
+ const {
+ proxy
+ } = getCurrentInstance();
+
// 状态管理
import {
Memberpay
@@ -194,6 +201,12 @@
});
}
+ const emitsmemberOpen = async () => {
+ asyncshopUserInfo()
+ await paygetActive()
+ // infoForn.show = false
+ }
+
// 监听金额修改
const amountChange = () => {
let item = infoForn.listdata.filter(item => infoForn.amount == item.amount)
@@ -212,36 +225,6 @@
}
- const shopInfo = async () => {
- let res = await this.api.shopUserInfo({
- shopId: this.shopId,
- userId: uni.cache.get('userInfo').id,
- })
- if (res.code == 0) {
- infoForn.shopUserInfo = res.data;
- uni.cache.remove('memberOpen', this.memberOpen)
- if (infoForn.shopUserInfo.isVip == 0) {
- this.memberOpen = true;
- uni.cache.set('memberOpen', this.memberOpen)
- }
- } else {
- let pages = getCurrentPages()
- if (pages.length > 1) {
- uni.navigateBack()
- } else {
- setTimeout(res => {
- uni.exitMiniProgram({
- success: function() {
- console.log('退出小程序成功');
- },
- fail: function(err) {
- console.log('退出小程序失败', err);
- }
- })
- }, 500)
- }
- }
- }
// * 进入明细\管理
const handleClick = (item) => {
@@ -268,12 +251,6 @@
complete: () => {}
})
}
- // 注册会员卡
- const getRegisterMember = (e) => {
- infoForn.memberOpen = e;
- this.shopInfo();
- this.paygetActive()
- }
// 解码
const getQueryString = (url, name) => {
@@ -319,7 +296,7 @@
});
return false;
}
- await store.actionspayltPayVip({
+ await store.actionspayltPayVip({
shopId: infoForn.shopId,
activateId: infoForn.id,
shopUserId: infoForn.userInfo.id,
@@ -347,6 +324,7 @@
onMounted(async () => {
+ await proxy.$onLaunched;
// 获取当前页面栈
const pages = getCurrentPages();
// 获取当前页面实例
diff --git a/pages/user/user.vue b/pages/user/user.vue
index a6e6654..df77509 100644
--- a/pages/user/user.vue
+++ b/pages/user/user.vue
@@ -196,7 +196,6 @@
}
}
onShow(() => {
- console.log(111)
store.actionsAPIuser()
if (uni.cache.get('shopId')) {
Object.assign(userInfo, uni.cache.get('orderVIP'))
diff --git a/stores/order.js b/stores/order.js
index 76e5c75..d4202e0 100644
--- a/stores/order.js
+++ b/stores/order.js
@@ -32,7 +32,7 @@ export const useCartStore = defineStore('cart', () => {
};
// 计算购物车商品总价格
- const getTotalTotalPrices = (matchedProducts, bwc = 2) => computed(() => {
+ const getTotalTotalPrices = (matchedProducts) => computed(() => {
if (!matchedProducts || !Array.isArray(matchedProducts)) {
return 0;
}
@@ -42,7 +42,7 @@ export const useCartStore = defineStore('cart', () => {
let cart = matchedProducts.reduce((total, item) => {
// 是否启用会员价 0否1是
if (uni.cache.get('orderVIP').isVip == 1 && uni.cache.get('ordershopUserInfo')
- .isMemberPrice == 1 && bwc == 2) {
+ .isMemberPrice == 1) {
// memberPrice会员价
return total + (parseFloat(item.memberPrice || item.price) * parseFloat(item
.num - item
@@ -52,9 +52,10 @@ export const useCartStore = defineStore('cart', () => {
return total + (parseFloat(item.price) * parseFloat(item.num - item.returnNum));
}
}, 0);
+ cart.toFixed(2)
// 向上取整并保留两位小数
- let result = roundUpToTwoDecimals(cart, 'upward')
- return result;
+ // let result = roundUpToTwoDecimals(cart, 'upward')
+ return cart;
});
// 计算商品卷所选择的总价格
diff --git a/stores/user.js b/stores/user.js
index 473dc8a..c64350c 100644
--- a/stores/user.js
+++ b/stores/user.js
@@ -150,10 +150,9 @@ export const productStore = defineStore('product', {
if (uni.cache.get('shopInfo').isTableFee == 0) {
uni.pro.navigateTo('product/choosetable')
} else {
- uni.pro.navigateTo(
- 'product/index', {
- tableCode: tableCode,
- })
+ uni.reLaunch({
+ url: '/pages/product/index'
+ });
}
}
@@ -188,9 +187,12 @@ export const productStore = defineStore('product', {
if (uni.cache.get('shopInfo').isTableFee == 0) {
uni.pro.navigateTo('product/choosetable')
} else {
- uni.pro.navigateTo('product/index', {
- tableCode: uni.cache.get('tableCode'),
- })
+ uni.reLaunch({
+ url: '/pages/product/index'
+ });
+ // uni.pro.navigateTo('product/index', {
+ // tableCode: uni.cache.get('tableCode'),
+ // })
}
}