From 2329fb7a5fb42dfffcc8d72faf76abb6873f74f3 Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Thu, 3 Sep 2026 17:57:44 +0800 Subject: [PATCH] feat: add full directory table export --- config/business_navigation.php | 1 + .../pages/partials/directory-table.blade.php | 72 +++++++++++++++++-- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/config/business_navigation.php b/config/business_navigation.php index 4110740f..bf30b271 100644 --- a/config/business_navigation.php +++ b/config/business_navigation.php @@ -225,6 +225,7 @@ return [ ['name' => 'profit_center', 'label' => '店铺所属利润中心'], ['name' => 'account_type', 'label' => '账号类型'], ['name' => 'account', 'label' => '账号'], + ['name' => 'password_configured', 'label' => '密码', 'kind' => 'secret'], ['name' => 'bound_phone', 'label' => '绑定手机号', 'kind' => 'secret'], ['name' => 'verification_contact', 'label' => '手机号验证码对接人'], ['name' => 'account_group_name', 'label' => '账号分组名称'], diff --git a/resources/views/business/pages/partials/directory-table.blade.php b/resources/views/business/pages/partials/directory-table.blade.php index 78670e55..6b1cf609 100644 --- a/resources/views/business/pages/partials/directory-table.blade.php +++ b/resources/views/business/pages/partials/directory-table.blade.php @@ -115,7 +115,7 @@ background: var(--vip-content-bg, #f8f6f1); } - .directory-table-tools input { + .directory-table-tools > [data-directory-search] { flex: 1 1 16rem; min-width: 12rem; height: 2.25rem; @@ -136,6 +136,11 @@ cursor: pointer; } + .directory-table-tools button:disabled { + cursor: wait; + opacity: 0.65; + } + .directory-field-picker { position: relative; display: inline-block; @@ -160,8 +165,29 @@ } .directory-field-picker__panel[hidden] { display: none; } - .directory-field-picker__option { display: flex; align-items: center; gap: 0.4rem; color: var(--vip-content-ink, #171717); font-size: 0.75rem; } - .directory-field-picker__option input { flex: 0 0 auto; } + .directory-field-picker__option { + display: flex; + align-items: center; + gap: 0.4rem; + min-width: 0; + color: var(--vip-content-ink, #171717); + font-size: 0.75rem; + line-height: 1.35; + cursor: pointer; + } + .directory-field-picker__option input[type="checkbox"] { + flex: 0 0 auto; + width: 1rem; + min-width: 1rem; + height: 1rem; + margin: 0; + accent-color: var(--vip-content-accent, #b9954f); + } + .directory-field-picker__option span { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } .directory-table [data-column-key="sales_01"], .directory-table [data-column-key="sales_02"], .directory-table [data-column-key="sales_03"], @@ -316,7 +342,7 @@ } -
+
@@ -368,6 +394,7 @@
+
@@ -499,6 +526,43 @@ link.click(); URL.revokeObjectURL(link.href); }); + tools.querySelector('[data-directory-export-all]')?.addEventListener('click', async (event) => { + const button = event.currentTarget; + const lastPage = Number(section.dataset.directoryLastPage || 1); + const selected = new Set(checks.filter((check) => check.checked).map((check) => check.value)); + const cellsForExport = (row) => [...row.children] + .filter((cell) => !cell.dataset.columnKey || selected.has(cell.dataset.columnKey)); + const header = cellsForExport(table.tHead.rows[0]).map((cell) => csvEscape(cell.textContent.trim())).join(','); + const lines = []; + button.disabled = true; + const originalLabel = button.textContent; + try { + for (let page = 1; page <= lastPage; page += 1) { + button.textContent = `导出中 ${page}/${lastPage}`; + const url = new URL(window.location.href); + url.searchParams.set('page', String(page)); + const response = await fetch(url, { headers: { 'X-Requested-With': 'XMLHttpRequest' } }); + if (!response.ok) throw new Error(`第 ${page} 页读取失败`); + const html = await response.text(); + const parsed = new DOMParser().parseFromString(html, 'text/html'); + parsed.querySelectorAll('.directory-table tbody tr:not(.is-empty)').forEach((row) => { + lines.push(cellsForExport(row).map((cell) => csvEscape(cell.textContent.trim())).join(',')); + }); + } + const csv = [header, ...lines].join('\n'); + const blob = new Blob([`\ufeff${csv}`], { type: 'text/csv;charset=utf-8' }); + const link = document.createElement('a'); + link.href = URL.createObjectURL(blob); + link.download = `${section.dataset.directoryPage || 'directory'}-all-export.csv`; + link.click(); + URL.revokeObjectURL(link.href); + } catch (error) { + window.alert(error.message || '导出全部数据失败,请稍后重试'); + } finally { + button.disabled = false; + button.textContent = originalLabel; + } + }); tools.querySelector('[data-directory-template]')?.addEventListener('click', () => { const header = [...table.querySelectorAll('thead th')].map((cell) => csvEscape(cell.textContent.trim())).join(','); const blob = new Blob([`\ufeff${header}\n`], { type: 'text/csv;charset=utf-8' });