Skip to content

Commit

Permalink
add upload file
Browse files Browse the repository at this point in the history
  • Loading branch information
shellteo committed Jan 7, 2019
1 parent 78fb703 commit 6727758
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export default {
for (let k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
},
uniqueid() {
let idstr = String.fromCharCode(Math.floor((Math.random() * 25) + 65));
do {
let ascicode = Math.floor((Math.random() * 42) + 48);
if (ascicode < 58 || ascicode > 64) {
idstr += String.fromCharCode(ascicode);
}
} while (idstr.length < 32);
return (idstr);
}

}
Expand Down
34 changes: 32 additions & 2 deletions src/views/CardDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<a class="btn btn-plain" @click="showBreed = true" v-if="!isOwner && isRental">
<span>{{$t('breed')}}</span>
</a>
<el-upload
action="string"
:http-request="handleUploadImage"
:file-list="fileList">
<el-button size="small" type="primary">点击上传</el-button>
</el-upload>
</div>
</div>
<div class="detail fixed-width">
Expand Down Expand Up @@ -258,7 +264,7 @@
import * as echarts from 'echarts/lib/echarts';
import 'echarts/lib/chart/line';
import 'echarts/lib/component/tooltip';
import axios from 'axios'
export default {
name: 'Detail',
data() {
Expand Down Expand Up @@ -327,13 +333,37 @@
currentAddress: '',
currentPrice: '',
hasIdol: true,
myIdolList: []
myIdolList: [],
fileList: []
}
},
created() {
this.id = this.$route.params.id;
},
methods: {
handleUploadImage(params) {
let reader = new FileReader();
reader.readAsDataURL(params.file);
reader.onload = (e) => {
let formData = new FormData();
formData.append('image', e.target.result);
formData.append('id', this.util.uniqueid());
formData.append('do_waifu2x', false);
let loading = this.$loading({
fullscreen: true,
background: 'rgba(0, 0, 0, 0.5)',
text: '文件上传中...'
});
axios.request({
url: 'http://47.74.229.37:8000/post',
method: 'post',
data: formData
}).then((res) => {
loading.close();
console.log(res)
})
}
},
updatePage() {
setTimeout(() => {
this.getDetail();
Expand Down

0 comments on commit 6727758

Please sign in to comment.