add data export
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<template #right>
|
||||
<navbar-actions :actions="actionList" :visible="canShowActionMenu" />
|
||||
<navbar-actions :actions="actionList" :visible="canCreateCustomer" />
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main v-can="permissionCodes.customer.read" class="page-content scroll list">
|
||||
@@ -170,7 +170,7 @@
|
||||
import type { NavbarAction } from "@/types/NavbarAction.ts";
|
||||
import type { DropdownValue } from "tdesign-mobile-vue";
|
||||
import { Message } from "@/utils/message";
|
||||
import { Time, Toolkit, WebToolkit } from "timi-web";
|
||||
import { Time, Toolkit } from "timi-web";
|
||||
import { type Page, type PageResult, useUserStore } from "timi-web-api";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
import CodeScanner from "@/components/CodeScanner.vue";
|
||||
@@ -194,7 +194,6 @@ const userStore = useUserStore();
|
||||
const currentStoreStore = useCurrentStoreStore();
|
||||
const settingStore = useSettingStore();
|
||||
const isRefreshing = ref(false);
|
||||
const isExporting = ref(false);
|
||||
const isRemoving = ref(false);
|
||||
const removeDialogVisible = ref(false);
|
||||
const removeTarget = ref<Customer>();
|
||||
@@ -203,8 +202,6 @@ const isGlobalManager = computed(() => userStore.hasRoles(gaoRoleCodes.globalMan
|
||||
const canReadTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.read));
|
||||
const canCreateCustomer = computed(() => userStore.hasPermissions(permissionCodes.customer.create));
|
||||
const canDeleteCustomer = computed(() => userStore.hasPermissions(permissionCodes.customer.delete));
|
||||
const canExportCustomer = computed(() => userStore.hasPermissions(permissionCodes.customer.export));
|
||||
const canShowActionMenu = computed(() => canCreateCustomer.value || canExportCustomer.value);
|
||||
const scannerVisible = ref(false);
|
||||
const scanStatus = ref("点击扫码开始识别");
|
||||
let latestDecodedText = "";
|
||||
@@ -261,15 +258,6 @@ const actionList = computed<NavbarAction[]>(() => {
|
||||
text: "新增客户"
|
||||
});
|
||||
}
|
||||
if (canExportCustomer.value) {
|
||||
list.push({
|
||||
action: doExport,
|
||||
icon: "download",
|
||||
key: "export",
|
||||
loading: isExporting.value,
|
||||
text: "导出 Excel"
|
||||
});
|
||||
}
|
||||
return list;
|
||||
});
|
||||
|
||||
@@ -473,22 +461,6 @@ async function removeCustomer(customer: Customer): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 导出 ----------
|
||||
|
||||
async function doExport(): Promise<void> {
|
||||
if (isExporting.value) {
|
||||
return;
|
||||
}
|
||||
isExporting.value = true;
|
||||
try {
|
||||
const blob = await CustomerAPI.exportXSSF(page);
|
||||
WebToolkit.downloadBlob(blob, `客户列表-${Time.toDate(new Date())}.xlsx`);
|
||||
Message.success("导出已开始");
|
||||
} finally {
|
||||
isExporting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function buildCreatedAtRange(): [number | undefined, number | undefined] {
|
||||
if (dateFilterType.value === "all") {
|
||||
return [undefined, undefined];
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
<template>
|
||||
<div class="page-layout navbar data-export-page">
|
||||
<t-navbar fixed :z-index="20" title="数据导出" left-arrow @left-click="$router.back()">
|
||||
<template #right>
|
||||
<t-button
|
||||
theme="primary"
|
||||
variant="text"
|
||||
size="small"
|
||||
:disabled="isNextDisabled"
|
||||
:loading="isStatLoading"
|
||||
content="下一步"
|
||||
@click="loadStat"
|
||||
/>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main class="page-content scroll column">
|
||||
<t-cell-group title="导出范围" theme="card">
|
||||
<t-cell title="时间范围" :note="dateFilterLabel" arrow @click="openDateFilterPicker" />
|
||||
<t-cell title="导出附件">
|
||||
<template #rightIcon>
|
||||
<t-switch size="small" v-model="includeAttachment" />
|
||||
</template>
|
||||
<template #description>
|
||||
<span class="orange">显著增加文件体积和生成时间</span>
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell
|
||||
v-if="dateFilterType === 'custom'"
|
||||
title="开始日期"
|
||||
:note="beginDate || '请选择'"
|
||||
arrow
|
||||
@click="openBeginDatePicker"
|
||||
/>
|
||||
<t-cell
|
||||
v-if="dateFilterType === 'custom'"
|
||||
title="结束日期"
|
||||
:note="endDate || '请选择'"
|
||||
arrow
|
||||
@click="openEndDatePicker"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<t-cell-group title="选择导出模块" theme="card">
|
||||
<t-cell class="module-cell" title="全部模块" @click="toggleAllModules">
|
||||
<template #left-icon>
|
||||
<t-checkbox
|
||||
:model-value="isAllModuleSelected"
|
||||
aria-label="选择全部模块"
|
||||
icon="line"
|
||||
borderless
|
||||
@click.stop
|
||||
@change="checked => setAllModuleSelected(checked === true)"
|
||||
/>
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell
|
||||
v-for="item in dataExportModuleOptionList"
|
||||
:key="item.value"
|
||||
class="module-cell"
|
||||
:title="item.label"
|
||||
@click="toggleModule(item.value)"
|
||||
>
|
||||
<template #left-icon>
|
||||
<t-checkbox
|
||||
:model-value="isModuleSelected(item.value)"
|
||||
:aria-label="`选择${item.label}`"
|
||||
icon="line"
|
||||
borderless
|
||||
@click.stop
|
||||
@change="checked => setModuleSelected(item.value, checked === true)"
|
||||
/>
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
</main>
|
||||
<t-popup v-model="dateFilterPickerVisible" placement="bottom">
|
||||
<t-picker
|
||||
v-if="dateFilterPickerVisible"
|
||||
v-model="dateFilterPickerDraft"
|
||||
:columns="dateFilterOptions"
|
||||
title="时间范围"
|
||||
@cancel="closeDateFilterPicker"
|
||||
@confirm="confirmDateFilter"
|
||||
/>
|
||||
</t-popup>
|
||||
<t-popup v-model="beginDatePickerVisible" placement="bottom">
|
||||
<t-date-time-picker
|
||||
v-if="beginDatePickerVisible"
|
||||
v-model="beginDateDraft"
|
||||
format="YYYY-MM-DD"
|
||||
:mode="['date']"
|
||||
title="开始日期"
|
||||
:default-value="beginDate"
|
||||
@cancel="closeBeginDatePicker"
|
||||
@confirm="confirmBeginDate"
|
||||
/>
|
||||
</t-popup>
|
||||
<t-popup v-model="endDatePickerVisible" placement="bottom">
|
||||
<t-date-time-picker
|
||||
v-if="endDatePickerVisible"
|
||||
v-model="endDateDraft"
|
||||
format="YYYY-MM-DD"
|
||||
:mode="['date']"
|
||||
title="结束日期"
|
||||
:default-value="endDate"
|
||||
@cancel="closeEndDatePicker"
|
||||
@confirm="confirmEndDate"
|
||||
/>
|
||||
</t-popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import DataExportAPI from "@/api/DataExportAPI";
|
||||
import { dataExportModuleOptionList } from "@/pages/dataExport/dataExport";
|
||||
import { useDataExportStore } from "@/store/dataExportStore";
|
||||
import type { DataExportModule, DataExportRequest } from "@/types/DataExport";
|
||||
import { buildPresetDateRange } from "@/utils/date";
|
||||
import { DATE_FILTER_OPTIONS as dateFilterOptions, type DateFilterType } from "@/utils/dateFilter";
|
||||
import { Message } from "@/utils/message";
|
||||
|
||||
defineOptions({
|
||||
name: "DataExport"
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const dataExportStore = useDataExportStore();
|
||||
|
||||
// ---------- 导出条件 ----------
|
||||
|
||||
const moduleList = ref<DataExportModule[]>([...(dataExportStore.request?.moduleList || [])]);
|
||||
const includeAttachment = ref(dataExportStore.request?.includeAttachment || false);
|
||||
const dateFilterType = ref<DateFilterType>(dataExportStore.request?.allTime === false ? "custom" : "all");
|
||||
const allTime = computed(() => dateFilterType.value === "all");
|
||||
const beginDate = ref(dataExportStore.request?.beginDate || "");
|
||||
const endDate = ref(dataExportStore.request?.endDate || "");
|
||||
const dateFilterPickerVisible = ref(false);
|
||||
const dateFilterPickerDraft = ref<DateFilterType[]>([dateFilterType.value]);
|
||||
const beginDatePickerVisible = ref(false);
|
||||
const endDatePickerVisible = ref(false);
|
||||
const beginDateDraft = ref("");
|
||||
const endDateDraft = ref("");
|
||||
const isStatLoading = ref(false);
|
||||
const isNextDisabled = computed(() => !allTime.value && (!beginDate.value || !endDate.value));
|
||||
const dateFilterLabel = computed(() => dateFilterOptions.find(item => item.value === dateFilterType.value)?.label || "自定义");
|
||||
const isAllModuleSelected = computed(() => dataExportModuleOptionList.every(item => isModuleSelected(item.value)));
|
||||
|
||||
function isModuleSelected(module: DataExportModule): boolean {
|
||||
return moduleList.value.includes(module);
|
||||
}
|
||||
|
||||
function setModuleSelected(module: DataExportModule, selected: boolean): void {
|
||||
if (selected && !isModuleSelected(module)) {
|
||||
moduleList.value = [...moduleList.value, module];
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selected && isModuleSelected(module)) {
|
||||
moduleList.value = moduleList.value.filter(item => item !== module);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleModule(module: DataExportModule): void {
|
||||
setModuleSelected(module, !isModuleSelected(module));
|
||||
}
|
||||
|
||||
function setAllModuleSelected(selected: boolean): void {
|
||||
moduleList.value = selected ? dataExportModuleOptionList.map(item => item.value) : [];
|
||||
}
|
||||
|
||||
function toggleAllModules(): void {
|
||||
setAllModuleSelected(!isAllModuleSelected.value);
|
||||
}
|
||||
|
||||
function buildRequest(): DataExportRequest | undefined {
|
||||
if (moduleList.value.length < 1) {
|
||||
Message.warning("请至少选择一个导出模块");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!allTime.value && (!beginDate.value || !endDate.value)) {
|
||||
Message.warning("请选择开始日期和结束日期");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!allTime.value && endDate.value < beginDate.value) {
|
||||
Message.warning("结束日期不能早于开始日期");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
moduleList: [...moduleList.value],
|
||||
includeAttachment: includeAttachment.value,
|
||||
allTime: allTime.value,
|
||||
...(allTime.value ? {} : {
|
||||
beginDate: beginDate.value,
|
||||
endDate: endDate.value
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
function openDateFilterPicker(): void {
|
||||
dateFilterPickerDraft.value = [dateFilterType.value];
|
||||
dateFilterPickerVisible.value = true;
|
||||
}
|
||||
|
||||
function closeDateFilterPicker(): void {
|
||||
dateFilterPickerVisible.value = false;
|
||||
dateFilterPickerDraft.value = [dateFilterType.value];
|
||||
}
|
||||
|
||||
function confirmDateFilter(value: Array<string | number>): void {
|
||||
const type = String(value[0] || "custom") as DateFilterType;
|
||||
dateFilterPickerVisible.value = false;
|
||||
dateFilterType.value = type;
|
||||
dateFilterPickerDraft.value = [type];
|
||||
if (type === "custom") {
|
||||
return;
|
||||
}
|
||||
|
||||
const [begin, end] = buildPresetDateRange(type);
|
||||
beginDate.value = begin.slice(0, 10);
|
||||
endDate.value = end.slice(0, 10);
|
||||
}
|
||||
|
||||
function openBeginDatePicker(): void {
|
||||
beginDateDraft.value = beginDate.value;
|
||||
beginDatePickerVisible.value = true;
|
||||
}
|
||||
|
||||
function openEndDatePicker(): void {
|
||||
endDateDraft.value = endDate.value;
|
||||
endDatePickerVisible.value = true;
|
||||
}
|
||||
|
||||
function closeBeginDatePicker(): void {
|
||||
beginDatePickerVisible.value = false;
|
||||
beginDateDraft.value = beginDate.value;
|
||||
}
|
||||
|
||||
function closeEndDatePicker(): void {
|
||||
endDatePickerVisible.value = false;
|
||||
endDateDraft.value = endDate.value;
|
||||
}
|
||||
|
||||
function confirmBeginDate(value?: string | number): void {
|
||||
beginDatePickerVisible.value = false;
|
||||
beginDate.value = String(value || beginDateDraft.value);
|
||||
dateFilterType.value = "custom";
|
||||
}
|
||||
|
||||
function confirmEndDate(value?: string | number): void {
|
||||
endDatePickerVisible.value = false;
|
||||
endDate.value = String(value || endDateDraft.value);
|
||||
dateFilterType.value = "custom";
|
||||
}
|
||||
|
||||
// ---------- 统计预览 ----------
|
||||
|
||||
async function loadStat(): Promise<void> {
|
||||
const request = buildRequest();
|
||||
if (!request || isStatLoading.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
isStatLoading.value = true;
|
||||
try {
|
||||
dataExportStore.setRequest(request);
|
||||
dataExportStore.setStat(await DataExportAPI.stat(request));
|
||||
await router.push({ name: "DataExportStat" });
|
||||
} finally {
|
||||
isStatLoading.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.data-export-page {
|
||||
|
||||
.module-cell {
|
||||
--td-checkbox-vertical-padding: 0;
|
||||
|
||||
:deep(.t-checkbox__icon) {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,133 @@
|
||||
<template>
|
||||
<div class="page-layout navbar data-export-stat-page">
|
||||
<t-navbar fixed :z-index="20" title="导出统计" left-arrow @left-click="router.back()">
|
||||
<template #right>
|
||||
<t-button
|
||||
theme="primary"
|
||||
variant="text"
|
||||
size="small"
|
||||
:loading="isTaskCreating"
|
||||
content="确认"
|
||||
@click="createExportTask"
|
||||
/>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main v-if="request && stat" class="page-content scroll column content">
|
||||
<t-cell-group title="统计范围" theme="card">
|
||||
<t-cell v-if="request.allTime" title="时间范围" note="全部时间" />
|
||||
<template v-else>
|
||||
<t-cell title="开始时间" :note="request.beginDate" />
|
||||
<t-cell title="结束时间" :note="request.endDate" />
|
||||
</template>
|
||||
<t-cell v-if="request.includeAttachment" title="导出附件" note="包含" />
|
||||
</t-cell-group>
|
||||
<card-container
|
||||
description="数据统计"
|
||||
:tips="request.includeAttachment ? '数据大小为预估,附件大小为精确' : '数据大小为预估'"
|
||||
>
|
||||
<t-table
|
||||
class="table"
|
||||
row-key="module"
|
||||
:data="moduleStatTableData"
|
||||
:columns="moduleStatColumns"
|
||||
table-content-width="max-content"
|
||||
table-layout="auto"
|
||||
/>
|
||||
</card-container>
|
||||
<t-cell-group class="stat-card" title="统计合计" theme="card">
|
||||
<t-cell title="业务数据量" :note="formatDataExportCount(stat.recordCount)" />
|
||||
<t-cell v-if="request.includeAttachment" title="附件数量" :note="formatDataExportCount(stat.attachmentCount)" />
|
||||
<t-cell title="业务数据预估大小" :note="formatDataExportFileSize(stat.businessEstimateSize)" />
|
||||
<t-cell v-if="request.includeAttachment" title="附件精确大小" :note="formatDataExportFileSize(stat.attachmentSize)" />
|
||||
<t-cell title="总预估大小" :note="formatDataExportFileSize(stat.estimateSize)" />
|
||||
</t-cell-group>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import DataExportAPI from "@/api/DataExportAPI";
|
||||
import {
|
||||
formatDataExportCount,
|
||||
formatDataExportFileSize,
|
||||
getDataExportModuleLabel
|
||||
} from "@/pages/dataExport/dataExport";
|
||||
import { useDataExportStore } from "@/store/dataExportStore";
|
||||
import { Message } from "@/utils/message";
|
||||
|
||||
defineOptions({
|
||||
name: "DataExportStat"
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const dataExportStore = useDataExportStore();
|
||||
const request = computed(() => dataExportStore.request);
|
||||
const stat = computed(() => dataExportStore.stat);
|
||||
const isTaskCreating = ref(false);
|
||||
const moduleStatColumns = computed(() => [
|
||||
{ colKey: "module", title: "模块", fixed: "left" },
|
||||
...(request.value?.includeAttachment
|
||||
? [{ colKey: "recordAndAttachmentCount", title: "数据/附件" }]
|
||||
: [{ colKey: "recordCount", title: "数据" }]),
|
||||
{ colKey: "businessEstimateSize", title: "业务大小", align: "right" },
|
||||
...(request.value?.includeAttachment ? [{ colKey: "attachmentSize", title: "附件大小", align: "right" }] : []),
|
||||
{ colKey: "estimateSize", title: "合计", align: "right" }
|
||||
]);
|
||||
const moduleStatTableData = computed(() => (stat.value?.moduleStatList || []).map(item => ({
|
||||
module: getDataExportModuleLabel(item.module),
|
||||
recordCount: formatDataExportCount(item.recordCount),
|
||||
recordAndAttachmentCount: `${formatDataExportCount(item.recordCount)} / ${formatDataExportCount(item.attachmentCount)}`,
|
||||
businessEstimateSize: formatDataExportFileSize(item.businessEstimateSize),
|
||||
attachmentSize: formatDataExportFileSize(item.attachmentSize),
|
||||
estimateSize: formatDataExportFileSize(item.estimateSize)
|
||||
})));
|
||||
|
||||
async function createExportTask(): Promise<void> {
|
||||
if (!request.value || isTaskCreating.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
isTaskCreating.value = true;
|
||||
try {
|
||||
const task = await DataExportAPI.createTask(request.value);
|
||||
dataExportStore.setStat(task.stat);
|
||||
dataExportStore.setTask(task);
|
||||
await router.push({
|
||||
name: "DataExportTask",
|
||||
params: {
|
||||
taskId: task.taskId
|
||||
}
|
||||
});
|
||||
Message.success("导出任务已创建");
|
||||
} finally {
|
||||
isTaskCreating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (request.value && stat.value) {
|
||||
return;
|
||||
}
|
||||
await router.replace({ name: "DataExport" });
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.data-export-stat-page {
|
||||
|
||||
.table {
|
||||
|
||||
:deep(.t-table--layout-auto) {
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
:deep(.t-table__cell--fixed-left) {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
:deep(td) {
|
||||
padding: .5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,178 @@
|
||||
<template>
|
||||
<div class="page-layout navbar data-export-task-page">
|
||||
<t-navbar fixed :z-index="20" title="导出任务" left-arrow @left-click="router.back()" />
|
||||
<main v-if="task" class="page-content scroll column">
|
||||
<t-cell-group class="task-card" title="导出任务" theme="card">
|
||||
<t-cell title="当前状态" :note="taskStatusText" />
|
||||
<t-cell title="任务进度">
|
||||
<template #note>
|
||||
<t-progress class="progress" v-if="isTaskProgressAvailable" :percentage="taskProgressPercentage" />
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</t-cell>
|
||||
<t-cell title="预估导出行数" :note="formatDataExportCount(task.stat.recordCount)" />
|
||||
<t-cell title="预估总大小" :note="formatDataExportFileSize(task.stat.estimateSize)" />
|
||||
<t-cell v-if="task.result" title="实际文件大小" :note="formatDataExportFileSize(task.result.size)" />
|
||||
</t-cell-group>
|
||||
<t-button
|
||||
v-if="canDownloadTask"
|
||||
class="cell-button"
|
||||
theme="primary"
|
||||
content="下载 ZIP 文件"
|
||||
@click="downloadTask"
|
||||
/>
|
||||
<t-button
|
||||
v-else-if="!isTaskActive"
|
||||
class="cell-button"
|
||||
theme="default"
|
||||
content="发起新的导出"
|
||||
@click="restartExport"
|
||||
/>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import DataExportAPI from "@/api/DataExportAPI";
|
||||
import { formatDataExportCount, formatDataExportFileSize } from "@/pages/dataExport/dataExport";
|
||||
import { useDataExportStore } from "@/store/dataExportStore";
|
||||
import type { DataExportTask, DataExportTaskStatus } from "@/types/DataExport";
|
||||
import { Message } from "@/utils/message";
|
||||
|
||||
const pollingInterval = 2000;
|
||||
const pendingTaskStatusList: DataExportTaskStatus[] = ["IDLE", "WAITING", "RUNNING", "PAUSE"];
|
||||
const taskStatusTextMap: Record<DataExportTaskStatus, string> = {
|
||||
IDLE: "等待执行",
|
||||
WAITING: "排队中",
|
||||
RUNNING: "正在生成",
|
||||
PAUSE: "已暂停",
|
||||
SUCCESS: "生成完成",
|
||||
ERROR: "生成失败",
|
||||
INTERRUPT: "任务中断",
|
||||
DIED: "任务异常结束"
|
||||
};
|
||||
|
||||
defineOptions({
|
||||
name: "DataExportTask"
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const dataExportStore = useDataExportStore();
|
||||
const task = computed(() => dataExportStore.task);
|
||||
const isTaskQuerying = ref(false);
|
||||
let pollingTimer: number | undefined;
|
||||
|
||||
const isTaskActive = computed(() => Boolean(task.value && pendingTaskStatusList.includes(task.value.status)));
|
||||
const taskStatusText = computed(() => task.value ? taskStatusTextMap[task.value.status] : "-");
|
||||
const isTaskProgressAvailable = computed(() => Boolean(task.value && 0 <= task.value.progress));
|
||||
const taskProgressPercentage = computed(() => Math.min(Math.round((task.value?.progress || 0) * 100), 100));
|
||||
const isTaskExpired = computed(() => Boolean(task.value?.expiresAt && task.value.expiresAt < Date.now()));
|
||||
const canDownloadTask = computed(() => task.value?.status === "SUCCESS" && Boolean(task.value.result) && !isTaskExpired.value);
|
||||
|
||||
function getTaskId(): string {
|
||||
return typeof route.params.taskId === "string" ? route.params.taskId : "";
|
||||
}
|
||||
|
||||
function updateTask(value: DataExportTask): void {
|
||||
dataExportStore.setTask(value);
|
||||
if (pendingTaskStatusList.includes(value.status)) {
|
||||
startPolling();
|
||||
return;
|
||||
}
|
||||
|
||||
stopPolling();
|
||||
if (value.status !== "SUCCESS") {
|
||||
Message.error(value.message || "导出任务失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function loadTask(): Promise<void> {
|
||||
const taskId = getTaskId();
|
||||
if (!taskId) {
|
||||
await router.replace({ name: "DataExport" });
|
||||
return;
|
||||
}
|
||||
|
||||
updateTask(await DataExportAPI.detail(taskId));
|
||||
}
|
||||
|
||||
function startPolling(): void {
|
||||
stopPolling();
|
||||
pollingTimer = window.setInterval(async () => {
|
||||
await queryTask();
|
||||
}, pollingInterval);
|
||||
}
|
||||
|
||||
function stopPolling(): void {
|
||||
if (pollingTimer === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.clearInterval(pollingTimer);
|
||||
pollingTimer = undefined;
|
||||
}
|
||||
|
||||
async function queryTask(): Promise<void> {
|
||||
if (!getTaskId() || isTaskQuerying.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
isTaskQuerying.value = true;
|
||||
try {
|
||||
await loadTask();
|
||||
} finally {
|
||||
isTaskQuerying.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function downloadTask(): void {
|
||||
if (!task.value?.result || !canDownloadTask.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = DataExportAPI.getDownloadURL(task.value.result.attachmentId);
|
||||
document.body.append(anchor);
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
Message.success("已发起浏览器下载");
|
||||
}
|
||||
|
||||
async function restartExport(): Promise<void> {
|
||||
stopPolling();
|
||||
dataExportStore.reset();
|
||||
await router.replace({ name: "DataExport" });
|
||||
}
|
||||
|
||||
watch(() => route.params.taskId, async () => {
|
||||
await loadTask();
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
await loadTask();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stopPolling();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.data-export-task-page {
|
||||
|
||||
.progress {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
:global(html.theme-dark) {
|
||||
.data-export-task-page {
|
||||
.task-card {
|
||||
.message {
|
||||
color: #94a3b8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,47 @@
|
||||
import type { DataExportModule, DataExportModuleStat } from "@/types/DataExport";
|
||||
import { IOSize } from "timi-ts";
|
||||
|
||||
export type DataExportModuleOption = {
|
||||
label: string;
|
||||
value: DataExportModule;
|
||||
};
|
||||
|
||||
export const dataExportModuleOptionList: DataExportModuleOption[] = [
|
||||
{ label: "客户档案", value: "CUSTOMER" },
|
||||
{ label: "客户消费记录", value: "CUSTOMER_CONSUMPTION_RECORD" },
|
||||
{ label: "客户跟进提醒", value: "CUSTOMER_FOLLOW_UP_REMINDER" },
|
||||
{ label: "客户套餐", value: "CUSTOMER_PACKAGE" },
|
||||
{ label: "事件登记", value: "EVENT_RECORD" },
|
||||
{ label: "销售订单", value: "SALES_ORDER" },
|
||||
{ label: "履约记录", value: "ORDER_FULFILLMENT" },
|
||||
{ label: "资金流水", value: "FUND_RECORD" },
|
||||
{ label: "积分账户", value: "POINT_ACCOUNT" },
|
||||
{ label: "积分流水", value: "POINT_LEDGER" },
|
||||
{ label: "积分兑换", value: "POINT_REDEMPTION" },
|
||||
{ label: "营业日", value: "STORE_BUSINESS_DAY" },
|
||||
{ label: "门店日记", value: "STORE_DIARY" },
|
||||
{ label: "库存流水", value: "PRODUCT_STOCK_RECORD" }
|
||||
];
|
||||
|
||||
const moduleLabelMap = new Map(dataExportModuleOptionList.map(item => [item.value, item.label]));
|
||||
const numberFormatter = new Intl.NumberFormat("zh-CN");
|
||||
|
||||
export function getDataExportModuleLabel(module: DataExportModule): string {
|
||||
return moduleLabelMap.get(module) || module;
|
||||
}
|
||||
|
||||
export function formatDataExportCount(value: number): string {
|
||||
return numberFormatter.format(value);
|
||||
}
|
||||
|
||||
export function formatDataExportFileSize(size: number): string {
|
||||
return IOSize.format(size);
|
||||
}
|
||||
|
||||
export function formatDataExportModuleCount(stat: DataExportModuleStat): string {
|
||||
return `数据 ${formatDataExportCount(stat.recordCount)} 条 · 附件 ${formatDataExportCount(stat.attachmentCount)} 个`;
|
||||
}
|
||||
|
||||
export function formatDataExportModuleSize(stat: DataExportModuleStat): string {
|
||||
return `业务 ${formatDataExportFileSize(stat.businessEstimateSize)} · 附件 ${formatDataExportFileSize(stat.attachmentSize)} · 合计 ${formatDataExportFileSize(stat.estimateSize)}`;
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<template #right>
|
||||
<navbar-actions :actions="actionList" :visible="canShowActionMenu" />
|
||||
<navbar-actions :actions="actionList" :visible="canCreateRecord" />
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main v-can="permissionCodes.eventRecord.read" class="page-content scroll list">
|
||||
@@ -160,7 +160,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { NavbarAction } from "@/types/NavbarAction.ts";
|
||||
import { CenterTips, Time, Text, WebToolkit } from "timi-web";
|
||||
import { CenterTips, Time, Text } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import EventAPI from "@/api/EventAPI";
|
||||
import EventRecordAPI from "@/api/EventRecordAPI";
|
||||
@@ -172,8 +172,6 @@ import { formatEventNumberValue } from "@/utils/eventValue";
|
||||
import { buildPresetDateRange, parseDateFilterType, parseDateTime } from "@/utils/date";
|
||||
import { DATE_FILTER_OPTIONS as dateOptions, type DateFilterType } from "@/utils/dateFilter";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { Message } from "@/utils/message.ts";
|
||||
|
||||
import type { EventItem, EventStatus } from "@/types/EventItem";
|
||||
|
||||
type VerificationFilter = "ALL" | VerificationStatus;
|
||||
@@ -211,7 +209,6 @@ const startVisible = ref(false);
|
||||
const endVisible = ref(false);
|
||||
let keywordTimer: number | undefined;
|
||||
let initialized = false;
|
||||
const isExporting = ref(false);
|
||||
let suppressOptionFilterReload = false;
|
||||
|
||||
const canCreateRecord = computed(() => userStore.hasPermissions(permissionCodes.eventRecord.create));
|
||||
@@ -275,8 +272,6 @@ const selectedNumberEvent = computed(() => {
|
||||
return event?.valueType === "NUMBER" ? event : undefined;
|
||||
});
|
||||
const hasSelectedOption = computed(() => !!selectedOptionEvent.value);
|
||||
const canExportRecord = computed(() => userStore.hasPermissions(permissionCodes.eventRecord.export));
|
||||
const canShowActionMenu = computed(() => canCreateRecord.value || canExportRecord.value);
|
||||
|
||||
const actionList = computed<NavbarAction[]>(() => {
|
||||
const list: NavbarAction[] = [];
|
||||
@@ -289,15 +284,6 @@ const actionList = computed<NavbarAction[]>(() => {
|
||||
text: "添加"
|
||||
});
|
||||
}
|
||||
if (canExportRecord.value) {
|
||||
list.push({
|
||||
action: exportExcel,
|
||||
icon: "download",
|
||||
key: "export",
|
||||
loading: isExporting.value,
|
||||
text: "导出 Excel"
|
||||
});
|
||||
}
|
||||
return list;
|
||||
});
|
||||
|
||||
@@ -541,24 +527,6 @@ async function confirmCustomRange(): Promise<void> {
|
||||
await reloadRecords();
|
||||
}
|
||||
|
||||
async function exportExcel(): Promise<void> {
|
||||
if (isExporting.value) {
|
||||
return;
|
||||
}
|
||||
isExporting.value = true;
|
||||
try {
|
||||
const blob = await EventRecordAPI.exportXSSF({
|
||||
index: 0,
|
||||
size: pageSize,
|
||||
...buildRangeReq()
|
||||
});
|
||||
WebToolkit.downloadBlob(blob, `登记事件记录-${Time.toDate(new Date())}.xlsx`);
|
||||
Message.success("导出已开始");
|
||||
} finally {
|
||||
isExporting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadOptionStats(): Promise<void> {
|
||||
if (!hasSelectedOption.value) {
|
||||
optionStatList.value = [];
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<template #right>
|
||||
<navbar-actions :actions="actionList" :visible="canShowActionMenu" />
|
||||
<navbar-actions :actions="actionList" :visible="canCreateStore || canSortStore" />
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main v-can="permissionCodes.store.read" class="page-content column scroll list">
|
||||
@@ -73,7 +73,6 @@
|
||||
<script setup lang="ts">
|
||||
import type { NavbarAction } from "@/types/NavbarAction.ts";
|
||||
import { Message } from "@/utils/message";
|
||||
import { Time, WebToolkit } from "timi-web";
|
||||
import { type Page, type PageResult, useUserStore } from "timi-web-api";
|
||||
import StoreAPI from "@/api/StoreAPI";
|
||||
import StoreRemoveDialog from "@/components/StoreRemoveDialog.vue";
|
||||
@@ -92,9 +91,6 @@ const isStoreManagerScope = computed(() => userStore.hasRoles(gaoRoleCodes.store
|
||||
const canCreateStore = computed(() => userStore.hasPermissions(permissionCodes.store.create));
|
||||
const canSortStore = computed(() => userStore.hasPermissions(permissionCodes.store.update));
|
||||
const canDeleteStore = computed(() => !isStoreManagerScope.value && userStore.hasPermissions(permissionCodes.store.delete));
|
||||
const canExportStore = computed(() => userStore.hasPermissions(permissionCodes.store.export));
|
||||
const canShowActionMenu = computed(() => canCreateStore.value || canSortStore.value || canExportStore.value);
|
||||
const isExporting = ref(false);
|
||||
const isRemoving = ref(false);
|
||||
const removeDialogVisible = ref(false);
|
||||
const removeTarget = ref<Store>();
|
||||
@@ -119,15 +115,6 @@ const actionList = computed<NavbarAction[]>(() => {
|
||||
text: "排序"
|
||||
});
|
||||
}
|
||||
if (canExportStore.value) {
|
||||
list.push({
|
||||
action: exportExcel,
|
||||
icon: "download",
|
||||
key: "export",
|
||||
loading: isExporting.value,
|
||||
text: "导出 Excel"
|
||||
});
|
||||
}
|
||||
return list;
|
||||
});
|
||||
|
||||
@@ -180,24 +167,6 @@ async function fetch(): Promise<void> {
|
||||
|
||||
// ---------- 操作 ----------
|
||||
|
||||
async function exportExcel(): Promise<void> {
|
||||
if (isExporting.value) {
|
||||
return;
|
||||
}
|
||||
isExporting.value = true;
|
||||
try {
|
||||
const blob = await StoreAPI.exportXSSF({
|
||||
index: 0,
|
||||
size: 10000,
|
||||
orderMap: page.orderMap
|
||||
});
|
||||
WebToolkit.downloadBlob(blob, `门店列表-${Time.toDate(new Date())}.xlsx`);
|
||||
Message.success("导出已开始");
|
||||
} finally {
|
||||
isExporting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function toEdit(item: Store): Promise<void> {
|
||||
if (!item.id) {
|
||||
return;
|
||||
|
||||
@@ -114,6 +114,8 @@ const canManagePermission = computed(() => userStore.hasPermissions([
|
||||
corePermissionCodes.permission.read
|
||||
], "and"));
|
||||
const canManageUser = computed(() => userStore.hasRoles([gaoRoleCodes.globalManager, gaoRoleCodes.storeManager], "or"));
|
||||
const canExportData = computed(() => userStore.hasRoles(gaoRoleCodes.storeManager)
|
||||
&& userStore.hasPermissions(permissionCodes.dataExport.export));
|
||||
const visibleMenuGroupList = computed<MenuGroup[]>(() => menuGroupList.value
|
||||
.map(group => ({
|
||||
...group,
|
||||
@@ -212,6 +214,12 @@ const menuGroupList = computed<MenuGroup[]>(() => [
|
||||
{
|
||||
title: "系统",
|
||||
items: [
|
||||
{
|
||||
icon: "download",
|
||||
path: "/management/data-export",
|
||||
title: "数据导出",
|
||||
visible: canExportData.value
|
||||
},
|
||||
{
|
||||
icon: "setting",
|
||||
path: "/management/settings",
|
||||
|
||||
Reference in New Issue
Block a user