feat:新增共享文件功能

This commit is contained in:
czhqwer
2025-03-29 16:56:19 +08:00
parent f7e7db9f84
commit 8bece56908
18 changed files with 411 additions and 18 deletions

View File

@@ -180,6 +180,55 @@ const testStorageConfig = ({ type, endpoint, accessKey, secretKey, bucket }) =>
});
}
/**
* 获取共享文件列表
* @param {Object} params 参数对象
* @param {string} params.password 密码
* @returns
*/
const getSharedFiles = () => {
return http.get('/file/sharedFiles');
};
/**
* 启用或禁用共享
* @param {Object} params 参数对象
* @param {boolean} params.enable 是否启用
* @returns
*/
const enableShare = ({ enable }) => {
const formData = new FormData();
formData.append('enable', enable);
return http.post("/file/enableShare", formData);
};
/**
* 获取分享状态
* @returns
*/
const getShareStatus = () => {
return http.get("/file/getShareStatus");
}
/**
* 获取分享地址
* @returns
*/
const shareAddress = () => {
return http.get("/file/shareAddress");
}
/**
* 移除共享文件
* @param {string} fileIdentifier
* @returns
*/
const unShareFile = (fileIdentifier) => {
const formData = new FormData();
formData.append('fileIdentifier', fileIdentifier);
return http.post("/file/unShareFile", formData);
}
export {
getUploadProgress,
createMultipartUpload,
@@ -191,5 +240,10 @@ export {
getStorageConfig,
setStorageConfig,
testStorageConfig,
getSharedFiles,
enableShare,
getShareStatus,
shareAddress,
unShareFile,
httpExtra
};

View File

@@ -8,6 +8,16 @@ const http = axios.create({
baseURL: baseUrl
});
// 请求拦截器 - 自动添加 Authorization
http.interceptors.request.use(config => {
// 从 localStorage 获取 password
const password = localStorage.getItem('password');
config.headers['Authorization'] = password ? password : '';
return config;
}, error => {
return Promise.reject(error);
});
// 配置拦截器,返回 response.data
http.interceptors.response.use(response => {
return response.data;
@@ -22,4 +32,14 @@ const httpExtra = axiosExtra.create({
}
});
httpExtra.interceptors.request.use(config => {
const password = localStorage.getItem('password');
if (password) {
config.headers['Authorization'] = password;
}
return config;
}, error => {
return Promise.reject(error);
});
export { http, baseUrl, httpExtra };

View File

@@ -22,7 +22,7 @@
<div class="tab-underline"></div>
</div>
</div>
<div v-if="activeTab !== 'gallery' && !isWipTab" class="upload-content">
<div v-if="activeTab !== 'gallery' && activeTab !== 'shared' && !isWipTab" class="upload-content">
<upload-file :file-list.sync="fileList" :accept="allowedFormats" :max-size="maxUploadSize" width="100%"
height="400px" :storage-type="activeTab" />
</div>
@@ -34,6 +34,7 @@
<p v-else-if="activeTab === 'qiniu'">七牛云功能正在被疯狂调教马上就能和大家见面啦</p>
</div>
</div>
<share-file v-else-if="activeTab === 'shared'" />
<file-gallery v-else />
<settings-modal :show="showSettings" :allowed-formats="allowedFormats" :max-upload-size="maxUploadSize"
@save="saveSettings" @close="closeSettings" />
@@ -49,10 +50,11 @@ import FileGallery from '@/components/FileGallery/FileGallery.vue';
import SettingsModal from '@/components/SettingsModal/SettingsModal.vue';
import StorageConfigModal from '@/components/StorageConfigModal/StorageConfigModal.vue';
import AboutModal from '@/components/AboutModal/AboutModal.vue';
import ShareFile from '@/components/ShareFile/ShareFile.vue';
export default {
name: 'MainPage',
components: { UploadFile, FileGallery, SettingsModal, StorageConfigModal, AboutModal },
components: { UploadFile, FileGallery, SettingsModal, StorageConfigModal, AboutModal, ShareFile },
data() {
return {
fileList: [],
@@ -63,7 +65,8 @@ export default {
{ label: 'OSS', value: 'oss' },
{ label: 'OBS', value: 'obs' },
{ label: 'QiNiu', value: 'qiniu' },
{ label: '已上传文件', value: 'gallery' }
{ label: '已上传文件', value: 'gallery' },
{ label: '共享文件', value: 'shared' },
],
showMenu: false,
showSettings: false,