style: 移除多余空行并统一代码格式

修复代码中的多余空行问题,统一字符串引号使用双引号,调整对象和数组的格式,优化代码缩进和换行,提升代码可读性和一致性
This commit is contained in:
zhangtao
2025-11-14 01:45:22 +08:00
parent 66c345d590
commit d588abb386
100 changed files with 9192 additions and 5181 deletions
+65 -62
View File
@@ -1,95 +1,98 @@
import axios, { AxiosResponse } from 'axios'
import { ElLoading, ElMessage } from 'element-plus'
import { saveAs as fileSaverSaveAs } from 'file-saver'
import { Auth } from '@/utils/auth'
import errorCode from '@/utils/errorCode'
import { blobValidate } from '@/utils/common'
import axios, { AxiosResponse } from "axios";
import { ElLoading, ElMessage } from "element-plus";
import { saveAs as fileSaverSaveAs } from "file-saver";
import { Auth } from "@/utils/auth";
import errorCode from "@/utils/errorCode";
import { blobValidate } from "@/utils/common";
const baseURL = import.meta.env.VITE_APP_BASE_API
let downloadLoadingInstance: any
const baseURL = import.meta.env.VITE_APP_BASE_API;
let downloadLoadingInstance: any;
interface DownloadUtil {
name(name: string, isDelete?: boolean): void
resource(resource: string): void
zip(url: string, name: string): void
saveAs(text: Blob | string, name: string, opts?: any): void
printErrMsg(data: Blob): Promise<void>
name(name: string, isDelete?: boolean): void;
resource(resource: string): void;
zip(url: string, name: string): void;
saveAs(text: Blob | string, name: string, opts?: any): void;
printErrMsg(data: Blob): Promise<void>;
}
const download: DownloadUtil = {
name(name: string, isDelete: boolean = true): void {
const url = baseURL + "/common/download?fileName=" + encodeURIComponent(name) + "&delete=" + isDelete
const url =
baseURL + "/common/download?fileName=" + encodeURIComponent(name) + "&delete=" + isDelete;
axios({
method: 'get',
url: url,
responseType: 'blob',
headers: { 'Authorization': 'Bearer ' + Auth.getAccessToken() }
method: "get",
url,
responseType: "blob",
headers: { Authorization: "Bearer " + Auth.getAccessToken() },
}).then((res: AxiosResponse<Blob>) => {
const isBlob = blobValidate(res.data)
const isBlob = blobValidate(res.data);
if (isBlob) {
const blob = new Blob([res.data])
download.saveAs(blob, decodeURIComponent(res.headers['download-filename']))
const blob = new Blob([res.data]);
download.saveAs(blob, decodeURIComponent(res.headers["download-filename"]));
} else {
download.printErrMsg(res.data)
download.printErrMsg(res.data);
}
})
});
},
resource(resource: string): void {
const url = baseURL + "/common/download/resource?resource=" + encodeURIComponent(resource)
const url = baseURL + "/common/download/resource?resource=" + encodeURIComponent(resource);
axios({
method: 'get',
url: url,
responseType: 'blob',
headers: { 'Authorization': 'Bearer ' + Auth.getAccessToken() }
method: "get",
url,
responseType: "blob",
headers: { Authorization: "Bearer " + Auth.getAccessToken() },
}).then((res: AxiosResponse<Blob>) => {
const isBlob = blobValidate(res.data)
const isBlob = blobValidate(res.data);
if (isBlob) {
const blob = new Blob([res.data])
download.saveAs(blob, decodeURIComponent(res.headers['download-filename']))
const blob = new Blob([res.data]);
download.saveAs(blob, decodeURIComponent(res.headers["download-filename"]));
} else {
download.printErrMsg(res.data)
download.printErrMsg(res.data);
}
})
});
},
zip(url: string, name: string): void {
const fullUrl = baseURL + url
downloadLoadingInstance = ElLoading.service({
text: "正在下载数据,请稍候",
background: "rgba(0, 0, 0, 0.7)"
})
const fullUrl = baseURL + url;
downloadLoadingInstance = ElLoading.service({
text: "正在下载数据,请稍候",
background: "rgba(0, 0, 0, 0.7)",
});
axios({
method: 'get',
method: "get",
url: fullUrl,
responseType: 'blob',
headers: { 'Authorization': 'Bearer ' + Auth.getAccessToken() }
}).then((res: AxiosResponse<Blob>) => {
const isBlob = blobValidate(res.data)
if (isBlob) {
const blob = new Blob([res.data], { type: 'application/zip' })
download.saveAs(blob, name)
} else {
download.printErrMsg(res.data)
}
downloadLoadingInstance.close()
}).catch((r: any) => {
console.error(r)
ElMessage.error('下载文件出现错误,请联系管理员!')
downloadLoadingInstance.close()
responseType: "blob",
headers: { Authorization: "Bearer " + Auth.getAccessToken() },
})
.then((res: AxiosResponse<Blob>) => {
const isBlob = blobValidate(res.data);
if (isBlob) {
const blob = new Blob([res.data], { type: "application/zip" });
download.saveAs(blob, name);
} else {
download.printErrMsg(res.data);
}
downloadLoadingInstance.close();
})
.catch((r: any) => {
console.error(r);
ElMessage.error("下载文件出现错误,请联系管理员!");
downloadLoadingInstance.close();
});
},
saveAs(text: Blob | string, name: string, opts?: any): void {
fileSaverSaveAs(text, name, opts)
fileSaverSaveAs(text, name, opts);
},
async printErrMsg(data: Blob): Promise<void> {
const resText = await data.text()
const rspObj = JSON.parse(resText)
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
ElMessage.error(errMsg)
}
}
const resText = await data.text();
const rspObj = JSON.parse(resText);
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode["default"];
ElMessage.error(errMsg);
},
};
export default download
export default download;
+1 -1
View File
@@ -7,7 +7,7 @@ import { setupStore } from "@/store";
import { setupElIcons } from "./icons";
import { setupPermission } from "./permission";
import { InstallCodeMirror } from "codemirror-editor-vue3";
import ElementPlus from 'element-plus'
import ElementPlus from "element-plus";
export default {
install(app: App<Element>) {
+13 -13
View File
@@ -14,15 +14,15 @@ export function setupPermission() {
try {
const isLoggedIn = Auth.isLoggedIn();
if (isLoggedIn) {
// 如果已登录但访问登录页,重定向到首页
if (to.path === "/login") {
next({ path: "/" });
return;
}
if (isLoggedIn) {
// 如果已登录但访问登录页,重定向到首页
if (to.path === "/login") {
next({ path: "/" });
return;
}
// 处理已登录用户的路由访问
await handleAuthenticatedUser(to, from, next);
// 处理已登录用户的路由访问
await handleAuthenticatedUser(to, from, next);
} else {
// 未登录用户的处理
if (whiteList.includes(to.path)) {
@@ -32,7 +32,7 @@ export function setupPermission() {
NProgress.done();
}
}
}catch (error) {
} catch (error) {
// 错误处理:重置状态并跳转登录
console.error("Route guard error:", error);
await useUserStore().resetAllState();
@@ -62,9 +62,9 @@ async function handleAuthenticatedUser(
// 检查路由是否已生成
if (!permissionStore.isRouteGenerated) {
if (!userStore.basicInfo?.roles?.length) {
await userStore.getUserInfo();
}
await userStore.getUserInfo();
}
const dynamicRoutes = await permissionStore.generateRoutes();
// 添加路由到路由器
dynamicRoutes.forEach((route: RouteRecordRaw) => {
@@ -95,7 +95,7 @@ async function handleAuthenticatedUser(
// 强制跳转到登录页
next("/login");
NProgress.done();
}
}
router.afterEach(() => {
NProgress.done();
});