用户列表新增导出功能

This commit is contained in:
gyq
2026-01-28 16:16:04 +08:00
parent ca182dc325
commit 71bec03475
6 changed files with 34 additions and 7 deletions

View File

@@ -71,7 +71,16 @@ const API = {
method: "get", method: "get",
params params
}); });
} },
// 导出
export(params: any) {
return request({
url: `${baseURL}/export`,
method: "get",
params,
responseType: 'blob'
});
},
} }
export default API; export default API;
export interface getRequest { export interface getRequest {

View File

@@ -26,7 +26,6 @@ const Api = {
method: "get", method: "get",
params, params,
responseType: 'blob' responseType: 'blob'
}); });
}, },
}; };

View File

@@ -111,8 +111,16 @@ export function downloadFile(obj: BlobPart, name: string, suffix: string, useUni
const link = document.createElement("a"); const link = document.createElement("a");
link.style.display = "none"; link.style.display = "none";
link.href = url; 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); link.setAttribute("download", fileName);
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();

View File

@@ -32,7 +32,7 @@ export const newMenus = [
intro: '协助商家拉来新客户,拓展客户群体', intro: '协助商家拉来新客户,拓展客户群体',
childrenList: [ childrenList: [
{ {
name: "全民分销", name: "全民股东",
icon: "zhcz", icon: "zhcz",
pathName: "distribution_page", pathName: "distribution_page",
intro: "用户成为股东,可促进消费" intro: "用户成为股东,可促进消费"

View File

@@ -21,7 +21,7 @@ const contentConfig: IContentConfig<any> = {
// // return shopUserApi.edit(data); // // return shopUserApi.edit(data);
// }, // },
pk: "id", pk: "id",
toolbar: ["add"], toolbar: ["add", 'export'],
defaultToolbar: ["refresh", "filter", "search"], defaultToolbar: ["refresh", "filter", "search"],
cols: [ cols: [
{ type: "selection", width: 50, align: "center" }, { type: "selection", width: 50, align: "center" },

View File

@@ -158,6 +158,7 @@ import { returnOptionsLabel } from "./config/config";
import shopUserApi from "@/api/account/shopUser"; import shopUserApi from "@/api/account/shopUser";
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { ElNotification } from 'element-plus' import { ElNotification } from 'element-plus'
import { downloadFile } from "@/utils/index";
const editMoneyModalRef = ref(null); const editMoneyModalRef = ref(null);
const userCouponDialogRef = ref(null); const userCouponDialogRef = ref(null);
const GiveCouponRef = ref(null); const GiveCouponRef = ref(null);
@@ -175,7 +176,7 @@ const {
// handleAddClick, // handleAddClick,
// handleEditClick, // handleEditClick,
handleSubmitClick, handleSubmitClick,
handleExportClick, // handleExportClick,
handleSearchClick, handleSearchClick,
handleFilterChange, handleFilterChange,
} = usePage(); } = 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() { async function handleAddClick() {
addModalRef.value?.setModalVisible(); addModalRef.value?.setModalVisible();