hookehuyr

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

更新多个文件的注释和描述信息,使其更清晰准确
添加 jsconfig.json 配置文件用于路径映射
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
"@/utils/*": ["src/utils/*"],
"@/components/*": ["src/components/*"],
"@/images/*": ["src/assets/images/*"],
"@/assets/*": ["src/assets/*"],
"@/composables/*": ["src/composables/*"],
"@/api/*": ["src/api/*"],
"@/stores/*": ["src/stores/*"],
"@/hooks/*": ["src/hooks/*"]
}
},
"include": ["src/**/*", "config/**/*"]
}
/*
* @Date: 2025-06-28 10:33:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-13 00:07:41
* @LastEditTime: 2026-01-13 00:28:35
* @FilePath: /xyxBooking-weapp/src/app.js
* @Description: 文件描述
* @Description: 应用入口文件
*/
import { createApp } from 'vue'
import { createPinia } from 'pinia'
......
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-05-26 10:17:04
* @LastEditTime: 2026-01-13 00:18:41
* @FilePath: /xyxBooking-weapp/src/pages/auth/index.vue
* @Description: 文件描述
* @Description: 授权页
-->
<template>
<view class="auth-page">
......@@ -18,6 +18,11 @@ import Taro, { useDidShow } from '@tarojs/taro'
import { silentAuth, returnToOriginalPage } from '@/utils/authRedirect'
useDidShow(() => {
/**
* 尝试静默授权
* - 授权成功后回跳到来源页
* - 授权失败则跳转至授权页面
*/
silentAuth()
.then(() => returnToOriginalPage())
.catch((error) => {
......
......@@ -11,7 +11,7 @@ import BASE_URL, { REQUEST_DEFAULT_PARAMS } from './config'
/**
* 获取当前页完整路径(含 query)
* @returns {string} 当前页路径,示例:pages/index/index?a=1
* @returns {string} 当前页路径,示例:pages/index/index?a=1;获取失败返回空字符串
*/
export const getCurrentPageFullPath = () => {
const pages = Taro.getCurrentPages()
......@@ -30,8 +30,8 @@ export const getCurrentPageFullPath = () => {
/**
* 保存当前页路径(用于授权成功后回跳)
* @param {string} custom_path 自定义路径,不传则取当前页
* @returns {void}
* @param {string} custom_path 自定义路径,不传则取当前页完整路径
* @returns {void} 无返回值
*/
export const saveCurrentPagePath = (custom_path) => {
const router = routerStore()
......@@ -61,7 +61,7 @@ let auth_promise = null
* - 复用 auth_promise,防止多个接口同时 401 时并发触发多次登录
* @param {object} options 可选项
* @param {boolean} options.show_loading 是否展示 loading,默认 true
* @returns {Promise<{code:number,msg?:string,data?:any,cookie?:string}>} 后端返回 + cookie
* @returns {Promise<{code:number,msg?:string,data?:any,cookie?:string}>} 授权结果(会把 cookie 写入 storage 的 sessionid)
*/
export const refreshSession = async (options) => {
const show_loading = options?.show_loading !== false
......@@ -152,6 +152,11 @@ export const refreshSession = async (options) => {
return auth_promise
}
/**
* 执行静默授权:检查是否已授权,若否则调用 refreshSession 刷新会话
* @param {boolean} show_loading 是否展示 loading,默认 true
* @returns {Promise<{code:number,msg?:string,data?:any,cookie?:string}>} 授权结果
*/
const do_silent_auth = async (show_loading) => {
// 已有 sessionid 时直接视为已授权
if (hasAuth()) {
......@@ -165,11 +170,11 @@ const do_silent_auth = async (show_loading) => {
/**
* 静默授权:用于启动阶段/分享页/授权页发起授权
* - 与 refreshSession 共用 auth_promise,避免并发重复调用
* @param {Function} on_success 成功回调
* @param {Function} on_error 失败回调(入参为错误文案)
* @param {(result: any) => void} on_success 成功回调(可选)
* @param {(error_msg: string) => void} on_error 失败回调(可选,入参为错误文案)
* @param {object} options 可选项
* @param {boolean} options.show_loading 是否展示 loading,默认 true
* @returns {Promise<any>} 授权结果
* @returns {Promise<any>} 授权结果(成功 resolve,失败 reject)
*/
export const silentAuth = async (on_success, on_error, options) => {
const show_loading = options?.show_loading !== false
......@@ -194,8 +199,8 @@ export const silentAuth = async (on_success, on_error, options) => {
/**
* 跳转到授权页(降级方案)
* - 会先保存回跳路径(默认当前页),授权成功后在 auth 页回跳
* @param {string} return_path 指定回跳路径
* @returns {void}
* @param {string} return_path 指定回跳路径(可选)
* @returns {void} 无返回值
*/
export const navigateToAuth = (return_path) => {
if (return_path) {
......@@ -221,7 +226,7 @@ export const navigateToAuth = (return_path) => {
* - 优先使用 routerStore 里保存的路径
* - 失败降级:redirectTo -> reLaunch
* @param {string} default_path 未保存来源页时的默认回跳路径
* @returns {Promise<void>}
* @returns {Promise<void>} 回跳完成
*/
export const returnToOriginalPage = async (default_path = '/pages/index/index') => {
const router = routerStore()
......@@ -263,7 +268,7 @@ export const returnToOriginalPage = async (default_path = '/pages/index/index')
/**
* 判断是否来自分享场景
* @param {object} options 页面 options
* @returns {boolean}
* @returns {boolean} true=来自分享场景,false=非分享场景
*/
export const isFromShare = (options) => {
return options && (options.from_share === '1' || options.scene)
......@@ -274,8 +279,8 @@ export const isFromShare = (options) => {
* - 来自分享且未授权:保存当前页路径,授权成功后回跳
* - 授权失败:返回 false,由调用方决定是否继续降级处理
* @param {object} options 页面 options
* @param {Function} callback 授权成功后的继续逻辑
* @returns {Promise<boolean>} true=已处理且可继续,false=授权失败
* @param {Function} callback 授权成功后的继续逻辑(可选)
* @returns {Promise<boolean>} true=授权已完成/无需授权,false=授权失败
*/
export const handleSharePageAuth = async (options, callback) => {
if (hasAuth()) {
......