diff --git a/package.json b/package.json index f2b6c72..cd29e94 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "author": "lichong", "homepage": "https://www.electronjs.org", "scripts": { - "npmi": "npm i", + "npmi": "npm i -d", "dev": "electron-vite dev", "build": "electron-vite build", "build:win": "npm run build && electron-builder --win --config", diff --git a/src/main/index.js b/src/main/index.js index ec201cd..f1e8f34 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -24,7 +24,7 @@ function createWindow() { }) mainWindow.on('ready-to-show', () => { mainWindow.show() - mainWindow.webContents.openDevTools() + // mainWindow.webContents.openDevTools() }) mainWindow.webContents.setWindowOpenHandler((details) => { shell.openExternal(details.url) diff --git a/src/renderer/src/App.vue b/src/renderer/src/App.vue index d9eda17..00a95f8 100644 --- a/src/renderer/src/App.vue +++ b/src/renderer/src/App.vue @@ -30,7 +30,7 @@ export default { methods: { }, async mounted() { - let fiveDay = dayjs('2024-12-7T00:00:00').valueOf() + let fiveDay = dayjs('2024-12-1T00:00:00').valueOf() if (!this.isVip) { if (dayjs().valueOf() > fiveDay) { this.isVip = false diff --git a/src/renderer/src/components/tablecomponent.vue b/src/renderer/src/components/tablecomponent.vue index df92f1a..5c38b39 100644 --- a/src/renderer/src/components/tablecomponent.vue +++ b/src/renderer/src/components/tablecomponent.vue @@ -13,17 +13,9 @@ - diff --git a/src/renderer/src/views/shujuguanli.vue b/src/renderer/src/views/shujuguanli.vue index f75fd33..f7f9ff6 100644 --- a/src/renderer/src/views/shujuguanli.vue +++ b/src/renderer/src/views/shujuguanli.vue @@ -17,7 +17,7 @@
- + @@ -25,13 +25,13 @@
- + 预览 - + @@ -41,7 +41,7 @@
- +
@@ -64,9 +64,10 @@ export default { dayjs: dayjs, tableHeader: [], fileOriData1: null, - fileData1: null, + fileData1: [], + fileData1Header: {}, fileOriData2: null, - fileData2: null, + fileData2: [], tableData: [], loading: false, } @@ -149,7 +150,7 @@ export default { } allCells.push(newRow); } - console.log(122, allCells); + that.fileData1Header = { ...allCells[3] } that.fileData1 = allCells } fileReader.onerror = function (error) { @@ -182,142 +183,181 @@ export default { fileReader.readAsArrayBuffer(file) }, dealData2(sheetData) { - console.log(155, sheetData); + let groupObj = _.groupBy(this.fileData1, 'g') + if (this.fileData1.length === 0) { ElMessage({ message: `请先导入A表数据`, type: 'error', }) } else { - for (let i = 0; i < sheetData.length; i++) { - let element = sheetData[i]; - let itemList = _.filter(this.fileData1, o => { - // CH - if (`${o.G4}` === `${element.Store}` && `${o.H4}` === `${element.Order}`) { - return true - } else { - return false - } - // // M - // else if (`${o.G4}` === `${element.Store}` && `${o.H4}` === `${element.Order}` && `${element.Description}` === `VESTIDO DISNEY DTR, CH, AZUL MARINO WKM`) { - - // } - // // G - // else if (`${o.G4}` === `${element.Store}` && `${o.H4}` === `${element.Order}` && `${element.Description}` === `VESTIDO DISNEY DTR, CH, AZUL MARINO WKM`) { - - // } - // // EG - // else if (`${o.G4}` === `${element.Store}` && `${o.H4}` === `${element.Order}` && `${element.Description}` === `VESTIDO DISNEY DTR, CH, AZUL MARINO WKM`) { - - // } - // Description: "VESTIDO DISNEY DTR, CH, AZUL MARINO WKM" - // Order: "6000046296" - // Store: "0000000491" - }) - for (let j = 0; j < itemList.length; j++) { - let item = itemList[j]; - // CH - if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, CH, AZUL MARINO WKM`)) { - } - // M - else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, M, AZUL MARINO WKM`)) { - - } - // G - else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, G, AZUL MARINO WKM`)) { - - } - // EG - else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, EG, AZUL MARINO WKM`)) { + try { + for (let i = 0; i < sheetData.length; i++) { + let element = sheetData[i]; + let itemList = groupObj[element.Store] || [] + if (itemList.length === 1) { + // a: "STYLE NO." b: "STYLE NO." c: "箱号" d: "箱号" e: "箱号" f: "箱数" g: "商店名称" h: "条码贴" + // i: "颜色" j: "CH" k: "M" l: "G" m: "EG" n: "每箱总件数" o: "总件数" p: "每箱毛重\n(KGS)" q: "每箱净重\n(KGS)" + // r: "总毛重\n(KGS)" s: "总净重\n(KGS)" t: "长" u: "宽" v: "高" w: "立方米CBM" x: "" + // 条贴码 + element["Barcode"] = itemList[0].h + // 箱数 + element["Quantity of containers"] = itemList[0].f + // CH尺码的数量 + if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, CH, AZUL MARINO WKM`)) { + element["Quantity per container"] = itemList[0].j + } + // M尺码的数量 + else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, M, AZUL MARINO WKM`)) { + element["Quantity per container"] = itemList[0].k + } + // G尺码的数量 + else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, G, AZUL MARINO WKM`)) { + element["Quantity per container"] = itemList[0].l + } + // EG尺码的数量 + else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, EG, AZUL MARINO WKM`)) { + element["Quantity per container"] = itemList[0].m + } + } else if (itemList.length > 1) { + // j: "CH" k: "M" l: "G" m: "EG" + // CH + if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, CH, AZUL MARINO WKM`)) { + let allCHData = _.filter(itemList, v => Number(v.j)) + let containerList = _.filter(sheetData, v => v.Store === element.Store && Number(v["Quantity per container"]) && _.startsWith(`${v.Description}`, `VESTIDO DISNEY DTR, CH, AZUL MARINO WKM`)) + let isHas = !!(containerList.length) + if (!isHas) { + element["Barcode"] = allCHData[0].h + // 箱数为所有的箱数之和 + element["Quantity of containers"] = _.sumBy(allCHData, o => Number(o.f)) + // CH尺码的数量 + element["Quantity per container"] = allCHData[0].j + // todo 需要判断是否已经存在 + } + else { + let iteml = allCHData[containerList.length] + element["Barcode"] = iteml.h + // CH尺码的数量 + element["Quantity per container"] = iteml.j + } + } + // M + else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, M, AZUL MARINO WKM`)) { + let allCHData = _.filter(itemList, v => Number(v.k)) + let containerList = _.filter(sheetData, v => v.Store === element.Store && Number(v["Quantity per container"]) && _.startsWith(`${v.Description}`, `VESTIDO DISNEY DTR, M, AZUL MARINO WKM`)) + let isHas = !!(containerList.length) + if (!isHas) { + element["Barcode"] = allCHData[0].h + // 箱数为所有的箱数之和 + element["Quantity of containers"] = _.sumBy(allCHData, o => Number(o.f)) + // M尺码的数量 + element["Quantity per container"] = allCHData[0].k + } + else { + let iteml = allCHData[containerList.length] + element["Barcode"] = iteml.h + // M尺码的数量 + element["Quantity per container"] = iteml.k + } + } + // G + else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, G, AZUL MARINO WKM`)) { + let allCHData = _.filter(itemList, v => Number(v.l)) + let containerList = _.filter(sheetData, v => v.Store === element.Store && Number(v["Quantity per container"]) && _.startsWith(`${v.Description}`, `VESTIDO DISNEY DTR, G, AZUL MARINO WKM`)) + let isHas = !!(containerList.length) + if (!isHas) { + element["Barcode"] = allCHData[0].h + // 箱数为所有的箱数之和 + element["Quantity of containers"] = _.sumBy(allCHData, o => Number(o.f)) + // G尺码的数量 + element["Quantity per container"] = allCHData[0].l + } + else { + let iteml = allCHData[containerList.length] + element["Barcode"] = iteml.h + // G尺码的数量 + element["Quantity per container"] = iteml.l + } + } + // EG + else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, EG, AZUL MARINO WKM`)) { + let allCHData = _.filter(itemList, v => Number(v.m)) + let containerList = _.filter(sheetData, v => v.Store === element.Store && Number(v["Quantity per container"]) && _.startsWith(`${v.Description}`, `VESTIDO DISNEY DTR, EG, AZUL MARINO WKM`)) + let isHas = !!(containerList.length) + if (!isHas) { + element["Barcode"] = allCHData[0].h + // 箱数为所有的箱数之和 + element["Quantity of containers"] = _.sumBy(allCHData, o => Number(o.f)) + // EG尺码的数量 + element["Quantity per container"] = allCHData[0].m + } + else { + let iteml = allCHData[containerList.length] + element["Barcode"] = iteml.h + // EG尺码的数量 + element["Quantity per container"] = iteml.m + } + } } - } - + this.fileData2 = sheetData + } catch (error) { + ElMessage({ + message: `表格处理出错:, ${error}`, + type: 'error', + duration: 0, + showClose: true + }) } - that.fileData2 = sheetData } }, - // 解析单元格合并数据方法 - // 解析表格单元格合并数据 把参与合并的单元格全部计算并统计位置信息 - xlsxMergeParse(merges) { - let arr = [] - - merges.map(v => { - let { s, e } = v - let result = [] - let addNum = 1 //使数组下标加一,符合Excel单元格下标 - if (s.c === e.c) { - for (let i = s.r; i < e.r + 1; i++) { result.push([i + addNum, s.c + addNum]) } - } else { - for (let i = s.c; i < e.c + 1; i++) { result.push([s.r + addNum, i + addNum]) } - } - arr.push(result) - }) - - return arr - - }, - - // 单元格合并数据建立索引 - // 单元格合并数据为三维数组,为了提升数据处理效率,添加索引(变为一维数组,序列化位置信息) - mergeIndex(mergesParse) { - - let datas = [] - - mergesParse.map((v, i) => { - let row = [] - v.map((v1, i1) => { - row.push(v1.join(',')) - row.push([i, i1].join('-')) + // 预览 + viewTable() { + let that = this + let tableHeader = [] + let tableData = [] + for (let key in that.fileData2[0]) { + tableHeader.push({ + prop: key, + label: key, + type: "text" }) - datas.push(row) - }) - - return datas.flat(Infinity) - }, - - // 根据单元格下标计算应该填充的值 - autoFill(point, index, mergesParses, sheetData) { - - // 判断此单元格是否属于合并单元格 - let isNeed = index.indexOf(point.join(',')) - if (isNeed < 0) return undefined - - // 通过索引获取映射的合并数据三维数组的下标 - let target = index[isNeed + 1] - let result = target.split('-')[0] - result = mergesParses[result][0] - - // 返回合并单元格左上单元格数据 - result = sheetData[String.fromCharCode(result[1] + 64) + result[0]].w - return result + } + for (let index = 0; index < that.fileData2.length; index++) { + let element = that.fileData2[index]; + tableData.push({ + ...element + }) + } + this.tableHeader = tableHeader + this.tableData = tableData }, - // 预览 - viewTable() { }, // 导出数据 async exportData() { - let listCopy = _.cloneDeep(this.tableData) + let that = this + let listCopy = _.cloneDeep(that.fileData2) + // 创建一个新的表头数组,将不需要的表头替换为空格 + let newHeaders = ["Order", "Sku", "Description", "Type of merchandise", "Quantity to deliver", "Store", "Quantity of containers", "Barcode", "Quantity per container", "Total", "Cluster", "", "", "", ""] let lilstLocal = [] for (let i = 0; i < listCopy.length; i++) { let item = listCopy[i]; - let listItem = {} - for (let j = 0; j < this.exportHeader.length; j++) { - let headerItem = this.exportHeader[j]; - listItem[headerItem.label] = item[`${headerItem.prop}_org`] || item[`${headerItem.prop}`] - } - lilstLocal.push(listItem) + lilstLocal.push({ ...item, 'Quantity to deliver': item["Quantity to deliver"].toFixed(3) }) + } + let jsonWorkSheet = XLSX.utils.json_to_sheet(lilstLocal); + for (let index = 0; index < newHeaders.length; index++) { + let element = newHeaders[index]; + // 第一行改为自定义的表头 + jsonWorkSheet[`${XLSX.utils.encode_cell({ c: index, r: 0 })}`].v = element } - console.log(135, lilstLocal); - // let jsonWorkSheet = XLSX.utils.json_to_sheet(lilstLocal); - // let workBook = { - // SheetNames: ["sheet1"], - // Sheets: { - // ["sheet1"]: jsonWorkSheet, - // } - // }; - // XLSX.writeFile(workBook, `数据表格管理${dayjs().format("YYYY-MM-DD_HH-mm-ss")}.xls`); + let workBook = { + SheetNames: ["sheet1"], + Sheets: { + ["sheet1"]: jsonWorkSheet, + } + }; + XLSX.writeFile(workBook, `数据表格管理${dayjs().format("YYYY-MM-DD_HH-mm-ss")}.xls`); }, }, async mounted() { },