商家端添加OSS资源素材管理

master
15386982806 2024-01-08 17:59:49 +08:00
parent c5d75a3570
commit b1f9c0adf2
3 changed files with 727 additions and 18 deletions

View File

@ -294,6 +294,7 @@
v-model="groupFormValidate.id"
:data="treeData"
change-on-select
@on-change="treeDataChange"
></Cascader>
</FormItem>
<FormItem label="分组名称" prop="directoryName">
@ -344,6 +345,7 @@ export default {
groupFormValidate: {
id: [],
level: 0,
directoryName: "",
},
groupRuleValidate: {
@ -742,7 +744,6 @@ export default {
methods: {
handleContextMenu(val) {
console.log("val", val);
this.selectedGroupData = val;
},
//
@ -757,7 +758,6 @@ export default {
this.groupFormValidate.level = this.selectedGroupData.level;
this.groupFormValidate.parentId = this.selectedGroupData.parentId;
console.log(this.groupFormValidate);
},
//
async handleContextMenuDelete(val) {
@ -773,6 +773,15 @@ export default {
},
});
},
treeDataChange(value, selectedData) {
if (value && value.length) {
if (value[value.length -1] == '0') {
this.groupFormValidate.level = 0;
} else {
this.groupFormValidate.level = Number(selectedData[selectedData.length -1].level) + 1;
}
}
},
// /
async submitAddGroup() {
this.$refs["formValidate"].validate(async (valid) => {
@ -784,8 +793,6 @@ export default {
// 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 {
@ -875,14 +882,14 @@ export default {
//
handleCateChange(data) {
this.selectedGroupData = data[0];
let {value, type} = data[0];
this.list.push({
value,
type,
});
let {value, type, level} = data[0];
this.list.push({value, type, level});
this.searchForm.fileDirectoryId = value;
if (value === "0") {
if (value === "0" || value === 0) {
delete this.searchForm.fileDirectoryId;
this.groupFormValidate.level = 0;
} else {
this.groupFormValidate.level = Number(level) + 1;
}
this.searchForm.userEnums = type;
this.getDataList();
@ -1061,7 +1068,7 @@ export default {
ids += e.id + ",";
});
ids = ids.substring(0, ids.length - 1);
deleteFile({ids: ids}).then((res) => {
deleteFile(ids).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("批量删除文件成功");
@ -1082,7 +1089,7 @@ export default {
content: "您确认要删除文件 " + v.name + " ?",
loading: true,
onOk: () => {
deleteFile({ids: v.id}).then((res) => {
deleteFile(v.id).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("删除文件 " + v.name + " 成功");
@ -1131,7 +1138,6 @@ export default {
},
//
clearSelectAll() {
console.log("清除选中状态");
this.$refs.table.selectAll(false);
this.totalSize = "";
},

View File

@ -387,3 +387,24 @@ export const editOtherUser = (id, params) => {
// export const searchDepartment = (params) => {
// return getRequest("/permission/department/search", 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,16 +1,698 @@
<template>
<div class="search">
<Card>
<Row @keydown.enter.native="handleSearch">
<Form ref="searchForm" :model="searchForm" inline :label-width="85" class="search-form">
<Form-item label="上传时间">
<DatePicker v-model="selectDate" type="daterange" format="yyyy-MM-dd" clearable
@on-change="selectDateRange" placeholder="选择起始时间" style="width: 200px"></DatePicker>
</Form-item>
<Button @click="handleSearch" type="primary" icon="ios-search" class="search-btn">搜索</Button>
</Form>
</Row>
<Row>
<div class="oss-operation padding-row">
<div>
OSS资源
ossManage
<Upload
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;margin-right: 5px;"
>
<Button type="primary">上传图片</Button>
</Upload>
<Dropdown @on-click="handleDropdown">
<Button>更多操作<Icon type="md-arrow-dropdown"/></Button>
<DropdownMenu slot="list">
<DropdownItem name="refresh">刷新</DropdownItem>
<DropdownItem name="removeAll">批量删除</DropdownItem>
</DropdownMenu>
</Dropdown>
</div>
</div>
</Row>
<!--<Row >-->
<Alert show-icon>
已选择<span >{{ selectCount }}</span>
<a class="select-clear" @click="clearSelectAll"></a>
<span v-if="selectCount > 0" style="margin-left: 15px"> {{ totalSize }} </span>
</Alert>
<!--</Row>-->
<Row 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
class="table"
sortable="custom"
@on-sort-change="changeSort"
@on-selection-change="changeSelect">
<template slot="fileKey" slot-scope="{ row }">
<a @click="copyFileUrl(row)">{{ row.fileKey }}</a>
</template>
</Table>
</Row>
<Row class="mt_10" justify="end" type="flex">
<Page
:current="searchForm.pageNumber"
:page-size="searchForm.pageSize"
:page-size-opts="pageSizeOpts"
:total="total"
show-elevator
show-sizer
show-total
size="small"
@on-change="changePage"
@on-page-size-change="changePageSize"
></Page>
</Row>
</Card>
<!--查看大图-->
<Modal v-model="picVisible" :title="picTitle" draggable>
<img :src="file.url" alt="无效的图片链接" style="width: 100%; margin: 0 auto; display: block"/>
<div slot="footer">
<span>文件类型{{file.fileType}} 文件大小{{file.msize}} 创建时间{{file.createTime}}</span>
</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 @on-change="treeDataChange"></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 { commonUrl } from "@/libs/axios";
const config = require('@/config/index');
import { getFileListData, deleteFile, getFileDirectory, addFileDirectory, delFileDirectory, updateFileDirectory } from "@/api/index";
export default {
name: "ossManage"
name: "ossManage",
data() {
return {
commonUrl, //
config, // api
accessToken: {}, // token
loading: false, //
searchForm: {
// data
name: "",
fileKey: "",
fileType: "",
pageNumber: 1, //
pageSize: 10, //
sort: "createTime", //
order: "desc", //
startDate: "", //
endDate: "", //
},
selectDate: null, // modal
oldKey: "", //
form: {
//
name: "",
fileKey: "",
},
file: {}, //
//
formValidate: {
name: [{required: true, message: "不能为空", trigger: "blur"}],
fileKey: [{required: true, message: "不能为空", trigger: "blur"}],
},
submitLoading: false, //
selectList: [], //
selectCount: 0, //
totalSize: "", //
columns: [
//
{type: "selection", width: 60, align: "center",},
{
title: "缩略图(点击预览)",
key: "url",
width: 300,
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: "fileType", width: 115, className: this.selectImage == true ? "none" : "",},
{
title: "文件大小",
key: "fileSize",
width: 115,
sortable: true,
className: this.selectImage == true ? "none" : "",
render: (h, params) => {
let m = ((params.row.fileSize * 1.0) / (1024 * 1024)).toFixed(2) + " MB";
return h("span", m);
},
},
{
title: "上传者",
key: "createBy",
width: 200,
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);},},
}, "选择"),
h("Button", {
props: {type: "info", size: "small",},
style: {marginRight: "5px", display: this.selectImage == true ? "none" : "inline-block",},
on: {click: () => {this.download(params.row);},},
}, "下载"),
h("Button", {
props: {type: "error", size: "small",},
style: {display: this.selectImage == true ? "none" : "inline-block",},
on: {click: () => {this.remove(params.row);},},
}, "删除"),
]);
},
},
],
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,
picVisible: false, // modal
picTitle: "", // title
enableGroup: false, //
groupFormValidate: {
id: [],
level: 0,
directoryName: "",
},
groupRuleValidate: {
directoryName: [{required: true, message: "请输入分组名称", trigger: "blur",},],
id: [{required: true, message: "请选择分组", trigger: "blur", type: "array",},],
},
}
},
props:{
isComponent:{
default: false,
type:Boolean
}
},
mounted() {
if(!this.isComponent) { //
this.init();
}
},
methods: {
//
init() {
this.accessToken = {
accessToken: this.getStore("accessToken"),
};
this.getDataList();
this.getAllList();
},
//
handleSearch() {
this.searchForm.title = this.searchForm.name;
this.searchForm.pageNumber = 1;
this.searchForm.pageSize = 5;
this.getDataList();
},
//
selectDateRange(v) {
if (v) {
this.searchForm.startDate = v[0];
this.searchForm.endDate = v[1];
}
},
//
changePage(v) {
this.searchForm.pageNumber = v;
this.getDataList();
this.clearSelectAll();
},
//
changePageSize(v) {
this.searchForm.pageNumber = 1;
this.searchForm.pageSize = v;
this.getDataList();
},
//
changeSort(e) {
this.searchForm.sort = e.key;
this.searchForm.order = e.order;
if (e.order == "normal") {
this.searchForm.order = "";
}
this.getDataList();
},
//
showPic(v) {
this.file = v;
this.file.msize = ((v.fileSize * 1.0) / (1024 * 1024)).toFixed(2) + " MB";
this.picTitle = v.name + "(" + v.fileKey + ")";
this.picVisible = true;
},
//
changeSelect(e) {
this.selectList = e;
this.selectCount = e.length;
let size = 0;
e.forEach((item) => {
size += item.fileSize * 1.0;
});
this.totalSize = ((size * 1.0) / (1024 * 1024)).toFixed(2) + " MB";
this.$emit("selected", e)
},
//
download(v) {
window.open(
v.url + "?attname=&response-content-type=application/octet-stream"
);
},
//
remove(v) {
this.$Modal.confirm({
title: "确认删除",
content: "您确认要删除文件 " + v.name + " ?",
loading: true,
onOk: () => {
deleteFile(v.id).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("删除文件 " + v.name + " 成功");
this.getDataList();
}
});
},
});
},
//
removeAll() {
if (this.selectCount <= 0) {
this.$Message.warning("您还未选择要删除的数据");
return;
}
this.$Modal.confirm({
title: "确认删除",
content: "您确认要删除所选的 " + this.selectCount + " 个文件?",
loading: true,
onOk: () => {
let ids = "";
this.selectList.forEach(function (e) {
ids += e.id + ",";
});
ids = ids.substring(0, ids.length - 1);
deleteFile(ids).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("批量删除文件成功");
this.clearSelectAll();
this.getDataList();
}
});
},
});
},
// OSS
getDataList() {
this.pageSizeOpts = [10, 20, 50];
this.loading = true;
getFileListData(this.searchForm).then((res) => {
this.loading = false;
this.data = res.result.records;
this.total = res.result.total;
});
},
//
handleMaxSize(file) {
this.$Notice.warning({
title: "文件大小过大",
desc: "所选文件大小过大, 不得超过 1M.",
});
},
//
handleSuccess(res, file) {
if (res.success) {
this.$Message.success("上传文件 " + file.name + " 成功");
this.getDataList();
} else {
this.$Message.error(res.message);
}
},
//
handleError(error, file, fileList) {
this.$Message.error(error.toString());
},
//
clearSelectAll() {
this.$refs.table.selectAll(false);
this.totalSize = "";
},
//
handleDropdown(name) {
if (name === "refresh") {
this.getDataList();
} else if (name === "removeAll") {
this.removeAll();
}
},
handleContextMenu(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;
},
//
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();
}
},
});
},
//
handleCateChange(data) {
this.selectedGroupData = data[0];
let {value, type, level} = data[0];
this.list.push({value, type, level});
this.searchForm.fileDirectoryId = value;
if (value === "0" || value === 0) {
delete this.searchForm.fileDirectoryId;
this.groupFormValidate.level = 0;
} else {
this.groupFormValidate.level = Number(level) + 1;
}
this.searchForm.userEnums = type;
this.getDataList();
},
treeDataChange(value, selectedData) {
if (value && value.length) {
if (value[value.length -1] == '0') {
this.groupFormValidate.level = 0;
} else {
this.groupFormValidate.level = Number(selectedData[selectedData.length -1].level) + 1;
}
}
},
// /
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
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;
},
}
}
</script>
<style scoped>
<style lang="scss">
//
@import "@/styles/table-common.scss";
.export {
margin: 10px 20px 10px 0;
}
.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>