From 71bec03475a9007422941080c9dbc4d0be6b1f7d Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Wed, 28 Jan 2026 16:16:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/account/shopUser.ts | 11 ++++++++++- src/api/order/sale-summary.ts | 1 - src/utils/index.ts | 12 ++++++++++-- src/views/marketing_center/data.js | 2 +- src/views/user/list/config/content.ts | 2 +- src/views/user/list/index.vue | 13 ++++++++++++- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/api/account/shopUser.ts b/src/api/account/shopUser.ts index 25faf3c..883bfa3 100644 --- a/src/api/account/shopUser.ts +++ b/src/api/account/shopUser.ts @@ -71,7 +71,16 @@ const API = { method: "get", params }); - } + }, + // 导出 + export(params: any) { + return request({ + url: `${baseURL}/export`, + method: "get", + params, + responseType: 'blob' + }); + }, } export default API; export interface getRequest { diff --git a/src/api/order/sale-summary.ts b/src/api/order/sale-summary.ts index 72f386d..d885d7f 100644 --- a/src/api/order/sale-summary.ts +++ b/src/api/order/sale-summary.ts @@ -26,7 +26,6 @@ const Api = { method: "get", params, responseType: 'blob' - }); }, }; diff --git a/src/utils/index.ts b/src/utils/index.ts index d3dbe87..7eea652 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -111,8 +111,16 @@ export function downloadFile(obj: BlobPart, name: string, suffix: string, useUni const link = document.createElement("a"); link.style.display = "none"; link.href = url; - const newFilename = useUnix ? (parseTime(new Date(), undefined) + "-") : '' + name.trim() - const fileName = newFilename + "." + suffix; + // 期望行为: + // - 当 useUnix 为 true 且传入 name 时:`${timestamp}-${name}` + // - 当 useUnix 为 true 且 name 为空时:仅 `${timestamp}`(不带多余的 `-`) + // - 当 useUnix 为 false:使用传入的 name(如为空则回退到时间戳) + const safeName = (name || "").trim(); + const timeStamp = parseTime(new Date(), undefined); + const fileBase = useUnix + ? (safeName ? `${timeStamp}-${safeName}` : timeStamp) + : (safeName || timeStamp); + const fileName = fileBase + "." + suffix; link.setAttribute("download", fileName); document.body.appendChild(link); link.click(); diff --git a/src/views/marketing_center/data.js b/src/views/marketing_center/data.js index f809cd7..7598b35 100644 --- a/src/views/marketing_center/data.js +++ b/src/views/marketing_center/data.js @@ -32,7 +32,7 @@ export const newMenus = [ intro: '协助商家拉来新客户,拓展客户群体', childrenList: [ { - name: "全民分销", + name: "全民股东", icon: "zhcz", pathName: "distribution_page", intro: "用户成为股东,可促进消费" diff --git a/src/views/user/list/config/content.ts b/src/views/user/list/config/content.ts index f739756..d7d8e45 100644 --- a/src/views/user/list/config/content.ts +++ b/src/views/user/list/config/content.ts @@ -21,7 +21,7 @@ const contentConfig: IContentConfig = { // // return shopUserApi.edit(data); // }, pk: "id", - toolbar: ["add"], + toolbar: ["add", 'export'], defaultToolbar: ["refresh", "filter", "search"], cols: [ { type: "selection", width: 50, align: "center" }, diff --git a/src/views/user/list/index.vue b/src/views/user/list/index.vue index 0a94f76..46ba916 100644 --- a/src/views/user/list/index.vue +++ b/src/views/user/list/index.vue @@ -158,6 +158,7 @@ import { returnOptionsLabel } from "./config/config"; import shopUserApi from "@/api/account/shopUser"; import { useRoute } from 'vue-router' import { ElNotification } from 'element-plus' +import { downloadFile } from "@/utils/index"; const editMoneyModalRef = ref(null); const userCouponDialogRef = ref(null); const GiveCouponRef = ref(null); @@ -175,7 +176,7 @@ const { // handleAddClick, // handleEditClick, handleSubmitClick, - handleExportClick, + // handleExportClick, handleSearchClick, handleFilterChange, } = usePage(); @@ -217,6 +218,16 @@ function formDataChange(type, val) { } } +// 导出 +async function handleExportClick() { + try { + const file = await shopUserApi.export(searchRef.value.getQueryParams()); + downloadFile(file, "用户列表", "xlsx"); + } catch (error) { + console.log(error); + } +} + // 新增 async function handleAddClick() { addModalRef.value?.setModalVisible();