添加文件-文件夹

master
pikachu1995@126.com 2023-09-26 18:48:55 +08:00
parent 2c66eaae2b
commit 46143beb83
2 changed files with 620 additions and 260 deletions

View File

@ -490,4 +490,24 @@ export const getHotWordsHistory = (params) => {
return getRequest(`/hotwords/hotwords/history`,params);
};
// 获取文件目录列表
export const getFileDirectory = () => {
return getRequest(commonUrl+`/common/resource/fileDirectory`);
};
// 添加文件目录
export const addFileDirectory = (params) => {
return postRequestWithNoForm(commonUrl+`/common/resource/fileDirectory`,params);
};
// 修改文件目录
export const updateFileDirectory = (params) => {
return putRequestWithNoForm(commonUrl+`/common/resource/fileDirectory`,params);
};
// 删除文件目录
export const delFileDirectory = (id) => {
return deleteRequest(commonUrl+`/common/resource/fileDirectory/${id}`);
};

View File

@ -1,44 +1,62 @@
<style lang="scss">
@import "./ossManage.scss";
.group-row {
padding-top: 10px;
border-top: 1px solid #ededed;
margin-top: 10px;
display: flex;
align-items: center;
justify-content: center;
> * {
margin-right: 10px;
}
}
.article-category {
flex: 2;
min-width: 200px;
}
.table {
flex: 11;
}
.ivu-card {
width: 100%;
}
.modal-footer {
text-align: center;
> * {
margin: 0 10px;
}
}
</style>
<template>
<div class="search">
<Row>
<Card>
<div class="operation">
<Row @keydown.enter.native="handleSearch">
<Form ref="searchForm" :model="searchForm" inline :label-width="85" class="search-form"
<Form
ref="searchForm"
:label-width="85"
:model="searchForm"
class="search-form"
inline
>
<Form-item label="原文件名" prop="name">
<Input
type="text"
v-model="searchForm.name"
placeholder="请输入原文件名"
clearable
style="width: 200px"
/>
</Form-item>
<Form-item label="存储文件名" prop="fileKey">
<Input
type="text"
v-model="searchForm.fileKey"
placeholder="请输入存储文件名"
clearable
style="width: 200px"
/>
</Form-item>
<Form-item label="上传时间">
<DatePicker
v-model="selectDate"
type="daterange"
format="yyyy-MM-dd"
clearable
@on-change="selectDateRange"
format="yyyy-MM-dd"
placeholder="选择起始时间"
style="width: 200px"
type="daterange"
@on-change="selectDateRange"
></DatePicker>
</Form-item>
<Button @click="handleSearch" type="primary" icon="ios-search" class="search-btn"
<Button
class="search-btn"
icon="ios-search"
type="primary"
@click="handleSearch"
>搜索
</Button>
</Form>
@ -46,62 +64,39 @@
<div class="oss-operation padding-row">
<div>
<Upload
style="display:inline-block;"
:action="commonUrl + '/common/common/upload/file'"
:headers="accessToken"
:on-success="handleSuccess"
:on-error="handleError"
:show-upload-list="false"
:max-size="2048"
:on-exceeded-size="handleMaxSize"
multiple
ref="up"
:action="commonUrl + '/common/common/upload/file'"
:data="{
directoryPath: searchForm.fileDirectoryId,
}"
:headers="accessToken"
:max-size="20480"
:on-error="handleError"
:on-exceeded-size="handleMaxSize"
:on-success="handleSuccess"
:show-upload-list="false"
multiple
style="display: inline-block"
>
<Button type="primary">上传文件</Button>
<Button>上传图片</Button>
</Upload>
<Dropdown @on-click="handleDropdown">
<Dropdown @on-click="handleDropdown" v-if="!isComponent">
<Button>
更多操作
<Icon type="md-arrow-dropdown"/>
</Button>
<DropdownMenu slot="list">
<DropdownItem name="refresh">刷新</DropdownItem>
<DropdownItem v-show="showType == 'list'" name="removeAll">
<DropdownItem v-show="showType == 'list'" name="removeAll"
>批量删除
</DropdownItem>
</DropdownMenu>
</Dropdown>
</div>
<div>
<RadioGroup
v-model="fileType"
@on-change="changeFileType"
type="button" button-style="solid"
style="margin-right: 25px"
>
<Radio label="all">所有类型</Radio>
<Radio label="pic">图片</Radio>
<Radio label="video">视频</Radio>
</RadioGroup>
<RadioGroup
v-model="showType"
type="button" button-style="solid"
@on-change="changeShowType"
>
<Radio title="列表" label="list">
<Icon type="md-list"></Icon>
</Radio>
<Radio title="缩略图" label="thumb">
<Icon type="ios-apps"></Icon>
</Radio>
</RadioGroup>
</div>
</div>
</div>
<div v-show="showType == 'list'">
<Row >
<Alert show-icon>
<Alert show-icon v-if="!isComponent">
已选择
<span>{{ selectCount }}</span>
<a class="select-clear" @click="clearSelectAll"></a>
@ -109,27 +104,60 @@
>共计 {{ totalSize }} 存储量</span
>
</Alert>
</Row>
<div v-show="showType === 'list'" >
<div class="flex">
<div class="article-category mr_10">
<Tree
:data="treeData"
@on-contextmenu="handleContextMenu"
@on-select-change="handleCateChange"
>
<template slot="contextMenu" v-if="!isComponent">
<DropdownItem @click.native="handleContextMenuEdit"
>编辑
</DropdownItem
>
<DropdownItem
style="color: #ed4014"
@click.native="handleContextMenuDelete"
>删除
</DropdownItem
>
</template>
</Tree>
<Alert v-if="!isComponent">/</Alert>
<div class="group-row flex" v-if="!isComponent">
<Button @click="handleClickAddGroup"></Button>
</div>
</div>
<Table
ref="table"
:columns="isComponent ? viewColumns : columns"
:data="data"
:loading="loading"
border
:columns="columns"
:data="data"
ref="table"
class="table"
sortable="custom"
@on-sort-change="changeSort"
@on-selection-change="changeSelect"
></Table>
>
<template slot="fileKey" slot-scope="{ row }">
<a @click="copyFileUrl(row)">{{ row.fileKey }}</a>
</template>
</Table>
</div>
<div v-show="showType == 'thumb'">
</div>
<div v-show="showType === 'thumb'">
<div class="oss-wrapper">
<Card v-for="(item, i) in data" :key="i" class="oss-card">
<div class="content">
<img
@click="showPic(item)"
v-if="item.fileType.indexOf('image') >= 0"
class="img"
:src="item.url"
class="img"
@click="showPic(item)"
/>
<div
v-else-if="item.fileType.indexOf('video') >= 0"
@ -137,7 +165,7 @@
@click="showVideo(item)"
>
<!-- 文件小于5MB显示video -->
<video class="cover" v-if="item.fileSize < 1024 * 1024 * 5">
<video v-if="item.fileSize < 1024 * 1024 * 5" class="cover">
<source :src="item.url"/>
</video>
<img class="play" src="@/assets/play.png"/>
@ -155,17 +183,21 @@
<div class="actions">
<div class="btn">
<Tooltip content="下载" placement="top">
<Icon @click="download(item)" type="md-download" size="16"/>
<Icon
size="16"
type="md-download"
@click="download(item)"
/>
</Tooltip>
</div>
<div class="btn">
<Tooltip content="重命名" placement="top">
<Icon @click="rename(item)" type="md-create" size="16"/>
<Icon size="16" type="md-create" @click="rename(item)"/>
</Tooltip>
</div>
<div class="btn-no">
<Tooltip content="删除" placement="top">
<Icon @click="remove(item)" type="md-trash" size="16"/>
<Icon size="16" type="md-trash" @click="remove(item)"/>
</Tooltip>
</div>
</div>
@ -173,31 +205,29 @@
</Card>
</div>
</div>
<Row type="flex" justify="end" class="mt_10">
<Row class="mt_10" justify="end" type="flex">
<Page
:current="searchForm.pageNumber"
:total="total"
:page-size="searchForm.pageSize"
@on-change="changePage"
@on-page-size-change="changePageSize"
:page-size-opts="pageSizeOpts"
size="small"
show-total
:total="total"
show-elevator
show-sizer
show-total
size="small"
@on-change="changePage"
@on-page-size-change="changePageSize"
></Page>
</Row>
</Card>
</Row>
<Modal
:title="modalTitle"
v-model="modalVisible"
:mask-closable="false"
:title="modalTitle"
:width="500"
>
<Form ref="form" :model="form" :label-width="95" :rules="formValidate">
<Form ref="form" :label-width="95" :model="form" :rules="formValidate">
<FormItem label="原文件名" prop="name">
<Input v-model="form.name"/>
</FormItem>
@ -207,10 +237,9 @@
</Form>
<div slot="footer">
<Button type="text" @click="handleCancel"></Button>
<Button type="primary" :loading="submitLoading" @click="handleSubmit"
<Button :loading="submitLoading" type="primary" @click="handleSubmit"
>提交
</Button
>
</Button>
</div>
</Modal>
@ -233,8 +262,8 @@
v-model="videoVisible"
:title="videoTitle"
:width="800"
@on-cancel="closeVideo"
draggable
@on-cancel="closeVideo"
>
<div id="dplayer"></div>
<div slot="footer">
@ -245,32 +274,96 @@
>
</div>
</Modal>
<!-- 添加分组修改分组编辑框 -->
<Modal
v-model="enableGroup"
:title="insertOrUpdate === 'insert' ? '添加分组' : '修改分组'"
:loading="groupLoading"
@on-ok="submitAddGroup"
footer-hide
>
<Form
ref="formValidate"
:label-width="80"
:model="groupFormValidate"
:rules="groupRuleValidate"
>
<FormItem label="所在分组" prop="id">
<Cascader
v-model="groupFormValidate.id"
:data="treeData"
change-on-select
></Cascader>
</FormItem>
<FormItem label="分组名称" prop="directoryName">
<Input v-model="groupFormValidate.directoryName"/>
</FormItem>
</Form>
<div class="modal-footer">
<Button @click="enableGroup = false">取消</Button>
<Button type="primary" @click="submitAddGroup"></Button>
</div>
</Modal>
</div>
</template>
<script>
import {
addFileDirectory,
deleteFile,
delFileDirectory,
getFileDirectory,
getFileListData,
renameFile,
deleteFile,
updateFileDirectory,
} from "@/api/index";
import DPlayer from "dplayer";
const config = require('@/config/index')
import { commonUrl } from "@/libs/axios";
var dp;
const config = require("@/config/index");
let dp;
export default {
name: "oss-manage",
props: {
isComponent: {
default: false,
type:Boolean
type: Boolean,
},
choose: {
type: String,
default: ""
}
},
data() {
return {
commonUrl, //
config, // api
fileDirectoryId: "",
groupFormValidate: {
id: [],
directoryName: "",
},
groupRuleValidate: {
directoryName: [
{
required: true,
message: "请输入分组名称",
trigger: "blur",
},
],
id: [
{
required: true,
message: "请选择分组",
trigger: "blur",
type: "array",
},
],
},
enableGroup: false, //
selectImage: false, //
accessToken: {}, // token
loading: false, //
@ -297,7 +390,8 @@ export default {
},
selectDate: null, // modal
oldKey: "", //
form: { //
form: {
//
name: "",
fileKey: "",
},
@ -318,32 +412,16 @@ export default {
width: 60,
align: "center",
},
{
title: "原文件名",
key: "name",
minWidth: 130,
sortable: true,
ellipsis: false,
tooltip: true,
},
{
title: "存储文件名",
key: "fileKey",
width: 165,
sortable: true,
ellipsis: false,
tooltip: true,
},
{
title: "缩略图(点击预览)",
key: "url",
width: 150,
width: 300,
align: "center",
render: (h, params) => {
if (params.row.fileType.includes("image") > 0) {
return h("img", {
attrs: {
src: params.row.url || '',
src: params.row.url || "",
alt: "加载图片失败",
},
style: {
@ -414,7 +492,6 @@ export default {
title: "文件类型",
key: "fileType",
width: 115,
sortable: true,
className: this.selectImage == true ? "none" : "",
},
{
@ -432,46 +509,39 @@ export default {
{
title: "上传者",
key: "createBy",
width: 120,
sortable: true,
width: 200,
render: (h, params) => {
let m = "";
if (params.row.userEnums == "MANAGER") {
m="[管理员]"
m = "[管理员]";
} else if (params.row.userEnums == "STORE") {
m="[店铺]"
m = "[店铺]";
} else {
m="[会员]"
m = "[会员]";
}
m += params.row.createBy
m += params.row.createBy;
return h("span", m);
},
},
{
title: "上传时间",
key: "createTime",
width: 180,
sortable: true,
sortType: "desc",
},
{
title: "操作",
key: "action",
align: "center",
fixed: "right",
width: 200,
// width: 300,
render: (h, params) => {
return h("div", [
h(
"Button",
{
props: {
type: "primary",
type: "default",
size: "small",
},
style: {
marginRight: "5px",
display: this.selectImage == true ? "inline-block" : "none",
display:
this.selectImage === true ? "inline-block" : "none",
},
on: {
click: () => {
@ -500,25 +570,6 @@ export default {
},
"下载"
),
h(
"Button",
{
props: {
size: "small",
type: 'success'
},
style: {
marginRight: "5px",
display: this.selectImage == true ? "none" : "inline-block",
},
on: {
click: () => {
this.rename(params.row);
},
},
},
"重命名"
),
h(
"Button",
{
@ -541,17 +592,301 @@ export default {
},
},
],
viewColumns: [
{
title: "缩略图(点击预览)",
key: "url",
// width: 150,
align: "center",
render: (h, params) => {
if (params.row.fileType.includes("image") > 0) {
return h("img", {
attrs: {
src: params.row.url || "",
alt: "加载图片失败",
},
style: {
cursor: "pointer",
width: "80px",
height: "60px",
margin: "10px 0",
"object-fit": "contain",
},
on: {
click: () => {
this.showPic(params.row);
},
},
});
} else if (params.row.fileType.includes("video") > 0) {
// 5MBvideo
if (params.row.fileSize < 1024 * 1024 * 5) {
return h(
"video",
{
style: {
cursor: "pointer",
width: "80px",
height: "60px",
margin: "10px 0",
"object-fit": "contain",
},
on: {
click: () => {
this.showVideo(params.row);
},
},
},
[
h("source", {
attrs: {
src: params.row.url,
},
}),
]
);
} else {
return h("img", {
attrs: {
src: require("@/assets/play.png"),
},
style: {
cursor: "pointer",
width: "80px",
height: "60px",
margin: "10px 0",
"object-fit": "contain",
},
on: {
click: () => {
this.showVideo(params.row);
},
},
});
}
} else {
return h("span", "非多媒体类型");
}
},
},
{
title: "上传者",
key: "createBy",
width: 120,
sortable: true,
render: (h, params) => {
let m = "";
if (params.row.userEnums == "MANAGER") {
m = "[管理员]";
} else if (params.row.userEnums == "STORE") {
m = "[店铺]";
} else {
m = "[会员]";
}
m += params.row.createBy;
return h("span", m);
},
},
{
title: "操作",
key: "action",
align: "center",
fixed: "right",
width: 300,
render: (h, params) => {
return h("div", [
h(
"Button",
{
props: {
type: "default",
size: "small",
},
style: {
marginRight: "5px",
display:
this.selectImage === true ? "inline-block" : "none",
},
on: {
click: () => {
this.selectedParams(params.row);
},
},
},
"选择"
)
]);
},
},
],
data: [], //
total: 0, //
pageSizeOpts: [5, 10, 20], //
list: [], //
//
treeData: [],
treeDataDefault: [],
selectedGroupData: "",
insertOrUpdate: "insert",
groupLoading: false,
};
},
watch: {
selectImage(val) {
if (val && !this.data.length) this.init()
if (val && !this.data.length) this.init();
},
choose(val) {
if (val) this.selectImage = val
}
},
methods: {
handleContextMenu(val) {
console.log("val", val);
this.selectedGroupData = val;
},
//
handleContextMenuEdit(val) {
this.insertOrUpdate = "update";
this.enableGroup = true;
// this.groupFormValidate = this.selectedGroupData;
this.groupFormValidate.directoryName = this.selectedGroupData.title;
this.groupFormValidate.id = [this.selectedGroupData.value];
this.groupFormValidate.level = this.selectedGroupData.level;
this.groupFormValidate.parentId = this.selectedGroupData.parentId;
console.log(this.groupFormValidate);
},
//
async handleContextMenuDelete(val) {
this.$Modal.confirm({
title: "提示",
content: "是否删除该分组",
onOk: async () => {
const res = await delFileDirectory(this.selectedGroupData.value);
if (res.success) {
this.$Message.success("删除成功!");
this.getAllList();
}
},
});
},
// /
async submitAddGroup() {
this.$refs["formValidate"].validate(async (valid) => {
if (valid) {
let res
const params = { ...this.groupFormValidate };
if (this.insertOrUpdate === "insert") {
// params.directoryType = this.selectedGroupData.directoryType
params.parentId = params.id[params.id.length - 1];
// params.type = this.selectedGroupData.type
params.level =
params.parentId == "0" ? 0 : this.selectedGroupData.level + 1;
delete params.id;
res = await addFileDirectory(params);
} else {
params.id = params.id[params.id.length - 1];
res = await updateFileDirectory(params);
}
if (res.success) {
this.$Message.success("操作成功!");
this.enableGroup = false;
this.getAllList();
}
this.$Modal.remove();
} else {
this.$Message.error("请填写完整信息!");
}
});
},
// /
handleClickAddGroup() {
this.insertOrUpdate = "insert";
if (this.selectedGroupData) {
this.groupFormValidate.id = [this.selectedGroupData.value];
} else {
this.groupFormValidate.id = ["0"];
}
this.enableGroup = true;
this.groupFormValidate.directoryName = "";
},
copyFileUrl(row) {
const textArea = document.createElement("textarea");
textArea.value = row.url;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand("copy");
this.$Message.success("复制成功");
} catch (err) {
console.error("Unable to copy to clipboard", err);
}
document.body.removeChild(textArea);
},
//
getAllList(parent_id) {
this.loading = true;
getFileDirectory(parent_id).then((res) => {
this.loading = false;
if (res.success) {
this.treeData = this.getTree(res.result);
this.treeDataDefault = this.getTree(res.result);
this.treeData.unshift({
title: "全部图片",
label: "全部分类",
value: "0",
level: 0,
children: [],
id: "0",
categoryId: 0,
});
}
});
},
//
getTree(tree = []) {
let arr = [];
if (!!tree && tree.length !== 0) {
tree.forEach((item) => {
let obj = {};
obj.title = item.directoryName;
obj.value = item.id; // id
obj.type = item.directoryType; //
obj.label = item.directoryName;
obj.level = item.level;
obj.expand = false;
obj.selected = false;
obj.contextmenu = true;
obj.parentId = item.parentId;
obj.children = this.getTree(item.children); //
arr.push(obj);
});
}
return arr;
},
//
handleCateChange(data) {
this.selectedGroupData = data[0];
let {value, type} = data[0];
this.list.push({
value,
type,
});
this.searchForm.fileDirectoryId = value;
if (value === "0") {
delete this.searchForm.fileDirectoryId;
}
this.searchForm.userEnums = type;
this.getDataList();
},
/**
* 选择
*/
@ -560,9 +895,9 @@ export default {
},
//
handleDropdown(name) {
if (name == "refresh") {
if (name === "refresh") {
this.getDataList();
} else if (name == "removeAll") {
} else if (name === "removeAll") {
this.removeAll();
}
},
@ -572,6 +907,7 @@ export default {
accessToken: this.getStore("accessToken"),
};
this.getDataList();
this.getAllList();
},
//
showPic(v) {
@ -725,13 +1061,16 @@ export default {
ids += e.id + ",";
});
ids = ids.substring(0, ids.length - 1);
deleteFile(ids).then((res) => {
deleteFile({ids: ids}).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("批量删除文件成功");
this.clearSelectAll();
this.getDataList();
}
})
.catch((err) => {
console.log("失败", err);
});
},
});
@ -743,13 +1082,13 @@ export default {
content: "您确认要删除文件 " + v.name + " ?",
loading: true,
onOk: () => {
deleteFile(v.id).then((res) => {
deleteFile({ids: v.id}).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("删除文件 " + v.name + " 成功");
this.getDataList();
}
});
})
},
});
},
@ -792,6 +1131,7 @@ export default {
},
//
clearSelectAll() {
console.log("清除选中状态");
this.$refs.table.selectAll(false);
this.totalSize = "";
},
@ -807,10 +1147,10 @@ export default {
},
},
mounted() {
if(!this.isComponent) { //
if (!this.isComponent) {
//
this.init();
}
},
};
</script>