瀏覽代碼

feat: 优化文件管理地址获取

许俊杰 2 年之前
父節點
當前提交
9919ef7f79
共有 2 個文件被更改,包括 14 次插入4 次删除
  1. 13 3
      Web/src/views/system/file/index.vue
  2. 1 1
      Web/vite.config.ts

+ 13 - 3
Web/src/views/system/file/index.vue

@@ -37,10 +37,10 @@
 					<template #default="scope">
 						<el-image
 							style="width: 60px; height: 60px"
-							:src="`/${scope.row.filePath}/${scope.row.id}${scope.row.suffix}`"
+							:src="getFileUrl(scope.row)"
 							:lazy="true"
 							:hide-on-click-modal="true"
-							:preview-src-list="[`/${scope.row.filePath}/${scope.row.id}${scope.row.suffix}`]"
+							:preview-src-list="[getFileUrl(scope.row)]"
 							:initial-index="0"
 							fit="scale-down"
 							preview-teleported
@@ -175,7 +175,8 @@ const uploadFile = async () => {
 // 下载
 const downloadFile = async (row: any) => {
 	// var res = await getAPI(SysFileApi).sysFileDownloadPost({ id: row.id });
-	downloadByUrl({ url: row.url });
+	var fileUrl = getFileUrl(row);
+	downloadByUrl({ url: fileUrl });
 };
 
 // 删除
@@ -204,4 +205,13 @@ const handleCurrentChange = (val: number) => {
 	state.tableParams.page = val;
 	handleQuery();
 };
+
+// 获取文件地址
+const getFileUrl = (row: SysFile): string => {
+	if (row.bucketName == 'Local') {
+		return `/${row.filePath}/${row.id}${row.suffix}`;
+	} else {
+		return row.url!;
+	}
+};
 </script>

+ 1 - 1
Web/vite.config.ts

@@ -35,7 +35,7 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
 					changeOrigin: true,
 					rewrite: (path) => path.replace(/^\/gitee/, ''),
 				},
-				'/Upload': {
+				'^/[Uu]pload': {
 					target: env.VITE_API_URL,
 					changeOrigin: true,
 				}