1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| let app = new Vue({ el: '#app', data: { imgSrc: '', }, created: function () {
}, methods: { upload: function (event) { var _self = this; var file = event.target.files[0]; var param = new FormData(); param.append('file', file); param.append('fileType', '3');
axios({ method: 'post', url: '/api/file/upload', headers: {'Content-Type':'multipart/form-data'}, data: param }).then(function(response) { var data = response.data; console.log(response); }); }, download: function () { axios({ method: 'post', url: '/api/file/download', data: { id: '855C4C501F6F4BEAABAC3ACCAA9ADC8F' } }).then(response => { let contentDisposition = response.headers['content-disposition']; let fileName = contentDisposition.substring(contentDisposition.indexOf('=') + 1); let data = this.dataURLtoBlob(response.data.data); let url = window.URL.createObjectURL(new Blob([data])); let link = document.createElement('a'); link.href = url; this.imgSrc = url; link.setAttribute('download', decodeURIComponent(fileName)); document.body.appendChild(link); link.click(); }).catch(error => { alert("文件下载失败"); console.log(error); }); }, dataURLtoBlob: function (dataurl) { try { let arr = dataurl.split(','); let mime = arr[0].match(/:(.*?);/)[1]; let bstr = atob(arr[1]); let n = bstr.length; let u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new Blob([u8arr], { type: mime }); } catch { let arr = dataurl.split(','); let bstr = atob(arr[0]); let n = bstr.length; let u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new Blob([u8arr]); } }, downloadExcel: function () { axios({ method: 'post', url: '/api/tbDevicesInfo/exportLostDevice', data: { "pageNumber": 1, "pageSize": 10, "queryBy": { "day": 3 } } }).then(response => { let contentDisposition = response.headers['content-disposition']; let fileName = contentDisposition.substring(contentDisposition.indexOf('=') + 1); let data = this.dataURLtoBlob(response.data.data); let url = window.URL.createObjectURL(new Blob([data])); let link = document.createElement('a'); link.href = url; this.imgSrc = url; link.setAttribute('download', decodeURIComponent(fileName)); document.body.appendChild(link); link.click(); }).catch(error => { alert("文件下载失败"); console.log(error); }); }, exportBusLineStation: function () { axios({ method: 'post', url: '/api/device/baseData/exportBusLineStation', data: {} }).then(response => { let contentDisposition = response.headers['content-disposition']; let fileName = contentDisposition.substring(contentDisposition.indexOf('=') + 1); let data = this.dataURLtoBlob(response.data.data); let url = window.URL.createObjectURL(new Blob([data])); let link = document.createElement('a'); link.href = url; link.setAttribute('download', decodeURIComponent(fileName)); document.body.appendChild(link); link.click(); }).catch(error => { alert("文件下载失败"); console.log(error); }); }, }, });
|