fix: 参赛记录分权限导出
This commit is contained in:
parent
b85c9fe383
commit
ffabdcb595
@ -39,6 +39,7 @@
|
|||||||
import { exportData } from "@/utils/excel";
|
import { exportData } from "@/utils/excel";
|
||||||
import { AllCompetition } from "@/api";
|
import { AllCompetition } from "@/api";
|
||||||
import RecordAction from "@/components/record/RecordAction";
|
import RecordAction from "@/components/record/RecordAction";
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Record",
|
name: "Record",
|
||||||
@ -165,7 +166,8 @@ export default {
|
|||||||
this.$api
|
this.$api
|
||||||
.RegistrationAll(this.query)
|
.RegistrationAll(this.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
return exportExcel(data.data);
|
// 将 this 传递给 exportExcel 函数
|
||||||
|
return exportExcel.call(this, data.data);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -185,15 +187,14 @@ const statusMap = {
|
|||||||
};
|
};
|
||||||
// 格式化日期函数
|
// 格式化日期函数
|
||||||
function formatDate(dateString) {
|
function formatDate(dateString) {
|
||||||
const date = new Date(dateString);
|
if (!dateString) return '';
|
||||||
if (isNaN(date.getTime())) {
|
|
||||||
console.error(`Invalid date: ${dateString}`);
|
try {
|
||||||
return "Invalid Date";
|
return dayjs(dateString).format('YYYY-MM-DD HH:mm:ss');
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error formatting date: ${dateString}`, error);
|
||||||
|
return dateString;
|
||||||
}
|
}
|
||||||
const year = date.getFullYear();
|
|
||||||
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
||||||
const day = String(date.getDate()).padStart(2, "0");
|
|
||||||
return `${year}-${month}-${day}`;
|
|
||||||
}
|
}
|
||||||
function createTableColumns(h) {
|
function createTableColumns(h) {
|
||||||
return [
|
return [
|
||||||
@ -246,19 +247,32 @@ function createTableColumns(h) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function exportExcel(data) {
|
function exportExcel(data) {
|
||||||
|
// 过滤数据,如果是学生用户,只导出自己的比赛
|
||||||
|
let filteredData = data;
|
||||||
|
if (this.$store.state.user.userPrivileges == 2) {
|
||||||
|
filteredData = data.filter(item => item.studentId == this.$store.state.user.userId);
|
||||||
|
}
|
||||||
|
|
||||||
const header = createTableColumns().map((v) => v.title);
|
const header = createTableColumns().map((v) => v.title);
|
||||||
header.pop(); // 去掉最后一栏操作栏
|
header.pop(); // 去掉最后一栏操作栏
|
||||||
|
|
||||||
|
// 格式化导出数据中的时间
|
||||||
|
const formattedData = filteredData.map(item => ({
|
||||||
|
...item,
|
||||||
|
registrationTime: formatDate(item.registrationTime)
|
||||||
|
}));
|
||||||
|
|
||||||
return exportData({
|
return exportData({
|
||||||
name: `参赛记录信息-${formatDate(new Date())}`, // 添加当前日期
|
name: `参赛记录信息-${dayjs().format('YYYY-MM-DD HH:mm:ss')}`,
|
||||||
data,
|
data: formattedData,
|
||||||
header,
|
header,
|
||||||
keyMap: {
|
keyMap: {
|
||||||
competitionId: "名称",
|
competitionName: "名称",
|
||||||
studentId: "参赛人",
|
studentName: "参赛人",
|
||||||
teamLeaderId: "组队编号",
|
teamLeaderName: "队长",
|
||||||
competitionType: "类型",
|
competitionType: "类型",
|
||||||
awardLevel: "成绩",
|
awardLevel: "成绩",
|
||||||
competitionType: "类型",
|
additionalInfo: "备注信息",
|
||||||
registrationTime: "登记时间",
|
registrationTime: "登记时间",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user