fix: 🐛 修复表格错位问题

This commit is contained in:
LOG1997
2025-12-30 20:18:24 +08:00
parent 71b8085dd8
commit 863ed8426c
2 changed files with 42 additions and 44 deletions

View File

@@ -30,11 +30,10 @@ const actionsColumns = computed<any[]>(() => {
<template> <template>
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table min-w-[600px]"> <table class="table min-w-150">
<!-- head --> <!-- head -->
<thead> <thead>
<tr> <tr>
<th />
<th v-for="(item, index) in dataColumns" :key="index"> <th v-for="(item, index) in dataColumns" :key="index">
{{ item.label }} {{ item.label }}
</th> </th>

View File

@@ -1,60 +1,59 @@
import * as XLSX from 'xlsx' import * as XLSX from 'xlsx'
import i18n from '@/locales/i18n'
import { addOtherInfo } from '@/utils' import { addOtherInfo } from '@/utils'
// 定义消息类型 // 定义消息类型
interface WorkerMessage { interface WorkerMessage {
type: 'start' | 'stop' | 'reset' type: 'start' | 'stop' | 'reset'
data: any data: any
templateData: any templateData: any
} }
let allData: any[] = [] let allData: any[] = []
function headersEqual(template: string[], actual: string[]): boolean { function headersEqual(template: string[], actual: string[]): boolean {
return template.length >= actual.length return template.length >= actual.length
&& actual.some(item => template.includes(item)) && actual.some(item => template.includes(item))
} }
// 接收主线程消息 // 接收主线程消息
globalThis.onmessage = async (e: MessageEvent<WorkerMessage>) => { globalThis.onmessage = async (e: MessageEvent<WorkerMessage>) => {
switch (e.data.type) { switch (e.data.type) {
case 'start': case 'start':
{ {
const fileData = e.data.data const fileData = e.data.data
const templateData = e.data.templateData const templateData = e.data.templateData
const workBook = XLSX.read(fileData, { type: 'binary', cellDates: true }) const workBook = XLSX.read(fileData, { type: 'binary', cellDates: true })
const workSheet = workBook.Sheets[workBook.SheetNames[0]] const workSheet = workBook.Sheets[workBook.SheetNames[0]]
const excelData: object[] = XLSX.utils.sheet_to_json(workSheet) const excelData: object[] = XLSX.utils.sheet_to_json(workSheet)
const templateWorkBook = XLSX.read(templateData, { type: 'array', cellDates: true }) const templateWorkBook = XLSX.read(templateData, { type: 'array', cellDates: true })
const templateWorkSheet = templateWorkBook.Sheets[templateWorkBook.SheetNames[0]] const templateWorkSheet = templateWorkBook.Sheets[templateWorkBook.SheetNames[0]]
const templateExcelData: object[] = XLSX.utils.sheet_to_json(templateWorkSheet) const templateExcelData: object[] = XLSX.utils.sheet_to_json(templateWorkSheet)
const templateHeader = Object.keys(templateExcelData[0]) const templateHeader = Object.keys(templateExcelData[0])
const header = Object.keys(excelData[0]) const header = Object.keys(excelData[0])
if (!headersEqual(templateHeader, header)) { if (!headersEqual(templateHeader, header)) {
globalThis.postMessage({ globalThis.postMessage({
type: 'error', type: 'error',
data: null, data: null,
message: 'not right template', message: 'not right template',
}) })
return return
} }
allData = addOtherInfo(excelData) allData = addOtherInfo(excelData)
globalThis.postMessage({ globalThis.postMessage({
type: 'done', type: 'done',
data: allData, data: allData,
message: '读取完成', message: '读取完成',
}) })
break break
}
default:
globalThis.postMessage({
type: 'fail',
data: null,
message: '读取失败',
})
break
} }
default:
globalThis.postMessage({
type: 'fail',
data: null,
message: '读取失败',
})
break
}
} }