feat(api): 新增文件上传相关API及用户邮箱字段
refactor(auth): 使用isApiSuccess统一校验API响应 refactor(store): 更新用户信息获取逻辑以适配新响应格式 chore: 添加eslint和prettier配置及脚本 style: 调整vite代理配置端口号 新增文件上传相关API接口及类型定义 扩展用户信息接口添加邮箱相关字段 统一API响应校验逻辑 更新package.json添加代码格式化工具
This commit is contained in:
1761
package-lock.json
generated
1761
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@@ -10,9 +10,32 @@
|
||||
"build:prod": "vue-tsc -b && vite build --mode prod",
|
||||
"preview": "vite preview",
|
||||
"lint": "eslint . --ext .ts,.vue",
|
||||
"lint:fix": "eslint . --ext .ts,.vue --fix",
|
||||
"format": "prettier . --write",
|
||||
"format:check": "prettier . --check",
|
||||
"type-check": "vue-tsc --noEmit",
|
||||
"build:types": "vue-tsc --declaration --emitDeclarationOnly"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"es2022": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:vue/vue3-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"parser": "vue-eslint-parser",
|
||||
"parserOptions": {
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@arco-design/web-vue": "^2.57.0",
|
||||
"axios": "^1.13.2",
|
||||
@@ -23,12 +46,19 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.10.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
||||
"@typescript-eslint/parser": "^7.18.0",
|
||||
"@vitejs/plugin-vue": "^6.0.1",
|
||||
"@vue/tsconfig": "^0.8.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-vue": "^9.23.0",
|
||||
"openapi-typescript-codegen": "^0.29.0",
|
||||
"prettier": "^3.2.5",
|
||||
"sass-embedded": "^1.93.3",
|
||||
"typescript": "~5.9.3",
|
||||
"vite": "npm:rolldown-vite@7.2.2",
|
||||
"vue-eslint-parser": "^9.4.3",
|
||||
"vue-tsc": "^3.1.3"
|
||||
},
|
||||
"overrides": {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -28,7 +28,7 @@ export default defineConfig(({ command, mode }) => {
|
||||
proxy: {
|
||||
// 代理所有 /api 开头的请求
|
||||
'/api': {
|
||||
target: 'http://localhost:8085', // 后端服务器地址
|
||||
target: 'http://localhost:18085', // 后端服务器地址
|
||||
changeOrigin: true, // 改变请求头中的 origin
|
||||
secure: false, // 支持 https
|
||||
// 如果后端 API 路径不包含 /api,可以重写路径
|
||||
|
||||
Reference in New Issue
Block a user