fix: xlsx static import + type cast for TS build
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useState, useEffect, useCallback, useRef } from 'react'
|
||||
import * as XLSX from 'xlsx'
|
||||
import {
|
||||
KeyRound, Save, RefreshCw, Check, X, AlertCircle,
|
||||
ChevronDown, ChevronRight, Trash2, Plus, Eye, EyeOff,
|
||||
@@ -174,21 +175,17 @@ export function TTLockPage() {
|
||||
|
||||
const handleImportFile = async (file: File) => {
|
||||
try {
|
||||
const { read, utils } = await import('xlsx')
|
||||
const buf = await file.arrayBuffer()
|
||||
const wb = read(buf, { type: 'array' })
|
||||
const wb = XLSX.read(buf, { type: 'array' })
|
||||
const ws = wb.Sheets[wb.SheetNames[0]]
|
||||
// header: true — первая строка как ключи
|
||||
const rows = utils.sheet_to_json<Record<string, string>>(ws, { defval: '' })
|
||||
const rows = XLSX.utils.sheet_to_json(ws, { defval: '' }) as Array<Record<string, unknown>>
|
||||
|
||||
const parsed: ImportRow[] = rows.map(row => {
|
||||
const doorName = String(row['Door Name'] ?? '').trim()
|
||||
const rawMac = String(row['Lock Mac'] ?? '').trim()
|
||||
const mac = rawMac.replace(/:/g, '').toUpperCase()
|
||||
|
||||
// Ищем комнату по номеру
|
||||
const matched = rooms.find(r => String(r.number).trim() === doorName)
|
||||
// Уже привязана?
|
||||
const matched = rooms.find(r => String(r.number).trim() === doorName)
|
||||
const alreadyMapped = matched ? mappings.some(m => m.roomId === matched.id) : false
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user