feat(api): 新增文件上传相关API及用户邮箱字段
refactor(auth): 使用isApiSuccess统一校验API响应 refactor(store): 更新用户信息获取逻辑以适配新响应格式 chore: 添加eslint和prettier配置及脚本 style: 调整vite代理配置端口号 新增文件上传相关API接口及类型定义 扩展用户信息接口添加邮箱相关字段 统一API响应校验逻辑 更新package.json添加代码格式化工具
This commit is contained in:
@@ -38,6 +38,16 @@ export interface UserInfo {
|
||||
*/
|
||||
userAvatar?: string;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
userEmail?: string;
|
||||
|
||||
/**
|
||||
* 用户邮箱是否验证
|
||||
*/
|
||||
userEmailVerified?: boolean;
|
||||
|
||||
/**
|
||||
* 用户简介
|
||||
*/
|
||||
@@ -62,8 +72,8 @@ export interface UserInfo {
|
||||
* 获取当前登录用户信息
|
||||
* @returns 当前登录用户信息
|
||||
*/
|
||||
export const getUserInfoByToken = () => {
|
||||
return request<ApiResponse<UserInfo>>({
|
||||
export const getUserInfoByToken = (): Promise<ApiResponse<UserInfo>> => {
|
||||
return request({
|
||||
url: "/v1/auth/getUserInfo",
|
||||
method: "GET",
|
||||
})
|
||||
|
||||
121
src/api/file/file.ts
Normal file
121
src/api/file/file.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
import request from "@/plugins/axios";
|
||||
/**
|
||||
* 分页查询文件列表
|
||||
*/
|
||||
export const getFileList = async(current: number,size: number) =>{
|
||||
return request({
|
||||
url: "/v1/file/page",
|
||||
method: "GET",
|
||||
params: {
|
||||
current,
|
||||
size,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询文件详情
|
||||
* @param id
|
||||
* @returns
|
||||
*/
|
||||
export const getFileById = async (id: number) => {
|
||||
return request({
|
||||
url: "/v1/file/" + id,
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 检查文件是否已经上传,本地计算文件哈希
|
||||
* @param hash
|
||||
* @returns
|
||||
*/
|
||||
export const checkHash = async (hash: string) => {
|
||||
return request({
|
||||
url: "/v1/file/check",
|
||||
method: "GET",
|
||||
params: {
|
||||
hash,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param file
|
||||
* @returns
|
||||
*/
|
||||
export const uploadFile = async (file: File,hash: string) => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("hash", hash);
|
||||
return request({
|
||||
url: "/v1/file/upload",
|
||||
method: "POST",
|
||||
data: formData,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param id
|
||||
* @returns
|
||||
*/
|
||||
export const deleteFile = async (id: number) => {
|
||||
return request({
|
||||
url: "/v1/file/" + id,
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface FileListItem {
|
||||
|
||||
/* */
|
||||
id: number;
|
||||
|
||||
/* */
|
||||
fileName: string;
|
||||
|
||||
/* */
|
||||
fileExtension: string;
|
||||
|
||||
/* */
|
||||
fileSize: number;
|
||||
|
||||
/* */
|
||||
fileHash: string;
|
||||
|
||||
/* */
|
||||
mimeType: string;
|
||||
|
||||
/* */
|
||||
storageType: string;
|
||||
|
||||
/* */
|
||||
storagePath: string;
|
||||
|
||||
/* */
|
||||
businessType: string;
|
||||
|
||||
/* */
|
||||
businessId: number;
|
||||
|
||||
/* */
|
||||
userId: number;
|
||||
|
||||
/* */
|
||||
imageInfo: string;
|
||||
|
||||
/* */
|
||||
isDeleted: number;
|
||||
|
||||
/* */
|
||||
createdAt: Record<string, unknown>;
|
||||
|
||||
/* */
|
||||
updatedAt: Record<string, unknown>;
|
||||
|
||||
}
|
||||
|
||||
export type FileList = FileListItem[];
|
||||
@@ -1,6 +1,11 @@
|
||||
// 统一响应格式
|
||||
export interface ApiResponse<T = any> {
|
||||
success: boolean;
|
||||
message: string;
|
||||
code?: string | number;
|
||||
success?: boolean;
|
||||
message?: string | null;
|
||||
data: T;
|
||||
}
|
||||
}
|
||||
|
||||
export const isApiSuccess = (response: ApiResponse<any> | any): boolean => {
|
||||
return response?.success === true || response?.code === 0 || response?.code === "0";
|
||||
};
|
||||
|
||||
0
src/components/file_upload/FileUpload.vue
Normal file
0
src/components/file_upload/FileUpload.vue
Normal file
@@ -10,6 +10,7 @@ import {
|
||||
clearTokens,
|
||||
} from "@/utils/token";
|
||||
import { Message } from "@arco-design/web-vue";
|
||||
import { isApiSuccess } from "@/api/response";
|
||||
|
||||
// 是否正在刷新 token
|
||||
let isRefreshing = false;
|
||||
@@ -86,7 +87,7 @@ request.interceptors.response.use(
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data?.success) {
|
||||
if (isApiSuccess(response.data)) {
|
||||
const { accessToken, refreshToken: newRefreshToken } =
|
||||
response.data.data;
|
||||
// 更新本地存储
|
||||
|
||||
@@ -2,6 +2,7 @@ import { defineStore } from "pinia";
|
||||
import ACCESS_ENUM from "../access/accessEnum";
|
||||
import type { LoginUesr } from "../store/types";
|
||||
import { getUserInfoByToken } from "@/api/auth/user";
|
||||
import { isApiSuccess } from "@/api/response";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -23,8 +24,8 @@ export const useUserStore = defineStore("user", {
|
||||
try {
|
||||
const res = await getUserInfoByToken();
|
||||
console.log("获取登录用户成功", res);
|
||||
if(res.data.success === true){
|
||||
this.updateUserLoginStatus(res.data.data);
|
||||
if (isApiSuccess(res)) {
|
||||
this.updateUserLoginStatus(res.data);
|
||||
}
|
||||
}catch(e) {
|
||||
console.error("获取登录用户失败", e);
|
||||
|
||||
@@ -78,6 +78,7 @@ import { login } from "@/api/auth/auth";
|
||||
import { setTokens } from "@/utils/token";
|
||||
import { useUserStore } from "@/store/user";
|
||||
import ACCESS_ENUM from "@/access/accessEnum";
|
||||
import { isApiSuccess } from "@/api/response";
|
||||
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
@@ -114,7 +115,7 @@ const handleSubmit = async (data: any) => {
|
||||
userPassword: form.userPassword,
|
||||
});
|
||||
|
||||
if (response.success) {
|
||||
if (isApiSuccess(response)) {
|
||||
Message.success("登录成功!");
|
||||
|
||||
// 存储 token
|
||||
@@ -124,7 +125,7 @@ const handleSubmit = async (data: any) => {
|
||||
userStore.updateUserLoginStatus({
|
||||
userName: response.data.userAccount,
|
||||
userRole: ACCESS_ENUM.USER,
|
||||
});
|
||||
});
|
||||
|
||||
// 跳转到首页
|
||||
router.push("/home");
|
||||
|
||||
Reference in New Issue
Block a user