hookehuyr

feat(离线预约): 添加离线预约缓存轮询功能

实现离线预约缓存自动轮询刷新机制,提升离线状态下的数据同步能力
移除不再使用的支付相关API和等待页面
/*
* @Date: 2023-08-24 09:42:27
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-13 20:55:13
* @LastEditTime: 2026-01-13 23:13:04
* @FilePath: /xyxBooking-weapp/src/api/index.js
* @Description: 文件描述
*/
......@@ -14,8 +14,8 @@ const Api = {
ADD_PERSON: '/srv/?a=api&t=add_person',
DEL_PERSON: '/srv/?a=api&t=del_person',
ADD_RESERVE: '/srv/?a=api&t=add_reserve',
PAY_PREPARE: '/srv/?a=api&t=pay_prepare',
PAY_CALLBACK: '/srv/?a=api&t=pay_callback',
// PAY_PREPARE: '/srv/?a=api&t=pay_prepare',
// PAY_CALLBACK: '/srv/?a=api&t=pay_callback',
BILL_INFO: '/srv/?a=api&t=bill_info',
ON_AUTH_BILL_INFO: '/srv/?a=no_auth_api&t=bill_info',
QRCODE_LIST: '/srv/?a=api&t=qrcode_list',
......@@ -24,7 +24,7 @@ const Api = {
BILL_OFFLINE_ALL: '/srv/?a=api&t=bill_all_info',
ICBC_REFUND: '/srv/?a=icbc_refund',
BILL_PREPARE: '/srv/?a=api&t=bill_person',
BILL_PAY_STATUS: '/srv/?a=api&t=bill_pay_status',
// BILL_PAY_STATUS: '/srv/?a=api&t=bill_pay_status',
QUERY_QR_CODE: '/srv/?a=api&t=id_number_query_qr_code',
ICBC_ORDER_QRY: '/srv/?a=icbc_orderqry',
WX_PAY: '/srv/?a=icbc_pay_wxamp',
......@@ -109,7 +109,7 @@ export const addReserveAPI = (params) => fn(fetch.post(Api.ADD_RESERVE, params))
* @param {String} bill_id
* @returns {String} bill_id 预约单id
*/
export const payPrepareAPI = (params) => fn(fetch.post(Api.PAY_PREPARE, params));
// export const payPrepareAPI = (params) => fn(fetch.post(Api.PAY_PREPARE, params));
/**
* @description: 支付回调(模拟)
......@@ -117,7 +117,7 @@ export const payPrepareAPI = (params) => fn(fetch.post(Api.PAY_PREPARE, params))
* @param {String} pay_status 支付状态,1为成功,0为失败(缺省)
* @returns {String} bill_id 预约单id
*/
export const payCallbackAPI = (params) => fn(fetch.post(Api.PAY_CALLBACK, params));
// export const payCallbackAPI = (params) => fn(fetch.post(Api.PAY_CALLBACK, params));
/**
* @description: 预约单详情,参观者列表
......@@ -193,7 +193,7 @@ export const billPersonAPI = (params) => fn(fetch.get(Api.BILL_PREPARE, params))
* @param {String}
* @returns {String}
*/
export const billPayStatusAPI = (params) => fn(fetch.get(Api.BILL_PAY_STATUS, params));
// export const billPayStatusAPI = (params) => fn(fetch.get(Api.BILL_PAY_STATUS, params));
/**
* @description: 身份证查询预约码
......
/*
* @Date: 2025-06-28 10:33:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-13 14:56:43
* @LastEditTime: 2026-01-13 23:19:52
* @FilePath: /xyxBooking-weapp/src/app.config.js
* @Description: 小程序配置文件
*/
......@@ -17,7 +17,6 @@ const pages = [
'pages/bookingList/index',
'pages/bookingDetail/index',
'pages/me/index',
'pages/waiting/index',
'pages/callback/index',
'pages/search/index',
'pages/visitorList/index',
......
/*
* @Date: 2025-06-28 10:33:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-13 15:22:40
* @LastEditTime: 2026-01-13 23:30:40
* @FilePath: /xyxBooking-weapp/src/app.js
* @Description: 应用入口文件
*/
......@@ -13,6 +13,7 @@ import { saveCurrentPagePath, hasAuth, silentAuth, navigateToAuth } from '@/util
import Taro from '@tarojs/taro'
import { refresh_offline_booking_cache, has_offline_booking_cache } from '@/composables/useOfflineBookingCache'
import { is_usable_network, get_network_type } from '@/utils/network'
import { start_offline_booking_cache_polling } from '@/composables/useOfflineBookingCachePolling'
import { weak_network_text, get_weak_network_modal_use_cache_options } from '@/utils/uiText'
let has_shown_network_modal = false
......@@ -124,7 +125,10 @@ const App = createApp({
* - 授权失败则跳转至授权页面
*/
if (hasAuth()) {
// 有授权时预加载数据
try_preload_when_online()
// 启动离线预约缓存轮询
start_offline_booking_cache_polling()
return
}
......@@ -135,6 +139,8 @@ const App = createApp({
await silentAuth()
// 授权成功后预加载数据
try_preload_when_online()
// 启动离线预约缓存轮询
start_offline_booking_cache_polling()
} catch (error) {
console.error('静默授权失败:', error)
// 授权失败则跳转至授权页面
......
import { ref, onMounted, onUnmounted } from 'vue'
import { refresh_offline_booking_cache } from '@/composables/useOfflineBookingCache'
let polling_timer_id = null
let polling_running = false
let polling_in_flight = false
let polling_ref_count = 0
/**
* @description: 刷新离线预约缓存一次
* @param {Object} options 选项
* @param {Boolean} options.force 是否强制刷新
*/
const run_refresh_once = async (options) => {
if (polling_in_flight) return
polling_in_flight = true
try {
await refresh_offline_booking_cache({ force: !!options?.force })
} finally {
polling_in_flight = false
}
}
/**
* @description: 启动离线预约缓存轮询
* @param {Object} options 选项
* @param {Number} options.interval_ms 轮询间隔,单位毫秒
* @param {Boolean} options.immediate 是否立即刷新一次
*/
export const start_offline_booking_cache_polling = (options) => {
const interval_ms = Number(options?.interval_ms || 60000)
if (polling_running) return
polling_running = true
if (options?.immediate !== false) {
run_refresh_once(options)
}
polling_timer_id = setInterval(() => {
run_refresh_once(options)
}, interval_ms)
}
/**
* @description: 停止离线预约缓存轮询
*/
export const stop_offline_booking_cache_polling = () => {
if (!polling_timer_id) {
polling_running = false
return
}
clearInterval(polling_timer_id)
polling_timer_id = null
polling_running = false
}
/**
* @description: 用于管理离线预约缓存轮询的组合式函数
* @param {Object} options 选项
* @param {Boolean} options.enabled 是否启用轮询
* @param {Boolean} options.auto 是否自动启动轮询
* @param {Number} options.interval_ms 轮询间隔,单位毫秒
* @param {Boolean} options.immediate 是否立即刷新一次
*/
export const use_offline_booking_cache_polling = (options) => {
const is_running = ref(false)
const enabled = options?.enabled !== false
const start = () => {
if (!enabled) return
polling_ref_count += 1
start_offline_booking_cache_polling(options)
is_running.value = true
}
const stop = () => {
if (!is_running.value) return
polling_ref_count = Math.max(0, polling_ref_count - 1)
if (polling_ref_count === 0) {
stop_offline_booking_cache_polling()
}
is_running.value = false
}
onMounted(() => {
if (options?.auto !== false) start()
})
onUnmounted(() => {
stop()
})
return {
is_running,
start,
stop,
}
}
<!--
* @Date: 2023-06-21 10:23:09
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-13 21:23:30
* @LastEditTime: 2026-01-13 23:26:08
* @FilePath: /xyxBooking-weapp/src/pages/index/index.vue
* @Description: 预约页首页
-->
......@@ -58,6 +58,7 @@ import { ref } from 'vue'
import { useGo } from '@/hooks/useGo'
import { get_network_type, is_usable_network } from '@/utils/network'
import { weak_network_text } from '@/utils/uiText'
import icon_1 from '@/assets/images/立即预约@2x.png'
import icon_3 from '@/assets/images/首页02@2x.png'
import icon_4 from '@/assets/images/二维码icon.png'
......
<!--
* @Date: 2024-01-15 18:28:25
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-01-30 15:18:54
* @LastEditTime: 2026-01-13 23:20:10
* @FilePath: /xyxBooking-weapp/src/pages/success/index.vue
* @Description: 预约成功提示页面
-->
......@@ -58,6 +58,7 @@ useDidShow(async () => {
data.datetime = data && formatDatetime(data);
billInfo.value = data;
}
// 刷新离线预约缓存
refresh_offline_booking_cache({ force: true })
})
</script>
......