Browse Source

修改

master
wen 2 years ago
parent
commit
02f35ff764
  1. 9
      src/api/user.js
  2. BIN
      src/common/img/file.png
  3. 19
      src/layout/components/Sidebar/index.vue
  4. 3
      src/utils/request.js
  5. 339
      src/views/subfile/index.vue

9
src/api/user.js

@ -42,3 +42,12 @@ export function uploadrequest(datas) { @@ -42,3 +42,12 @@ export function uploadrequest(datas) {
data: datas
})
}
// 删除目录
export function rmdirs(datas) {
return request({
url: '/api/rmdir',
method: 'post',
data: datas
})
}

BIN
src/common/img/file.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

19
src/layout/components/Sidebar/index.vue

@ -112,7 +112,6 @@ export default { @@ -112,7 +112,6 @@ export default {
let thiss = this;
//console.log(1);
// console.log(this.$store);
mirlist().then(response => {
let datamain = response.data;
this.routes[1].children = this.SplicingMenuTree(datamain.data.menus);
@ -122,13 +121,19 @@ export default { @@ -122,13 +121,19 @@ export default {
//this.$router.push({path: '/filemange/subfile?id='+dirTree.id});
}
}).catch(function (error) {
thiss.$message({
showClose: true,
message: error,
type: 'error'
});
if (error.response) {
if (error.response.status == 401) {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
thiss.$router.push({path: '/login'});
return;
}
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
} else if (error.request) {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
} else {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
}
});
}
}

3
src/utils/request.js

@ -7,7 +7,8 @@ import axios from 'axios' @@ -7,7 +7,8 @@ import axios from 'axios'
const service = axios.create({
//baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests
headers: { 'Content-Type': 'multipart/form-data' },
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
// headers: { 'Content-Type': 'multipart/form-data' },
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded'
// },

339
src/views/subfile/index.vue

@ -15,55 +15,118 @@ @@ -15,55 +15,118 @@
</div> -->
<div>
<!-- 目录数据列表 -->
<div class="folder_bottom">
<!-- <span>目录</span> -->
<!-- <div class="folder_bottom">
<a v-for="data in dirdata" :key="data.id" :href="'#/filemange/subfile?id='+data.id"><el-button type="warning" icon="el-icon-notebook-1">{{data.directory}}</el-button></a>
</div>
</div> -->
<div class="use_button textright">
<el-button type="primary" icon="el-icon-edit" @click="dirbox = true">创建目录</el-button>
<el-button type="primary" icon="el-icon-edit" @click="rmdirm">删除目录</el-button>
<el-button type="primary" icon="el-icon-edit">重命名</el-button>
<el-button type="primary" @click="drawer = true">上传<i class="el-icon-upload el-icon--right"></i></el-button>
<!-- <el-button type="primary" icon="el-icon-edit" @click="rmdirm">删除目录</el-button>
<el-button type="primary" icon="el-icon-edit">重命名</el-button> -->
<el-button type="primary" @click="uploadDrawer = true">上传<i class="el-icon-upload el-icon--right"></i></el-button>
</div>
<!-- 文件数据列表 -->
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column
prop="date"
label="时间"
width="auto">
</el-table-column>
<el-table-column
label="图片"
width="auto">
<template slot-scope="scope">
<img :src="'http://192.168.0.100/'+scope.row.image" alt="图片"/>
</template>
</el-table-column>
<el-table-column
prop="name"
label="名称">
</el-table-column>
<el-table-column
label="操作">
<div class="file_caozuo vercenter">
<el-button size="mini">重命名</el-button>
<el-button size="mini">下载</el-button>
</div>
<div class="file_caozuo2 vercenter">
<el-button size="mini">移动</el-button>
<el-button size="mini" type="danger">删除</el-button>
</div>
</el-table-column>
</el-table>
<div v-on:click="fileTableMClick">
<!-- 子目录数据列表 如果不需要显示空数据提示可以用css隐藏-->
<el-table
:data="dirdata"
empty-text="暂无子目录数据"
border
style="width: 100%" class="filesmd">
<!-- <el-table-column
align="center"
prop="date"
label="时间"
width="auto">
</el-table-column> -->
<el-table-column
align="center"
prop="name"
label="名称">
</el-table-column>
<el-table-column
align="center"
label="类型"
width="auto">
<template slot-scope="scope">
<div class="type_file_click">
<a :href="'#/filemange/subfile?id='+scope.row.id">
<!-- <el-button type="warning" icon="el-icon-notebook-1">{{scope.row.name}}</el-button> -->
<img src="../../common/img/file.png" alt="图片"/>
</a>
</div>
</template>
</el-table-column>
<el-table-column
align="center"
label="操作"
width="auto">
<template slot-scope="scope">
<div class="file_caozuo">
<el-button size="mini">重命名</el-button>
<!-- <el-button size="mini">下载</el-button> -->
</div>
<div class="file_caozuo2">
<el-button size="mini">移动</el-button>
<el-button size="mini" mark="dirdelete" :names="scope.row.id" type="danger">删除</el-button>
</div>
</template>
</el-table-column>
</el-table>
<!-- 文件数据列表 -->
<el-table
:show-header="false"
empty-text="暂无文件数据"
:data="tableData"
border
style="width: 100%;">
<!-- <el-table-column
align="center"
prop="date"
label="时间"
width="auto">
</el-table-column> -->
<el-table-column
align="center"
prop="name"
label="名称">
</el-table-column>
<el-table-column
align="center"
label="图片"
width="auto">
<template slot-scope="scope">
<img :src="'http://192.168.0.100/'+scope.row.image" alt="图片"/>
</template>
</el-table-column>
<el-table-column
align="center"
label="操作">
<div class="file_caozuo">
<el-button size="mini">重命名</el-button>
<!-- <el-button size="mini">下载</el-button> -->
</div>
<div class="file_caozuo2">
<el-button size="mini">移动</el-button>
<el-button size="mini" type="danger">删除</el-button>
</div>
</el-table-column>
</el-table>
</div>
<!-- 创建目录弹框 -->
</div>
<!-- 创建目录弹框 -->
<el-dialog title="创建目录" :visible.sync="dirbox">
<el-form :model="dirform">
<el-form-item label="目录名称" :label-width="formLabelWidth">
@ -80,32 +143,33 @@ @@ -80,32 +143,33 @@
<el-button type="primary" @click="mkdirs" :loading="mkdirloadings"> </el-button>
</div>
</el-dialog>
</div>
<el-drawer
title="上传图片"
:visible.sync="drawer"
:visible.sync="uploadDrawer"
:direction="direction"
size="100%"
>
<el-upload
action=""
:limit="1"
list-type="picture-card"
:on-remove="handleRemove"
:on-exceed="fileexceed"
:multiple="false"
:multiple="true"
:on-change="filechange"
:on-preview="handlePictureCardPreview"
:disabled="false"
accept=".jpg, .jpeg, .png, .gif"
:auto-upload="false">
<i slot="default" class="el-icon-plus"></i>
<span class="addimgtext">添加照片</span>
</el-upload>
<div class="request_main">
<el-button type="success" @click="UploadRequest(file)">开始上传<i class="el-icon-upload el-icon--right"></i></el-button>
<el-button type="success" :loading="uploadLoad" @click="UploadRequest()">开始上传<i class="el-icon-upload el-icon--right"></i></el-button>
</div>
<div class="el-upload__tip">只能上传.jpg, .jpeg, .png, .gif文件且不超过500kb</div>
<el-dialog :visible.sync="dialogVisible">
<div class="el-upload__tip">只能上传.jpg, .jpeg, .png, .gif文件且不超过5MB</div>
<el-dialog :modal="false" :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="图片">
</el-dialog>
</el-drawer>
@ -115,7 +179,7 @@ @@ -115,7 +179,7 @@
<script>
import EventBus from '@/utils/EventBus.js'
import { mirlist, mkdir, uploadrequest} from '@/api/user'
import { mirlist, mkdir, uploadrequest, rmdirs} from '@/api/user'
import defaultSettings from '@/settings.js'
export default {
@ -189,18 +253,25 @@ export default { @@ -189,18 +253,25 @@ export default {
mkdirloadings: false,
//
drawer: false,
uploadDrawer: false,
direction: 'ttb',
//
dialogImageUrl: '',
dialogVisible: false,
disabled: false
disabled: false,
imgUploadData: {
name: '',
file: '',
parent: ''
},
uploadLoad: false
};
},
methods: {
//
handleRemove(file, fileList) {
console.log(fileList);
//this.$refs.upload.clearFiles;
},
handlePictureCardPreview(file) {
@ -215,30 +286,92 @@ export default { @@ -215,30 +286,92 @@ export default {
},
//
fileexceed(files, fileList) {
this.$message({showClose:true, message:'一次只能上传一个文件', type:'warning'});
//this.$message({showClose:true, message:` 1 ${files.length} ${files.length + fileList.length} `, type:'warning'});
this.$message({showClose:true, message:`当前版本限制上传一个文件`, type:'warning'});
//this.$message.warning(``);
},
filechange(files, fileList) {
console.log(files);
console.log(fileList);
//console.log(files);
const isLt2M = files.size / 1024 / 1024 < 5;
if (!isLt2M) {
this.$message.error('文件大小不能超过 5MB!'+files.name+'已超过,重新选择');
fileList.splice(-1, 1); //
//window.setTimeout(() => {fileList.splice(-1, 1);}, 3000);
//console.log(fileList);
return;
}
//
this.imgUploadData.name = files.name;
this.getBase64(files.raw).then(res => {
//this.dialogImageUrl = 1;
this.imgUploadData.file = res;
//console.log(res)
})
},
UploadRequest(file) {
// base64
getBase64(file) {
let thiss = this;
console.log(file);
uploadrequest().then(response => {
let datamain = response.data;
return new Promise(function(resolve, reject) {
if (window.FileReader && file) {
let reader = new FileReader();
let imgResult = "";
reader.readAsDataURL(file);
reader.onload = function() {
imgResult = reader.result;
};
reader.onerror = function(error) {
reject(error);
};
reader.onloadend = function() {
resolve(imgResult);
};
} else {
thiss.$message({showClose: true,message: '获取base64出错',type: 'error'});
}
}).catch(function (error) {
});
// if (window.FileReader && file) {
// //
// var reader = new FileReader();
// //
// reader.readAsDataURL(file);
// //
// reader.onloadend = function(e) {
// //base64
// let imgBase64 = e.target.result;
// console.log(imgBase64);
// }
// }
},
//
UploadRequest() {
let thiss = this;
//console.log(file);
this.uploadLoad = true;
uploadrequest(this.imgUploadData).then(response => {
let datamain = response.data;
if (datamain.code == 1) {
console.log(datamain);
this.$message({showClose: true,message: datamain.msg, type:'success'});
this.uploadDrawer = false;
this.getFileData();
}
this.uploadLoad = false;
}).catch(error => {
if (error.response) {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
this.uploadLoad = false;
} else if (error.request) {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
} else {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
}
});
},
getFileData() {
@ -259,7 +392,7 @@ export default { @@ -259,7 +392,7 @@ export default {
this.dirdata = []
this.tableData = []
if (maindata.directories) {
this.dirdata = maindata.directories;
this.dirdata = this.forObjectData(maindata.directories);
}
if (maindata.files) {
@ -270,13 +403,16 @@ export default { @@ -270,13 +403,16 @@ export default {
this.dirform.parent = maindata.realpath;
this.subloading = false;
this.imgUploadData.parent = maindata.realpath;
}
}).catch(error => {
if (error.response) {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
} else if (error.request) {
thiss.$message({showClose: true,message: error,type: 'error'});
} else {
thiss.$message({showClose: true,message: error.message,type: 'error'});
}
}).catch(function (error) {
thiss.$message({
showClose: true,
message: error,
type: 'error'
});
});
},
@ -288,7 +424,8 @@ export default { @@ -288,7 +424,8 @@ export default {
newObject = {
date: '2016-05-03',
image: objectd[item].path,
name: objectd[item].filename
name: objectd[item].filename || objectd[item].directory,
id: objectd[item].id
}
arrObjs.push(newObject);
@ -300,32 +437,44 @@ export default { @@ -300,32 +437,44 @@ export default {
//
mkdirs() {
let thiss = this;
if (!this.dirform.dir) {
thiss.$message({showClose: true,message: '目录名不能为空',type: 'error'});
return;
}
this.mkdirloadings = true;
EventBus.$emit('mkdirSuccess');
mkdir(this.dirform).then(response => {
let datamain = response.data;
let maindata = datamain.data.dirTree;
if (datamain.code == 1) {
EventBus.$emit('mkdirSuccess'); //
this.getFileData();
this.dirform.dir = '';
thiss.$message({showClose: true,message: '创建成功',type: ''});
//this.subloading = false;
}
this.mkdirloadings = false;
this.dirbox = false;
}).catch(function (error) {
thiss.$message({
showClose: true,
message: error,
type: 'error'
});
}).catch(error => {
if (error.response) {
thiss.mkdirloadings = false;
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
} else if (error.request) {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
} else {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
}
});
},
//
rmdirm() {
let thiss = this;
this.rmdirloadings = true;
mkdir(this.dirform).then(response => {
this.dirform.dir = 'test';
rmdirs(this.dirform).then(response => {
let datamain = response.data;
let maindata = datamain.data.dirTree;
if (datamain.code == 1) {
@ -335,14 +484,31 @@ export default { @@ -335,14 +484,31 @@ export default {
}
this.dirbox = false;
}).catch(function (error) {
thiss.$message({
showClose: true,
message: error,
type: 'error'
});
}).catch(error => {
if (error.response) {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
} else if (error.request) {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
} else {
thiss.$message({showClose: true,message: error.response.data.err,type: 'error'});
}
});
}
},
fileTableMClick(e) {
let dangQian = e.target, labelname = dangQian.tagName.toLowerCase(), chufazhe = e.currentTarget; //currentTarget
let objmark = dangQian.getAttribute('mark');
if (labelname == 'span') {
//console.log(dangQian.parentNode);
objmark = dangQian.parentNode.getAttribute('mark');
}
//
if (objmark == 'dirdelete') {
this.rmdirm();
}
//console.log(dangQian);
}
}
}
</script>
@ -354,7 +520,7 @@ export default { @@ -354,7 +520,7 @@ export default {
.sou_bottom{margin-left:10px;}
.use_button{margin:15px 0 16px 0;}
// .use_button>button{margin:0 10px 10px 0;}
.file_caozuo2{margin:6px 0 0 0;}
.file_caozuo2>button{margin-top:6px;}
.el-table td{padding:9px 0}
.folder_bottom a{margin:0 6px;}
.el-table__body-wrapper img{width:100px;height:71px;}
@ -362,5 +528,6 @@ export default { @@ -362,5 +528,6 @@ export default {
.request_main{text-align:center;margin:12px 0;}
.addimgtext{line-height:25px;display:inline-block;color:#8c939d;vertical-align: middle;}
.el-upload--picture-card i{vertical-align:middle;}
.type_file_click img{width:64px;height:48px;}
}
</style>

Loading…
Cancel
Save