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",
"element-plus": "^2.7.1",
"lodash": "^4.17.21",
"vxe-table": "^4.7.87"
"vxe-table": "^4.7.87",
"xlsx": "^0.18.5"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.2.0",

2
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)

6
src/renderer/src/App.vue

@ -12,9 +12,7 @@
<script>
import _ from 'lodash'
import dayjs from 'dayjs'
import { myDatabase } from './assets/js/db.js'
import shujuguanliComponent from "./views/shujuguanli.vue"
import { ElMessage } from 'element-plus';
export default {
name: 'app',
components: { shujuguanliComponent },
@ -22,7 +20,7 @@ export default {
return {
_: _,
dayjs: dayjs,
isVip: true,
isVip: false,
jihuoma: "",
zhucema: "",
}
@ -32,7 +30,7 @@ export default {
methods: {
},
async mounted() {
let fiveDay = dayjs('2024-11-7T00:00:00').valueOf()
let fiveDay = dayjs('2024-12-7T00:00:00').valueOf()
if (!this.isVip) {
if (dayjs().valueOf() > fiveDay) {
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-col>
<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">
<el-button type="success">
<el-icon>
@ -15,7 +15,7 @@
</el-upload>
</div>
<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">
<el-button type="success">
<el-icon>
@ -25,6 +25,12 @@
</el-button>
</el-upload>
</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-icon>
<Download />
@ -35,7 +41,7 @@
</el-row>
</div>
<div v-loading="loading">
<tablecomponent :tableHeader="tableHeader" :tableData="tableData" ref="tableComponentRef">
<tablecomponent :tableHeader="tableHeader" :tableData="fileData2" ref="tableComponentRef">
</tablecomponent>
</div>
</div>
@ -43,8 +49,8 @@
<script>
import _ from 'lodash'
import tableHeaderLocal from '../assets/json/shujuguanli.json'
import dayjs from 'dayjs'
import * as XLSX from 'xlsx';
import tablecomponent from "../components/tablecomponent.vue"
import { ElMessage, ElMessageBox } from 'element-plus'
export default {
@ -57,6 +63,10 @@ export default {
_: _,
dayjs: dayjs,
tableHeader: [],
fileOriData1: null,
fileData1: null,
fileOriData2: null,
fileData2: null,
tableData: [],
loading: false,
}
@ -84,34 +94,63 @@ export default {
this.fileDealData = []
let fileReader = new FileReader()
fileReader.onload = async function () {
let data = this.result
let workbook = XLSX.read(data, { type: 'binary' })
let sheetName = workbook.SheetNames[0]
let sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName])
for (let i = 0; i < sheetData.length; i++) {
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',
})
let data = this.result;
// Excel
let workbook = XLSX.read(data, { type: 'array' });
//
let sheetName = workbook.SheetNames[0];
let sheetData = workbook.Sheets[sheetName];
let range = XLSX.utils.decode_range(sheetData['!ref']);
//
let mergeRanges = sheetData['!merges'];
if (!mergeRanges) {
mergeRanges = [];
}
let allCells = [];
for (let rowIndex = range.s.r; rowIndex <= range.e.r; ++rowIndex) {
let newRow = {};
for (let colIndex = range.s.c; colIndex <= range.e.c; ++colIndex) {
let cell = sheetData[XLSX.utils.encode_cell({
c: colIndex,
r: rowIndex
})];
let cellContent = '';
if (cell && cell.t) {
cellContent = XLSX.utils.format_cell(cell);
}
//
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) {
ElMessage({
@ -132,30 +171,7 @@ export default {
let workbook = XLSX.read(data, { type: 'binary' })
let sheetName = workbook.SheetNames[0]
let sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName])
for (let i = 0; i < sheetData.length; i++) {
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)
that.dealData2(sheetData)
}
fileReader.onerror = function (error) {
ElMessage({
@ -165,6 +181,121 @@ export default {
}
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() {
let listCopy = _.cloneDeep(this.tableData)
@ -178,22 +309,18 @@ export default {
}
lilstLocal.push(listItem)
}
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`);
},
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`);
},
async mounted() {
this.tableHeader = _.filter(tableHeaderLocal, o => o.tableShow)
this.formHeader = _.filter(tableHeaderLocal, o => o.formShow)
await this.updateSeach()
},
async mounted() { },
}
</script>
<style scoped>

Loading…
Cancel
Save