فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

perf(A07): defer bundled Excel library until a user explicitly requests Excel

davoodmehraban89 committed Oct 15, 2026 at 21:00 UTC 8bbc63c18ce7b0bc48e9dea85d4504a92dd27f3f
1 file changed +18 -1
src/controllers/ExcelController.js
+18 -1
@@ -2,7 +2,18 @@
2 // ExcelController — خروجی و ورودی Excel
3 // ============================================================
4
5 -import * as XLSX from 'xlsx';
5 +// Excel and Persian text editing are not needed on the login screen.
6 +// Load the locally bundled, pinned library only when an Excel action starts.
7 +let XLSX = null;
8 +let xlsxPending = null;
9 +async function loadSheetJS() {
10 + if (XLSX) return XLSX;
11 + if (!xlsxPending) {
12 + xlsxPending = import('xlsx').then(module => { XLSX = module; return module; })
13 + .catch(error => { xlsxPending = null; throw error; });
14 + }
15 + return xlsxPending;
16 +}
17 import { StorageService } from '../core/StorageService.js';
18 import { Auth } from '../core/Auth.js';
19 import { DataScope } from '../core/DataScope.js';
@@ -16,6 +27,7 @@ class ExcelControllerImpl {
27 // ذخیره فایل + نمایش پیام + باز کردن خودکار (سازگار با Tauri)
28 // ============================================================
29 async _saveFile(wb, fileName) {
30 + await loadSheetJS();
31 const isTauri = '__TAURI_INTERNALS__' in window;
32
33 // حالت مرورگر: دانلود معمولی
@@ -61,6 +73,7 @@ class ExcelControllerImpl {
73 // خروجی کامل (Backup Excel)
74 // ============================================================
75 async exportAll() {
76 + await loadSheetJS();
77 const user = Auth.current();
78 if (!user) throw new Error('کاربر یافت نشد');
79
@@ -295,6 +308,7 @@ class ExcelControllerImpl {
308 // خروجی انتخابی
309 // ============================================================
310 async exportSection(section) {
311 + await loadSheetJS();
312 const user = Auth.current();
313 if (!user) throw new Error('کاربر یافت نشد');
314
@@ -402,6 +416,7 @@ class ExcelControllerImpl {
416 // ورودی از Excel
417 // ============================================================
418 async readExcelFile(file) {
419 + await loadSheetJS();
420 return new Promise((resolve, reject) => {
421 const reader = new FileReader();
422 reader.onload = (e) => {
@@ -558,6 +573,7 @@ class ExcelControllerImpl {
573 // دانلود قالب‌های نمونه
574 // ============================================================
575 async downloadProductsTemplate() {
576 + await loadSheetJS();
577 const data = [
578 ['کد', 'نام', 'مشخصه', 'واحد', 'قیمت خرید', 'قیمت فروش', 'نقطه سفارش', 'نوع'],
579 ['P001', 'هارد سرور 2.5 اینچ', 'SAS 1TB', 'عدد', 30000000, 37000000, 5, 'کالا'],
@@ -571,6 +587,7 @@ class ExcelControllerImpl {
587 }
588
589 async downloadContactsTemplate() {
590 + await loadSheetJS();
591 const data = [
592 ['نام', 'نوع', 'نقش', 'موبایل', 'تلفن', 'کد ملی/شناسه', 'کد اقتصادی', 'شماره ثبت', 'کد پستی', 'نشانی'],
593 ['شرکت آرا بتن', 'حقوقی', 'مشتری', '09124376991', '', '14008507476', '14008507476', '544926', '1445956311', 'تهران'],