hookehuyr

docs: 添加函数注释及改进日期时间格式化功能

为 bookingList 页面的 loadData 函数添加注释说明
完善 useGo 和 useReplace 钩子函数的文档注释
重构 formatDatetime 函数,添加详细注释并改进时间处理逻辑
1 +/*
2 + * @Date: 2026-01-06 20:47:00
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2026-01-13 11:42:00
5 + * @FilePath: /xyxBooking-weapp/src/hooks/useGo.js
6 + * @Description: 封装路由跳转方便行内调用
7 + */
1 import Taro from '@tarojs/taro'; 8 import Taro from '@tarojs/taro';
2 9
3 /** 10 /**
...@@ -5,6 +12,11 @@ import Taro from '@tarojs/taro'; ...@@ -5,6 +12,11 @@ import Taro from '@tarojs/taro';
5 * @returns 12 * @returns
6 */ 13 */
7 export function useGo () { 14 export function useGo () {
15 + /**
16 + * 路由跳转
17 + * @param {string} path - 目标页面路径,支持 / 开头
18 + * @param {Object} query - 查询参数,键值对形式
19 + */
8 function go (path, query = {}) { 20 function go (path, query = {}) {
9 // 补全路径,如果是 / 开头,去掉 / 21 // 补全路径,如果是 / 开头,去掉 /
10 let url = path.startsWith('/') ? path.substring(1) : path; 22 let url = path.startsWith('/') ? path.substring(1) : path;
...@@ -36,7 +48,16 @@ export function useGo () { ...@@ -36,7 +48,16 @@ export function useGo () {
36 return go 48 return go
37 } 49 }
38 50
51 +/**
52 + * 封装路由替换方便行内调用
53 + * @returns
54 + */
39 export function useReplace () { 55 export function useReplace () {
56 + /**
57 + * 路由替换
58 + * @param {string} path - 目标页面路径,支持 / 开头
59 + * @param {Object} query - 查询参数,键值对形式
60 + */
40 function replace (path, query = {}) { 61 function replace (path, query = {}) {
41 let url = path.startsWith('/') ? path.substring(1) : path; 62 let url = path.startsWith('/') ? path.substring(1) : path;
42 if (!url.startsWith('pages/')) { 63 if (!url.startsWith('pages/')) {
......
1 <!-- 1 <!--
2 * @Date: 2024-01-16 11:37:10 2 * @Date: 2024-01-16 11:37:10
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-01-30 15:20:12 4 + * @LastEditTime: 2026-01-13 11:43:13
5 * @FilePath: /xyxBooking-weapp/src/pages/bookingList/index.vue 5 * @FilePath: /xyxBooking-weapp/src/pages/bookingList/index.vue
6 * @Description: 预约记录列表页 6 * @Description: 预约记录列表页
7 --> 7 -->
...@@ -34,6 +34,10 @@ const bookingList = ref([]); ...@@ -34,6 +34,10 @@ const bookingList = ref([]);
34 const loading = ref(false); 34 const loading = ref(false);
35 const finished = ref(false); 35 const finished = ref(false);
36 36
37 +/**
38 + * 加载预约记录列表
39 + * @param isRefresh 是否刷新,默认 false
40 + */
37 const loadData = async (isRefresh = false) => { 41 const loadData = async (isRefresh = false) => {
38 if (loading.value || (finished.value && !isRefresh)) return; 42 if (loading.value || (finished.value && !isRefresh)) return;
39 43
......
1 /* 1 /*
2 * @Date: 2022-04-18 15:59:42 2 * @Date: 2022-04-18 15:59:42
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-01-30 15:43:33 4 + * @LastEditTime: 2026-01-13 11:39:03
5 * @FilePath: /xyxBooking-weapp/src/utils/tools.js 5 * @FilePath: /xyxBooking-weapp/src/utils/tools.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -59,12 +59,48 @@ const strExist = (array, str) => { ...@@ -59,12 +59,48 @@ const strExist = (array, str) => {
59 return exist.length > 0 59 return exist.length > 0
60 } 60 }
61 61
62 -const formatDatetime = (data) => { // 格式化日期 62 +/**
63 + * 格式化日期时间字符串,提取开始/结束时间并拼接为「日期 开始时间-结束时间」格式
64 + * @description 处理包含 begin_time/end_time 的数据对象,截取时间戳最后6位(毫秒/时区等冗余部分),
65 + * 最终拼接为 "YYYY-MM-DD HH:mm:ss-HH:mm:ss" 格式的字符串
66 + * @param {Object} data - 包含开始/结束时间的数据源对象
67 + * @param {string} [data.begin_time] - 开始时间字符串(格式示例:2026-01-13T12:30:45.123456+08:00)
68 + * @param {string} [data.end_time] - 结束时间字符串(格式同 begin_time)
69 + * @returns {string} 格式化后的日期时间字符串,格式为「日期 开始时间-结束时间」;若入参无效返回空字符串
70 + * @example
71 + * 输入示例
72 + * const timeData = {
73 + * begin_time: '2026-01-13T10:00:00.987654+08:00',
74 + * end_time: '2026-01-13T18:30:00.123456+08:00'
75 + * };
76 + * 调用函数
77 + * formatDatetime(timeData); // 返回 "2026-01-13 10:00:00-18:30:00"
78 + *
79 + * @example
80 + * 入参为空的情况
81 + * formatDatetime(null); // 返回 ""
82 + * formatDatetime({}); // 返回 ""
83 + *
84 + * @note 1. 入参时间字符串需保证前19位为有效格式(YYYY-MM-DDTHH:mm:ss),否则截取后可能出现异常;
85 + * 2. 若 begin_time/end_time 缺失,拼接后可能出现 "undefined-undefined" 等异常,需保证入参完整性;
86 + * 3. 该函数默认截取时间字符串前19位(slice(0, -6)),需根据实际时间格式调整截取长度
87 + */
88 +const formatDatetime = (data) => {
89 + // 格式化日期
63 if (!data) return ''; 90 if (!data) return '';
64 - let begin_time = data?.begin_time.slice(0, -6); 91 +
65 - let end_time = data?.end_time.slice(0, -6); 92 + // 截取时间字符串最后6位(去除毫秒/时区等冗余部分)
66 - let str = begin_time + ' ' + end_time; 93 + const begin_time = data?.begin_time?.slice(0, -6) || '';
67 - return `${str.split(' ')[0]} ${str.split(' ')[1]}-${str.split(' ')[3]}`; 94 + const end_time = data?.end_time?.slice(0, -6) || '';
68 -} 95 +
96 + // 拆分时间片段并拼接目标格式:日期 开始时间-结束时间
97 + const [date, beginTime] = begin_time.split('T');
98 + const [, endTime] = end_time.split('T');
99 +
100 + // 兼容时间拆分失败的情况,避免返回 NaN/-undefined 等异常
101 + if (!date || !beginTime || !endTime) return '';
102 +
103 + return `${date} ${beginTime}-${endTime}`;
104 +};
69 105
70 export { formatDate, wxInfo, parseQueryString, strExist, formatDatetime }; 106 export { formatDate, wxInfo, parseQueryString, strExist, formatDatetime };
......