|
@ -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> |
|
|