From 119f2d3fb0696749ff26b96ebecc2d31958614fd Mon Sep 17 00:00:00 2001 From: xy <271556543@qq.com> Date: Thu, 27 Mar 2025 10:48:30 +0800 Subject: [PATCH] init --- src/utils/downloadRequest.js | 3 +- src/utils/index.js | 39 ++++++++++ src/views/Area/Area.vue | 11 ++- src/views/Aspiration/Aspiration.vue | 11 ++- src/views/Batch/Batch.vue | 11 ++- src/views/BatchData/BatchData.vue | 72 ++++++++++++++++++- src/views/BatchSub/BatchSub.vue | 11 ++- src/views/BatchSubSchool/BatchSubSchool.vue | 11 ++- .../IndependentRecruitment.vue | 11 ++- .../MiddleSchoolIndicator.vue | 11 ++- src/views/Recommend/Recommend.vue | 11 ++- src/views/RecommendForm/RecommendForm.vue | 11 ++- src/views/School/School.vue | 35 +++++---- src/views/Score/Score.vue | 11 ++- src/views/Specialty/Specialty.vue | 11 ++- src/views/User/User.vue | 11 ++- src/views/UserFollow/UserFollow.vue | 11 ++- 17 files changed, 235 insertions(+), 57 deletions(-) diff --git a/src/utils/downloadRequest.js b/src/utils/downloadRequest.js index 9c033b1..6a22501 100644 --- a/src/utils/downloadRequest.js +++ b/src/utils/downloadRequest.js @@ -8,7 +8,7 @@ import { Loading, Message } from "element-ui"; */ let loading; -export async function download(url, method = "get", info, filename) { +export async function download(url, method = "get", info, filename, paramsSerializer) { loading = Loading.service({ lock: true, background: "rgba(0,0,0,0.4)", @@ -27,6 +27,7 @@ export async function download(url, method = "get", info, filename) { withCredentials: true, Authorization: "Bearer " + getToken(), }, + paramsSerializer }; if (method === "get") { Object.defineProperty(options, "params", { diff --git a/src/utils/index.js b/src/utils/index.js index 6c978ed..c27aaee 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -194,3 +194,42 @@ export function download(url) { // 清理下载链接 document.body.removeChild(downloadLink); } + +export function paramsSerializer(params) { + const parts = []; + + // 递归处理嵌套对象 + const serialize = (obj, parentKey) => { + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + const value = obj[key]; + const fullKey = parentKey ? `${parentKey}[${key}]` : key; + + if (value && typeof value === 'object' && !Array.isArray(value)) { + // 如果是嵌套对象,递归处理 + serialize(value, fullKey); + } else if (Array.isArray(value)) { + // 如果是数组,遍历数组并处理每个元素 + value.forEach((item, index) => { + if (item && typeof item === 'object') { + // 如果数组元素是对象,递归处理 + serialize(item, `${fullKey}[${index}]`); + } else { + // 如果数组元素是普通值,直接序列化 + parts.push(`${encodeURIComponent(`${fullKey}[${index}]`)}=${encodeURIComponent(item)}`); + } + }); + } else { + // 如果是普通键值对,直接序列化 + parts.push(`${encodeURIComponent(fullKey)}=${encodeURIComponent(value)}`); + } + } + } + }; + + // 开始序列化 + serialize(params, ''); + + // 将部分拼接为查询字符串 + return parts.join('&'); +} diff --git a/src/views/Area/Area.vue b/src/views/Area/Area.vue index 7ab6830..5cdd284 100644 --- a/src/views/Area/Area.vue +++ b/src/views/Area/Area.vue @@ -182,7 +182,7 @@ import VxeUI from "vxe-pc-ui"; import { authMixin } from "@/mixin/authMixin"; import { uploadSize } from "@/settings"; -import { deepCopy } from "@/utils"; +import {deepCopy, paramsSerializer} from "@/utils"; import { download } from "@/utils/downloadRequest"; import { destroy, index, save } from "@/api/area/area"; import AddArea from "./components/AddArea.vue"; @@ -254,13 +254,18 @@ export default { distinguishCancelAndClose: true, }) .then((_) => { + const tableColumns = this.$refs['table'].getFullColumns() + let export_fields = {} + Object.keys(this.form).forEach(key => { + export_fields[key] = tableColumns.find(col => col.field === key)?.title || key + }) download("/api/admin/school/index", "get", { ...this.select, page: 1, page_size: 9999, is_export: 1, - export_fields: Object.keys(this.form), - }); + export_fields + }, `${this.$route.meta.title}_${this.$moment().valueOf()}.xlsx`,paramsSerializer); }) .catch((action) => { if (action === "cancel" && this.$refs["table"]) { diff --git a/src/views/Aspiration/Aspiration.vue b/src/views/Aspiration/Aspiration.vue index f5d6711..00fdea3 100644 --- a/src/views/Aspiration/Aspiration.vue +++ b/src/views/Aspiration/Aspiration.vue @@ -331,7 +331,7 @@ import VxeUI from "vxe-pc-ui"; import { authMixin } from "@/mixin/authMixin"; import { uploadSize } from "@/settings"; -import { deepCopy } from "@/utils"; +import {deepCopy, paramsSerializer} from "@/utils"; import { download } from "@/utils/downloadRequest"; import { destroy, index, save, clone } from "@/api/aspiration/aspiration"; import AddAspiration from "./components/AddAspiration.vue"; @@ -442,13 +442,18 @@ export default { distinguishCancelAndClose: true, }) .then((_) => { + const tableColumns = this.$refs['table'].getFullColumns() + let export_fields = {} + Object.keys(this.form).forEach(key => { + export_fields[key] = tableColumns.find(col => col.field === key)?.title || key + }) download("/api/admin/school/index", "get", { ...this.select, page: 1, page_size: 9999, is_export: 1, - export_fields: Object.keys(this.form), - }); + export_fields + }, `${this.$route.meta.title}_${this.$moment().valueOf()}.xlsx`,paramsSerializer); }) .catch((action) => { if (action === "cancel" && this.$refs["table"]) { diff --git a/src/views/Batch/Batch.vue b/src/views/Batch/Batch.vue index d7dcf14..e90c642 100644 --- a/src/views/Batch/Batch.vue +++ b/src/views/Batch/Batch.vue @@ -326,7 +326,7 @@ import VxeUI from "vxe-pc-ui"; import { authMixin } from "@/mixin/authMixin"; import { uploadSize } from "@/settings"; -import { deepCopy } from "@/utils"; +import {deepCopy, paramsSerializer} from "@/utils"; import { download } from "@/utils/downloadRequest"; import { destroy, index, save } from "@/api/batch/batch"; import { save as batchSubSave } from "@/api/batch-sub/batch-sub"; @@ -439,13 +439,18 @@ export default { distinguishCancelAndClose: true, }) .then((_) => { + const tableColumns = this.$refs['table'].getFullColumns() + let export_fields = {} + Object.keys(this.form).forEach(key => { + export_fields[key] = tableColumns.find(col => col.field === key)?.title || key + }) download("/api/admin/school/index", "get", { ...this.select, page: 1, page_size: 9999, is_export: 1, - export_fields: Object.keys(this.form), - }); + export_fields + }, `${this.$route.meta.title}_${this.$moment().valueOf()}.xlsx`,paramsSerializer); }) .catch((action) => { if (action === "cancel" && this.$refs["table"]) { diff --git a/src/views/BatchData/BatchData.vue b/src/views/BatchData/BatchData.vue index a5911cd..ba0cb95 100644 --- a/src/views/BatchData/BatchData.vue +++ b/src/views/BatchData/BatchData.vue @@ -14,6 +14,17 @@ >