Skip to content

Commit

Permalink
明确参数
Browse files Browse the repository at this point in the history
  • Loading branch information
JChehe committed May 5, 2017
1 parent d315323 commit 744a19a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 55 deletions.
5 changes: 2 additions & 3 deletions app/src/background/excelUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ function Excel() {
Excel.prototype = {
constructor: Excel,

init(arg) {
init({ type, path }) {
let isParseSuccess = true
try {
let type = arg.type
if (!!type) {
if (type === 'node') {
this.readByPath(arg.path)
this.readByPath(path)
} else if (type === 'data') {
this.readByData(data)
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/background/filterUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ let filterUtils = {
for (let i = 1, len = filterCol.length; i < len; i++) {
let cKey = colKeys[filterCol[i]],
curVal = row[cKey] === undefined ? 0 : +row[cKey]
console.log('curVal', curVal)

if (isNaN(curVal)) return undefined

switch (colOperator) {
Expand All @@ -98,7 +98,6 @@ let filterUtils = {
default: console.log('calcNumSet未匹配操作符')
}
}
console.log('result', result)
return isNaN(result) ? undefined : result
},
filterUnit(args) {
Expand All @@ -113,7 +112,7 @@ let filterUtils = {
target = typeof (+target) === 'number' ? +(+target).toFixed(12) : (+target)
}
// console.log(typeof curVal, typeof operator, typeof target)
console.log(curVal, operator, target)

switch (operator) {
case '>': return (curVal > target); break;
case '<': return (curVal < target); break;
Expand Down
5 changes: 2 additions & 3 deletions app/src/background/generateHTMLString.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

module.exports = function generateHTMLString(arg) {
let { sheetData, colKeys } = arg,
resultHeadStr = '<tr><td>1</td>',
module.exports = function generateHTMLString({ sheetData, colKeys }) {
let resultHeadStr = '<tr><td>1</td>',
resultBodyStr = ''

colKeys.forEach((row, index) => {
Expand Down
46 changes: 17 additions & 29 deletions app/src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let excelData,
filRow = {}

window.addEventListener('load', (event) => {
ipcRenderer.on('readFile-start', (event, arg) => {
ipcRenderer.on('readFile-start', (event, { data, activeSheetIndex }) => {
/* excelData 的数据结构
{
sheetNameN: [] 所有行
Expand All @@ -23,11 +23,11 @@ window.addEventListener('load', (event) => {
workbook: {} Excel 相关
}
*/
excelData = new Excel().init(arg.data)
excelData = new Excel().init(data)
oriRow = {}
filRow = {}
activeSheetIndex = activeSheetIndex || 0
let filterTagList = {},
activeSheetIndex = arg.activeSheetIndex || 0,
activeSheetName = excelData.sheetNameList[activeSheetIndex],
curColKeys = excelData[activeSheetName + SUFFIX_COLKEYS],
curSheetData = excelData[activeSheetName];
Expand All @@ -39,12 +39,6 @@ window.addEventListener('load', (event) => {
filterTagList[sheetName] = []
})

console.log('colKeys', colKeys)
// console.info('curSheetData', curSheetData);
for (var i = 0; i < curSheetData.length; i++) {
console.log(curSheetData[i])
}

ipcRenderer.send('generate-htmlstring-response', {
sheetHTML: generateHTMLString({
sheetData: curSheetData,
Expand All @@ -60,16 +54,15 @@ window.addEventListener('load', (event) => {
sheetNameList: excelData.sheetNameList
})
})
ipcRenderer.on('filter-start', (event, arg) => {
filteredData = filterHandler(arg)
let activeSheetName = arg.activeSheetName,
curColKeys = colKeys[activeSheetName],
ipcRenderer.on('filter-start', (event, { activeSheetName, filterTagList, filterWay, uniqueCols }) => {
filteredData = filterHandler({ filterTagList, filterWay, uniqueCols })
let curColKeys = colKeys[activeSheetName],
tempFilRow = {}

excelData.sheetNameList.forEach((sheetName, index) => {
tempFilRow[sheetName] = filteredData[sheetName].length
})
console.log('tempFilRow', tempFilRow)

ipcRenderer.send('filter-response', {
filRow: tempFilRow
})
Expand All @@ -82,10 +75,9 @@ window.addEventListener('load', (event) => {
})
})

ipcRenderer.on('changeTab-start', (event, arg) => {
filteredData = filterHandler(arg)
let activeSheetName = arg.activeSheetName,
curColKeys = colKeys[activeSheetName],
ipcRenderer.on('changeTab-start', (event, { activeSheetName, filterTagList, filterWay, uniqueCols }) => {
filteredData = filterHandler({ filterTagList, filterWay, uniqueCols })
let curColKeys = colKeys[activeSheetName],
tempFilRow = {}

ipcRenderer.send('generate-htmlstring-response', {
Expand All @@ -96,17 +88,16 @@ window.addEventListener('load', (event) => {
})
})

ipcRenderer.on('exportFile-start', (event, arg) => {
ipcRenderer.on('exportFile-start', (event) => {
excelData.exportFileByWB({
filteredData,
excelData
})
ipcRenderer.send('exportFile-response', { info: '成功导出' })
})

ipcRenderer.on('delAllFilterTag-start', (event, arg) => {
let activeSheetName = arg.activeSheetName,
curColKeys = colKeys[activeSheetName],
ipcRenderer.on('delAllFilterTag-start', (event, { activeSheetName }) => {
let curColKeys = colKeys[activeSheetName],
curSheetData = excelData[activeSheetName]

ipcRenderer.send('generate-htmlstring-response', {
Expand All @@ -119,16 +110,14 @@ window.addEventListener('load', (event) => {
})
}, false)

function filterHandler(arg) {
let { filterTagList, filterWay, uniqueCols } = arg,
tempFilteredData = Object.assign({}, excelData)
function filterHandler({ filterTagList, filterWay, uniqueCols }) {
let tempFilteredData = Object.assign({}, excelData)
for (let i = 0, len = excelData.sheetNameList.length; i < len; i++) {
let curSheetName = excelData.sheetNameList[i],
curFilterTagList = filterTagList[curSheetName],
colKeys = excelData[curSheetName + SUFFIX_COLKEYS],
curUniqueCols = uniqueCols[curSheetName]
console.log('curSheetName', curSheetName)
console.log('curFilterTagList', curFilterTagList.length)

if (curFilterTagList.length !== 0) {
tempFilteredData[curSheetName] = tempFilteredData[curSheetName].filter((row, index) => {
let rowExpStr = ''
Expand Down Expand Up @@ -178,12 +167,11 @@ function filterHandler(arg) {
return filterWay == 0 ? rowResult : !rowResult
})
}
console.log('uniqueCols', uniqueCols)

if (curUniqueCols.length !== 0) {
let curUniqueColKeys = curUniqueCols.map((item) => {
return colKeys[item]
})
console.log('curUniqueColKeys', curUniqueColKeys)
tempFilteredData[curSheetName] = uniqBy(tempFilteredData[curSheetName], curUniqueColKeys)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/FirstScreenPageView/ExcelDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
}
},
mounted() {
ipcRenderer.on('generate-htmlstring-response', (event, arg) => {
this.sheetHTML = arg.sheetHTML
ipcRenderer.on('generate-htmlstring-response', (event, { sheetHTML }) => {
this.sheetHTML = sheetHTML
})
let dropArea = document.querySelector('.drop_area')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@
changeSelHandler(groupId) {
this.groupId = groupId
},
setMultiColInput(arg) {
this.operatorCol = arg
},
showColSelectDialog() {
this.setColSelectType(1)
this.setColSelectDialogStatus(true)
Expand Down
13 changes: 6 additions & 7 deletions app/src/components/FirstScreenPageView/FilterPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,20 @@
}
},
created() {
ipcRenderer.on('filter-response', (event, arg) => {
ipcRenderer.on('filter-response', (event, { filRow }) => {
this.setFileStatus(2)
this.setFilteredData(arg.filRow)
console.log('(arg.filRow', arg.filRow)
this.setFilteredData(filRow)
ipcRenderer.send('exportFile-start')
})
ipcRenderer.on('exportFile-response', (event, arg) => {
console.log(arg.info)
ipcRenderer.on('exportFile-response', (event, { info, type }) => {
console.log(info)
this.setFileStatus(-1)
if (arg.type === -1) {
if (type === -1) {
setTimeout(() => {
ipcRenderer.send('sync-alert-dialog', {
content: arg.info
content: info
})
}, 30)
}
Expand Down
9 changes: 4 additions & 5 deletions app/src/update/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
checkoutSourceBtn = $('.checkout_source_btn'),
pauseBtn = $('.pause_btn'),
cancelBtn = $('.cancel_btn'),
willDownloadResponse = function(event, arg) {
let { curReceivedBytes, totalBytes, downloadStatus } = arg,
percentage = curReceivedBytes / totalBytes * 100 + '%'
willDownloadResponse = function(event, { curReceivedBytes, totalBytes, downloadStatus }) {
let percentage = curReceivedBytes / totalBytes * 100 + '%'

cur.innerText = (curReceivedBytes / 1024 / 1024).toFixed(2)
total.innerText = (totalBytes / 1024 / 1024).toFixed(2)
Expand All @@ -47,8 +46,8 @@
pauseBtnHandler = function() {
ipcRenderer.send('update-switch')
},
togglePauseBtn = function(event, arg) {
pauseBtn.innerText = arg.text
togglePauseBtn = function(event, { text }) {
pauseBtn.innerText = text
}

ipcRenderer.on('will-download-response', willDownloadResponse)
Expand Down

0 comments on commit 744a19a

Please sign in to comment.