From 9b1a2f51e886125cb21f107dc4d20e6decba47c8 Mon Sep 17 00:00:00 2001 From: bakaEC <1064071566@qq.com> Date: Mon, 16 Dec 2024 10:58:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E9=80=BB=E8=BE=91=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/mmg/types/JsonResponse.java | 41 ++ minio-fornt/src/App.vue | 6 + minio-fornt/src/api/resource.js | 17 + minio-fornt/src/api/resourceCategory.js | 6 + minio-fornt/src/api/upload.js | 99 +++-- .../src/components/Resource/FileUploader.vue | 260 +++++++++++++ .../Resource/UploadCoursewareButton.vue | 285 ++++++++++++++ minio-fornt/src/main.js | 24 +- minio-fornt/src/utils/dateFormat.js | 11 + minio-fornt/src/utils/request.js | 62 ++- minio-fornt/src/views/FileView.vue | 361 ++---------------- 11 files changed, 767 insertions(+), 405 deletions(-) create mode 100644 minio-admin/src/main/java/com/mmg/types/JsonResponse.java create mode 100644 minio-fornt/src/api/resource.js create mode 100644 minio-fornt/src/api/resourceCategory.js create mode 100644 minio-fornt/src/components/Resource/FileUploader.vue create mode 100644 minio-fornt/src/components/Resource/UploadCoursewareButton.vue create mode 100644 minio-fornt/src/utils/dateFormat.js diff --git a/minio-admin/src/main/java/com/mmg/types/JsonResponse.java b/minio-admin/src/main/java/com/mmg/types/JsonResponse.java new file mode 100644 index 0000000..9396436 --- /dev/null +++ b/minio-admin/src/main/java/com/mmg/types/JsonResponse.java @@ -0,0 +1,41 @@ +package com.mmg.types; + +import lombok.Data; + +@Data +public class JsonResponse { + + private Integer code; + private String msg; + private Object data; + + public JsonResponse(Integer code, String msg, Object data) { + this.code = code; + this.msg = msg; + this.data = data; + } + + public static JsonResponse success(String msg) { + return new JsonResponse(0, msg, null); + } + + public static JsonResponse success() { + return new JsonResponse(0, "", null); + } + + public static JsonResponse data(Object data) { + return new JsonResponse(0, "", data); + } + + public static JsonResponse error(String msg, Integer code) { + return new JsonResponse(code, msg, null); + } + + public static JsonResponse error(String msg) { + return new JsonResponse(-1, msg, null); + } + + public static JsonResponse error(String msg, Object data) { + return new JsonResponse(-1, msg, data); + } +} diff --git a/minio-fornt/src/App.vue b/minio-fornt/src/App.vue index 5ea4555..f51b5b3 100644 --- a/minio-fornt/src/App.vue +++ b/minio-fornt/src/App.vue @@ -7,4 +7,10 @@ import {RouterLink, RouterView} from 'vue-router' diff --git a/minio-fornt/src/api/resource.js b/minio-fornt/src/api/resource.js new file mode 100644 index 0000000..20cc862 --- /dev/null +++ b/minio-fornt/src/api/resource.js @@ -0,0 +1,17 @@ +// src/api/resource.js +import axios from '../utils/request'; + +export const resource = { + resourceList: (page, size, title, type, categoryIds) => + axios.get('/resource/list', { + params: { page, size, title, type, categoryIds }, + }), + + destroyResource: (id) => axios.delete(`/resource/${id}`), + + destroyResourceMulti: (ids) => axios.post('/resource/batch-delete', { ids }), + + videoDetail: (id) => axios.get(`/resource/${id}`), + + videoUpdate: (id, data) => axios.put(`/resource/${id}`, data), +}; diff --git a/minio-fornt/src/api/resourceCategory.js b/minio-fornt/src/api/resourceCategory.js new file mode 100644 index 0000000..24c877e --- /dev/null +++ b/minio-fornt/src/api/resourceCategory.js @@ -0,0 +1,6 @@ +// src/api/resourceCategory.js +import axios from '../utils/request'; + +export const resourceCategory = { + resourceCategoryList: () => axios.get('/resource-category/list'), +}; diff --git a/minio-fornt/src/api/upload.js b/minio-fornt/src/api/upload.js index 68ffd6b..93a12ee 100644 --- a/minio-fornt/src/api/upload.js +++ b/minio-fornt/src/api/upload.js @@ -1,49 +1,66 @@ -import request from '@/utils/request' +// src/api/upload.js +import axios from '../utils/request'; -//上传信息 -export function uploadScreenshot(data){ - return request({ - url:'upload/multipart/uploadScreenshot', - method:'post', - data - }) -} - -//上传信息 -export function uploadFileInfo(data){ - return request({ - url:'upload/multipart/uploadFileInfo', - method:'post', - data - }) -} - -// 上传校验 -export function checkUpload(MD5) { - return request({ - url: `upload/multipart/check?md5=${MD5}`, - method: 'get', - }) +/** + * 获取上传中的文件信息 + * @param {string} fileMD5 - 文件的 MD5 值 + * @returns {Promise} + */ +export const getUploadingFile = (fileMD5) => { + return axios.get(`/upload/getUploadingFile/${fileMD5}`); }; - -// 初始化上传 -export function initUpload(data) { - return request({ - url: `upload/multipart/init`, - method: 'post', - data - }) +/** + * 校验文件是否已经上传 + * @param {string} md5 - 文件的 MD5 值 + * @returns {Promise} + */ +export const checkFileUploadedByMd5 = (md5) => { + return axios.get('/upload/multipart/check', { + params: { md5 }, + }); }; - -// 初始化上传 -export function mergeUpload(data) { - return request({ - url: `upload/multipart/merge`, - method: 'post', - data - }) +/** + * 初始化分片上传 + * @param {Object} fileUploadInfo - 文件上传信息 + * @returns {Promise} + */ +export const initMultiPartUpload = (fileUploadInfo) => { + return axios.post('/upload/multipart/init', fileUploadInfo); }; +/** + * 完成分片上传 + * @param {Object} fileUploadInfo - 文件上传信息 + * @returns {Promise} + */ +export const completeMultiPartUpload = (fileUploadInfo) => { + return axios.post('/upload/multipart/merge', fileUploadInfo); +}; +/** + * 上传截图 + * @param {FormData} formData - 包含截图文件的 FormData + * @param {string} bucketName - Bucket 名称 + * @returns {Promise} + */ +export const uploadScreenshot = (formData, bucketName) => { + return axios.post('/upload/multipart/uploadScreenshot', formData, { + params: { bucketName }, + headers: { + 'Content-Type': 'multipart/form-data', + }, + }); +}; + +/** + * 创建 Bucket + * @param {string} bucketName - Bucket 名称 + * @returns {Promise} + */ +export const createBucket = (bucketName) => { + return axios.post('/upload/createBucket', null, { + params: { bucketName }, + }); +}; diff --git a/minio-fornt/src/components/Resource/FileUploader.vue b/minio-fornt/src/components/Resource/FileUploader.vue new file mode 100644 index 0000000..d2d38f4 --- /dev/null +++ b/minio-fornt/src/components/Resource/FileUploader.vue @@ -0,0 +1,260 @@ + + + + + diff --git a/minio-fornt/src/components/Resource/UploadCoursewareButton.vue b/minio-fornt/src/components/Resource/UploadCoursewareButton.vue new file mode 100644 index 0000000..d5d2b61 --- /dev/null +++ b/minio-fornt/src/components/Resource/UploadCoursewareButton.vue @@ -0,0 +1,285 @@ + + + + diff --git a/minio-fornt/src/main.js b/minio-fornt/src/main.js index d930802..7383a42 100644 --- a/minio-fornt/src/main.js +++ b/minio-fornt/src/main.js @@ -1,13 +1,19 @@ -import {createApp} from 'vue' -import App from './App.vue' -import router from './router' -import ElementPlus from 'element-plus' -import 'element-plus/dist/index.css' +// src/main.js +import { createApp } from 'vue'; +import App from './App.vue'; +import router from './router'; -const app = createApp(App) +// 引入 Element Plus 及其样式 +import ElementPlus from 'element-plus'; +import 'element-plus/dist/index.css'; +const app = createApp(App); -app.use(router) -app.use(ElementPlus) +// 使用 Element Plus +app.use(ElementPlus); -app.mount('#app') +// 使用路由 +app.use(router); + +// 挂载应用 +app.mount('#app'); diff --git a/minio-fornt/src/utils/dateFormat.js b/minio-fornt/src/utils/dateFormat.js new file mode 100644 index 0000000..8712f72 --- /dev/null +++ b/minio-fornt/src/utils/dateFormat.js @@ -0,0 +1,11 @@ +// src/utils/dateFormat.js +export const dateFormat = (dateStr) => { + const date = new Date(dateStr); + const year = date.getFullYear(); + const month = (`0${date.getMonth() + 1}`).slice(-2); + const day = (`0${date.getDate()}`).slice(-2); + const hours = (`0${date.getHours()}`).slice(-2); + const minutes = (`0${date.getMinutes()}`).slice(-2); + const seconds = (`0${date.getSeconds()}`).slice(-2); + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; +}; diff --git a/minio-fornt/src/utils/request.js b/minio-fornt/src/utils/request.js index 18929ea..aea1069 100644 --- a/minio-fornt/src/utils/request.js +++ b/minio-fornt/src/utils/request.js @@ -1,42 +1,34 @@ -import axios from 'axios' +// src/utils/request.js +import axios from 'axios'; +import { ElMessage } from 'element-plus'; -const request = axios.create({ - baseURL: `http://localhost:9090`, - timeout: 30000 -}) - -// request 拦截器 -// 可以自请求发送前对请求做一些处理 -// 比如统一加token,对请求参数统一加密 -request.interceptors.request.use(config => { - config.headers['Content-Type'] = 'application/json;charset=utf-8'; - return config -}, error => { - return Promise.reject(error) +// 创建 axios 实例 +const instance = axios.create({ + baseURL: 'http://localhost:9090', // 替换为您的后端地址 + timeout: 10000, }); -// response 拦截器 -// 可以在接口响应后统一处理结果 -request.interceptors.response.use( - response => { - let res = response.data; - // 如果是返回的文件 - if (response.headers === 'blob') { - return res - } - // 兼容服务端返回的字符串数据 - if (typeof res === 'string') { - res = res ? JSON.parse(res) : res - console.log(res) - } - return res; +// 请求拦截器 +instance.interceptors.request.use( + (config) => { + // 可以在这里添加请求头,例如 token + // config.headers['Authorization'] = 'Bearer token'; + return config; }, - error => { - console.log('err' + error) // for debug - return Promise.reject(error) + (error) => { + return Promise.reject(error); } -) +); +// 响应拦截器 +instance.interceptors.response.use( + (response) => { + return response; + }, + (error) => { + ElMessage.error(error.response?.data?.message || '请求失败'); + return Promise.reject(error); + } +); -export default request - +export default instance; diff --git a/minio-fornt/src/views/FileView.vue b/minio-fornt/src/views/FileView.vue index ed5931d..1da1c7c 100644 --- a/minio-fornt/src/views/FileView.vue +++ b/minio-fornt/src/views/FileView.vue @@ -1,338 +1,59 @@ + -