修改地图导入导出
This commit is contained in:
parent
216b8ceab1
commit
8e431bade1
@ -47,7 +47,8 @@ export default {
|
|||||||
}],
|
}],
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: 'value',
|
type: 'value',
|
||||||
show: false
|
show: false,
|
||||||
|
minInterval: 1
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
type: 'category',
|
type: 'category',
|
||||||
|
@ -4,12 +4,19 @@
|
|||||||
<span>{{ $t('map.sketchMap') }}</span>
|
<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" style="float: right; padding: 3px 0" @click="createMap">{{ $t('map.newConstruction') }}</el-button>
|
||||||
<el-button type="text" class="uploadDemo">
|
<el-button type="text" class="uploadDemo">
|
||||||
<input
|
<!-- <input
|
||||||
ref="files"
|
ref="files"
|
||||||
type="file"
|
type="file"
|
||||||
class="file_box"
|
class="file_box"
|
||||||
accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
|
accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
|
||||||
@change="importf"
|
@change="importf"
|
||||||
|
> -->
|
||||||
|
<input
|
||||||
|
ref="files"
|
||||||
|
type="file"
|
||||||
|
class="file_box"
|
||||||
|
accept=".json, application/json"
|
||||||
|
@change="importf"
|
||||||
>
|
>
|
||||||
{{ $t('map.importMap') }}
|
{{ $t('map.importMap') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
@ -50,12 +57,12 @@ import { DeviceMenu } from '@/scripts/ConstDic';
|
|||||||
import { getMapTree, getMapDetail, postBuildMapImport } from '@/api/jmap/mapdraft';
|
import { getMapTree, getMapDetail, postBuildMapImport } from '@/api/jmap/mapdraft';
|
||||||
// import { UrlConfig } from '@/router/index';
|
// import { UrlConfig } from '@/router/index';
|
||||||
import { translate, translateSheetTitle } from '@/scripts/translate';
|
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 PopMenu from '@/components/PopMenu';
|
||||||
import MapOperateMenu from './operateMenu';
|
import MapOperateMenu from './operateMenu';
|
||||||
import MapCreate from './create';
|
import MapCreate from './create';
|
||||||
import WindowResizeHandler from '@/mixin/WindowResizeHandler';
|
import WindowResizeHandler from '@/mixin/WindowResizeHandler';
|
||||||
import XLSX from 'xlsx';
|
// import XLSX from 'xlsx';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'MapListDraft',
|
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({
|
const loading = this.$loading({
|
||||||
lock: true,
|
lock: true,
|
||||||
text: '正在导入中...',
|
text: '正在导入中...',
|
||||||
@ -153,57 +219,24 @@ export default {
|
|||||||
background: 'rgba(0, 0, 0, 0.7)'
|
background: 'rgba(0, 0, 0, 0.7)'
|
||||||
});
|
});
|
||||||
const obj = this.$refs.files;
|
const obj = this.$refs.files;
|
||||||
let wb;
|
|
||||||
if (!obj.files) return;
|
if (!obj.files) return;
|
||||||
const f = obj.files[0];
|
const f = obj.files[0];
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
const that = this;
|
const that = this;
|
||||||
reader.onload = function (e) {
|
reader.readAsText(f, 'utf-8');
|
||||||
|
reader.onload = function(e) {
|
||||||
const data = e.target.result;
|
const data = e.target.result;
|
||||||
if (that.rABS) {
|
postBuildMapImport(JSON.parse(data)).then(res => {
|
||||||
wb = XLSX.read(btoa(that.fixdata(data)), {// 手动转化
|
loading.close();
|
||||||
type: 'base64'
|
that.$message.success('导入成功!');
|
||||||
});
|
that.refresh();
|
||||||
} else {
|
}).catch(error => {
|
||||||
wb = XLSX.read(data, {
|
loading.close();
|
||||||
type: 'binary'
|
that.$message.error('导入失败' + error.message);
|
||||||
});
|
});
|
||||||
}
|
obj.value = '';
|
||||||
const resultJSONData = { 'devices': {} };
|
loading.close();
|
||||||
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);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
// 转换数据格式
|
// 转换数据格式
|
||||||
handelData(key) {
|
handelData(key) {
|
||||||
|
@ -202,14 +202,24 @@ export default {
|
|||||||
if (resultData === false) {
|
if (resultData === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const self = this;
|
|
||||||
import('@/utils/Export2Excel').then(excel => {
|
// const self = this;
|
||||||
self.queryExportData(resultData).then(data => {
|
// import('@/utils/Export2Excel').then(excel => {
|
||||||
excel.export_json_excel(data, resultData.name);
|
// self.queryExportData(resultData).then(data => {
|
||||||
}).catch(error => {
|
// excel.export_json_excel(data, resultData.name);
|
||||||
self.$message.error('导出执行异常:' + error.message);
|
// }).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