mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-10-15 05:19:17 +00:00
fix(frontend): 修复 5 条 P0(生产构建开关、令牌刷新、上传路径、WS 与开发地址)
- web/vite.config.ts:生产判据由 `mode === "prod"`(恒 false)改为 `production || prod`, 压缩/去 console/剔除 vue-devtools 插件真正生效;同时修正 terser `comments: true` (是「保留全部注释」,与注释文字相反)为 `"some"`,保留 @license 等版权声明 - app 刷新令牌:改为发送 JSON 字符串(后端为 Body(str)),与 web 端已知可用实现一致, 修掉移动端 token 过期必然 422 强制登出 - app 上传:路径补 /common(真实路径 /api/v1/common/file/upload),并改走统一 http 层的 wd-upload upload-method 钩子,Authorization 由 http 层注入,不再页面自拼 URL - app 生产 WS:ws://localhost:5180/ws → wss://service.fastapiadmin.com;开发 WS 指向本机 - app 开发接口地址:改为 http://127.0.0.1:8001,与 web 端开发策略一致 复核证据(队长独立执行):web/app type-check 均 exit 0;build:prod 与 build:h5 均 exit 0; 生产包内第一方 console 特征串 9/9 全部 0 命中(剩余 5 处 console 为字符串文案或 第三方 typeof 守卫,非可执行调用);H5 产物内 localhost:5180 命中 0、wss 域名命中 1、 裸 /file/upload 命中 0、/common/file/upload 命中 1。
This commit is contained in:
@@ -28,13 +28,21 @@ const AuthAPI = {
|
||||
|
||||
/**
|
||||
* 刷新令牌
|
||||
* @param body 刷新令牌请求体
|
||||
*
|
||||
* 后端 `POST /system/auth/token/refresh` 的入参是 `Annotated[str, Body(...)]`
|
||||
* (`backend/app/modules/system/auth/controller.py:57`),即请求体必须是一个
|
||||
* **JSON 字符串**(形如 `"eyJ..."`),而不是 `{ "refresh_token": "..." }` 对象,
|
||||
* 否则 FastAPI 解析失败返回 422。因此这里与 `logout` 一致,先
|
||||
* `JSON.stringify` 让请求体成为合法 JSON 字符串(uni.request 对字符串原样发送)。
|
||||
* web 端 `frontend/web/src/api/module_system/auth.ts` 同名方法即直接发字符串。
|
||||
*
|
||||
* @param refreshToken 刷新令牌原文
|
||||
* @returns 新的访问令牌
|
||||
*/
|
||||
refreshToken(body: RefreshToekenBody): Promise<LoginResult> {
|
||||
refreshToken(refreshToken: string): Promise<LoginResult> {
|
||||
// authRole: 'refreshToken':让 http 层 401 处理器识别刷新请求,自身 401 时不触发刷新逻辑(避免死循环)
|
||||
// silent:刷新失败由 http 层统一跳转登录,无需全局 toast
|
||||
return http.Post(`${AUTH_BASE_URL}/token/refresh`, body, {
|
||||
return http.Post(`${AUTH_BASE_URL}/token/refresh`, JSON.stringify(refreshToken), {
|
||||
meta: { ignoreAuth: true, silent: true, authRole: 'refreshToken' },
|
||||
})
|
||||
},
|
||||
@@ -131,11 +139,6 @@ export interface LoginFormData {
|
||||
login_type?: string
|
||||
}
|
||||
|
||||
/** 刷新令牌请求体 */
|
||||
export interface RefreshToekenBody {
|
||||
refresh_token: string
|
||||
}
|
||||
|
||||
/** JWT 响应 */
|
||||
export interface LoginResult {
|
||||
access_token: string
|
||||
|
||||
@@ -19,13 +19,23 @@ const UserAPI = {
|
||||
/**
|
||||
* 当前用户头像上传
|
||||
*
|
||||
* 路径必须是 `/common/file/upload`:后端 `FileRouter` 自身前缀是 `/file`,但挂在
|
||||
* `/common` 域下(`backend/app/api/v1/routers.py:63`),配合 `VITE_APP_BASE_API=/api/v1`
|
||||
* 得到 `/api/v1/common/file/upload`;`upload_type` 是 Query 参数、文件字段名约定为 `file`
|
||||
* (`backend/app/modules/common/file/controller.py:18-31`)。
|
||||
* 旧实现写成 `/file/upload`,后端无此路由 → 404。
|
||||
*
|
||||
* 走统一 http 层(`requestType: 'upload'`):请求头由 http 层 `beforeRequest` 统一注入
|
||||
* `Authorization`(该接口要求 `module_common:file:upload` 权限),失败复用全局错误处理,
|
||||
* 调用方无需自己拼 URL 与请求头。
|
||||
*
|
||||
* @param body 上传参数
|
||||
* @param body.filePath 本地临时文件路径(uni.chooseImage 选择结果)
|
||||
* @param body.name 上传字段名,后端约定为 file
|
||||
* @returns uni.uploadFile 成功回调(statusCode + data 响应体字符串,需调用方解析)
|
||||
* @returns uni.uploadFile 成功回调结果(statusCode + data 响应体字符串,需调用方解析)
|
||||
*/
|
||||
uploadCurrentUserAvatar(body: { filePath: string, name?: string }): Promise<{ statusCode: number, data: string }> {
|
||||
return http.Post('/file/upload?upload_type=avatar', body, { requestType: 'upload' })
|
||||
uploadCurrentUserAvatar(body: { filePath: string, name?: string }): Promise<UniApp.UploadFileSuccessCallbackResult> {
|
||||
return http.Post('/common/file/upload?upload_type=avatar', body, { requestType: 'upload' })
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user