import * as XLSX from 'xlsx' import { ElMessage } from 'element-plus' export function getPageInfo (){ return new Promise((res, rej) => { chrome.runtime.sendMessage( { type: 'FROM_SIDE_PANEL_TO_GET_PAGE_INFO' }, async (response) => { if (chrome.runtime.lastError) { console.error('消息发送错误:', chrome.runtime.lastError) rej(chrome.runtime.lastError) } else { res(response.data) } } ) }) } export function handleInput (xlsxData, formMap) { chrome.runtime.sendMessage({ type: 'FROM_SIDE_PANEL_TO_INPUT_FORM', data: { excelData: xlsxData, formData: formMap } }) } export function getXlsxValue (file) { return new Promise((res, rej) => { try { const reader = new FileReader() reader.readAsArrayBuffer(file) reader.onload = (e) => { const data = new Uint8Array(e.target.result) const workbook = XLSX.read(data, { type: 'array', cellDates: false, cellNF: true, cellText: true, dateNF: 'yyyy-mm-dd' }) // 修复日期处理 const firstSheet = workbook.Sheets[workbook.SheetNames[0]] // 转换为JSON数据 const readData = XLSX.utils.sheet_to_json(firstSheet, { header: 1, raw: false, defval: '', dateNF: 'yyyy-mm-dd' }) res(readData) } } catch (error) { rej() } }) }