This commit is contained in:
2026-08-04 11:22:04 +08:00
parent c894f07cbb
commit 3dcc8b30db
4 changed files with 95 additions and 5 deletions
@@ -19,8 +19,16 @@ import { createPlatformExportTask } from '@/modules/downloads'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
import { useAuthStore } from '@/core/auth/auth'
import QueryToolbar from '@/shared/components/QueryToolbar.vue'
import { showExportTaskCreatedDialog } from '@/shared/components/exportTaskCreatedDialog'
import CustomersView from './CustomersView.vue'
const { routerPush } = vi.hoisted(() => ({ routerPush: vi.fn() }))
vi.mock('vue-router', async (importOriginal) => ({
...await importOriginal<typeof import('vue-router')>(),
useRouter: () => ({ push: routerPush }),
}))
vi.mock('@/modules/iam', () => ({
approveEnterpriseReview: vi.fn(),
changePlatformTenantStatus: vi.fn(),
@@ -39,6 +47,7 @@ vi.mock('@/modules/iam', () => ({
}))
vi.mock('@/modules/downloads', () => ({ createPlatformExportTask: vi.fn() }))
vi.mock('@/shared/components/exportTaskCreatedDialog', () => ({ showExportTaskCreatedDialog: vi.fn() }))
class ResizeObserverStub implements ResizeObserver {
observe() {}
@@ -97,7 +106,10 @@ describe('CustomersView', () => {
vi.mocked(uploadPlatformTenantQualification).mockResolvedValue({
qualificationId: 'qualification-1', reviewId: null, tenantStatus: 'PROFILE_REQUIRED', documentUrl: '/files/license.png',
})
vi.mocked(createPlatformExportTask).mockResolvedValue({ id: 'export-1', status: 'PENDING' } as never)
vi.mocked(createPlatformExportTask).mockResolvedValue({
id: 'export-1', taskName: '客户列表', taskNo: 'EXP2084', status: 'PENDING',
} as never)
vi.mocked(showExportTaskCreatedDialog).mockResolvedValue(false)
})
it('loads the complete customer detail before editing masked list fields', async () => {
@@ -272,9 +284,27 @@ describe('CustomersView', () => {
exportType: 'CUSTOMER_LIST', format: 'XLSX', taskName: '客户列表',
parameters: { keyword: 'Acme', status: 'ACTIVE' },
})
expect(showExportTaskCreatedDialog).toHaveBeenCalledWith({ taskName: '客户列表', taskNo: 'EXP2084' })
expect(listPlatformTenants).toHaveBeenCalledTimes(1)
})
it('opens the download center when the export-created dialog action is confirmed', async () => {
vi.mocked(createPlatformExportTask).mockResolvedValue({
id: 'export-1', taskName: '客户列表', taskNo: 'EXP2084', status: 'PENDING',
} as never)
vi.mocked(showExportTaskCreatedDialog).mockResolvedValue(true)
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
const exportButton = [...document.querySelectorAll<HTMLButtonElement>('button')]
.find((button) => button.textContent?.trim() === '导出Excel')
exportButton?.click()
await flushPromises()
expect(showExportTaskCreatedDialog).toHaveBeenCalledWith({ taskName: '客户列表', taskNo: 'EXP2084' })
expect(routerPush).toHaveBeenCalledWith({ name: 'download-center' })
})
it('hides customer export when the stable export permission is absent', async () => {
const auth = useAuthStore()
auth.permissions = ['platform:customer:list', 'platform:customer:view']
+14 -4
View File
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { Building2, CheckCircle2, Download, Eye, FileCheck2, FileText, FileUp, Pencil, Plus, Power, ShieldCheck, ShieldX } from '@lucide/vue'
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
import { getApiErrorDetails, getApiErrorMessage, type ApiErrorDetails } from '@/shared/api/http'
@@ -31,6 +32,7 @@ import ApiErrorMeta from '@/shared/components/ApiErrorMeta.vue'
import CopyButton from '@/shared/components/CopyButton.vue'
import DataTable, { type DataTableColumn } from '@/shared/components/DataTable.vue'
import QueryToolbar, { type QueryField, type QueryModel } from '@/shared/components/QueryToolbar.vue'
import { showExportTaskCreatedDialog } from '@/shared/components/exportTaskCreatedDialog'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
type CustomerFilters = QueryModel & { keyword: string; status: PlatformTenantStatus | '' }
@@ -58,6 +60,7 @@ type DetailQualificationPreview = {
}
const access = useAccessPreviewStore()
const router = useRouter()
const page = ref(1)
const pageSize = ref(10)
const loading = ref(false)
@@ -650,8 +653,9 @@ function closeApprovalResult() {
async function exportCustomers() {
exportSubmitting.value = true
let task: Awaited<ReturnType<typeof createPlatformExportTask>>
try {
await createPlatformExportTask({
task = await createPlatformExportTask({
exportType: 'CUSTOMER_LIST',
format: 'XLSX',
taskName: '客户列表',
@@ -660,9 +664,15 @@ async function exportCustomers() {
status: filters.value.status || undefined,
},
})
ElMessage.success('导出任务已创建,可前往下载中心查看')
} catch (error) { ElMessage.error(getApiErrorMessage(error, '客户导出任务创建失败')) }
finally { exportSubmitting.value = false }
} catch (error) {
ElMessage.error(getApiErrorMessage(error, '客户导出任务创建失败'))
return
} finally {
exportSubmitting.value = false
}
const openDownloadCenter = await showExportTaskCreatedDialog({ taskName: task.taskName, taskNo: task.taskNo })
if (openDownloadCenter) await router.push({ name: 'download-center' })
}
watch([page, pageSize], () => { void loadCustomers() })