diff --git a/src/util/util.js b/src/util/util.js index 54891d0..0ce4521 100644 --- a/src/util/util.js +++ b/src/util/util.js @@ -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); } } diff --git a/src/views/CardDetail.vue b/src/views/CardDetail.vue index bf58c22..cb696e2 100644 --- a/src/views/CardDetail.vue +++ b/src/views/CardDetail.vue @@ -36,6 +36,12 @@ {{$t('breed')}} + + 点击上传 +
@@ -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() { @@ -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();