Browse Source

11.19

master
lichong 1 month ago
parent
commit
a4454b05ef
  1. 3
      package.json
  2. 2
      src/main/index.js
  3. 6
      src/renderer/src/App.vue
  4. BIN
      src/renderer/src/assets/excel/WKM25471-02D装箱单(1) - 副本.xlsx
  5. 263
      src/renderer/src/views/shujuguanli.vue

3
package.json

@ -20,7 +20,8 @@
"dexie": "^4.0.8", "dexie": "^4.0.8",
"element-plus": "^2.7.1", "element-plus": "^2.7.1",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"vxe-table": "^4.7.87" "vxe-table": "^4.7.87",
"xlsx": "^0.18.5"
}, },
"devDependencies": { "devDependencies": {
"@rushstack/eslint-patch": "^1.2.0", "@rushstack/eslint-patch": "^1.2.0",

2
src/main/index.js

@ -24,7 +24,7 @@ function createWindow() {
}) })
mainWindow.on('ready-to-show', () => { mainWindow.on('ready-to-show', () => {
mainWindow.show() mainWindow.show()
// mainWindow.webContents.openDevTools() mainWindow.webContents.openDevTools()
}) })
mainWindow.webContents.setWindowOpenHandler((details) => { mainWindow.webContents.setWindowOpenHandler((details) => {
shell.openExternal(details.url) shell.openExternal(details.url)

6
src/renderer/src/App.vue

@ -12,9 +12,7 @@
<script> <script>
import _ from 'lodash' import _ from 'lodash'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { myDatabase } from './assets/js/db.js'
import shujuguanliComponent from "./views/shujuguanli.vue" import shujuguanliComponent from "./views/shujuguanli.vue"
import { ElMessage } from 'element-plus';
export default { export default {
name: 'app', name: 'app',
components: { shujuguanliComponent }, components: { shujuguanliComponent },
@ -22,7 +20,7 @@ export default {
return { return {
_: _, _: _,
dayjs: dayjs, dayjs: dayjs,
isVip: true, isVip: false,
jihuoma: "", jihuoma: "",
zhucema: "", zhucema: "",
} }
@ -32,7 +30,7 @@ export default {
methods: { methods: {
}, },
async mounted() { async mounted() {
let fiveDay = dayjs('2024-11-7T00:00:00').valueOf() let fiveDay = dayjs('2024-12-7T00:00:00').valueOf()
if (!this.isVip) { if (!this.isVip) {
if (dayjs().valueOf() > fiveDay) { if (dayjs().valueOf() > fiveDay) {
this.isVip = false this.isVip = false

BIN
src/renderer/src/assets/excel/WKM25471-02D装箱单(1) - 副本.xlsx

Binary file not shown.

263
src/renderer/src/views/shujuguanli.vue

@ -4,7 +4,7 @@
<el-row style="margin-bottom: 8px;"> <el-row style="margin-bottom: 8px;">
<el-col> <el-col>
<div class="inputClass uploadClass"> <div class="inputClass uploadClass">
<el-upload :show-file-list="false" v-model="fileOriData" :before-upload="beforeAvatarUpload" <el-upload :show-file-list="false" v-model="fileOriData1" :before-upload="beforeAvatarUpload"
:http-request="successSubmit1" accept=".xls,.xlsx,.csv"> :http-request="successSubmit1" accept=".xls,.xlsx,.csv">
<el-button type="success"> <el-button type="success">
<el-icon> <el-icon>
@ -15,7 +15,7 @@
</el-upload> </el-upload>
</div> </div>
<div class="inputClass uploadClass"> <div class="inputClass uploadClass">
<el-upload :show-file-list="false" v-model="fileOriData" :before-upload="beforeAvatarUpload" <el-upload :show-file-list="false" v-model="fileOriData2" :before-upload="beforeAvatarUpload"
:http-request="successSubmit2" accept=".xls,.xlsx,.csv"> :http-request="successSubmit2" accept=".xls,.xlsx,.csv">
<el-button type="success"> <el-button type="success">
<el-icon> <el-icon>
@ -25,6 +25,12 @@
</el-button> </el-button>
</el-upload> </el-upload>
</div> </div>
<el-button type="primary" @click="viewTable" :disabled="!tableData.length">
<el-icon>
<Download />
</el-icon>
<span>预览</span>
</el-button>
<el-button type="primary" @click="exportData" :disabled="!tableData.length"> <el-button type="primary" @click="exportData" :disabled="!tableData.length">
<el-icon> <el-icon>
<Download /> <Download />
@ -35,7 +41,7 @@
</el-row> </el-row>
</div> </div>
<div v-loading="loading"> <div v-loading="loading">
<tablecomponent :tableHeader="tableHeader" :tableData="tableData" ref="tableComponentRef"> <tablecomponent :tableHeader="tableHeader" :tableData="fileData2" ref="tableComponentRef">
</tablecomponent> </tablecomponent>
</div> </div>
</div> </div>
@ -43,8 +49,8 @@
<script> <script>
import _ from 'lodash' import _ from 'lodash'
import tableHeaderLocal from '../assets/json/shujuguanli.json'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import * as XLSX from 'xlsx';
import tablecomponent from "../components/tablecomponent.vue" import tablecomponent from "../components/tablecomponent.vue"
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
export default { export default {
@ -57,6 +63,10 @@ export default {
_: _, _: _,
dayjs: dayjs, dayjs: dayjs,
tableHeader: [], tableHeader: [],
fileOriData1: null,
fileData1: null,
fileOriData2: null,
fileData2: null,
tableData: [], tableData: [],
loading: false, loading: false,
} }
@ -84,34 +94,63 @@ export default {
this.fileDealData = [] this.fileDealData = []
let fileReader = new FileReader() let fileReader = new FileReader()
fileReader.onload = async function () { fileReader.onload = async function () {
let data = this.result let data = this.result;
let workbook = XLSX.read(data, { type: 'binary' }) // Excel
let sheetName = workbook.SheetNames[0] let workbook = XLSX.read(data, { type: 'array' });
let sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]) //
for (let i = 0; i < sheetData.length; i++) { let sheetName = workbook.SheetNames[0];
let element = sheetData[i]; let sheetData = workbook.Sheets[sheetName];
let dealItem = {} let range = XLSX.utils.decode_range(sheetData['!ref']);
for (let key in element) { //
let headerItem = _.find(tableHeaderLocal, o => o.label === key) let mergeRanges = sheetData['!merges'];
if (headerItem) { if (!mergeRanges) {
dealItem[headerItem.prop] = element[key] mergeRanges = [];
} }
} let allCells = [];
try { for (let rowIndex = range.s.r; rowIndex <= range.e.r; ++rowIndex) {
await myDatabase.student.add({ let newRow = {};
...dealItem, for (let colIndex = range.s.c; colIndex <= range.e.c; ++colIndex) {
...that.dealRow(dealItem), let cell = sheetData[XLSX.utils.encode_cell({
create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), c: colIndex,
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss') r: rowIndex
}) })];
} catch (error) { let cellContent = '';
ElMessage({ if (cell && cell.t) {
message: `${dealItem.name}(${dealItem.xuejihao})学籍号重复,不可再次新增该学生信息`, cellContent = XLSX.utils.format_cell(cell);
type: 'error', }
}) //
let isMergedCell = false;
for (let i = 0; i < mergeRanges.length; i++) {
let mergeRange = mergeRanges[i];
if (rowIndex >= mergeRange.s.r && rowIndex <= mergeRange.e.r &&
colIndex >= mergeRange.s.c && colIndex <= mergeRange.e.c) {
isMergedCell = true;
break;
}
}
if (isMergedCell) {
//
for (let i = 0; i < mergeRanges.length; i++) {
let mergeRange = mergeRanges[i];
if (rowIndex >= mergeRange.s.r && rowIndex <= mergeRange.e.r &&
colIndex >= mergeRange.s.c && colIndex <= mergeRange.e.c) {
let topLeftCell = sheetData[XLSX.utils.encode_cell({
c: mergeRange.s.c,
r: mergeRange.s.r
})];
if (topLeftCell && topLeftCell.t) {
cellContent = XLSX.utils.format_cell(topLeftCell);
}
break;
}
} }
} }
await that.searchData(true) newRow[String.fromCharCode("a".charCodeAt() + colIndex)] = cellContent;
}
allCells.push(newRow);
}
console.log(122, allCells);
that.fileData1 = allCells
} }
fileReader.onerror = function (error) { fileReader.onerror = function (error) {
ElMessage({ ElMessage({
@ -132,30 +171,7 @@ export default {
let workbook = XLSX.read(data, { type: 'binary' }) let workbook = XLSX.read(data, { type: 'binary' })
let sheetName = workbook.SheetNames[0] let sheetName = workbook.SheetNames[0]
let sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]) let sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName])
for (let i = 0; i < sheetData.length; i++) { that.dealData2(sheetData)
let element = sheetData[i];
let dealItem = {}
for (let key in element) {
let headerItem = _.find(tableHeaderLocal, o => o.label === key)
if (headerItem) {
dealItem[headerItem.prop] = element[key]
}
}
try {
await myDatabase.student.add({
...dealItem,
...that.dealRow(dealItem),
create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
update_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
})
} catch (error) {
ElMessage({
message: `${dealItem.name}(${dealItem.xuejihao})学籍号重复,不可再次新增该学生信息`,
type: 'error',
})
}
}
await that.searchData(true)
} }
fileReader.onerror = function (error) { fileReader.onerror = function (error) {
ElMessage({ ElMessage({
@ -165,6 +181,121 @@ export default {
} }
fileReader.readAsArrayBuffer(file) fileReader.readAsArrayBuffer(file)
}, },
dealData2(sheetData) {
console.log(155, sheetData);
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`)) {
}
}
}
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('-'))
})
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
},
//
viewTable() { },
// //
async exportData() { async exportData() {
let listCopy = _.cloneDeep(this.tableData) let listCopy = _.cloneDeep(this.tableData)
@ -178,22 +309,18 @@ export default {
} }
lilstLocal.push(listItem) lilstLocal.push(listItem)
} }
let jsonWorkSheet = XLSX.utils.json_to_sheet(lilstLocal); console.log(135, lilstLocal);
let workBook = { // let jsonWorkSheet = XLSX.utils.json_to_sheet(lilstLocal);
SheetNames: ["sheet1"], // let workBook = {
Sheets: { // SheetNames: ["sheet1"],
["sheet1"]: jsonWorkSheet, // Sheets: {
} // ["sheet1"]: jsonWorkSheet,
}; // }
XLSX.writeFile(workBook, `数据表格管理${dayjs().format("YYYY-MM-DD_HH-mm-ss")}.xls`); // };
// XLSX.writeFile(workBook, `${dayjs().format("YYYY-MM-DD_HH-mm-ss")}.xls`);
},
}, },
async mounted() {
this.tableHeader = _.filter(tableHeaderLocal, o => o.tableShow)
this.formHeader = _.filter(tableHeaderLocal, o => o.formShow)
await this.updateSeach()
}, },
async mounted() { },
} }
</script> </script>
<style scoped> <style scoped>

Loading…
Cancel
Save