From 83897a4a9cecf4f6585622fe3ec3ba87d6a5fd0b Mon Sep 17 00:00:00 2001 From: Timi Date: Mon, 26 Oct 2026 11:45:36 +0800 Subject: [PATCH] add data export --- package.json | 1 + pnpm-lock.yaml | 3 + src/api/CustomerAPI.ts | 7 - src/api/DataExportAPI.ts | 28 +++ src/api/EventRecordAPI.ts | 7 - src/api/StoreAPI.ts | 7 - src/pages/customer/CustomerList.vue | 32 +-- src/pages/dataExport/DataExport.vue | 287 ++++++++++++++++++++++++ src/pages/dataExport/DataExportStat.vue | 133 +++++++++++ src/pages/dataExport/DataExportTask.vue | 178 +++++++++++++++ src/pages/dataExport/dataExport.ts | 47 ++++ src/pages/event/EventRecordList.vue | 36 +-- src/pages/store/StoreList.vue | 33 +-- src/pages/tabs/SettingTab.vue | 8 + src/router/index.ts | 10 +- src/router/routes/dataExportRoutes.ts | 39 ++++ src/store/dataExportStore.ts | 40 ++++ src/types/DataExport.ts | 70 ++++++ src/utils/permission.ts | 9 +- 19 files changed, 851 insertions(+), 124 deletions(-) create mode 100644 src/api/DataExportAPI.ts create mode 100644 src/pages/dataExport/DataExport.vue create mode 100644 src/pages/dataExport/DataExportStat.vue create mode 100644 src/pages/dataExport/DataExportTask.vue create mode 100644 src/pages/dataExport/dataExport.ts create mode 100644 src/router/routes/dataExportRoutes.ts create mode 100644 src/store/dataExportStore.ts create mode 100644 src/types/DataExport.ts diff --git a/package.json b/package.json index fb01304..6e4792b 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "less": "^4.3.0", "pinia": "^3.0.2", "tdesign-mobile-vue": "^1.16.2", + "timi-ts": "link:E:/WebProject/timi-ts", "timi-tdesign-mobile": "link:E:/WebProject/timi-tdesign-mobile", "timi-web": "link:E:/WebProject/timi-web", "timi-web-api": "link:E:/WebProject/timi-web-api", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f06ec76..59f0959 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,6 +35,9 @@ importers: timi-tdesign-mobile: specifier: link:E:/WebProject/timi-tdesign-mobile version: link:../timi-tdesign-mobile + timi-ts: + specifier: link:E:/WebProject/timi-ts + version: link:../timi-ts timi-web: specifier: link:E:/WebProject/timi-web version: link:../timi-web diff --git a/src/api/CustomerAPI.ts b/src/api/CustomerAPI.ts index 6aedc8f..320ebf4 100644 --- a/src/api/CustomerAPI.ts +++ b/src/api/CustomerAPI.ts @@ -71,12 +71,6 @@ async function findByName(name: string): Promise { }); } -async function exportXSSF(page: Page): Promise { - return await axios.post(`${BASE_URI}/export`, withCurrentStorePage(page), { - responseType: "blob" - }); -} - async function listInvited(introducerCustomerId: string): Promise { return await axios.post(`${BASE_URI}/invited/list`, undefined, { params: { introducerCustomerId } @@ -117,7 +111,6 @@ export default { findById, findByCode, findByName, - exportXSSF, listInvited, saveInvite, deleteInvite, diff --git a/src/api/DataExportAPI.ts b/src/api/DataExportAPI.ts new file mode 100644 index 0000000..ead4612 --- /dev/null +++ b/src/api/DataExportAPI.ts @@ -0,0 +1,28 @@ +import { axios, getBaseURI } from "timi-web-api/api/BaseAPI"; +import type { DataExportRequest, DataExportStat, DataExportTask } from "@/types/DataExport"; + +const BASE_URI = "/gao/data-export"; + +async function stat(request: DataExportRequest): Promise { + return await axios.post(`${BASE_URI}/stat`, request); +} + +async function createTask(request: DataExportRequest): Promise { + return await axios.post(`${BASE_URI}/task`, request); +} + +async function detail(taskId: string): Promise { + return await axios.get(`${BASE_URI}/task/${encodeURIComponent(taskId)}`); +} + +/** 获取由浏览器直接处理的导出文件下载地址。 */ +function getDownloadURL(attachmentId: string): string { + return `${getBaseURI()}/attach/download/${encodeURIComponent(attachmentId)}`; +} + +export default { + stat, + createTask, + detail, + getDownloadURL +}; diff --git a/src/api/EventRecordAPI.ts b/src/api/EventRecordAPI.ts index 53e6a62..c7f6b81 100644 --- a/src/api/EventRecordAPI.ts +++ b/src/api/EventRecordAPI.ts @@ -52,16 +52,9 @@ async function optionStat(page: EventRecordPage): Promise { return await axios.post(`${BASE_URI}/option/stat`, withCurrentStoreId(page)); } -async function exportXSSF(page: EventRecordPage): Promise { - return await axios.post(`${BASE_URI}/export`, withCurrentStoreId(page), { - responseType: "blob" - }); -} - export default { list, detail, - exportXSSF, create, createBatch, createWithCustomer, diff --git a/src/api/StoreAPI.ts b/src/api/StoreAPI.ts index 12a0431..b4d63cc 100644 --- a/src/api/StoreAPI.ts +++ b/src/api/StoreAPI.ts @@ -37,12 +37,6 @@ async function remove(id: string): Promise { }); } -async function exportXSSF(page: Page): Promise { - return await axios.post(`${STORE_BASE_URI}/export`, page, { - responseType: "blob" - }); -} - async function businessDayList(page: Page): Promise> { return await axios.post(`${BUSINESS_DAY_BASE_URI}/list`, page); } @@ -85,7 +79,6 @@ export default { update, sort, remove, - exportXSSF, businessDayList, businessDayCalendar, businessDayDetail, diff --git a/src/pages/customer/CustomerList.vue b/src/pages/customer/CustomerList.vue index dd293d6..c821a17 100644 --- a/src/pages/customer/CustomerList.vue +++ b/src/pages/customer/CustomerList.vue @@ -8,7 +8,7 @@ @left-click="$router.back()" >
@@ -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(); @@ -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(() => { 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 { } } -// ---------- 导出 ---------- - -async function doExport(): Promise { - 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]; diff --git a/src/pages/dataExport/DataExport.vue b/src/pages/dataExport/DataExport.vue new file mode 100644 index 0000000..c8a8972 --- /dev/null +++ b/src/pages/dataExport/DataExport.vue @@ -0,0 +1,287 @@ + + + + + diff --git a/src/pages/dataExport/DataExportStat.vue b/src/pages/dataExport/DataExportStat.vue new file mode 100644 index 0000000..72961b0 --- /dev/null +++ b/src/pages/dataExport/DataExportStat.vue @@ -0,0 +1,133 @@ + + + + + diff --git a/src/pages/dataExport/DataExportTask.vue b/src/pages/dataExport/DataExportTask.vue new file mode 100644 index 0000000..0dd9548 --- /dev/null +++ b/src/pages/dataExport/DataExportTask.vue @@ -0,0 +1,178 @@ + + + + + diff --git a/src/pages/dataExport/dataExport.ts b/src/pages/dataExport/dataExport.ts new file mode 100644 index 0000000..fe21776 --- /dev/null +++ b/src/pages/dataExport/dataExport.ts @@ -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)}`; +} diff --git a/src/pages/event/EventRecordList.vue b/src/pages/event/EventRecordList.vue index 577d5ce..5e83d65 100644 --- a/src/pages/event/EventRecordList.vue +++ b/src/pages/event/EventRecordList.vue @@ -8,7 +8,7 @@ @left-click="$router.back()" >
@@ -160,7 +160,7 @@