From 08fa00809060ec8e38a50ea67dc3f71d3874969c Mon Sep 17 00:00:00 2001 From: linyongLynn <15926056+linyonglynn@user.noreply.gitee.com> Date: Thu, 9 Oct 2025 16:48:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=99=E5=B8=88=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/config/teacher.vue | 79 +++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 14 deletions(-) diff --git a/src/views/config/teacher.vue b/src/views/config/teacher.vue index 877ad8f..1a49ea2 100644 --- a/src/views/config/teacher.vue +++ b/src/views/config/teacher.vue @@ -7,7 +7,7 @@
- +
查询 @@ -243,11 +243,12 @@ const res = await index({ page: this.select.page, page_size: this.select.page_size, - filter: [{ - key: 'name', - op: 'like', - value: this.select.name - }] + keyword: this.select.name + // filter: [{ + // key: 'name', + // op: 'like', + // value: this.select.name + // }] }) this.list = res.data this.total = res.total @@ -265,25 +266,75 @@ page_size: 9999 }) if (res.data) { - let headers = this.table_item.map(i => { + // 跳过第一列(序号列),从第二列开始 + let headers = this.table_item.slice(1).map(i => { return { key: i.prop, title: i.label } }) - const data = res.data.map(row => headers.map(header => row[header.key])); - data.unshift(headers.map(header => header.title)); - const wb = XLSX.utils.book_new(); - const ws = XLSX.utils.aoa_to_sheet(data); - XLSX.utils.book_append_sheet(wb, ws, sheetName); + + // 处理数据,将复杂对象和null值转换为Excel可用的格式 + const data = res.data.map((row, rowIndex) => { + return headers.map((header, colIndex) => { + let value = row[header.key] + + // 处理 undefined 值 + if (value === undefined) { + return '' + } + + // 处理 null 值 + if (value === null) { + return '' + } + + // 处理数组对象(如排课历史) + if (Array.isArray(value)) { + if (value.length === 0) { + return '' + } + // 将数组转换为可读的字符串格式 + return value.map(item => { + if (typeof item === 'object' && item !== null) { + // 如果是对象,提取关键信息 + let parts = [] + if (item.course && item.course.name) parts.push(`课程: ${item.course.name}`) + if (item.theme) parts.push(`主题: ${item.theme}`) + if (item.direction) parts.push(`方向: ${item.direction}`) + if (item.salary) parts.push(`课酬: ${item.salary}`) + if (item.tutor) parts.push(`导师: ${item.tutor}`) + if (item.remark) parts.push(`备注: ${item.remark}`) + return parts.join('; ') + } + return String(item) + }).join('\n') + } + + // 处理普通对象 + if (typeof value === 'object' && value !== null) { + return JSON.stringify(value) + } + + // 处理字符串(保持换行符,Excel会正确显示) + return String(value) + }) + }) + + // 添加表头 + data.unshift(headers.map(header => header.title)) + + const wb = XLSX.utils.book_new() + const ws = XLSX.utils.aoa_to_sheet(data) + XLSX.utils.book_append_sheet(wb, ws, sheetName) const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' - }); + }) saveAs(new Blob([wbout], { type: 'application/octet-stream' - }), `${sheetName}.xlsx`); + }), `${sheetName}.xlsx`) } }, editTeacher(type, id) {