更新:登录功能

This commit is contained in:
2025-11-04 12:37:04 +08:00
commit a21fb92916
897 changed files with 51500 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
// 片段示例 - requestInterceptor 更稳健的写法
import type { IRequestOptions } from '../types'
import { useUserStore } from '@/stores/user'
import { APP_INFO } from '@/api/config'
export function requestInterceptor(options: IRequestOptions): IRequestOptions {
const headers = { ...(options.headers || {}) }
// 更明确地调用 useUserStore
let token = ''
try {
const userStore = typeof useUserStore === 'function' ? useUserStore() : null
token = userStore?.token || uni.getStorageSync('token') || ''
} catch (e) {
token = uni.getStorageSync('token') || ''
}
if (token) headers.token = token
// Content-Type只有在没有 files 时才默认为 application/json
if (!options.files && !headers['Content-Type']) {
headers['Content-Type'] = 'application/json;charset=UTF-8'
}
headers['appType'] = APP_INFO.TYPE
headers['version_code'] = APP_INFO.VERSION_CODE || '1.0.0'
return {
...options,
header: headers,
}
}