refactor(auth): 移除token认证逻辑并重构用户登录流程
- 删除auth.ts及相关token管理函数 - 修改登录接口和用户信息获取接口,不再依赖token - 使用uni-app存储替代cookie存储用户信息 - 重构微信登录流程,简化参数传递 - 更新用户头像默认路径为新增的default-avatar.png - 在个人中心页面增加登录状态判断和登录按钮 ``` 这个提交消息遵循了以下原则: 1. 使用refactor类型,因为这是对现有代码结构的重构 2. 添加了scope(auth)来明确这是认证相关的重构 3. 描述简明扼要地说明了主要变更 4. 在body中列出了主要变更点,没有重复描述 5. 使用中文并保持简洁,每个变更点用短句说明 6. 使用动词开头并保持一致的格式
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
import Cookie from 'js-cookie'
|
||||
import { isMpWeixin } from './platform'
|
||||
/**
|
||||
* TokeKey的名字
|
||||
*/
|
||||
const TokenKey: string = 'token'
|
||||
|
||||
/**
|
||||
* 获取tokenKeyName
|
||||
* @returns tokenKeyName
|
||||
*/
|
||||
export const getTokenKey = (): string => {
|
||||
return TokenKey
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否登录,即是否有token,不检查Token是否过期和是否有效
|
||||
* @returns 是否登录
|
||||
*/
|
||||
export const isLogin = () => {
|
||||
return !!getToken()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Token
|
||||
* @returns 令牌
|
||||
*/
|
||||
export const getToken = () => {
|
||||
return getCookieMap<string>(getTokenKey())
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Token
|
||||
* @param token 令牌
|
||||
*/
|
||||
export const setToken = (token: string) => {
|
||||
setCookieMap(getTokenKey(), token)
|
||||
}
|
||||
/**
|
||||
* 删除Token
|
||||
*/
|
||||
export const removeToken = () => {
|
||||
removeCookieMap(getTokenKey())
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Cookie
|
||||
* @param key Cookie的key
|
||||
* @param value Cookie的value
|
||||
*/
|
||||
export const setCookieMap = (key: string, value: any) => {
|
||||
if (isMpWeixin) {
|
||||
uni.setStorageSync(key, value)
|
||||
return
|
||||
}
|
||||
Cookie.set(key, value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Cookie
|
||||
* @param key Cookie的key
|
||||
* @returns Cookie的value
|
||||
*/
|
||||
export const getCookieMap = <T>(key: string) => {
|
||||
if (isMpWeixin) {
|
||||
return uni.getStorageSync(key) as T
|
||||
}
|
||||
return Cookie.get(key) as T
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除Cookie
|
||||
* @param key Cookie的key
|
||||
*/
|
||||
export const removeCookieMap = (key: string) => {
|
||||
if (isMpWeixin) {
|
||||
uni.removeStorageSync(key)
|
||||
return
|
||||
}
|
||||
Cookie.remove(key)
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getToken, getTokenKey } from './auth'
|
||||
import { toast } from './toast'
|
||||
|
||||
/**
|
||||
@@ -286,7 +285,6 @@ function uploadFile<T>({
|
||||
// #ifndef H5
|
||||
'Content-Type': 'multipart/form-data',
|
||||
// #endif
|
||||
[getTokenKey()]: getToken(), // 添加认证token
|
||||
},
|
||||
// 确保文件名称合法
|
||||
success: (uploadFileRes) => {
|
||||
|
||||
Reference in New Issue
Block a user