|
|
@@ -154,7 +154,7 @@
|
|
|
></span>
|
|
|
导入
|
|
|
</el-button>
|
|
|
- <el-button class="add" type="danger" @click="exportTemplate()">
|
|
|
+ <el-button class="add" type="danger" @click="download('upload/voltageLoad_template.xlsx')">
|
|
|
<span
|
|
|
class="icon iconfont icon-xihuan"
|
|
|
:style="{
|
|
|
@@ -306,6 +306,7 @@
|
|
|
<script>
|
|
|
import AddOrUpdate from './components/add-or-update.vue';
|
|
|
import uploadModal from './components/uploadModal.vue';
|
|
|
+import axios from 'axios';
|
|
|
export default {
|
|
|
components: {
|
|
|
AddOrUpdate,
|
|
|
@@ -352,26 +353,94 @@ export default {
|
|
|
this.$refs.uploadModal.openDialog();
|
|
|
},
|
|
|
exportTemplate() {
|
|
|
- this.$http({
|
|
|
- url: `/file/download`,
|
|
|
- method: 'get',
|
|
|
- params: {
|
|
|
- fileName: 'voltageLoad_template.xlsx',
|
|
|
- },
|
|
|
- responseType: 'blob',
|
|
|
- }).then(({ data }) => {
|
|
|
- if (data && data.code === 0) {
|
|
|
+ axios
|
|
|
+ .get(this.$base.url + 'file/download?fileName=' + 'voltageLoad_template.xlsx', {
|
|
|
+ headers: {
|
|
|
+ token: this.$storage.get('Token'),
|
|
|
+ },
|
|
|
+ responseType: 'blob',
|
|
|
+ })
|
|
|
+ .then(({ data }) => {
|
|
|
const blob = new Blob([data], { type: 'application/vnd.ms-excel' });
|
|
|
- const fileName = '模板.xlsx';
|
|
|
+ const fileName = 'voltageLoad_template.xlsx';
|
|
|
const a = document.createElement('a');
|
|
|
a.href = URL.createObjectURL(blob);
|
|
|
a.download = fileName;
|
|
|
a.click();
|
|
|
URL.revokeObjectURL(a.href);
|
|
|
- } else {
|
|
|
- this.$message.error(data.msg || '导出失败');
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 下载
|
|
|
+ download(file) {
|
|
|
+ let arr = file.replace(new RegExp('upload/', 'g'), '');
|
|
|
+ axios
|
|
|
+ .get(this.$base.url + 'file/download?fileName=' + arr, {
|
|
|
+ headers: {
|
|
|
+ token: this.$storage.get('Token'),
|
|
|
+ },
|
|
|
+ responseType: 'blob',
|
|
|
+ })
|
|
|
+ .then(
|
|
|
+ ({ data }) => {
|
|
|
+ const binaryData = [];
|
|
|
+ binaryData.push(data);
|
|
|
+ const objectUrl = window.URL.createObjectURL(
|
|
|
+ new Blob(binaryData, {
|
|
|
+ type: 'application/pdf;chartset=UTF-8',
|
|
|
+ })
|
|
|
+ );
|
|
|
+ const a = document.createElement('a');
|
|
|
+ a.href = objectUrl;
|
|
|
+ a.download = arr;
|
|
|
+ // a.click()
|
|
|
+ // 下面这个写法兼容火狐
|
|
|
+ a.dispatchEvent(
|
|
|
+ new MouseEvent('click', {
|
|
|
+ bubbles: true,
|
|
|
+ cancelable: true,
|
|
|
+ view: window,
|
|
|
+ })
|
|
|
+ );
|
|
|
+ window.URL.revokeObjectURL(data);
|
|
|
+ },
|
|
|
+ err => {
|
|
|
+ axios
|
|
|
+ .get(
|
|
|
+ (location.href.split(this.$base.name).length > 1 ? location.href.split(this.$base.name)[0] : '') +
|
|
|
+ this.$base.name +
|
|
|
+ '/file/download?fileName=' +
|
|
|
+ arr,
|
|
|
+ {
|
|
|
+ headers: {
|
|
|
+ token: this.$storage.get('Token'),
|
|
|
+ },
|
|
|
+ responseType: 'blob',
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then(({ data }) => {
|
|
|
+ const binaryData = [];
|
|
|
+ binaryData.push(data);
|
|
|
+ const objectUrl = window.URL.createObjectURL(
|
|
|
+ new Blob(binaryData, {
|
|
|
+ type: 'application/pdf;chartset=UTF-8',
|
|
|
+ })
|
|
|
+ );
|
|
|
+ const a = document.createElement('a');
|
|
|
+ a.href = objectUrl;
|
|
|
+ a.download = arr;
|
|
|
+ // a.click()
|
|
|
+ // 下面这个写法兼容火狐
|
|
|
+ a.dispatchEvent(
|
|
|
+ new MouseEvent('click', {
|
|
|
+ bubbles: true,
|
|
|
+ cancelable: true,
|
|
|
+ view: window,
|
|
|
+ })
|
|
|
+ );
|
|
|
+ window.URL.revokeObjectURL(data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ );
|
|
|
},
|
|
|
search() {
|
|
|
this.pageIndex = 1;
|