hookehuyr

docs: 完善代码注释和文件描述

更新多个文件的注释和描述信息,使其更清晰准确
添加 jsconfig.json 配置文件用于路径映射
1 +{
2 + "compilerOptions": {
3 + "baseUrl": ".",
4 + "paths": {
5 + "@/*": ["src/*"],
6 + "@/utils/*": ["src/utils/*"],
7 + "@/components/*": ["src/components/*"],
8 + "@/images/*": ["src/assets/images/*"],
9 + "@/assets/*": ["src/assets/*"],
10 + "@/composables/*": ["src/composables/*"],
11 + "@/api/*": ["src/api/*"],
12 + "@/stores/*": ["src/stores/*"],
13 + "@/hooks/*": ["src/hooks/*"]
14 + }
15 + },
16 + "include": ["src/**/*", "config/**/*"]
17 +}
1 /* 1 /*
2 * @Date: 2025-06-28 10:33:00 2 * @Date: 2025-06-28 10:33:00
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2026-01-13 00:07:41 4 + * @LastEditTime: 2026-01-13 00:28:35
5 * @FilePath: /xyxBooking-weapp/src/app.js 5 * @FilePath: /xyxBooking-weapp/src/app.js
6 - * @Description: 文件描述 6 + * @Description: 应用入口文件
7 */ 7 */
8 import { createApp } from 'vue' 8 import { createApp } from 'vue'
9 import { createPinia } from 'pinia' 9 import { createPinia } from 'pinia'
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-05-26 10:17:04 4 + * @LastEditTime: 2026-01-13 00:18:41
5 * @FilePath: /xyxBooking-weapp/src/pages/auth/index.vue 5 * @FilePath: /xyxBooking-weapp/src/pages/auth/index.vue
6 - * @Description: 文件描述 6 + * @Description: 授权页
7 --> 7 -->
8 <template> 8 <template>
9 <view class="auth-page"> 9 <view class="auth-page">
...@@ -18,6 +18,11 @@ import Taro, { useDidShow } from '@tarojs/taro' ...@@ -18,6 +18,11 @@ import Taro, { useDidShow } from '@tarojs/taro'
18 import { silentAuth, returnToOriginalPage } from '@/utils/authRedirect' 18 import { silentAuth, returnToOriginalPage } from '@/utils/authRedirect'
19 19
20 useDidShow(() => { 20 useDidShow(() => {
21 + /**
22 + * 尝试静默授权
23 + * - 授权成功后回跳到来源页
24 + * - 授权失败则跳转至授权页面
25 + */
21 silentAuth() 26 silentAuth()
22 .then(() => returnToOriginalPage()) 27 .then(() => returnToOriginalPage())
23 .catch((error) => { 28 .catch((error) => {
......
...@@ -11,7 +11,7 @@ import BASE_URL, { REQUEST_DEFAULT_PARAMS } from './config' ...@@ -11,7 +11,7 @@ import BASE_URL, { REQUEST_DEFAULT_PARAMS } from './config'
11 11
12 /** 12 /**
13 * 获取当前页完整路径(含 query) 13 * 获取当前页完整路径(含 query)
14 - * @returns {string} 当前页路径,示例:pages/index/index?a=1 14 + * @returns {string} 当前页路径,示例:pages/index/index?a=1;获取失败返回空字符串
15 */ 15 */
16 export const getCurrentPageFullPath = () => { 16 export const getCurrentPageFullPath = () => {
17 const pages = Taro.getCurrentPages() 17 const pages = Taro.getCurrentPages()
...@@ -30,8 +30,8 @@ export const getCurrentPageFullPath = () => { ...@@ -30,8 +30,8 @@ export const getCurrentPageFullPath = () => {
30 30
31 /** 31 /**
32 * 保存当前页路径(用于授权成功后回跳) 32 * 保存当前页路径(用于授权成功后回跳)
33 - * @param {string} custom_path 自定义路径,不传则取当前页 33 + * @param {string} custom_path 自定义路径,不传则取当前页完整路径
34 - * @returns {void} 34 + * @returns {void} 无返回值
35 */ 35 */
36 export const saveCurrentPagePath = (custom_path) => { 36 export const saveCurrentPagePath = (custom_path) => {
37 const router = routerStore() 37 const router = routerStore()
...@@ -61,7 +61,7 @@ let auth_promise = null ...@@ -61,7 +61,7 @@ let auth_promise = null
61 * - 复用 auth_promise,防止多个接口同时 401 时并发触发多次登录 61 * - 复用 auth_promise,防止多个接口同时 401 时并发触发多次登录
62 * @param {object} options 可选项 62 * @param {object} options 可选项
63 * @param {boolean} options.show_loading 是否展示 loading,默认 true 63 * @param {boolean} options.show_loading 是否展示 loading,默认 true
64 - * @returns {Promise<{code:number,msg?:string,data?:any,cookie?:string}>} 后端返回 + cookie 64 + * @returns {Promise<{code:number,msg?:string,data?:any,cookie?:string}>} 授权结果(会把 cookie 写入 storage 的 sessionid)
65 */ 65 */
66 export const refreshSession = async (options) => { 66 export const refreshSession = async (options) => {
67 const show_loading = options?.show_loading !== false 67 const show_loading = options?.show_loading !== false
...@@ -152,6 +152,11 @@ export const refreshSession = async (options) => { ...@@ -152,6 +152,11 @@ export const refreshSession = async (options) => {
152 return auth_promise 152 return auth_promise
153 } 153 }
154 154
155 +/**
156 + * 执行静默授权:检查是否已授权,若否则调用 refreshSession 刷新会话
157 + * @param {boolean} show_loading 是否展示 loading,默认 true
158 + * @returns {Promise<{code:number,msg?:string,data?:any,cookie?:string}>} 授权结果
159 + */
155 const do_silent_auth = async (show_loading) => { 160 const do_silent_auth = async (show_loading) => {
156 // 已有 sessionid 时直接视为已授权 161 // 已有 sessionid 时直接视为已授权
157 if (hasAuth()) { 162 if (hasAuth()) {
...@@ -165,11 +170,11 @@ const do_silent_auth = async (show_loading) => { ...@@ -165,11 +170,11 @@ const do_silent_auth = async (show_loading) => {
165 /** 170 /**
166 * 静默授权:用于启动阶段/分享页/授权页发起授权 171 * 静默授权:用于启动阶段/分享页/授权页发起授权
167 * - 与 refreshSession 共用 auth_promise,避免并发重复调用 172 * - 与 refreshSession 共用 auth_promise,避免并发重复调用
168 - * @param {Function} on_success 成功回调 173 + * @param {(result: any) => void} on_success 成功回调(可选)
169 - * @param {Function} on_error 失败回调(入参为错误文案) 174 + * @param {(error_msg: string) => void} on_error 失败回调(可选,入参为错误文案)
170 * @param {object} options 可选项 175 * @param {object} options 可选项
171 * @param {boolean} options.show_loading 是否展示 loading,默认 true 176 * @param {boolean} options.show_loading 是否展示 loading,默认 true
172 - * @returns {Promise<any>} 授权结果 177 + * @returns {Promise<any>} 授权结果(成功 resolve,失败 reject)
173 */ 178 */
174 export const silentAuth = async (on_success, on_error, options) => { 179 export const silentAuth = async (on_success, on_error, options) => {
175 const show_loading = options?.show_loading !== false 180 const show_loading = options?.show_loading !== false
...@@ -194,8 +199,8 @@ export const silentAuth = async (on_success, on_error, options) => { ...@@ -194,8 +199,8 @@ export const silentAuth = async (on_success, on_error, options) => {
194 /** 199 /**
195 * 跳转到授权页(降级方案) 200 * 跳转到授权页(降级方案)
196 * - 会先保存回跳路径(默认当前页),授权成功后在 auth 页回跳 201 * - 会先保存回跳路径(默认当前页),授权成功后在 auth 页回跳
197 - * @param {string} return_path 指定回跳路径 202 + * @param {string} return_path 指定回跳路径(可选)
198 - * @returns {void} 203 + * @returns {void} 无返回值
199 */ 204 */
200 export const navigateToAuth = (return_path) => { 205 export const navigateToAuth = (return_path) => {
201 if (return_path) { 206 if (return_path) {
...@@ -221,7 +226,7 @@ export const navigateToAuth = (return_path) => { ...@@ -221,7 +226,7 @@ export const navigateToAuth = (return_path) => {
221 * - 优先使用 routerStore 里保存的路径 226 * - 优先使用 routerStore 里保存的路径
222 * - 失败降级:redirectTo -> reLaunch 227 * - 失败降级:redirectTo -> reLaunch
223 * @param {string} default_path 未保存来源页时的默认回跳路径 228 * @param {string} default_path 未保存来源页时的默认回跳路径
224 - * @returns {Promise<void>} 229 + * @returns {Promise<void>} 回跳完成
225 */ 230 */
226 export const returnToOriginalPage = async (default_path = '/pages/index/index') => { 231 export const returnToOriginalPage = async (default_path = '/pages/index/index') => {
227 const router = routerStore() 232 const router = routerStore()
...@@ -263,7 +268,7 @@ export const returnToOriginalPage = async (default_path = '/pages/index/index') ...@@ -263,7 +268,7 @@ export const returnToOriginalPage = async (default_path = '/pages/index/index')
263 /** 268 /**
264 * 判断是否来自分享场景 269 * 判断是否来自分享场景
265 * @param {object} options 页面 options 270 * @param {object} options 页面 options
266 - * @returns {boolean} 271 + * @returns {boolean} true=来自分享场景,false=非分享场景
267 */ 272 */
268 export const isFromShare = (options) => { 273 export const isFromShare = (options) => {
269 return options && (options.from_share === '1' || options.scene) 274 return options && (options.from_share === '1' || options.scene)
...@@ -274,8 +279,8 @@ export const isFromShare = (options) => { ...@@ -274,8 +279,8 @@ export const isFromShare = (options) => {
274 * - 来自分享且未授权:保存当前页路径,授权成功后回跳 279 * - 来自分享且未授权:保存当前页路径,授权成功后回跳
275 * - 授权失败:返回 false,由调用方决定是否继续降级处理 280 * - 授权失败:返回 false,由调用方决定是否继续降级处理
276 * @param {object} options 页面 options 281 * @param {object} options 页面 options
277 - * @param {Function} callback 授权成功后的继续逻辑 282 + * @param {Function} callback 授权成功后的继续逻辑(可选)
278 - * @returns {Promise<boolean>} true=已处理且可继续,false=授权失败 283 + * @returns {Promise<boolean>} true=授权已完成/无需授权,false=授权失败
279 */ 284 */
280 export const handleSharePageAuth = async (options, callback) => { 285 export const handleSharePageAuth = async (options, callback) => {
281 if (hasAuth()) { 286 if (hasAuth()) {
......