Commit 496a1c4c authored by 吴冠's avatar 吴冠

last

parent aad5a28f
<template> <template>
<div class="hello"> <div class="hello">
<el-upload <el-upload
:http-request="handleUpload"   
:on-preview="handlePreview"
:on-remove="handleRemove" :on-remove="handleRemove"
:on-success="handleSuccess" :on-success="handleSuccess"
:before-remove="beforeRemove" :before-remove="beforeRemove"
:limit="limit" :show-file-list="false"
:on-exceed="handleExceed"
:file-list="fileList"
:list-type="listType"
:accept="accept" :accept="accept"
:before-upload="beforeUpload"
class="upload-demo" class="upload-demo"
action action="Fake Action"
:http-request="handleUpload"
multiple multiple
> >
<el-button size="small" type="primary">点击上传</el-button> <el-button size="small" type="primary" v-loading.fullscreen.lock="loading">点击上传</el-button>
<div slot="tip" class="el-upload__tip">{{ tip }}</div> <div slot="tip" class="el-upload__tip">
{{ tip }}
</div>
</el-upload> </el-upload>
<ul>
<li class="flex-item link" v-for="(item, index) in fileList" :key="index">
<el-popover placement="top-start" title="文件名称" width="500" trigger="hover" :content="item.name">
<div class="upload" slot="reference">
<a :href="item.url" target="_blank">{{ item.name }}</a>
</div>
</el-popover>
<div @click="handleDelete(index, item)">删除</div>
</li>
</ul>
</div> </div>
</template> </template>
<script> <script>
import { put, getFileNameUUID } from "~/api/ali-oss"; import { put, getFileNameUUID } from '@/api/ali-oss';
export default { export default {
name: "Upload", name: 'Upload',
props: { props: {
accept: { accept: {
type: String, type: String,
default: ".pdf,.jpg,.jpeg,.zip,.rar,.doc,.docx", default: '.pdf,.jpg,.jpeg,.zip,.rar,.doc,.docx,.JPEG'
}, },
tip: { tip: {
type: String, type: String,
default: "上传大小不能超过2M", default: '上传大小不能超过80M'
}, },
limit: { limit: {
type: Number, type: Number,
default: 5, default: 3
}, },
action: { action: {
type: String, type: String,
default: "", default: ''
}, },
headers: { headers: {
type: Object, type: Object,
default: () => {}, default: () => {}
},
fileList: {
type: Array,
default: () => []
}, },
name: { name: {
type: String, type: String,
default: "", default: ''
}, },
listType: { listType: {
type: String, type: String,
default: "text", default: 'text'
}, },
max: { max: {
type: Number, type: Number,
default: 10, default: 100
}, }
fileList: {
type: Array,
default: () => [],
},
}, },
data() { data() {
return {}; return {
loading: false
};
},
created() {
console.log(this.fileList);
}, },
methods: { methods: {
emitInput(fileList) { emitInput(fileList) {
...@@ -76,58 +91,77 @@ export default { ...@@ -76,58 +91,77 @@ export default {
message.url = fileList[i].url; message.url = fileList[i].url;
message.fileName = fileList[i].name; message.fileName = fileList[i].name;
message.fileUrl = fileList[i].url; message.fileUrl = fileList[i].url;
message.uid = fileList[i].uid;
value.push(message); value.push(message);
} }
this.$emit("input", value); console.log(value);
this.$emit('input', value);
}, },
beforeUpload(file) { beforeUpload(file) {
const max = this.max; const max = this.max;
const isLt2M = file.size / 1024 / 1024 < max; const isLt2M = file.size / 1024 / 1024 < max;
if (!isLt2M) { if (!isLt2M) {
this.$message.error(`上传附件大小不能超过 ${max} MB!`); this.$message.error(`上传附件大小不能超过 ${max} MB!`);
return;
}
if (this.fileList.length == this.limit) {
this.$message.warning(`每次只能上传 ${this.limit} 个文件`);
return;
} }
return isLt2M; this.loading=true
// 生成的文件名称
let objName = getFileNameUUID();
// 调用 ali-oss 中的方法
put(`${objName}${file.name}`, file).then((res) => {
console.log(res);
this.fileList.push(res);
this.emitInput(this.fileList);
this.loading=false
});
}, },
handleRemove(file, fileList, index) { handleRemove(file, fileList, index) {
this.$emit("on-remove", file, fileList); this.$emit('on-remove', file, fileList);
this.fileList = fileList; this.fileList = fileList;
this.emitInput(fileList); this.emitInput(fileList);
}, },
handlePreview(file) {
this.$emit("on-preview", file);
},
handleExceed(files, fileList) {
this.$message.warning(`每次只能上传 ${this.limit} 个文件`);
},
beforeRemove(file, fileList) { beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`); return this.$confirm(`确定移除 ${file.name}?`);
}, },
handleSuccess(response, file, fileList) { handleSuccess(response, file, fileList) {
console.log("成功"); console.log('成功');
this.fileList = fileList;
this.$emit("on-success", file, fileList);
}, },
/** /**
* 自定义上传方法 * 自定义上传方法
*/ */
handleUpload(option) { handleDelete(index, item) {
const max = this.max; this.$confirm(`确定要删除${item.name}么?`, '提示', {
const isLt2M = option.file.size / 1024 / 1024 < max; type: 'warning'
if (isLt2M) { })
// 生成的文件名称 .then(() => {
let objName = getFileNameUUID(); this.$message.success('删除成功');
// 调用 ali-oss 中的方法 this.fileList.splice(index, 1);
put(`${objName}${option.file.name}`, option.file).then( this.$emit('input', this.fileList);
(res) => { })
res.fileName = res.name; .catch(() => {});
res.fileUrl = res.url;
this.fileList.push(res);
this.emitInput(this.fileList);
}
);
}
}, },
},
handleUpload(option) {
console.log(option.file);
}
}
}; };
</script> </script>
<style scoped></style>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.upload {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin-right: 30px;
width: 100px;
}
</style>
...@@ -218,8 +218,9 @@ export default { ...@@ -218,8 +218,9 @@ export default {
}, },
//返回 //返回
returnPrev() { returnPrev() {
/* Cookies.set() */
this.isList = true; this.isList = true;
if(Cookies.get("status")){ /* if(Cookies.get("status")){
let mess = {} let mess = {}
mess.cateId = this.detailsId mess.cateId = this.detailsId
this.getListContent(mess); this.getListContent(mess);
...@@ -228,7 +229,7 @@ export default { ...@@ -228,7 +229,7 @@ export default {
let mess = {} let mess = {}
mess.cateId = this.detailsId mess.cateId = this.detailsId
this.getListContent(mess); this.getListContent(mess);
} } */
/* if(this.activeName =='124'){ /* if(this.activeName =='124'){
let mess = {} let mess = {}
mess.cateId = 124 mess.cateId = 124
...@@ -236,8 +237,8 @@ export default { ...@@ -236,8 +237,8 @@ export default {
} */ } */
/* console.log(this.detailsId) /* console.log(this.detailsId)
this.getListContent(mess); */ this.getListContent(mess); */
Cookies.remove("status") /* Cookies.remove("status")
Cookies.remove("contentStatus") Cookies.remove("contentStatus") */
}, },
}, },
}; };
......
...@@ -824,7 +824,7 @@ export default { ...@@ -824,7 +824,7 @@ export default {
fileList: [], fileList: [],
flag: true, //该值变化,就会触发刷新 flag: true, //该值变化,就会触发刷新
code: "", //刷新后的验证码 code: "", //刷新后的验证码
active: 0, active: 1,
checked: true, checked: true,
adminform: { adminform: {
name: "", name: "",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment