forked from macrozheng/mall-admin-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhh
committed
May 31, 2018
1 parent
bd7b632
commit a7d2085
Showing
3 changed files
with
179 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<template> | ||
<div> | ||
<el-upload | ||
action="http:https://macro-oss.oss-cn-shenzhen.aliyuncs.com" | ||
:data="dataObj" | ||
list-type="picture-card" | ||
:file-list="fileList" | ||
:before-upload="beforeUpload" | ||
:on-remove="handleRemove" | ||
:on-success="handleUploadSuccess" | ||
:on-preview="handlePreview" | ||
:limit="maxCount" | ||
:on-exceed="handleExceed" | ||
> | ||
<i class="el-icon-plus"></i> | ||
</el-upload> | ||
<el-dialog :visible.sync="dialogVisible"> | ||
<img width="100%" :src="dialogImageUrl" alt=""> | ||
</el-dialog> | ||
</div> | ||
</template> | ||
<script> | ||
import {policy} from '@/api/oss' | ||
export default { | ||
name: 'multiUpload', | ||
props: { | ||
//图片属性数组 | ||
value: Array, | ||
//最大上传图片数量 | ||
maxCount:{ | ||
type:Number, | ||
default:5 | ||
} | ||
}, | ||
data() { | ||
return { | ||
dataObj: { | ||
policy: '', | ||
signature: '', | ||
key: '', | ||
ossaccessKeyId: '', | ||
dir: '', | ||
host: '' | ||
}, | ||
dialogVisible: false, | ||
dialogImageUrl:null | ||
}; | ||
}, | ||
computed: { | ||
fileList() { | ||
let fileList=[]; | ||
for(let i=0;i<this.value.length;i++){ | ||
fileList.push({url:this.value[i]}); | ||
} | ||
return fileList; | ||
} | ||
}, | ||
methods: { | ||
emitInput(fileList) { | ||
let value=[]; | ||
for(let i=0;i<fileList.length;i++){ | ||
value.push(fileList[i].url); | ||
} | ||
this.$emit('input', value) | ||
}, | ||
handleRemove(file, fileList) { | ||
this.emitInput(fileList); | ||
}, | ||
handlePreview(file) { | ||
this.dialogVisible = true; | ||
this.dialogImageUrl=file.url; | ||
}, | ||
beforeUpload(file) { | ||
let _self = this; | ||
return new Promise((resolve, reject) => { | ||
policy().then(response => { | ||
_self.dataObj.policy = response.data.policy; | ||
_self.dataObj.signature = response.data.signature; | ||
_self.dataObj.ossaccessKeyId = response.data.accessKeyId; | ||
_self.dataObj.key = response.data.dir + '/${filename}'; | ||
_self.dataObj.dir = response.data.dir; | ||
_self.dataObj.host = response.data.host; | ||
resolve(true) | ||
}).catch(err => { | ||
console.log(err) | ||
reject(false) | ||
}) | ||
}) | ||
}, | ||
handleUploadSuccess(res, file) { | ||
this.fileList.push({url: file.name,url:this.dataObj.host + '/' + this.dataObj.dir + '/' + file.name}); | ||
this.emitInput(this.fileList); | ||
}, | ||
handleExceed(files, fileList) { | ||
this.$message({ | ||
message: '最多只能上传'+this.maxCount+'张图片', | ||
type: 'warning', | ||
duration:1000 | ||
}); | ||
}, | ||
} | ||
} | ||
</script> | ||
<style> | ||
</style> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters