liufumingren 8f1a8b7ddb feat(miniprogram): 新增 uni-app + Vue3 + TS 微信小程序
- 登录:微信一键登录(code2Session)+ 账号登录双 tab;个人中心为整页登录,其它页走抽屉
- 协议:登录前必须阅读并同意,版本号随登录上报落库
- 不强制登录:启动不弹窗,点功能或遇到 401 才提示(符合小程序审核)
- 页面:首页统计 / 扫码记录 / 个人中心;H5 预览端口 7304

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-21 00:47:16 +08:00

35 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 登录策略:集中控制「页面 / 接口是否必须登录」
*
* 微信小程序审核要求:**不能一打开就强制登录**,要让用户先能浏览;
* 所以默认策略是「游客可浏览,只有真正需要使用功能时才提示登录」:
*
* - 首页 / 我的:游客可进,点页面里的「登录」才进登录流程;
* - 扫码记录:属于 `pageGuards`,**进入页面时**才提示登录(`autoPromptOnEnter`);
* - 接口:只有页面真的发请求拿到 401 才弹登录(`promptOnUnauthorized`)。
*
* 需要收紧/放宽时只改这里,页面与 `api/client.ts` 都读它。
*/
export const AUTH_POLICY = {
/**
* 必须登录才能使用的页面。
* 现在只有「首页 / 我的」两个 tab,且都能游客浏览(首页给功能介绍、我的给欢迎卡片),
* 所以这里是空的;将来加「仅登录可见」的页面时把 route 加进来即可。
*/
pageGuards: [] as string[],
/** 进入 pageGuards 页面时是否自动弹出登录(false → 页面内只给「登录」按钮) */
autoPromptOnEnter: true,
/** 业务接口是否必须登录(false → 游客也允许请求,401 不弹登录,页面按空数据处理) */
apiRequireAuth: true,
/** 收到 401 时是否自动弹出登录 */
promptOnUnauthorized: true,
};
/** 页面是否需要登录 */
export function isGuardedPage(route: string): boolean {
return AUTH_POLICY.pageGuards.includes(route);
}