提交文件上传代码
This commit is contained in:
parent
0c6d5f97a5
commit
0498f8a018
|
@ -46,6 +46,7 @@
|
||||||
"pinia": "2.1.7",
|
"pinia": "2.1.7",
|
||||||
"preact": "10.19.7",
|
"preact": "10.19.7",
|
||||||
"screenfull": "6.0.2",
|
"screenfull": "6.0.2",
|
||||||
|
"spark-md5": "^3.0.2",
|
||||||
"vform3-builds": "3.0.10",
|
"vform3-builds": "3.0.10",
|
||||||
"vue": "3.4.25",
|
"vue": "3.4.25",
|
||||||
"vue-cropper": "1.1.1",
|
"vue-cropper": "1.1.1",
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
import request from '@/utils/request';
|
||||||
|
import { AxiosPromise } from 'axios';
|
||||||
|
import { CatalogPersonVO, CatalogPersonForm, CatalogPersonQuery } from '@/api/resource/catalogPerson/types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询目录-我的空间列表
|
||||||
|
* @param query
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const listCatalogPerson = (query?: CatalogPersonQuery): AxiosPromise<CatalogPersonVO[]> => {
|
||||||
|
return request({
|
||||||
|
url: '/catalog/person/list',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询目录-我的空间详细
|
||||||
|
* @param catalogId
|
||||||
|
*/
|
||||||
|
export const getCatalogPerson = (catalogId: string | number): AxiosPromise<CatalogPersonVO> => {
|
||||||
|
return request({
|
||||||
|
url: '/catalog/person/' + catalogId,
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增目录-我的空间
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export const addCatalogPerson = (data: CatalogPersonForm) => {
|
||||||
|
return request({
|
||||||
|
url: '/catalog/person',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改目录-我的空间
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export const updateCatalogPerson = (data: CatalogPersonForm) => {
|
||||||
|
return request({
|
||||||
|
url: '/catalog/person',
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除目录-我的空间
|
||||||
|
* @param catalogId
|
||||||
|
*/
|
||||||
|
export const delCatalogPerson = (catalogId: string | number | Array<string | number>) => {
|
||||||
|
return request({
|
||||||
|
url: '/catalog/person/' + catalogId,
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
export interface CatalogPersonVO {
|
||||||
|
/**
|
||||||
|
* 目录id
|
||||||
|
*/
|
||||||
|
catalogId: string | number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户编号
|
||||||
|
*/
|
||||||
|
userId: string | number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父目录id
|
||||||
|
*/
|
||||||
|
parentId: string | number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 祖级列表
|
||||||
|
*/
|
||||||
|
ancestors: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目录名称
|
||||||
|
*/
|
||||||
|
catalogName: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示顺序
|
||||||
|
*/
|
||||||
|
orderNum: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子对象
|
||||||
|
*/
|
||||||
|
children: CatalogPersonVO[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CatalogPersonForm extends BaseEntity {
|
||||||
|
/**
|
||||||
|
* 目录id
|
||||||
|
*/
|
||||||
|
catalogId?: string | number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户编号
|
||||||
|
*/
|
||||||
|
userId?: string | number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父目录id
|
||||||
|
*/
|
||||||
|
parentId?: string | number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 祖级列表
|
||||||
|
*/
|
||||||
|
ancestors?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目录名称
|
||||||
|
*/
|
||||||
|
catalogName?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示顺序
|
||||||
|
*/
|
||||||
|
orderNum?: number;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CatalogPersonQuery {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户编号
|
||||||
|
*/
|
||||||
|
userId?: string | number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父目录id
|
||||||
|
*/
|
||||||
|
parentId?: string | number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 祖级列表
|
||||||
|
*/
|
||||||
|
ancestors?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目录名称
|
||||||
|
*/
|
||||||
|
catalogName?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示顺序
|
||||||
|
*/
|
||||||
|
orderNum?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期范围参数
|
||||||
|
*/
|
||||||
|
params?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,14 @@ export function listByIds(ossId: string | number): AxiosPromise<OssVO[]> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getByMd5(md5: string): any {
|
||||||
|
return request({
|
||||||
|
url: '/resource/oss/identifier',
|
||||||
|
method: 'get',
|
||||||
|
params: { md5 }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 删除OSS对象存储
|
// 删除OSS对象存储
|
||||||
export function delOss(ossId: string | number | Array<string | number>) {
|
export function delOss(ossId: string | number | Array<string | number>) {
|
||||||
return request({
|
return request({
|
||||||
|
@ -57,3 +65,11 @@ export function delOss(ossId: string | number | Array<string | number>) {
|
||||||
method: 'delete'
|
method: 'delete'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const addTextbook = (data: any) => {
|
||||||
|
return request({
|
||||||
|
url: '/file/textbook',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,284 @@
|
||||||
|
<template>
|
||||||
|
<div class="upload-file">
|
||||||
|
<el-upload ref="fileUploadRef" drag multiple :action="uploadFileUrl" :before-upload="handleBeforeUpload"
|
||||||
|
:file-list="fileList" :limit="limit" :on-error="handleUploadError" :on-exceed="handleExceed"
|
||||||
|
:on-success="handleUploadSuccess" :show-file-list="false" :headers="headers" class="upload-file-uploader">
|
||||||
|
<el-icon class="el-icon--upload"><upload-filled color="#FF4D4F" /></el-icon>
|
||||||
|
<div class="el-upload__text">
|
||||||
|
请将文件拖拽到此处上传 <em>点击上传</em>
|
||||||
|
</div>
|
||||||
|
</el-upload>
|
||||||
|
<!-- 上传提示 -->
|
||||||
|
<div v-if="showTip" class="el-upload__tip">
|
||||||
|
支持上传
|
||||||
|
<template v-if="fileType">
|
||||||
|
<b style="color: #f56c6c">{{ fileType.join('、') }}</b>
|
||||||
|
</template>
|
||||||
|
格式文件
|
||||||
|
</div>
|
||||||
|
<!-- 文件列表 -->
|
||||||
|
<transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
|
||||||
|
<li v-for="(file, index) in fileList" :key="file.uid" class="el-upload-list__item ele-upload-list__item-content">
|
||||||
|
<el-link :href="`${file.url}`" :underline="false" target="_blank">
|
||||||
|
<span class="el-icon-document"> {{ getFileName(file.name) }} </span>
|
||||||
|
</el-link>
|
||||||
|
<div class="ele-upload-list__item-content-action">
|
||||||
|
<el-button type="danger" link @click="handleDelete(index)">删除</el-button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</transition-group>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { propTypes } from '@/utils/propTypes';
|
||||||
|
import { delOss, listByIds, getByMd5 } from '@/api/system/oss';
|
||||||
|
import { globalHeaders } from '@/utils/request';
|
||||||
|
import SparkMD5 from 'spark-md5'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: {
|
||||||
|
type: [String, Object, Array],
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
// 数量限制
|
||||||
|
limit: propTypes.number.def(1),
|
||||||
|
// 大小限制(MB)
|
||||||
|
fileSize: propTypes.number.def(1024),
|
||||||
|
// 文件类型, 例如['png', 'jpg', 'jpeg']
|
||||||
|
fileType: propTypes.array.def(['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'txt']),
|
||||||
|
// 是否显示提示
|
||||||
|
isShowTip: propTypes.bool.def(true)
|
||||||
|
});
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||||
|
const emit = defineEmits(['update:modelValue', 'onFileName']);
|
||||||
|
const number = ref(0);
|
||||||
|
const uploadList = ref<any[]>([]);
|
||||||
|
|
||||||
|
const baseUrl = import.meta.env.VITE_APP_BASE_API;
|
||||||
|
const uploadFileUrl = ref(baseUrl + '/resource/oss/upload'); // 上传文件服务器地址
|
||||||
|
const headers = ref(globalHeaders());
|
||||||
|
|
||||||
|
const fileList = ref<any[]>([]);
|
||||||
|
const currentFile = ref({ name: '', url: '', ossId: '' });
|
||||||
|
const showTip = computed(() => props.isShowTip && (props.fileType || props.fileSize));
|
||||||
|
|
||||||
|
const fileUploadRef = ref<ElUploadInstance>();
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
async (val: any) => {
|
||||||
|
if (val) {
|
||||||
|
// 首先将值转为数组
|
||||||
|
let list: any[] = [];
|
||||||
|
if (Array.isArray(val)) {
|
||||||
|
list = val;
|
||||||
|
} else {
|
||||||
|
const res = await listByIds(val);
|
||||||
|
list = res.data.map((oss) => {
|
||||||
|
return {
|
||||||
|
name: currentFile.value.name,
|
||||||
|
url: oss.url,
|
||||||
|
ossId: oss.ossId
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 然后将数组转为对象数组
|
||||||
|
fileList.value = list.map((item) => {
|
||||||
|
item = { name: currentFile.value.name, url: item.url, ossId: item.ossId };
|
||||||
|
item.uid = item.uid || new Date().getTime();
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fileList.value = [];
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ deep: true, immediate: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const fileMd5: any = ref('')
|
||||||
|
// 上传前校检格式和大小
|
||||||
|
const handleBeforeUpload = async (file: any) => {
|
||||||
|
// 校检文件类型
|
||||||
|
if (props.fileType.length) {
|
||||||
|
const fileName = file.name.split('.');
|
||||||
|
const fileExt = fileName[fileName.length - 1];
|
||||||
|
const isTypeOk = props.fileType.indexOf(fileExt) >= 0;
|
||||||
|
if (!isTypeOk) {
|
||||||
|
proxy?.$modal.msgError(`文件格式不正确, 请上传${props.fileType.join('/')}格式文件!`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 校检文件大小
|
||||||
|
if (props.fileSize) {
|
||||||
|
const isLt = file.size / 1024 / 1024 < props.fileSize;
|
||||||
|
if (!isLt) {
|
||||||
|
proxy?.$modal.msgError(`上传文件大小不能超过 ${props.fileSize} MB!`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 计算文件md5值
|
||||||
|
currentFile.value.name = file.name
|
||||||
|
|
||||||
|
const md5 = await computeFileMd5(file);
|
||||||
|
fileMd5.value = md5
|
||||||
|
|
||||||
|
const res = await getByMd5(md5 as string);
|
||||||
|
if (res.code === 200 && res.data) {
|
||||||
|
fileList.value.push({
|
||||||
|
name: currentFile.value.name,
|
||||||
|
url: res.data.url,
|
||||||
|
ossId: res.data.ossId
|
||||||
|
})
|
||||||
|
|
||||||
|
emit('onFileName', currentFile.value.name)
|
||||||
|
emit('update:modelValue', listToString(fileList.value));
|
||||||
|
proxy?.$modal.msgSuccess(`文件极速上传成功!`);
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy?.$modal.loading('正在上传文件,请稍候...');
|
||||||
|
number.value++;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 计算文件md5值
|
||||||
|
const computeFileMd5 = (file: any) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice
|
||||||
|
let chunkSize = 10 * 1024 * 1024
|
||||||
|
let chunks = Math.ceil(file.size / chunkSize)
|
||||||
|
let currentChunk = 0
|
||||||
|
let spark = new SparkMD5.ArrayBuffer()
|
||||||
|
let fileReader = new FileReader()
|
||||||
|
|
||||||
|
fileReader.onload = (e: any) => {
|
||||||
|
spark.append(e.target.result)
|
||||||
|
currentChunk++
|
||||||
|
if (currentChunk < chunks) {
|
||||||
|
loadNext()
|
||||||
|
} else {
|
||||||
|
const md5 = spark.end()
|
||||||
|
resolve(md5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileReader.onerror = (e: any) => {
|
||||||
|
reject(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadNext() {
|
||||||
|
const start = currentChunk * chunkSize
|
||||||
|
const end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize
|
||||||
|
fileReader.readAsArrayBuffer(blobSlice.call(file, start, end))
|
||||||
|
}
|
||||||
|
|
||||||
|
loadNext()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件个数超出
|
||||||
|
const handleExceed = () => {
|
||||||
|
proxy?.$modal.msgError(`上传文件数量不能超过 ${props.limit} 个!`);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 上传失败
|
||||||
|
const handleUploadError = () => {
|
||||||
|
proxy?.$modal.msgError('上传文件失败');
|
||||||
|
};
|
||||||
|
|
||||||
|
// 上传成功回调
|
||||||
|
const handleUploadSuccess = (res: any, file: UploadFile) => {
|
||||||
|
if (res.code === 200) {
|
||||||
|
uploadList.value.push({
|
||||||
|
name: res.data.fileName,
|
||||||
|
url: res.data.url,
|
||||||
|
ossId: res.data.ossId
|
||||||
|
});
|
||||||
|
uploadedSuccessfully();
|
||||||
|
} else {
|
||||||
|
number.value--;
|
||||||
|
proxy?.$modal.closeLoading();
|
||||||
|
proxy?.$modal.msgError(res.msg);
|
||||||
|
fileUploadRef.value?.handleRemove(file);
|
||||||
|
uploadedSuccessfully();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除文件
|
||||||
|
const handleDelete = (index: number) => {
|
||||||
|
let ossId = fileList.value[index].ossId;
|
||||||
|
delOss(ossId);
|
||||||
|
fileList.value.splice(index, 1);
|
||||||
|
emit('onFileName', currentFile.value.name)
|
||||||
|
emit('update:modelValue', listToString(fileList.value));
|
||||||
|
};
|
||||||
|
|
||||||
|
// 上传结束处理
|
||||||
|
const uploadedSuccessfully = () => {
|
||||||
|
if (number.value > 0 && uploadList.value.length === number.value) {
|
||||||
|
fileList.value = fileList.value.filter((f) => f.url !== undefined).concat(uploadList.value);
|
||||||
|
uploadList.value = [];
|
||||||
|
number.value = 0;
|
||||||
|
emit('onFileName', currentFile.value.name)
|
||||||
|
emit('update:modelValue', listToString(fileList.value));
|
||||||
|
proxy?.$modal.closeLoading();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取文件名称
|
||||||
|
const getFileName = (name: string) => {
|
||||||
|
// 如果是url那么取最后的名字 如果不是直接返回
|
||||||
|
if (name && name.lastIndexOf('/') > -1) {
|
||||||
|
return name.slice(name.lastIndexOf('/') + 1);
|
||||||
|
} else {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 对象转成指定字符串分隔
|
||||||
|
const listToString = (list: any[], separator?: string) => {
|
||||||
|
let strs = '';
|
||||||
|
separator = separator || ',';
|
||||||
|
list.forEach((item) => {
|
||||||
|
if (item.ossId) {
|
||||||
|
strs += item.ossId + separator;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return strs != '' ? strs.substring(0, strs.length - 1) : '';
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.upload-file {
|
||||||
|
width: 680px;
|
||||||
|
|
||||||
|
.el-upload__tip {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-file-uploader {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-file-list .el-upload-list__item {
|
||||||
|
border: 1px solid #e4e7ed;
|
||||||
|
line-height: 2;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-file-list .ele-upload-list__item-content {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ele-upload-list__item-content-action .el-link {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -119,6 +119,7 @@ const handleBeforeUpload = (file: any) => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy?.$modal.loading('正在上传文件,请稍候...');
|
proxy?.$modal.loading('正在上传文件,请稍候...');
|
||||||
number.value++;
|
number.value++;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -0,0 +1,545 @@
|
||||||
|
<template>
|
||||||
|
<div class="p-2">
|
||||||
|
<transition :enter-active-class="proxy?.animate.searchAnimate.enter"
|
||||||
|
:leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||||
|
<div v-show="showSearch" class="mb-[10px]">
|
||||||
|
<el-card shadow="hover">
|
||||||
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||||
|
<el-form-item label="课件名称" prop="fileName">
|
||||||
|
<el-input v-model="queryParams.fileName" placeholder="请输入课件名称" clearable @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="格式" prop="fileSuffix">
|
||||||
|
<el-select v-model="queryParams.fileSuffix" placeholder="请选择" style="width: 240px"
|
||||||
|
@keyup.enter="handleQuery">
|
||||||
|
<el-option v-for="item in formatOptions" :key="item.value" :label="item.label" :value="item.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="search" @click="handleQuery">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</el-card>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
|
||||||
|
<el-card shadow="hover">
|
||||||
|
<template #header>
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button v-hasPermi="['system:oss:upload']" type="primary" plain icon="Upload"
|
||||||
|
@click="handleFile">上传课件</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button v-hasPermi="['system:oss:remove']" type="danger" plain icon="Delete" :disabled="multiple"
|
||||||
|
@click="handleDelete()">
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
</el-col>
|
||||||
|
<right-toolbar v-model:showSearch="showSearch" @query-table="getList"></right-toolbar>
|
||||||
|
</el-row>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<el-table v-if="showTable" v-loading="loading" :data="ossList" :header-cell-class-name="handleHeaderClass"
|
||||||
|
@selection-change="handleSelectionChange" @header-click="handleHeaderCLick">
|
||||||
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
|
<el-table-column label="课件名" align="center" prop="originalName" width="240" />
|
||||||
|
<el-table-column label="课件格式" align="center" prop="fileSuffix" />
|
||||||
|
<el-table-column label="课件大小" align="center" prop="fileSuffix" />
|
||||||
|
<el-table-column label="创建人" align="center" prop="createByName" />
|
||||||
|
<el-table-column label="创建时间" align="center" prop="createTime" sortable="custom">
|
||||||
|
<template #default="scope">
|
||||||
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="350">
|
||||||
|
<template #default="scope">
|
||||||
|
|
||||||
|
<el-tooltip v-if="isAudit" content="审核通过" placement="top">
|
||||||
|
<el-button link type="primary" icon="CopyDocument" @click="handleDownload(scope.row)">审核通过</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip v-if="isAudit" content="审核不通过" placement="top">
|
||||||
|
<el-button link type="primary" icon="DocumentCopy" @click="handleDownload(scope.row)">审核不通过</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
|
||||||
|
<el-tooltip content="预览" placement="top">
|
||||||
|
<el-button link type="primary" icon="View" @click="handlePreview(scope.row)">预览</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip v-hasPermi="['system:oss:download']" content="下载" placement="top">
|
||||||
|
<el-button link type="primary" icon="Download" @click="handleDownload(scope.row)">下载</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
|
||||||
|
<el-tooltip content="移动" placement="top">
|
||||||
|
<el-button link type="primary" icon="CopyDocument" @click="handleMove(scope.row)">移动</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="复制" placement="top">
|
||||||
|
<el-button link type="primary" icon="DocumentCopy" @click="handleCopy(scope.row)">复制</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="删除" placement="top">
|
||||||
|
<el-button v-hasPermi="['system:oss:remove']" link type="primary" icon="Delete"
|
||||||
|
@click="handleDelete(scope.row)">删除</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
|
||||||
|
:total="total" @pagination="getList" />
|
||||||
|
</el-card>
|
||||||
|
|
||||||
|
<!-- 添加或修改OSS对象存储对话框 -->
|
||||||
|
<el-dialog v-model="dialog.visible" :title="dialog.title" width="700px" append-to-body>
|
||||||
|
<el-form ref="ossFormRef" :model="form" :rules="rules">
|
||||||
|
<el-form-item label="">
|
||||||
|
<!-- <fileUpload v-if="type === 0" v-model="form.file" /> -->
|
||||||
|
<FileMd5Upload v-if="type === 0" v-model="form.file" />
|
||||||
|
<imageUpload v-if="type === 1" v-model="form.file" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||||
|
<el-button @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
|
<el-dialog v-model="previewDialog.visible" :title="previewDialog.title" width="900px" append-to-body>
|
||||||
|
<vue-office-docx v-loading="fileLoading" element-loading-text="加载中..."
|
||||||
|
v-if="currentFile.fileSuffix == '.doc' || currentFile.fileSuffix == '.docx'" :src="file" />
|
||||||
|
|
||||||
|
<vue-office-excel v-loading="fileLoading" element-loading-text="加载中..." :options="options"
|
||||||
|
style="height: 100vh;width: 100vh;" v-if="currentFile.fileSuffix == '.xls' || currentFile.fileSuffix == '.xlsx'"
|
||||||
|
:src="file" />
|
||||||
|
|
||||||
|
<vue-office-pdf v-loading="fileLoading" element-loading-text="加载中..." v-if="currentFile.fileSuffix == '.pdf'"
|
||||||
|
:src="file" />
|
||||||
|
|
||||||
|
<div v-loading="fileLoading" element-loading-text="加载中..." v-if="currentFile.fileSuffix == '.txt'"
|
||||||
|
style="white-space: pre-wrap;">{{ txt }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ImagePreview v-loading="fileLoading" element-loading-text="加载中..." style="width: 100%; text-align: center;"
|
||||||
|
v-if="imgSuffix.includes(currentFile.fileSuffix)" :src="imgUrl" />
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
|
<el-dialog v-model="treeMoveDialog.visible" :title="treeMoveDialog.title" width="500px" append-to-body>
|
||||||
|
<el-form ref="treeMoveFormRef" :model="treeMoveForm" :rules="treeMoveRules">
|
||||||
|
<el-form-item label="移动至" prop="catalogId">
|
||||||
|
<el-tree-select v-model="treeMoveForm.catalogId" :data="treeData"
|
||||||
|
:props="{ value: 'catalogId', label: 'catalogName', children: 'children' }" value-key="catalogId"
|
||||||
|
placeholder="请选择" check-strictly />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitMoveForm">确 定</el-button>
|
||||||
|
<el-button @click="cancelMove">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
|
<el-dialog v-model="treeCopyDialog.visible" :title="treeCopyDialog.title" width="500px" append-to-body>
|
||||||
|
<el-form ref="treeCopyFormRef" :model="treeCopyForm" :rules="treeCopyRules">
|
||||||
|
<el-form-item label="复制至" prop="catalogId">
|
||||||
|
<el-tree-select v-model="treeCopyForm.catalogId" :data="treeData"
|
||||||
|
:props="{ value: 'catalogId', label: 'catalogName', children: 'children' }" value-key="catalogId"
|
||||||
|
placeholder="请选择" check-strictly />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitCopyForm">确 定</el-button>
|
||||||
|
<el-button @click="cancelCopy">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="Oss" lang="ts">
|
||||||
|
import { listOss, preview, previewTxt, delOss } from '@/api/system/oss';
|
||||||
|
import ImagePreview from '@/components/ImagePreview/index.vue';
|
||||||
|
import FileMd5Upload from '@/components/FileMd5Upload/index.vue';
|
||||||
|
import { OssForm, OssQuery, OssVO } from '@/api/system/oss/types';
|
||||||
|
import { listCatalogTextbook } from "@/api/resource/catalogTextbook";
|
||||||
|
import { CatalogTextbookVO } from '@/api/resource/catalogTextbook/types';
|
||||||
|
|
||||||
|
//引入VueOfficeDocx组件
|
||||||
|
import VueOfficeDocx from '@vue-office/docx'
|
||||||
|
//引入相关样式
|
||||||
|
import '@vue-office/docx/lib/index.css'
|
||||||
|
//引入VueOfficeExcel组件
|
||||||
|
import VueOfficeExcel from '@vue-office/excel'
|
||||||
|
//引入相关样式
|
||||||
|
import '@vue-office/excel/lib/index.css'
|
||||||
|
//引入VueOfficePdf组件
|
||||||
|
import VueOfficePdf from '@vue-office/pdf'
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||||
|
|
||||||
|
const fileSuffix = ['.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.pdf']
|
||||||
|
const imgSuffix = ['.jpg', '.png', '.jpeg', '.gif', '.bmp']
|
||||||
|
|
||||||
|
const formatOptions = [
|
||||||
|
{
|
||||||
|
value: '.doc',
|
||||||
|
label: 'doc',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.docx',
|
||||||
|
label: 'docx',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.xls',
|
||||||
|
label: 'xls',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.xlsx',
|
||||||
|
label: 'xlsx',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.ppt',
|
||||||
|
label: 'ppt',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.pptx',
|
||||||
|
label: 'pptx',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.pdf',
|
||||||
|
label: 'pdf',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.txt',
|
||||||
|
label: 'txt',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const catalogRadio = ref('course')
|
||||||
|
const defaultProps = {
|
||||||
|
children: 'children',
|
||||||
|
label: 'catalogName',
|
||||||
|
}
|
||||||
|
|
||||||
|
const treeData = ref<CatalogTextbookVO[]>([])
|
||||||
|
|
||||||
|
const ossList = ref<OssVO[]>([]);
|
||||||
|
const showTable = ref(true);
|
||||||
|
const buttonLoading = ref(false);
|
||||||
|
const loading = ref(true);
|
||||||
|
const showSearch = ref(true);
|
||||||
|
const ids = ref<Array<string | number>>([]);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
const type = ref(0);
|
||||||
|
const previewListResource = ref(true);
|
||||||
|
const dateRangeCreateTime = ref<[DateModelType, DateModelType]>(['', '']);
|
||||||
|
|
||||||
|
const dialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const previewDialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: '文件预览'
|
||||||
|
});
|
||||||
|
|
||||||
|
const treeMoveDialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: '移动'
|
||||||
|
});
|
||||||
|
const treeMoveFormRef = ref()
|
||||||
|
const treeMoveForm = ref<any>({ catalogId: '' });
|
||||||
|
const treeMoveRules = ref({
|
||||||
|
catalogId: [{ required: true, message: '请选择', trigger: 'blur' }]
|
||||||
|
})
|
||||||
|
|
||||||
|
const treeCopyDialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: '复制'
|
||||||
|
});
|
||||||
|
const treeCopyFormRef = ref()
|
||||||
|
const treeCopyForm = ref<any>({ catalogId: '' });
|
||||||
|
const treeCopyRules = ref({
|
||||||
|
catalogId: [{ required: true, message: '请选择', trigger: 'blur' }]
|
||||||
|
})
|
||||||
|
|
||||||
|
// 默认排序
|
||||||
|
const defaultSort = ref({ prop: 'createTime', order: 'ascending' });
|
||||||
|
|
||||||
|
const ossFormRef = ref<ElFormInstance>();
|
||||||
|
const queryFormRef = ref<ElFormInstance>();
|
||||||
|
|
||||||
|
const initFormData = {
|
||||||
|
file: undefined
|
||||||
|
};
|
||||||
|
const data = reactive<PageData<OssForm, OssQuery>>({
|
||||||
|
form: { ...initFormData },
|
||||||
|
// 查询参数
|
||||||
|
queryParams: {
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
ossId: '',
|
||||||
|
fileName: '',
|
||||||
|
originalName: '',
|
||||||
|
fileSuffix: '',
|
||||||
|
createTime: '',
|
||||||
|
service: '',
|
||||||
|
orderByColumn: defaultSort.value.prop,
|
||||||
|
isAsc: defaultSort.value.order
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
file: [{ required: true, message: '文件不能为空', trigger: 'blur' }]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const { queryParams, form, rules } = toRefs(data);
|
||||||
|
|
||||||
|
/** 查询OSS对象存储列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
const res = await proxy?.getConfigKey('sys.oss.previewListResource');
|
||||||
|
previewListResource.value = res?.data === undefined ? true : res.data === 'true';
|
||||||
|
const response = await listOss(proxy?.addDateRange(queryParams.value, dateRangeCreateTime.value, 'CreateTime'));
|
||||||
|
ossList.value = response.rows;
|
||||||
|
total.value = response.total;
|
||||||
|
loading.value = false;
|
||||||
|
showTable.value = true;
|
||||||
|
};
|
||||||
|
function checkFileSuffix(fileSuffix: string | string[]) {
|
||||||
|
const arr = [".png", ".jpg", ".jpeg"];
|
||||||
|
const suffixArray = Array.isArray(fileSuffix) ? fileSuffix : [fileSuffix];
|
||||||
|
return suffixArray.some(suffix => arr.includes(suffix.toLowerCase()));
|
||||||
|
}
|
||||||
|
/** 取消按钮 */
|
||||||
|
function cancel() {
|
||||||
|
dialog.visible = false;
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
/** 表单重置 */
|
||||||
|
function reset() {
|
||||||
|
form.value = { ...initFormData };
|
||||||
|
ossFormRef.value?.resetFields();
|
||||||
|
}
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
function handleQuery() {
|
||||||
|
queryParams.value.pageNum = 1;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
function resetQuery() {
|
||||||
|
showTable.value = false;
|
||||||
|
dateRangeCreateTime.value = ['', ''];
|
||||||
|
queryFormRef.value?.resetFields();
|
||||||
|
queryParams.value.orderByColumn = defaultSort.value.prop;
|
||||||
|
queryParams.value.isAsc = defaultSort.value.order;
|
||||||
|
handleQuery();
|
||||||
|
}
|
||||||
|
/** 选择条数 */
|
||||||
|
function handleSelectionChange(selection: OssVO[]) {
|
||||||
|
ids.value = selection.map((item) => item.ossId);
|
||||||
|
single.value = selection.length != 1;
|
||||||
|
multiple.value = !selection.length;
|
||||||
|
}
|
||||||
|
/** 设置列的排序为我们自定义的排序 */
|
||||||
|
const handleHeaderClass = ({ column }: any): any => {
|
||||||
|
column.order = column.multiOrder;
|
||||||
|
};
|
||||||
|
/** 点击表头进行排序 */
|
||||||
|
const handleHeaderCLick = (column: any) => {
|
||||||
|
if (column.sortable !== 'custom') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (column.multiOrder) {
|
||||||
|
case 'descending':
|
||||||
|
column.multiOrder = 'ascending';
|
||||||
|
break;
|
||||||
|
case 'ascending':
|
||||||
|
column.multiOrder = '';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
column.multiOrder = 'descending';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
handleOrderChange(column.property, column.multiOrder);
|
||||||
|
};
|
||||||
|
const handleOrderChange = (prop: string, order: string) => {
|
||||||
|
let orderByArr = queryParams.value.orderByColumn ? queryParams.value.orderByColumn.split(',') : [];
|
||||||
|
let isAscArr = queryParams.value.isAsc ? queryParams.value.isAsc.split(',') : [];
|
||||||
|
let propIndex = orderByArr.indexOf(prop);
|
||||||
|
if (propIndex !== -1) {
|
||||||
|
if (order) {
|
||||||
|
//排序里已存在 只修改排序
|
||||||
|
isAscArr[propIndex] = order;
|
||||||
|
} else {
|
||||||
|
//如果order为null 则删除排序字段和属性
|
||||||
|
isAscArr.splice(propIndex, 1); //删除排序
|
||||||
|
orderByArr.splice(propIndex, 1); //删除属性
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//排序里不存在则新增排序
|
||||||
|
orderByArr.push(prop);
|
||||||
|
isAscArr.push(order);
|
||||||
|
}
|
||||||
|
//合并排序
|
||||||
|
queryParams.value.orderByColumn = orderByArr.join(',');
|
||||||
|
queryParams.value.isAsc = isAscArr.join(',');
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
/** 任务日志列表查询 */
|
||||||
|
const handleOssConfig = () => {
|
||||||
|
router.push('/system/oss-config/index');
|
||||||
|
};
|
||||||
|
/** 文件按钮操作 */
|
||||||
|
const handleFile = () => {
|
||||||
|
reset();
|
||||||
|
type.value = 0;
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = '上传文件';
|
||||||
|
};
|
||||||
|
/** 图片按钮操作 */
|
||||||
|
const handleImage = () => {
|
||||||
|
reset();
|
||||||
|
type.value = 1;
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = '上传图片';
|
||||||
|
};
|
||||||
|
/** 提交按钮 */
|
||||||
|
const submitForm = () => {
|
||||||
|
dialog.visible = false;
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitMoveForm = () => {
|
||||||
|
treeMoveFormRef.value?.validate(async (valid: boolean) => {
|
||||||
|
if (valid) {
|
||||||
|
treeMoveDialog.visible = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const cancelMove = () => {
|
||||||
|
treeMoveDialog.visible = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitCopyForm = () => {
|
||||||
|
treeCopyFormRef.value?.validate(async (valid: boolean) => {
|
||||||
|
if (valid) {
|
||||||
|
treeCopyDialog.visible = false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const cancelCopy = () => {
|
||||||
|
treeCopyDialog.visible = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 下载按钮操作 */
|
||||||
|
const handleDownload = (row: OssVO) => {
|
||||||
|
proxy?.$download.oss(row.ossId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMove = (row: OssVO) => {
|
||||||
|
treeMoveDialog.visible = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCopy = (row: OssVO) => {
|
||||||
|
treeCopyDialog.visible = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 用户状态修改 */
|
||||||
|
const handlePreviewListResource = async (preview: boolean) => {
|
||||||
|
let text = preview ? '启用' : '停用';
|
||||||
|
try {
|
||||||
|
await proxy?.$modal.confirm('确认要"' + text + '""预览列表图片"配置吗?');
|
||||||
|
await proxy?.updateConfigByKey('sys.oss.previewListResource', preview);
|
||||||
|
await getList();
|
||||||
|
proxy?.$modal.msgSuccess(text + '成功');
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
const handleDelete = async (row?: OssVO) => {
|
||||||
|
const ossIds = row?.ossId || ids.value;
|
||||||
|
await proxy?.$modal.confirm('是否确认删除OSS对象存储编号为"' + ossIds + '"的数据项?');
|
||||||
|
loading.value = true;
|
||||||
|
await delOss(ossIds).finally(() => (loading.value = false));
|
||||||
|
await getList();
|
||||||
|
proxy?.$modal.msgSuccess('删除成功');
|
||||||
|
};
|
||||||
|
|
||||||
|
const isAudit = ref(false)
|
||||||
|
const isTree = ref(false)
|
||||||
|
const handleAudit = () => {
|
||||||
|
isAudit.value = true
|
||||||
|
isTree.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleNode = (node: any) => {
|
||||||
|
console.log(node)
|
||||||
|
isAudit.value = false
|
||||||
|
isTree.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const options = ref({
|
||||||
|
xls: false, //预览xlsx文件设为false;预览xls文件设为true
|
||||||
|
minColLength: 0, // excel最少渲染多少列,如果想实现xlsx文件内容有几列,就渲染几列,可以将此值设置为0.
|
||||||
|
minRowLength: 0, // excel最少渲染多少行,如果想实现根据xlsx实际函数渲染,可以将此值设置为0.
|
||||||
|
widthOffset: 10, //如果渲染出来的结果感觉单元格宽度不够,可以在默认渲染的列表宽度上再加 Npx宽
|
||||||
|
heightOffset: 10, //在默认渲染的列表高度上再加 Npx高
|
||||||
|
beforeTransformData: (workbookData) => { return workbookData }, //底层通过exceljs获取excel文件内容,通过该钩子函数,可以对获取的excel文件内容进行修改,比如某个单元格的数据显示不正确,可以在此自行修改每个单元格的value值。
|
||||||
|
transformData: (workbookData) => { return workbookData }, //将获取到的excel数据进行处理之后且渲染到页面之前,可通过transformData对即将渲染的数据及样式进行修改,此时每个单元格的text值就是即将渲染到页面上的内容
|
||||||
|
})
|
||||||
|
|
||||||
|
const currentFile = ref()
|
||||||
|
const file = ref('')
|
||||||
|
const fileLoading = ref(false)
|
||||||
|
const txt = ref('')
|
||||||
|
const imgUrl = ref('')
|
||||||
|
const handlePreview = async (row: OssVO) => {
|
||||||
|
file.value = ''
|
||||||
|
fileLoading.value = true
|
||||||
|
previewDialog.visible = true
|
||||||
|
currentFile.value = row
|
||||||
|
|
||||||
|
if (row.fileSuffix == '.txt') {
|
||||||
|
const fileRes = await previewTxt(row.ossId)
|
||||||
|
console.log(fileRes)
|
||||||
|
txt.value = fileRes
|
||||||
|
} else if (imgSuffix.includes(row.fileSuffix)) {
|
||||||
|
const fileRes = await preview(row.ossId)
|
||||||
|
let blob = new Blob([fileRes], { type: `image/${row.fileSuffix.substring(1)}` })
|
||||||
|
imgUrl.value = URL.createObjectURL(blob)
|
||||||
|
} else if (fileSuffix.includes(row.fileSuffix)) {
|
||||||
|
const fileRes = await preview(row.ossId)
|
||||||
|
fileRes.arrayBuffer().then(res => file.value = res)
|
||||||
|
}
|
||||||
|
|
||||||
|
fileLoading.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const treeLoading = ref(false)
|
||||||
|
/** 查询目录-同步教材列表 */
|
||||||
|
const getListCatalogTextbook = async () => {
|
||||||
|
treeLoading.value = true;
|
||||||
|
const res = await listCatalogTextbook();
|
||||||
|
const data = proxy?.handleTree<CatalogTextbookVO>(res.data, "catalogId", "parentId");
|
||||||
|
if (data) {
|
||||||
|
treeData.value = data;
|
||||||
|
treeLoading.value = false;
|
||||||
|
}
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getListCatalogTextbook()
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped></style>
|
|
@ -0,0 +1,315 @@
|
||||||
|
<template>
|
||||||
|
<div class="p-2">
|
||||||
|
<el-row>
|
||||||
|
<el-col :span="6">
|
||||||
|
<div class="tree-container">
|
||||||
|
<div class="top">
|
||||||
|
<el-radio-group v-model="catalogRadio" size="middle">
|
||||||
|
<el-radio-button label="课件" value="course" />
|
||||||
|
<el-radio-button label="精品课堂" value="room" />
|
||||||
|
<el-radio-button label="作业" value="job" />
|
||||||
|
<el-radio-button label="试卷" value="exam" />
|
||||||
|
</el-radio-group>
|
||||||
|
<div class="line"></div>
|
||||||
|
<el-card shadow="never">
|
||||||
|
<template #header>
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="primary" plain icon="Plus" @click="handleAdd()"
|
||||||
|
v-hasPermi="['resource:catalogPerson:add']">新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="info" plain icon="Sort" @click="handleToggleExpandAll">展开/折叠</el-button>
|
||||||
|
</el-col>
|
||||||
|
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
|
</el-row>
|
||||||
|
</template>
|
||||||
|
<el-table ref="catalogPersonTableRef" v-loading="loading" :data="catalogPersonList" row-key="catalogId"
|
||||||
|
:default-expand-all="isExpandAll" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
|
||||||
|
<el-table-column label="分类名称" align="center" prop="catalogName" />
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tooltip content="修改" placement="top">
|
||||||
|
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
|
||||||
|
v-hasPermi="['resource:catalogPerson:edit']" />
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="新增" placement="top">
|
||||||
|
<el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)"
|
||||||
|
v-hasPermi="['resource:catalogPerson:add']" />
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="删除" placement="top">
|
||||||
|
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
|
||||||
|
v-hasPermi="['resource:catalogPerson:remove']" />
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</el-card>
|
||||||
|
</div>
|
||||||
|
<div class="bottom">
|
||||||
|
<span>资源空间:639.7MB / 1TB</span>
|
||||||
|
<el-progress :percentage="55" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="18">
|
||||||
|
<file-list></file-list>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<!-- 添加或修改目录-我的空间对话框 -->
|
||||||
|
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||||
|
<el-form ref="catalogPersonFormRef" :model="form" :rules="rules" label-width="80px">
|
||||||
|
<el-form-item label="所属上级" prop="parentId">
|
||||||
|
<el-tree-select v-model="form.parentId" :data="catalogPersonOptions"
|
||||||
|
:props="{ value: 'catalogId', label: 'catalogName', children: 'children' }" value-key="catalogId"
|
||||||
|
placeholder="请选择" check-strictly />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="分类名称" prop="catalogName">
|
||||||
|
<el-input v-model="form.catalogName" placeholder="请输入" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||||
|
<el-button @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="CatalogPerson" lang="ts">
|
||||||
|
import { listCatalogPerson, getCatalogPerson, delCatalogPerson, addCatalogPerson, updateCatalogPerson } from "@/api/resource/catalogPerson";
|
||||||
|
import { CatalogPersonVO, CatalogPersonQuery, CatalogPersonForm } from '@/api/resource/catalogPerson/types';
|
||||||
|
import useUserStore from '@/store/modules/user';
|
||||||
|
|
||||||
|
import FileList from "./components/FileList.vue";
|
||||||
|
|
||||||
|
type CatalogPersonOption = {
|
||||||
|
catalogId: number;
|
||||||
|
catalogName: string;
|
||||||
|
children?: CatalogPersonOption[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||||
|
|
||||||
|
const userStore = useUserStore();
|
||||||
|
const catalogRadio = ref('course')
|
||||||
|
const catalogPersonList = ref<CatalogPersonVO[]>([]);
|
||||||
|
const catalogPersonOptions = ref<CatalogPersonOption[]>([]);
|
||||||
|
const buttonLoading = ref(false);
|
||||||
|
const showSearch = ref(true);
|
||||||
|
const isExpandAll = ref(true);
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const queryFormRef = ref<ElFormInstance>();
|
||||||
|
const catalogPersonFormRef = ref<ElFormInstance>();
|
||||||
|
const catalogPersonTableRef = ref<ElTableInstance>()
|
||||||
|
|
||||||
|
const dialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const initFormData: CatalogPersonForm = {
|
||||||
|
catalogId: undefined,
|
||||||
|
userId: userStore.userId,
|
||||||
|
parentId: undefined,
|
||||||
|
ancestors: undefined,
|
||||||
|
catalogName: undefined,
|
||||||
|
orderNum: undefined,
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = reactive<PageData<CatalogPersonForm, CatalogPersonQuery>>({
|
||||||
|
form: { ...initFormData },
|
||||||
|
queryParams: {
|
||||||
|
userId: undefined,
|
||||||
|
parentId: undefined,
|
||||||
|
ancestors: undefined,
|
||||||
|
catalogName: undefined,
|
||||||
|
orderNum: undefined,
|
||||||
|
params: {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
catalogId: [
|
||||||
|
{ required: true, message: "目录id不能为空", trigger: "blur" }
|
||||||
|
],
|
||||||
|
userId: [
|
||||||
|
{ required: true, message: "用户编号不能为空", trigger: "blur" }
|
||||||
|
],
|
||||||
|
parentId: [
|
||||||
|
{ required: true, message: "父目录id不能为空", trigger: "blur" }
|
||||||
|
],
|
||||||
|
ancestors: [
|
||||||
|
{ required: true, message: "祖级列表不能为空", trigger: "blur" }
|
||||||
|
],
|
||||||
|
catalogName: [
|
||||||
|
{ required: true, message: "目录名称不能为空", trigger: "blur" }
|
||||||
|
],
|
||||||
|
orderNum: [
|
||||||
|
{ required: true, message: "显示顺序不能为空", trigger: "blur" }
|
||||||
|
],
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const { queryParams, form, rules } = toRefs(data);
|
||||||
|
|
||||||
|
/** 查询目录-我的空间列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
const res = await listCatalogPerson(queryParams.value);
|
||||||
|
const data = proxy?.handleTree<CatalogPersonVO>(res.data, "catalogId", "parentId");
|
||||||
|
if (data) {
|
||||||
|
catalogPersonList.value = data;
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查询目录-我的空间下拉树结构 */
|
||||||
|
const getTreeselect = async () => {
|
||||||
|
const res = await listCatalogPerson();
|
||||||
|
catalogPersonOptions.value = [];
|
||||||
|
const data: CatalogPersonOption = { catalogId: 0, catalogName: '顶级节点', children: [] };
|
||||||
|
data.children = proxy?.handleTree<CatalogPersonOption>(res.data, "catalogId", "parentId");
|
||||||
|
catalogPersonOptions.value.push(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消按钮
|
||||||
|
const cancel = () => {
|
||||||
|
reset();
|
||||||
|
dialog.visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表单重置
|
||||||
|
const reset = () => {
|
||||||
|
form.value = { ...initFormData }
|
||||||
|
catalogPersonFormRef.value?.resetFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value?.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增按钮操作 */
|
||||||
|
const handleAdd = (row?: CatalogPersonVO) => {
|
||||||
|
reset();
|
||||||
|
getTreeselect();
|
||||||
|
if (row != null && row.catalogId) {
|
||||||
|
form.value.parentId = row.catalogId;
|
||||||
|
} else {
|
||||||
|
form.value.parentId = 0;
|
||||||
|
}
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = "添加目录-我的空间";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 展开/折叠操作 */
|
||||||
|
const handleToggleExpandAll = () => {
|
||||||
|
isExpandAll.value = !isExpandAll.value;
|
||||||
|
toggleExpandAll(catalogPersonList.value, isExpandAll.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 展开/折叠操作 */
|
||||||
|
const toggleExpandAll = (data: CatalogPersonVO[], status: boolean) => {
|
||||||
|
data.forEach((item) => {
|
||||||
|
catalogPersonTableRef.value?.toggleRowExpansion(item, status)
|
||||||
|
if (item.children && item.children.length > 0) toggleExpandAll(item.children, status)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 修改按钮操作 */
|
||||||
|
const handleUpdate = async (row: CatalogPersonVO) => {
|
||||||
|
reset();
|
||||||
|
await getTreeselect();
|
||||||
|
if (row != null) {
|
||||||
|
form.value.parentId = row.parentId;
|
||||||
|
}
|
||||||
|
const res = await getCatalogPerson(row.catalogId);
|
||||||
|
Object.assign(form.value, res.data);
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = "修改目录-我的空间";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 提交按钮 */
|
||||||
|
const submitForm = () => {
|
||||||
|
catalogPersonFormRef.value?.validate(async (valid: boolean) => {
|
||||||
|
if (valid) {
|
||||||
|
buttonLoading.value = true;
|
||||||
|
if (form.value.catalogId) {
|
||||||
|
await updateCatalogPerson(form.value).finally(() => buttonLoading.value = false);
|
||||||
|
} else {
|
||||||
|
await addCatalogPerson(form.value).finally(() => buttonLoading.value = false);
|
||||||
|
}
|
||||||
|
proxy?.$modal.msgSuccess("操作成功");
|
||||||
|
dialog.visible = false;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
const handleDelete = async (row: CatalogPersonVO) => {
|
||||||
|
await proxy?.$modal.confirm('是否确认删除目录-我的空间编号为"' + row.catalogId + '"的数据项?');
|
||||||
|
loading.value = true;
|
||||||
|
await delCatalogPerson(row.catalogId).finally(() => loading.value = false);
|
||||||
|
await getList();
|
||||||
|
proxy?.$modal.msgSuccess("删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.tree-container {
|
||||||
|
margin-top: 10px;
|
||||||
|
padding-top: 10px;
|
||||||
|
height: calc(100vh - 120px);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
|
||||||
|
.top {
|
||||||
|
margin: 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottom {
|
||||||
|
text-align: center;
|
||||||
|
padding-left: 20px;
|
||||||
|
padding-right: 20px;
|
||||||
|
padding-bottom: 30px;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line {
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-audit {
|
||||||
|
text-indent: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
background-color: #F5F7FA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.docx-wrapper) {
|
||||||
|
background-color: #fff;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -82,10 +82,10 @@
|
||||||
<!-- 添加或修改目录-专题资源对话框 -->
|
<!-- 添加或修改目录-专题资源对话框 -->
|
||||||
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||||
<el-form ref="catalogResourceFormRef" :model="form" :rules="rules" label-width="80px">
|
<el-form ref="catalogResourceFormRef" :model="form" :rules="rules" label-width="80px">
|
||||||
<el-form-item label="父目录id" prop="parentId">
|
<el-form-item label="所属上级" prop="parentId">
|
||||||
<el-tree-select v-model="form.parentId" :data="catalogResourceOptions"
|
<el-tree-select v-model="form.parentId" :data="catalogResourceOptions"
|
||||||
:props="{ value: 'catalogId', label: 'catalogName', children: 'children' }" value-key="catalogId"
|
:props="{ value: 'catalogId', label: 'catalogName', children: 'children' }" value-key="catalogId"
|
||||||
placeholder="请选择父目录id" check-strictly />
|
placeholder="请选择" check-strictly />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="专题名称" prop="catalogName">
|
<el-form-item label="专题名称" prop="catalogName">
|
||||||
|
|
|
@ -103,18 +103,21 @@
|
||||||
<!-- 添加或修改目录-同步教材对话框 -->
|
<!-- 添加或修改目录-同步教材对话框 -->
|
||||||
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||||
<el-form ref="catalogTextbookFormRef" :model="form" :rules="rules" label-width="80px">
|
<el-form ref="catalogTextbookFormRef" :model="form" :rules="rules" label-width="80px">
|
||||||
<el-form-item label="父目录id" prop="parentId">
|
<el-form-item label="所属上级" prop="parentId">
|
||||||
<el-tree-select v-model="form.parentId" :data="catalogTextbookOptions"
|
<el-tree-select v-model="form.parentId" :data="catalogTextbookOptions"
|
||||||
:props="{ value: 'catalogId', label: 'catalogName', children: 'children' }" value-key="catalogId"
|
:props="{ value: 'catalogId', label: 'catalogName', children: 'children' }" value-key="catalogId"
|
||||||
placeholder="请选择父目录id" check-strictly />
|
placeholder="请选择" check-strictly />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="类型" prop="type">
|
<el-form-item label="分类名称" prop="catalogName">
|
||||||
|
<el-input v-model="form.catalogName" placeholder="请输入分类名称" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="目录类型" prop="type">
|
||||||
<el-select v-model="form.type" placeholder="请选择类型">
|
<el-select v-model="form.type" placeholder="请选择类型">
|
||||||
<el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
|
<el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="教材名称" prop="catalogName">
|
<el-form-item label="封面" prop="cover">
|
||||||
<el-input v-model="form.catalogName" placeholder="请输入教材名称" />
|
<image-upload v-model="form.cover" :limit="1" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
|
|
|
@ -1,28 +1,45 @@
|
||||||
<template>
|
<template>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="6">
|
<el-col :span="5">
|
||||||
<el-tabs v-model="activeName" type="border-card" style="padding-left: 20px;margin-top: 10px;"
|
<div class="tree-container">
|
||||||
tab-click="handleTabClick">
|
<div class="top">
|
||||||
<el-tab-pane label="课件" name="first">课件</el-tab-pane>
|
<el-radio-group v-model="catalogRadio" size="middle">
|
||||||
<el-tab-pane label="精品课堂" name="second">精品课堂</el-tab-pane>
|
<el-radio-button label="课件" value="1" />
|
||||||
<el-tab-pane label="作业" name="third">作业</el-tab-pane>
|
<el-radio-button label="精品课堂" value="2" />
|
||||||
<el-tab-pane label="试卷" name="fourth">试卷</el-tab-pane>
|
<el-radio-button label="作业" value="3" />
|
||||||
</el-tabs>
|
<el-radio-button label="试卷" value="4" />
|
||||||
|
</el-radio-group>
|
||||||
|
<div class="line"></div>
|
||||||
|
<el-button type="" text="plain">全部课件</el-button>
|
||||||
|
<br>
|
||||||
|
<el-button :class="['btn-audit', isAudit && 'active']" type="" text="plain"
|
||||||
|
@click="handleAudit">待审核</el-button>
|
||||||
|
<el-tree ref="treeRef" v-loading="treeLoading" :data="treeData" :props="defaultProps" default-expand-all
|
||||||
|
@node-click="handleNode" />
|
||||||
|
</div>
|
||||||
|
<div class="bottom">
|
||||||
|
<span>资源空间:639.7MB / 1TB</span>
|
||||||
|
<el-progress :percentage="55" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
|
||||||
<el-col :span="18">
|
<el-col :span="19">
|
||||||
<div class="p-2">
|
<div class="p-2">
|
||||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter"
|
<transition :enter-active-class="proxy?.animate.searchAnimate.enter"
|
||||||
:leave-active-class="proxy?.animate.searchAnimate.leave">
|
:leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||||
<div v-show="showSearch" class="mb-[10px]">
|
<div v-show="showSearch" class="mb-[10px]">
|
||||||
<el-card shadow="hover">
|
<el-card shadow="hover">
|
||||||
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||||
<el-form-item label="文件名" prop="fileName">
|
<el-form-item label="课件名称" prop="fileName">
|
||||||
<el-input v-model="queryParams.fileName" placeholder="请输入文件名" clearable @keyup.enter="handleQuery" />
|
<el-input v-model="queryParams.fileName" placeholder="请输入课件名称" clearable @keyup.enter="handleQuery" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="格式" prop="fileSuffix">
|
<el-form-item label="格式" prop="fileSuffix">
|
||||||
<el-input v-model="queryParams.fileSuffix" placeholder="请输入文件后缀" clearable
|
<el-select v-model="queryParams.fileSuffix" placeholder="请选择" style="width: 240px"
|
||||||
@keyup.enter="handleQuery" />
|
@keyup.enter="handleQuery">
|
||||||
|
<el-option v-for="item in formatOptions" :key="item.value" :label="item.label"
|
||||||
|
:value="item.value" />
|
||||||
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" icon="search" @click="handleQuery">搜索</el-button>
|
<el-button type="primary" icon="search" @click="handleQuery">搜索</el-button>
|
||||||
|
@ -36,9 +53,9 @@
|
||||||
<el-card shadow="hover">
|
<el-card shadow="hover">
|
||||||
<template #header>
|
<template #header>
|
||||||
<el-row :gutter="10" class="mb8">
|
<el-row :gutter="10" class="mb8">
|
||||||
<el-col :span="1.5">
|
<el-col v-if="isUpload" :span="1.5">
|
||||||
<el-button v-hasPermi="['system:oss:upload']" type="primary" plain icon="Upload"
|
<el-button v-hasPermi="['system:oss:upload']" type="primary" plain icon="Upload"
|
||||||
@click="handleFile">上传文件</el-button>
|
@click="handleFile">上传课件</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button v-hasPermi="['system:oss:remove']" type="danger" plain icon="Delete" :disabled="multiple"
|
<el-button v-hasPermi="['system:oss:remove']" type="danger" plain icon="Delete" :disabled="multiple"
|
||||||
|
@ -53,34 +70,40 @@
|
||||||
<el-table v-if="showTable" v-loading="loading" :data="ossList" :header-cell-class-name="handleHeaderClass"
|
<el-table v-if="showTable" v-loading="loading" :data="ossList" :header-cell-class-name="handleHeaderClass"
|
||||||
@selection-change="handleSelectionChange" @header-click="handleHeaderCLick">
|
@selection-change="handleSelectionChange" @header-click="handleHeaderCLick">
|
||||||
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
<el-table-column label="文件名" align="center" prop="originalName" width="240" />
|
<el-table-column label="课件名" align="center" prop="originalName" width="240" />
|
||||||
<el-table-column label="文件格式" align="center" prop="fileSuffix" />
|
<el-table-column label="课件格式" align="center" prop="fileSuffix" />
|
||||||
<el-table-column label="文件大小" align="center" prop="fileSuffix" />
|
<el-table-column label="课件大小" align="center" prop="fileSuffix" />
|
||||||
<el-table-column label="创建人" align="center" prop="createByName" />
|
<el-table-column label="创建人" align="center" prop="createByName" />
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" sortable="custom">
|
<el-table-column label="创建时间" align="center" prop="createTime" sortable="custom">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="340">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="350">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
|
|
||||||
|
<el-tooltip v-if="isAudit" content="审核通过" placement="top">
|
||||||
|
<el-button link type="primary" icon="CopyDocument" @click="handleDownload(scope.row)">审核通过</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip v-if="isAudit" content="审核不通过" placement="top">
|
||||||
|
<el-button link type="primary" icon="DocumentCopy"
|
||||||
|
@click="handleDownload(scope.row)">审核不通过</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
|
||||||
<el-tooltip content="预览" placement="top">
|
<el-tooltip content="预览" placement="top">
|
||||||
<el-button v-hasPermi="['system:oss:download']" link type="primary" icon="View"
|
<el-button link type="primary" icon="View" @click="handlePreview(scope.row)">预览</el-button>
|
||||||
@click="handlePreview(scope.row)">预览</el-button>
|
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<el-tooltip content="下载" placement="top">
|
<el-tooltip v-hasPermi="['system:oss:download']" content="下载" placement="top">
|
||||||
<el-button v-hasPermi="['system:oss:download']" link type="primary" icon="Download"
|
<el-button link type="primary" icon="Download" @click="handleDownload(scope.row)">下载</el-button>
|
||||||
@click="handleDownload(scope.row)">下载</el-button>
|
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<el-tooltip content="移动" placement="top">
|
|
||||||
<el-button v-hasPermi="['system:oss:download']" link type="primary" icon="CopyDocument"
|
<el-tooltip v-if="isTree" content="移动" placement="top">
|
||||||
@click="handleDownload(scope.row)">移动</el-button>
|
<el-button link type="primary" icon="CopyDocument" @click="handleMove(scope.row)">移动</el-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<el-tooltip content="复制" placement="top">
|
<el-tooltip v-if="isTree" content="复制" placement="top">
|
||||||
<el-button v-hasPermi="['system:oss:download']" link type="primary" icon="DocumentCopy"
|
<el-button link type="primary" icon="DocumentCopy" @click="handleCopy(scope.row)">复制</el-button>
|
||||||
@click="handleDownload(scope.row)">复制</el-button>
|
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<el-tooltip content="删除" placement="top">
|
<el-tooltip v-if="isTree" content="删除" placement="top">
|
||||||
<el-button v-hasPermi="['system:oss:remove']" link type="primary" icon="Delete"
|
<el-button v-hasPermi="['system:oss:remove']" link type="primary" icon="Delete"
|
||||||
@click="handleDelete(scope.row)">删除</el-button>
|
@click="handleDelete(scope.row)">删除</el-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
|
@ -91,11 +114,12 @@
|
||||||
<pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
|
<pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
|
||||||
:total="total" @pagination="getList" />
|
:total="total" @pagination="getList" />
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
<!-- 添加或修改OSS对象存储对话框 -->
|
<!-- 添加或修改OSS对象存储对话框 -->
|
||||||
<el-dialog v-model="dialog.visible" :title="dialog.title" width="700px" append-to-body>
|
<el-dialog v-model="dialog.visible" :title="dialog.title" width="700px" append-to-body>
|
||||||
<el-form ref="ossFormRef" :model="form" :rules="rules">
|
<el-form ref="ossFormRef" :model="form" :rules="rules">
|
||||||
<el-form-item label="">
|
<el-form-item prop="file">
|
||||||
<fileUpload v-if="type === 0" v-model="form.file" />
|
<FileMd5Upload v-if="type === 0" v-model="form.file" @onFileName="handleFileName" />
|
||||||
<imageUpload v-if="type === 1" v-model="form.file" />
|
<imageUpload v-if="type === 1" v-model="form.file" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
@ -125,15 +149,50 @@
|
||||||
<ImagePreview v-loading="fileLoading" element-loading-text="加载中..." style="width: 100%; text-align: center;"
|
<ImagePreview v-loading="fileLoading" element-loading-text="加载中..." style="width: 100%; text-align: center;"
|
||||||
v-if="imgSuffix.includes(currentFile.fileSuffix)" :src="imgUrl" />
|
v-if="imgSuffix.includes(currentFile.fileSuffix)" :src="imgUrl" />
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
<el-dialog v-model="treeMoveDialog.visible" :title="treeMoveDialog.title" width="500px" append-to-body>
|
||||||
|
<el-form ref="treeMoveFormRef" :model="treeMoveForm" :rules="treeMoveRules">
|
||||||
|
<el-form-item label="移动至" prop="catalogId">
|
||||||
|
<el-tree-select v-model="treeMoveForm.catalogId" :data="treeData"
|
||||||
|
:props="{ value: 'catalogId', label: 'catalogName', children: 'children' }" value-key="catalogId"
|
||||||
|
placeholder="请选择" check-strictly />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitMoveForm">确 定</el-button>
|
||||||
|
<el-button @click="cancelMove">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
|
<el-dialog v-model="treeCopyDialog.visible" :title="treeCopyDialog.title" width="500px" append-to-body>
|
||||||
|
<el-form ref="treeCopyFormRef" :model="treeCopyForm" :rules="treeCopyRules">
|
||||||
|
<el-form-item label="复制至" prop="catalogId">
|
||||||
|
<el-tree-select v-model="treeCopyForm.catalogId" :data="treeData"
|
||||||
|
:props="{ value: 'catalogId', label: 'catalogName', children: 'children' }" value-key="catalogId"
|
||||||
|
placeholder="请选择" check-strictly />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitCopyForm">确 定</el-button>
|
||||||
|
<el-button @click="cancelCopy">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="Oss" lang="ts">
|
<script setup name="Oss" lang="ts">
|
||||||
import { listOss, preview, previewTxt, delOss } from '@/api/system/oss';
|
import { listOss, preview, previewTxt, delOss, addTextbook } from '@/api/system/oss';
|
||||||
import ImagePreview from '@/components/ImagePreview/index.vue';
|
import ImagePreview from '@/components/ImagePreview/index.vue';
|
||||||
|
import FileMd5Upload from '@/components/FileMd5Upload/index.vue';
|
||||||
import { OssForm, OssQuery, OssVO } from '@/api/system/oss/types';
|
import { OssForm, OssQuery, OssVO } from '@/api/system/oss/types';
|
||||||
|
import { listCatalogTextbook } from "@/api/resource/catalogTextbook";
|
||||||
|
import { CatalogTextbookVO } from '@/api/resource/catalogTextbook/types';
|
||||||
|
|
||||||
//引入VueOfficeDocx组件
|
//引入VueOfficeDocx组件
|
||||||
import VueOfficeDocx from '@vue-office/docx'
|
import VueOfficeDocx from '@vue-office/docx'
|
||||||
|
@ -152,7 +211,50 @@ const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||||
const fileSuffix = ['.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.pdf']
|
const fileSuffix = ['.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.pdf']
|
||||||
const imgSuffix = ['.jpg', '.png', '.jpeg', '.gif', '.bmp']
|
const imgSuffix = ['.jpg', '.png', '.jpeg', '.gif', '.bmp']
|
||||||
|
|
||||||
const activeName = ref('first')
|
const formatOptions = [
|
||||||
|
{
|
||||||
|
value: '.doc',
|
||||||
|
label: 'doc',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.docx',
|
||||||
|
label: 'docx',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.xls',
|
||||||
|
label: 'xls',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.xlsx',
|
||||||
|
label: 'xlsx',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.ppt',
|
||||||
|
label: 'ppt',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.pptx',
|
||||||
|
label: 'pptx',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.pdf',
|
||||||
|
label: 'pdf',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '.txt',
|
||||||
|
label: 'txt',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const catalogRadio = ref('1')
|
||||||
|
const defaultProps = {
|
||||||
|
children: 'children',
|
||||||
|
label: 'catalogName',
|
||||||
|
}
|
||||||
|
|
||||||
|
const isUpload = ref(false)
|
||||||
|
const currentNode = ref<any>({})
|
||||||
|
const treeData = ref<CatalogTextbookVO[]>([])
|
||||||
|
|
||||||
const ossList = ref<OssVO[]>([]);
|
const ossList = ref<OssVO[]>([]);
|
||||||
const showTable = ref(true);
|
const showTable = ref(true);
|
||||||
|
@ -177,6 +279,26 @@ const previewDialog = reactive<DialogOption>({
|
||||||
title: '文件预览'
|
title: '文件预览'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const treeMoveDialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: '移动'
|
||||||
|
});
|
||||||
|
const treeMoveFormRef = ref()
|
||||||
|
const treeMoveForm = ref<any>({ catalogId: '' });
|
||||||
|
const treeMoveRules = ref({
|
||||||
|
catalogId: [{ required: true, message: '请选择', trigger: 'blur' }]
|
||||||
|
})
|
||||||
|
|
||||||
|
const treeCopyDialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: '复制'
|
||||||
|
});
|
||||||
|
const treeCopyFormRef = ref()
|
||||||
|
const treeCopyForm = ref<any>({ catalogId: '' });
|
||||||
|
const treeCopyRules = ref({
|
||||||
|
catalogId: [{ required: true, message: '请选择', trigger: 'blur' }]
|
||||||
|
})
|
||||||
|
|
||||||
// 默认排序
|
// 默认排序
|
||||||
const defaultSort = ref({ prop: 'createTime', order: 'ascending' });
|
const defaultSort = ref({ prop: 'createTime', order: 'ascending' });
|
||||||
|
|
||||||
|
@ -219,6 +341,7 @@ const getList = async () => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
showTable.value = true;
|
showTable.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkFileSuffix(fileSuffix: string | string[]) {
|
function checkFileSuffix(fileSuffix: string | string[]) {
|
||||||
const arr = [".png", ".jpg", ".jpeg"];
|
const arr = [".png", ".jpg", ".jpeg"];
|
||||||
const suffixArray = Array.isArray(fileSuffix) ? fileSuffix : [fileSuffix];
|
const suffixArray = Array.isArray(fileSuffix) ? fileSuffix : [fileSuffix];
|
||||||
|
@ -317,15 +440,58 @@ const handleImage = () => {
|
||||||
dialog.visible = true;
|
dialog.visible = true;
|
||||||
dialog.title = '上传图片';
|
dialog.title = '上传图片';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fileName = ref('')
|
||||||
|
const handleFileName = (val) => {
|
||||||
|
fileName.value = val
|
||||||
|
}
|
||||||
|
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
const submitForm = () => {
|
const submitForm = async () => {
|
||||||
|
const ossId = form.value.file
|
||||||
|
const catalogId = currentNode.value.catalogId
|
||||||
|
await addTextbook({ ossId, catalogId, fileName: fileName.value, type: catalogRadio.value })
|
||||||
dialog.visible = false;
|
dialog.visible = false;
|
||||||
getList();
|
getList();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const submitMoveForm = () => {
|
||||||
|
treeMoveFormRef.value?.validate(async (valid: boolean) => {
|
||||||
|
if (valid) {
|
||||||
|
treeMoveDialog.visible = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const cancelMove = () => {
|
||||||
|
treeMoveDialog.visible = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitCopyForm = () => {
|
||||||
|
treeCopyFormRef.value?.validate(async (valid: boolean) => {
|
||||||
|
if (valid) {
|
||||||
|
treeCopyDialog.visible = false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const cancelCopy = () => {
|
||||||
|
treeCopyDialog.visible = false
|
||||||
|
}
|
||||||
|
|
||||||
/** 下载按钮操作 */
|
/** 下载按钮操作 */
|
||||||
const handleDownload = (row: OssVO) => {
|
const handleDownload = (row: OssVO) => {
|
||||||
proxy?.$download.oss(row.ossId);
|
proxy?.$download.oss(row.ossId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleMove = (row: OssVO) => {
|
||||||
|
treeMoveDialog.visible = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCopy = (row: OssVO) => {
|
||||||
|
treeCopyDialog.visible = true
|
||||||
|
}
|
||||||
|
|
||||||
/** 用户状态修改 */
|
/** 用户状态修改 */
|
||||||
const handlePreviewListResource = async (preview: boolean) => {
|
const handlePreviewListResource = async (preview: boolean) => {
|
||||||
let text = preview ? '启用' : '停用';
|
let text = preview ? '启用' : '停用';
|
||||||
|
@ -348,8 +514,19 @@ const handleDelete = async (row?: OssVO) => {
|
||||||
proxy?.$modal.msgSuccess('删除成功');
|
proxy?.$modal.msgSuccess('删除成功');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTabClick = () => {
|
const isAudit = ref(false)
|
||||||
|
const isTree = ref(false)
|
||||||
|
const handleAudit = () => {
|
||||||
|
isAudit.value = true
|
||||||
|
isTree.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleNode = (node: any) => {
|
||||||
|
console.log(node)
|
||||||
|
isAudit.value = false
|
||||||
|
isTree.value = true
|
||||||
|
isUpload.value = true
|
||||||
|
currentNode.value = node
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = ref({
|
const options = ref({
|
||||||
|
@ -381,7 +558,7 @@ const handlePreview = async (row: OssVO) => {
|
||||||
const fileRes = await preview(row.ossId)
|
const fileRes = await preview(row.ossId)
|
||||||
let blob = new Blob([fileRes], { type: `image/${row.fileSuffix.substring(1)}` })
|
let blob = new Blob([fileRes], { type: `image/${row.fileSuffix.substring(1)}` })
|
||||||
imgUrl.value = URL.createObjectURL(blob)
|
imgUrl.value = URL.createObjectURL(blob)
|
||||||
} else if(fileSuffix.includes(row.fileSuffix)){
|
} else if (fileSuffix.includes(row.fileSuffix)) {
|
||||||
const fileRes = await preview(row.ossId)
|
const fileRes = await preview(row.ossId)
|
||||||
fileRes.arrayBuffer().then(res => file.value = res)
|
fileRes.arrayBuffer().then(res => file.value = res)
|
||||||
}
|
}
|
||||||
|
@ -389,12 +566,60 @@ const handlePreview = async (row: OssVO) => {
|
||||||
fileLoading.value = false
|
fileLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const treeLoading = ref(false)
|
||||||
|
/** 查询目录-同步教材列表 */
|
||||||
|
const getListCatalogTextbook = async () => {
|
||||||
|
treeLoading.value = true;
|
||||||
|
const res = await listCatalogTextbook();
|
||||||
|
const data = proxy?.handleTree<CatalogTextbookVO>(res.data, "catalogId", "parentId");
|
||||||
|
if (data) {
|
||||||
|
treeData.value = data;
|
||||||
|
treeLoading.value = false;
|
||||||
|
}
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
getListCatalogTextbook()
|
||||||
getList();
|
getList();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
.tree-container {
|
||||||
|
padding-top: 10px;
|
||||||
|
height: calc(100vh - 120px);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
|
||||||
|
.top {
|
||||||
|
margin: 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottom {
|
||||||
|
text-align: center;
|
||||||
|
padding-left: 20px;
|
||||||
|
padding-right: 20px;
|
||||||
|
padding-bottom: 30px;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line {
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-audit {
|
||||||
|
text-indent: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
background-color: #F5F7FA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
:deep(.docx-wrapper) {
|
:deep(.docx-wrapper) {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
Loading…
Reference in New Issue