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 18, 2018
1 parent
d444433
commit dce85e2
Showing
3 changed files
with
123 additions
and
6 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,7 @@ | ||
import request from '@/utils/request' | ||
export function policy() { | ||
return request({ | ||
url:'/aliyun/oss/policy', | ||
method:'get', | ||
}) | ||
} |
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,107 @@ | ||
<template> | ||
<div> | ||
<el-upload | ||
action="https://macro-oss.oss-cn-shenzhen.aliyuncs.com" | ||
:data="dataObj" | ||
list-type="picture" | ||
:multiple="false" :show-file-list="showFileList" | ||
:file-list="fileList" | ||
:before-upload="beforeUpload" | ||
:on-remove="handleRemove" | ||
:on-success="handleUploadSuccess" | ||
:on-preview="handlePreview"> | ||
<el-button size="small" type="primary">点击上传</el-button> | ||
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过10MB</div> | ||
</el-upload> | ||
<el-dialog :visible.sync="dialogVisible"> | ||
<img width="100%" :src="fileList[0].url" alt=""> | ||
</el-dialog> | ||
</div> | ||
</template> | ||
<script> | ||
import {policy} from '@/api/oss' | ||
export default { | ||
name: 'singleUpload', | ||
props: { | ||
value: String | ||
}, | ||
computed: { | ||
imageUrl() { | ||
return this.value; | ||
}, | ||
imageName() { | ||
if (this.value != null && this.value !== '') { | ||
return this.value.substr(this.value.lastIndexOf("/") + 1); | ||
} else { | ||
return null; | ||
} | ||
}, | ||
fileList() { | ||
return [{ | ||
name: this.imageName, | ||
url: this.imageUrl | ||
}] | ||
}, | ||
showFileList: { | ||
get: function () { | ||
return this.value !== null && this.value !== ''; | ||
}, | ||
set: function (newValue) { | ||
} | ||
} | ||
}, | ||
data() { | ||
return { | ||
dataObj: { | ||
policy: '', | ||
signature: '', | ||
key: '', | ||
ossaccessKeyId: '', | ||
dir: '', | ||
host: '' | ||
}, | ||
dialogVisible: false | ||
}; | ||
}, | ||
methods: { | ||
emitInput(val) { | ||
this.$emit('input', val) | ||
}, | ||
handleRemove(file, fileList) { | ||
this.emitInput(''); | ||
}, | ||
handlePreview(file) { | ||
this.dialogVisible = true; | ||
}, | ||
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.showFileList = true; | ||
this.fileList.pop(); | ||
this.fileList.push({name: file.name, url: this.dataObj.host + '/' + this.dataObj.dir + '/' + file.name}); | ||
this.emitInput(this.fileList[0].url); | ||
} | ||
} | ||
} | ||
</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