优化
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { showExportTaskCreatedDialog } from './exportTaskCreatedDialog'
|
||||
|
||||
describe('showExportTaskCreatedDialog', () => {
|
||||
beforeEach(() => vi.restoreAllMocks())
|
||||
|
||||
it('offers a direct path to the download center with the task reference', async () => {
|
||||
const confirm = vi.spyOn(ElMessageBox, 'confirm').mockResolvedValue({} as never)
|
||||
|
||||
await expect(showExportTaskCreatedDialog({ taskName: '客户列表', taskNo: 'EXP2084' })).resolves.toBe(true)
|
||||
expect(confirm).toHaveBeenCalledWith(
|
||||
expect.stringContaining('任务编号:EXP2084'),
|
||||
'导出任务已创建',
|
||||
expect.objectContaining({ confirmButtonText: '前往下载中心', cancelButtonText: '留在当前页' }),
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps the user on the current page when the dialog is dismissed', async () => {
|
||||
vi.spyOn(ElMessageBox, 'confirm').mockRejectedValue('cancel')
|
||||
|
||||
await expect(showExportTaskCreatedDialog({ taskName: '客户列表' })).resolves.toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,26 @@
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
|
||||
export interface ExportTaskCreatedDialogOptions {
|
||||
taskName: string
|
||||
taskNo?: string | null
|
||||
}
|
||||
|
||||
export async function showExportTaskCreatedDialog(options: ExportTaskCreatedDialogOptions) {
|
||||
const taskReference = options.taskNo ? `\n任务编号:${options.taskNo}` : ''
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`${options.taskName}已进入后台生成队列。文件生成后可在下载中心查看并下载。${taskReference}`,
|
||||
'导出任务已创建',
|
||||
{
|
||||
type: 'success',
|
||||
confirmButtonText: '前往下载中心',
|
||||
cancelButtonText: '留在当前页',
|
||||
distinguishCancelAndClose: true,
|
||||
},
|
||||
)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user