修改地图导入导出
This commit is contained in:
parent
216b8ceab1
commit
8e431bade1
@ -47,7 +47,8 @@ export default {
|
||||
}],
|
||||
xAxis: {
|
||||
type: 'value',
|
||||
show: false
|
||||
show: false,
|
||||
minInterval: 1
|
||||
},
|
||||
yAxis: {
|
||||
type: 'category',
|
||||
|
@ -4,12 +4,19 @@
|
||||
<span>{{ $t('map.sketchMap') }}</span>
|
||||
<el-button type="text" style="float: right; padding: 3px 0" @click="createMap">{{ $t('map.newConstruction') }}</el-button>
|
||||
<el-button type="text" class="uploadDemo">
|
||||
<input
|
||||
<!-- <input
|
||||
ref="files"
|
||||
type="file"
|
||||
class="file_box"
|
||||
accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
|
||||
@change="importf"
|
||||
> -->
|
||||
<input
|
||||
ref="files"
|
||||
type="file"
|
||||
class="file_box"
|
||||
accept=".json, application/json"
|
||||
@change="importf"
|
||||
>
|
||||
{{ $t('map.importMap') }}
|
||||
</el-button>
|
||||
@ -50,12 +57,12 @@ import { DeviceMenu } from '@/scripts/ConstDic';
|
||||
import { getMapTree, getMapDetail, postBuildMapImport } from '@/api/jmap/mapdraft';
|
||||
// import { UrlConfig } from '@/router/index';
|
||||
import { translate, translateSheetTitle } from '@/scripts/translate';
|
||||
import { sheet_to_json } from '@/utils/Export2Excel';
|
||||
// import { sheet_to_json } from '@/utils/Export2Excel';
|
||||
// import PopMenu from '@/components/PopMenu';
|
||||
import MapOperateMenu from './operateMenu';
|
||||
import MapCreate from './create';
|
||||
import WindowResizeHandler from '@/mixin/WindowResizeHandler';
|
||||
import XLSX from 'xlsx';
|
||||
// import XLSX from 'xlsx';
|
||||
|
||||
export default {
|
||||
name: 'MapListDraft',
|
||||
@ -145,7 +152,66 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
importf() { // 导入
|
||||
importf() {
|
||||
// const loading = this.$loading({
|
||||
// lock: true,
|
||||
// text: '正在导入中...',
|
||||
// spinner: 'el-icon-loading',
|
||||
// background: 'rgba(0, 0, 0, 0.7)'
|
||||
// });
|
||||
// const obj = this.$refs.files;
|
||||
// let wb;
|
||||
// if (!obj.files) return;
|
||||
// const f = obj.files[0];
|
||||
// const reader = new FileReader();
|
||||
// const that = this;
|
||||
// reader.onload = function (e) {
|
||||
// const data = e.target.result;
|
||||
// if (that.rABS) {
|
||||
// wb = XLSX.read(btoa(that.fixdata(data)), {// 手动转化
|
||||
// type: 'base64'
|
||||
// });
|
||||
// } else {
|
||||
// wb = XLSX.read(data, {
|
||||
// type: 'binary'
|
||||
// });
|
||||
// }
|
||||
// const resultJSONData = { 'devices': {} };
|
||||
// for (const index in wb.Sheets) {
|
||||
|
||||
// const titleNum = that.formatSheetTitle(index);
|
||||
// const key = translateSheetTitle.sheetName[titleNum];
|
||||
|
||||
// const filterVal = that.handelData(key);
|
||||
// const jsonData = sheet_to_json(wb.Sheets[index]);
|
||||
// const data = that.formatJson(filterVal, jsonData, key);
|
||||
// if (key === 'base') {
|
||||
// Object.assign(resultJSONData, data[0]);
|
||||
// } else if (key === 'skinVO') {
|
||||
// resultJSONData['devices'][key] = data[0];
|
||||
// } else {
|
||||
// resultJSONData['devices'][key] = data;
|
||||
// }
|
||||
// }
|
||||
// that.resultJSON = resultJSONData;
|
||||
// if (that.resultJSON) {
|
||||
// postBuildMapImport(that.resultJSON).then(res => {
|
||||
// loading.close();
|
||||
// that.$message.success('导入成功!');
|
||||
// that.refresh();
|
||||
// }).catch(error => {
|
||||
// loading.close();
|
||||
// that.$message.error('导入失败' + error.message);
|
||||
// });
|
||||
// }
|
||||
// obj.value = ''; // 清空上次导入文件
|
||||
// };
|
||||
// if (that.rABS) {
|
||||
// reader.readAsArrayBuffer(f);
|
||||
// } else {
|
||||
// reader.readAsBinaryString(f);
|
||||
// }
|
||||
|
||||
const loading = this.$loading({
|
||||
lock: true,
|
||||
text: '正在导入中...',
|
||||
@ -153,57 +219,24 @@ export default {
|
||||
background: 'rgba(0, 0, 0, 0.7)'
|
||||
});
|
||||
const obj = this.$refs.files;
|
||||
let wb;
|
||||
if (!obj.files) return;
|
||||
const f = obj.files[0];
|
||||
const reader = new FileReader();
|
||||
const that = this;
|
||||
reader.onload = function (e) {
|
||||
reader.readAsText(f, 'utf-8');
|
||||
reader.onload = function(e) {
|
||||
const data = e.target.result;
|
||||
if (that.rABS) {
|
||||
wb = XLSX.read(btoa(that.fixdata(data)), {// 手动转化
|
||||
type: 'base64'
|
||||
});
|
||||
} else {
|
||||
wb = XLSX.read(data, {
|
||||
type: 'binary'
|
||||
});
|
||||
}
|
||||
const resultJSONData = { 'devices': {} };
|
||||
for (const index in wb.Sheets) {
|
||||
|
||||
const titleNum = that.formatSheetTitle(index);
|
||||
const key = translateSheetTitle.sheetName[titleNum];
|
||||
|
||||
const filterVal = that.handelData(key);
|
||||
const jsonData = sheet_to_json(wb.Sheets[index]);
|
||||
const data = that.formatJson(filterVal, jsonData, key);
|
||||
if (key === 'base') {
|
||||
Object.assign(resultJSONData, data[0]);
|
||||
} else if (key === 'skinVO') {
|
||||
resultJSONData['devices'][key] = data[0];
|
||||
} else {
|
||||
resultJSONData['devices'][key] = data;
|
||||
}
|
||||
}
|
||||
that.resultJSON = resultJSONData;
|
||||
if (that.resultJSON) {
|
||||
postBuildMapImport(that.resultJSON).then(res => {
|
||||
loading.close();
|
||||
that.$message.success('导入成功!');
|
||||
that.refresh();
|
||||
}).catch(error => {
|
||||
loading.close();
|
||||
that.$message.error('导入失败' + error.message);
|
||||
});
|
||||
}
|
||||
obj.value = ''; // 清空上次导入文件
|
||||
postBuildMapImport(JSON.parse(data)).then(res => {
|
||||
loading.close();
|
||||
that.$message.success('导入成功!');
|
||||
that.refresh();
|
||||
}).catch(error => {
|
||||
loading.close();
|
||||
that.$message.error('导入失败' + error.message);
|
||||
});
|
||||
obj.value = '';
|
||||
loading.close();
|
||||
};
|
||||
if (that.rABS) {
|
||||
reader.readAsArrayBuffer(f);
|
||||
} else {
|
||||
reader.readAsBinaryString(f);
|
||||
}
|
||||
},
|
||||
// 转换数据格式
|
||||
handelData(key) {
|
||||
|
@ -202,14 +202,24 @@ export default {
|
||||
if (resultData === false) {
|
||||
return;
|
||||
}
|
||||
const self = this;
|
||||
import('@/utils/Export2Excel').then(excel => {
|
||||
self.queryExportData(resultData).then(data => {
|
||||
excel.export_json_excel(data, resultData.name);
|
||||
}).catch(error => {
|
||||
self.$message.error('导出执行异常:' + error.message);
|
||||
});
|
||||
});
|
||||
|
||||
// const self = this;
|
||||
// import('@/utils/Export2Excel').then(excel => {
|
||||
// self.queryExportData(resultData).then(data => {
|
||||
// excel.export_json_excel(data, resultData.name);
|
||||
// }).catch(error => {
|
||||
// self.$message.error('导出执行异常:' + error.message);
|
||||
// });
|
||||
// });
|
||||
|
||||
const content = new Blob([JSON.stringify(resultData)]);
|
||||
const urlObject = window.URL || window.webkitURL || window;
|
||||
const url = urlObject.createObjectURL(content);
|
||||
const el = document.createElement('a');
|
||||
el.href = url;
|
||||
el.download =`${resultData.name}.json`;
|
||||
el.click();
|
||||
urlObject.revokeObjectURL(url);
|
||||
},
|
||||
|
||||
// 部分导出
|
||||
|
Loading…
Reference in New Issue
Block a user