-
+
查询
@@ -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) {