文件存储添加分组功能

This commit is contained in:
huangge1199 2024-09-02 09:20:25 +08:00
parent b3c36e27cf
commit a0748feb3f
2 changed files with 147 additions and 62 deletions

View File

@ -24,3 +24,12 @@ export function delOss(ossId) {
method: 'delete' method: 'delete'
}); });
} }
// 修改OSS对象存储
export function editOss(params) {
return request({
url: '/resource/oss/update',
method: 'get',
params: params
});
}

View File

@ -1,50 +1,59 @@
<template> <template>
<div class="p-2"> <div class="p-2">
<div class="mb-[10px]" v-show="showSearch"> <div class="mb-[10px]" v-show="showSearch">
<el-card shadow="hover"> <el-card shadow="hover">
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px"> <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
<el-form-item label="文件名" prop="fileName"> <el-form-item label="文件名" prop="fileName">
<el-input v-model="queryParams.fileName" placeholder="请输入文件名" clearable style="width: 200px" @keyup.enter="handleQuery" /> <el-input v-model="queryParams.fileName" placeholder="请输入文件名" clearable style="width: 200px"
</el-form-item> @keyup.enter="handleQuery"/>
<el-form-item label="原名" prop="originalName"> </el-form-item>
<el-input v-model="queryParams.originalName" placeholder="请输入原名" clearable style="width: 200px" @keyup.enter="handleQuery" /> <el-form-item label="原名" prop="originalName">
</el-form-item> <el-input v-model="queryParams.originalName" placeholder="请输入原名" clearable style="width: 200px"
<el-form-item label="文件后缀" prop="fileSuffix"> @keyup.enter="handleQuery"/>
<el-input v-model="queryParams.fileSuffix" placeholder="请输入文件后缀" clearable style="width: 200px" @keyup.enter="handleQuery" /> </el-form-item>
</el-form-item> <el-form-item label="文件后缀" prop="fileSuffix">
<el-form-item label="创建时间"> <el-input v-model="queryParams.fileSuffix" placeholder="请输入文件后缀" clearable style="width: 200px"
<el-date-picker @keyup.enter="handleQuery"/>
v-model="dateRangeCreateTime" </el-form-item>
value-format="YYYY-MM-DD HH:mm:ss" <el-form-item label="创建时间">
type="daterange" <el-date-picker
range-separator="-" v-model="dateRangeCreateTime"
start-placeholder="开始日期" value-format="YYYY-MM-DD HH:mm:ss"
end-placeholder="结束日期" type="daterange"
:default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]" range-separator="-"
></el-date-picker> start-placeholder="开始日期"
</el-form-item> end-placeholder="结束日期"
<el-form-item label="服务商" prop="service"> :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
<el-input v-model="queryParams.service" placeholder="请输入服务商" clearable style="width: 200px" @keyup.enter="handleQuery" /> ></el-date-picker>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item label="服务商" prop="service">
<el-button type="primary" icon="search" @click="handleQuery">搜索</el-button> <el-input v-model="queryParams.service" placeholder="请输入服务商" clearable style="width: 200px"
<el-button icon="Refresh" @click="resetQuery">重置</el-button> @keyup.enter="handleQuery"/>
</el-form-item> </el-form-item>
</el-form> <el-form-item>
</el-card> <el-button type="primary" icon="search" @click="handleQuery">搜索</el-button>
</div> <el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
<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 :span="1.5">
<el-button type="primary" plain icon="Upload" @click="handleFile" v-hasPermi="['system:oss:upload']">上传文件</el-button> <el-button type="primary" plain icon="Upload" @click="handleFile" v-hasPermi="['system:oss:upload']">
上传文件
</el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="primary" plain icon="Upload" @click="handleImage" v-hasPermi="['system:oss:upload']">上传图片</el-button> <el-button type="primary" plain icon="Upload" @click="handleImage" v-hasPermi="['system:oss:upload']">
上传图片
</el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:oss:remove']"> <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()"
v-hasPermi="['system:oss:remove']">
删除 删除
</el-button> </el-button>
</el-col> </el-col>
@ -54,13 +63,17 @@
plain plain
@click="handlePreviewListResource(!previewListResource)" @click="handlePreviewListResource(!previewListResource)"
v-hasPermi="['system:oss:edit']" v-hasPermi="['system:oss:edit']"
>预览开关 : >预览开关 :
{{ {{
previewListResource ? "禁用" : "启用" }}</el-button previewListResource ? "禁用" : "启用"
}}
</el-button
> >
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="info" plain icon="Operation" @click="handleOssConfig" v-hasPermi="['system:oss:list']">配置管理</el-button> <el-button type="info" plain icon="Operation" @click="handleOssConfig" v-hasPermi="['system:oss:list']">
配置管理
</el-button>
</el-col> </el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
@ -74,11 +87,36 @@
@header-click="handleHeaderCLick" @header-click="handleHeaderCLick"
v-if="showTable" v-if="showTable"
> >
<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="ossId" v-if="false" /> <el-table-column label="对象存储主键" align="center" prop="ossId" v-if="false"/>
<el-table-column label="文件名" align="center" prop="fileName" /> <el-table-column label="文件名" align="center" prop="fileName"/>
<el-table-column label="原名" align="center" prop="originalName" /> <el-table-column label="原名" align="center" prop="originalName"/>
<el-table-column label="文件后缀" align="center" prop="fileSuffix" /> <el-table-column label="文件后缀" align="center" prop="fileSuffix"/>
<el-table-column label="分组" align="center" prop="team">
<template #default="scope">
<span v-if="scope.row.isEdit===true">
<el-select
v-model="oss.team"
filterable
allow-create
default-first-option
:reserve-keyword="false"
placeholder="请选择分组"
@change="changeTeam(scope.row)"
>
<el-option
v-for="item in teamList"
:key="item"
:label="item"
:value="item"
/>
</el-select>
</span>
<span v-else>{{ scope.row.team }}
<el-button :icon="Edit" type="primary" link @click="onClick(scope.row)"/>
</span>
</template>
</el-table-column>
<el-table-column label="文件展示" align="center" prop="url"> <el-table-column label="文件展示" align="center" prop="url">
<template #default="scope"> <template #default="scope">
<ImagePreview <ImagePreview
@ -88,7 +126,7 @@
:src="scope.row.url" :src="scope.row.url"
:preview-src-list="[scope.row.url]" :preview-src-list="[scope.row.url]"
/> />
<span v-text="scope.row.url" v-if="!checkFileSuffix(scope.row.fileSuffix) || !previewListResource" /> <span v-text="scope.row.url" v-if="!checkFileSuffix(scope.row.fileSuffix) || !previewListResource"/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="180" sortable="custom"> <el-table-column label="创建时间" align="center" prop="createTime" width="180" sortable="custom">
@ -96,28 +134,31 @@
<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" prop="createByName" /> <el-table-column label="上传人" align="center" prop="createByName"/>
<el-table-column label="服务商" align="center" prop="service" sortable="custom" /> <el-table-column label="服务商" align="center" prop="service" sortable="custom"/>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope"> <template #default="scope">
<el-tooltip content="下载" placement="top"> <el-tooltip content="下载" placement="top">
<el-button link type="primary" icon="Download" @click="handleDownload(scope.row)" v-hasPermi="['system:oss:download']"></el-button> <el-button link type="primary" icon="Download" @click="handleDownload(scope.row)"
v-hasPermi="['system:oss:download']"></el-button>
</el-tooltip> </el-tooltip>
<el-tooltip content="删除" placement="top"> <el-tooltip content="删除" placement="top">
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:oss:remove']"></el-button> <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
v-hasPermi="['system:oss:remove']"></el-button>
</el-tooltip> </el-tooltip>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" /> <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize" @pagination="getList"/>
</el-card> </el-card>
<!-- 添加或修改OSS对象存储对话框 --> <!-- 添加或修改OSS对象存储对话框 -->
<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="ossFormRef" :model="form" :rules="rules" label-width="80px"> <el-form ref="ossFormRef" :model="form" :rules="rules" label-width="80px">
<el-form-item label="文件名"> <el-form-item label="文件名">
<fileUpload v-model="form.file" v-if="type === 0" /> <fileUpload v-model="form.file" v-if="type === 0"/>
<imageUpload v-model="form.file" v-if="type === 1" /> <imageUpload v-model="form.file" v-if="type === 1"/>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
@ -131,12 +172,13 @@
</template> </template>
<script setup name="Oss"> <script setup name="Oss">
import { listOss, delOss } from "@/api/system/oss"; import {listOss, delOss, editOss} from "@/api/system/oss";
import ImagePreview from "@/components/ImagePreview/index.vue"; import ImagePreview from "@/components/ImagePreview/index.vue";
import { getConfigKey,updateConfigByKey } from "@/api/system/config"; import {getConfigKey, updateConfigByKey} from "@/api/system/config";
import {Edit} from "@element-plus/icons-vue";
const router = useRouter(); const router = useRouter();
const { proxy } = getCurrentInstance(); const {proxy} = getCurrentInstance();
const ossList = ref([]); const ossList = ref([]);
const showTable = ref(true); const showTable = ref(true);
@ -150,6 +192,8 @@ const total = ref(0);
const type = ref(0); const type = ref(0);
const previewListResource = ref(true); const previewListResource = ref(true);
const dateRangeCreateTime = ref(['', '']); const dateRangeCreateTime = ref(['', '']);
const teamList = ref([]);
const oss = ref({});
const dialog = reactive({ const dialog = reactive({
visible: false, visible: false,
@ -157,13 +201,13 @@ const dialog = reactive({
}); });
// //
const defaultSort = ref({ prop: 'createTime', order: 'ascending' }); const defaultSort = ref({prop: 'createTime', order: 'ascending'});
const initFormData = { const initFormData = {
file: undefined, file: undefined,
} }
const data = reactive({ const data = reactive({
form: { ...initFormData }, form: {...initFormData},
// //
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
@ -178,12 +222,12 @@ const data = reactive({
}, },
rules: { rules: {
file: [ file: [
{ required: true, message: "文件不能为空", trigger: "blur" } {required: true, message: "文件不能为空", trigger: "blur"}
] ]
} }
}); });
const { queryParams, form, rules } = toRefs(data); const {queryParams, form, rules} = toRefs(data);
/** 查询OSS对象存储列表 */ /** 查询OSS对象存储列表 */
const getList = async () => { const getList = async () => {
@ -192,31 +236,43 @@ const getList = async () => {
previewListResource.value = res?.data === undefined ? true : res.data === "true"; previewListResource.value = res?.data === undefined ? true : res.data === "true";
const response = await listOss(proxy?.addDateRange(queryParams.value, dateRangeCreateTime.value, "CreateTime")); const response = await listOss(proxy?.addDateRange(queryParams.value, dateRangeCreateTime.value, "CreateTime"));
ossList.value = response.rows; ossList.value = response.rows;
teamList.value = []
ossList.value.forEach((item, index) => {
item.isEdit = false;
if (!teamList.value.includes(item.team)) {
teamList.value.push(item.team)
}
})
total.value = response.total; total.value = response.total;
loading.value = false; loading.value = false;
showTable.value = true; showTable.value = true;
} }
function checkFileSuffix(fileSuffix) { function checkFileSuffix(fileSuffix) {
let arr = ["png", "jpg", "jpeg"]; let arr = ["png", "jpg", "jpeg"];
return arr.some(type => { return arr.some(type => {
return fileSuffix.indexOf(type) > -1; return fileSuffix.indexOf(type) > -1;
}); });
} }
/** 取消按钮 */ /** 取消按钮 */
function cancel() { function cancel() {
dialog.visible = false; dialog.visible = false;
reset(); reset();
} }
/** 表单重置 */ /** 表单重置 */
function reset() { function reset() {
form.value = { ...initFormData }; form.value = {...initFormData};
proxy.resetForm("ossFormRef"); proxy.resetForm("ossFormRef");
} }
/** 搜索按钮操作 */ /** 搜索按钮操作 */
function handleQuery() { function handleQuery() {
queryParams.value.pageNum = 1; queryParams.value.pageNum = 1;
getList(); getList();
} }
/** 重置按钮操作 */ /** 重置按钮操作 */
function resetQuery() { function resetQuery() {
showTable.value = false; showTable.value = false;
@ -226,14 +282,16 @@ function resetQuery() {
queryParams.value.isAsc = defaultSort.value.order; queryParams.value.isAsc = defaultSort.value.order;
handleQuery(); handleQuery();
} }
/** 选择条数 */ /** 选择条数 */
function handleSelectionChange(selection) { function handleSelectionChange(selection) {
ids.value = selection.map(item => item.ossId); ids.value = selection.map(item => item.ossId);
single.value = selection.length != 1; single.value = selection.length != 1;
multiple.value = !selection.length; multiple.value = !selection.length;
} }
/** 设置列的排序为我们自定义的排序 */ /** 设置列的排序为我们自定义的排序 */
const handleHeaderClass = ({ column }) => { const handleHeaderClass = ({column}) => {
column.order = column.multiOrder column.order = column.multiOrder
} }
/** 点击表头进行排序 */ /** 点击表头进行排序 */
@ -312,7 +370,9 @@ const handlePreviewListResource = async (preview) => {
await updateConfigByKey("sys.oss.previewListResource", preview); await updateConfigByKey("sys.oss.previewListResource", preview);
await getList() await getList()
proxy?.$modal.msgSuccess(text + "成功"); proxy?.$modal.msgSuccess(text + "成功");
} catch { return } } catch {
return
}
} }
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = async (row) => { const handleDelete = async (row) => {
@ -324,6 +384,22 @@ const handleDelete = async (row) => {
proxy?.$modal.msgSuccess("删除成功"); proxy?.$modal.msgSuccess("删除成功");
} }
/** 编辑分组 */
function onClick(row) {
row.isEdit = true
oss.value = row
}
/** 修改分组 */
function changeTeam(row) {
loading.value = true;
editOss(oss.value).then(response => {
proxy?.$modal.msgSuccess("修改成功");
row.isEdit = false
getList()
})
}
onMounted(() => { onMounted(() => {
getList(); getList();
}) })