From dc0b5301e09bbeed6187e89cf09d10b9e56e4892 Mon Sep 17 00:00:00 2001 From: ival <610568032@qq.com> Date: Mon, 12 Aug 2019 18:22:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=BC=E5=87=BA=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=9C=B0=E5=9B=BE=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 5 +- src/i18n/langs/en/scriptRecord.js | 42 ++++----- src/i18n/langs/zh/router.js | 1 + src/i18n/langs/zh/scriptRecord.js | 42 ++++----- src/utils/Export2Excel.js | 51 ++++++++++- src/views/publish/publishMap/index.vue | 121 ++++++++++++++++++++++++- vue.config.js | 5 +- 7 files changed, 217 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index d875c8123..9a5041ae3 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "axios": "0.18.0", "echarts": "^4.2.1", "element-ui": "2.7.2", + "file-saver": "^1.3.3", "js-cookie": "2.2.0", "js-md5": "^0.7.3", "lodash": "^4.17.11", @@ -49,8 +50,8 @@ "babel-eslint": "10.0.1", "babel-jest": "23.6.0", "chalk": "2.4.2", - "copy-webpack-plugin": "^4.5.2", "connect": "3.6.6", + "copy-webpack-plugin": "^4.5.2", "eslint": "5.15.3", "eslint-plugin-vue": "5.2.2", "file-loader": "^3.0.1", @@ -60,7 +61,7 @@ "runjs": "^4.3.2", "sass-loader": "^7.1.0", "script-ext-html-webpack-plugin": "2.1.3", - "script-loader": "0.7.2", + "script-loader": "^0.7.2", "serve-static": "^1.13.2", "svg-sprite-loader": "4.1.3", "svgo": "1.2.2", diff --git a/src/i18n/langs/en/scriptRecord.js b/src/i18n/langs/en/scriptRecord.js index 82f75c13a..e48e0c82f 100644 --- a/src/i18n/langs/en/scriptRecord.js +++ b/src/i18n/langs/en/scriptRecord.js @@ -1,22 +1,22 @@ export default { - scriptTitle: "Task Recording", - saveMaplocation: "Update Location", - saveBackground: "Save Background", - saveData: "Save Data", - roleManage: "Role Manage", - targetCondition: "Task Target", - taskScript: "Task Script", - roleName: "Role Name", - roleType: "Role Type", - deviceCode: "Device Code", - roleList: "Role List", - operation:"Operation", - roleAdd: "Add", - delete: "Delete", - behaviorOperate: "Behavior Operate", - conditionTitle: "Target condition", - deviceType: "Device Type", - deviceCondition: "Device Condition", - paramDeviceType: "Param DeviceType", - paramDeviceCode: "Param DeviceCode", -}; \ No newline at end of file + scriptTitle: 'Task Recording', + saveMaplocation: 'Update Location', + saveBackground: 'Save Background', + saveData: 'Save Data', + roleManage: 'Role Manage', + targetCondition: 'Task Target', + taskScript: 'Task Script', + roleName: 'Role Name', + roleType: 'Role Type', + deviceCode: 'Device Code', + roleList: 'Role List', + operation: 'Operation', + roleAdd: 'Add', + delete: 'Delete', + behaviorOperate: 'Behavior Operate', + conditionTitle: 'Target condition', + deviceType: 'Device Type', + deviceCondition: 'Device Condition', + paramDeviceType: 'Param DeviceType', + paramDeviceCode: 'Param DeviceCode' +}; diff --git a/src/i18n/langs/zh/router.js b/src/i18n/langs/zh/router.js index af7cd4c52..747e66c0e 100644 --- a/src/i18n/langs/zh/router.js +++ b/src/i18n/langs/zh/router.js @@ -32,6 +32,7 @@ export default { pulishManage: '发布内容管理', publishMapManage: '发布地图管理', productStateManage: '产品状态管理', + publishLessonManage: '发布课程管理', runPlanTemplateManage: '模板运行图管理', runPlanCommonManage: '通用运行图管理', runPlanEveryDayManage: '每日运行图管理', diff --git a/src/i18n/langs/zh/scriptRecord.js b/src/i18n/langs/zh/scriptRecord.js index 5e759bae8..ec33bfae3 100644 --- a/src/i18n/langs/zh/scriptRecord.js +++ b/src/i18n/langs/zh/scriptRecord.js @@ -1,22 +1,22 @@ export default { - scriptTitle: "任务录制", - saveMaplocation: "更新定位", - saveBackground: "保存背景", - saveData: "保存数据", - roleManage:"角色管理", - targetCondition:"任务目标", - taskScript:"任务剧本", - roleName: "角色名称", - roleType: "角色类型", - deviceCode: "设备编码", - roleList: "角色列表", - operation: "操作", - roleAdd: "添加", - delete: "删除", - behaviorOperate: "行为操作", - conditionTitle: "目标条件", - deviceType: "设备类型", - deviceCondition: "设备条件", - paramDeviceType: "参数设备类型", - paramDeviceCode: "参数设备编号", -}; \ No newline at end of file + scriptTitle: '任务录制', + saveMaplocation: '更新定位', + saveBackground: '保存背景', + saveData: '保存数据', + roleManage: '角色管理', + targetCondition: '任务目标', + taskScript: '任务剧本', + roleName: '角色名称', + roleType: '角色类型', + deviceCode: '设备编码', + roleList: '角色列表', + operation: '操作', + roleAdd: '添加', + delete: '删除', + behaviorOperate: '行为操作', + conditionTitle: '目标条件', + deviceType: '设备类型', + deviceCondition: '设备条件', + paramDeviceType: '参数设备类型', + paramDeviceCode: '参数设备编号' +}; diff --git a/src/utils/Export2Excel.js b/src/utils/Export2Excel.js index bdb6f7989..ef6998882 100644 --- a/src/utils/Export2Excel.js +++ b/src/utils/Export2Excel.js @@ -1,5 +1,9 @@ /* eslint-disable */ +require('script-loader!file-saver'); +require('script-loader!@/utils/Blob'); import XLSX from 'xlsx'; +import { translate } from '@/scripts/translate'; + function generateArray(table) { var out = []; @@ -81,7 +85,6 @@ function sheet_from_array_of_arrays(data, opts) { if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); return ws; } - function encode_row(row) { return "" + (row + 1); }; function encode_col(col) { var s = ""; for (++col; col; col = Math.floor((col - 1) / 26)) s = String.fromCharCode(((col - 1) % 26) + 65) + s; return s; } function safe_format_cell(cell, v) { @@ -179,7 +182,6 @@ export function sheet_to_json(sheet, opts) { out.length = outi; return out; } - function safe_decode_range(range) { var o = { s: { c: 0, r: 0 }, e: { c: 0, r: 0 } }; var idx = 0, i = 0, cc = 0; @@ -227,12 +229,14 @@ function s2ab(s) { export function export_table_to_excel(id) { var theTable = document.getElementById(id); + console.log('a') var oo = generateArray(theTable); var ranges = oo[1]; /* original data */ var data = oo[0]; var ws_name = "SheetJS"; + console.log(data); var wb = new Workbook(), ws = sheet_from_array_of_arrays(data); @@ -249,6 +253,9 @@ export function export_table_to_excel(id) { saveAs(new Blob([s2ab(wbout)], { type: "application/octet-stream" }), "test.xlsx") } +function formatJson(filterVal, jsonData) { + return jsonData.map(v => filterVal.map(j => v[j])) +} export function export_json_to_excel(th, jsonData, defaultTitle) { /* original data */ @@ -268,3 +275,43 @@ export function export_json_to_excel(th, jsonData, defaultTitle) { var title = defaultTitle || '列表' saveAs(new Blob([s2ab(wbout)], { type: "application/octet-stream" }), title + ".xlsx") } + +export function export_json_excel(jsonData, defaultTitle) { + + let data = jsonData; + let wb = new Workbook(); + + for (let index in data) { + let filterVal = handelData(index); + if (filterVal.tHeader.length) { + let dataDetail = formatJson(filterVal.tHeaderF, data[index]); + dataDetail.unshift(filterVal.tHeader); // 设置表头的 + let ws = sheet_from_array_of_arrays(dataDetail); + /* add worksheet to workbook */ + + let title = translate[index].sheetName || index; + wb.SheetNames.push(title); + wb.Sheets[`${title}`] = ws; + } + } + let wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: false, type: 'binary' }); + + var title = defaultTitle || '列表' + saveAs(new Blob([s2ab(wbout)], { type: "application/octet-stream" }), title + ".xlsx") +} +// 转换数据格式 +function handelData(key) { + let tHeader = []; + let tHeaderF = []; + if (translate[key]) { + translate[key].columns.forEach(item => { + tHeader.push(item.tHeader); + tHeaderF.push(item.key); + }); + } + let filterVal = { + tHeader: tHeader, + tHeaderF: tHeaderF, + }; + return filterVal; +} \ No newline at end of file diff --git a/src/views/publish/publishMap/index.vue b/src/views/publish/publishMap/index.vue index 962d25a1b..be34017bc 100644 --- a/src/views/publish/publishMap/index.vue +++ b/src/views/publish/publishMap/index.vue @@ -8,6 +8,7 @@ import { getPublishMapList, delPublishMap, getPublishMapExport, putMapOnLine, putMapOffLine } from '@/api/jmap/map'; import { getSkinStyleList } from '@/api/management/mapskin'; import { UrlConfig } from '@/router/index'; +import deviceType from '@/jmap/constant/deviceType'; import localStore from 'storejs'; export default { @@ -68,7 +69,7 @@ export default { { type: 'button', title: '操作', - width: '380', + width: '420', buttons: [ { name: '上架', @@ -95,6 +96,11 @@ export default { { name: '导出地图', handleClick: this.handleExportMap + }, + { + name: '导出', + handleClick: this.handleExportMapSame, + showControl: () => { return process.env.NODE_ENV === 'development'; } } ] } @@ -217,6 +223,24 @@ export default { }); }, + // 部分导出 + async handleExportMapSame(index, row) { + const res = await getPublishMapExport(row.id); + const resultData = res.data; + if (resultData === false) { + return; + } + + const self = this; + import('@/utils/Export2Excel').then(excel => { + self.queryExportDataSame(resultData).then(data => { + excel.export_json_excel(data, resultData.name); + }).catch(error => { + self.$message.error('导出执行异常:' + error.message); + }); + }); + }, + formatJson(filterVal, jsonData) { return jsonData.map(v => filterVal.map(j => v[j])); }, @@ -245,6 +269,101 @@ export default { } } + result.base.push(obj); + resolve(result); + }); + }, + // 格式化数据列表 + queryExportDataSame(data) { + const mapProps = {}; + const switchType = `${deviceType.Switch.toLowerCase()}List`; + const signalType = `${deviceType.Signal.toLowerCase()}List`; + const sectionType = `${deviceType.Section.toLowerCase()}List`; + + mapProps[switchType] = { + filter: item => { return true; }, + propList: { + 'name': item =>{ + return item.name; + }, + 'code': item => { + return item.code; + } + } + }; + mapProps[signalType] = { + filter: item => { return true; }, + propList: { + 'name': item =>{ + return item.name; + }, + 'code': item => { + return item.code; + } + } + }; + mapProps[sectionType] = { + filter: item => { return item.type == '01'; }, + propList: { + 'name': (item, devices) =>{ + let name = item.name; + if (item.isSwitchSection) { + const swchList = devices[switchType]; + const swch = swchList.find(elem => { return item.relSwitchCode == elem.code; }); + if (swch) { + if (item.code == swch.sectionACode) { + name = `${name} (${swch.name}-A)`; + } else if (item.code == swch.sectionBCode) { + name = `${name} (${swch.name}-B)`; + } else if (item.code == swch.sectionCCode) { + name = `${name} (${swch.name}-C)`; + } + } + } + + return name; + }, + 'code': item => { + return item.code; + } + } + }; + + return new Promise((resolve, reject) => { + const result = { + base: [] + }; + const obj = {}; + for (const i in data) { + if (i == 'devices') { + for (const v in data[i]) { + if (data[i][v].length) { + if (mapProps[v]) { + const list = []; + data[i][v].forEach(device => { + if (mapProps[v].filter(device)) { + const obj = {}; + Object.keys(mapProps[v].propList || []).forEach(key => { + obj[key] = mapProps[v].propList[key](device, data[i]); + }); + list.push(obj); + } + }); + result[v] = list; + } + } else if (v == 'skinVO') { + result[v] = [data[i][v]]; + } + } + } else if (data[i] instanceof Object || typeof data[i] != 'object') { + obj[i] = data[i]; + } else if (data[i] instanceof Array) { + if (data[i].length) { + obj[i] = [...data[i]]; + } + } + } + result.base.push(obj); resolve(result); }); diff --git a/vue.config.js b/vue.config.js index c52e95015..8afa11e06 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,4 +1,4 @@ -; + // import { getBasePathConfig } from '@/utils/baseUrl' const path = require('path'); @@ -13,7 +13,6 @@ function resolve(dir) { const name = defaultSettings.title; // page title const port = 9527; // dev port - // All configuration item explanations can be find in https://cli.vuejs.org/config/ module.exports = { /** @@ -143,6 +142,6 @@ module.exports = { config.optimization.runtimeChunk('single'); } ); - }, + } };