diff --git a/mock/modules/lcz.js b/mock/modules/lcz.js new file mode 100644 index 0000000..19e4c97 --- /dev/null +++ b/mock/modules/lcz.js @@ -0,0 +1,70 @@ +import Mock from "mockjs" + +const student = Mock.mock({ + "list|100": [ + { + "Id|+1": 1, + "name": "@cname", + "gender":`@pick(['男', '女'])`, + "studentId": "@integer(1000000000,9999999999)", + "department":`@pick(['机电工程系', '护理分院','建筑系','材料科学与工程系','环境科学与工程系'])`, + "major":`@pick(['机械制造与自动化', '材料科学与工程', '环境科学与工程', '建筑工程', '护理学'])`, + "classes":`@pick(['机制1班', '材料1班', '环境1班', '建筑1班','护理1班'])`, + "status":`@pick(['休学', '退学', '复学'])`, + }, + ], + }); + + export default [ + { + url:'/api-list', + method:'get', + response: () => { + return { + code: 200, + data: student + } + } + }, + { + url: '/api-student', + method: 'post', + response: (req) => { + if (req.body.name !== '') { + return student.list.filter(item => item.name.includes(req.body.name)) + } + else if (req.body.studentId !== '') { + const studentId = Number(req.body.studentId) + if (!isNaN(studentId)) { + return student.list.filter(item => item.studentId === studentId) + } else { + return { + code: 400, + message: 'Invalid student number format' + } + } + } + else if (req.body.name !== '') { + return student.list.filter(item => item.name.includes(req.body.name)) + } + else if (req.body.gender !== '') { + return student.list.filter(item => item.gender.includes(req.body.gender)) + } + else if (req.body.department !== '') { + return student.list.filter(item => item.grade.includes(req.body.department)) + } + else if (req.body.major !== '') { + return student.list.filter(item => item.major.includes(req.body.major)) + } + else if (req.body.classes !== '') { + return student.list.filter(item => item.classes.includes(req.body.classes)) + } + else if (req.body.status !== '') { + return student.list.filter(item => item.major.includes(req.body.status)) + } + return { + code: 200, + } + } + } + ] \ No newline at end of file diff --git a/package.json b/package.json index a027f07..beb66d2 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ "axios": "^1.6.8", "dayjs": "^1.11.10", "echarts": "^5.5.0", + "exceljs": "^4.4.0", + "file-saver": "^2.0.5", "less": "^4.2.0", "mockjs": "^1.1.0", "pinia": "^2.1.7", diff --git a/src/api/login.js b/src/api/login.js index 9efab9a..3bde586 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -5,4 +5,4 @@ const API = { }; export const reqUser = () => request.post(API.LOGIN_URL); -export const reqUserone = (data) => request.post(API.LOGIN_URL, data); \ No newline at end of file +// export const reqUserone = (data) => request.post(API.LOGIN_URL, data); \ No newline at end of file diff --git a/src/api/students.js b/src/api/students.js index b85d7e0..0bc246a 100644 --- a/src/api/students.js +++ b/src/api/students.js @@ -1,7 +1,8 @@ -import request from "@/utils/request"; -// 统一管理接口 -const API = { - STUDENT_URL: "/api/student", -}; +import request from '@/utils/request' -export const reqStudent = () => request.post(API.STUDENT_URL); \ No newline at end of file +export function getList() { + return request.get('/api-list') +} +export function getStudents(studentData) { + return request.post('/api-student', studentData) +} \ No newline at end of file diff --git a/src/pages/finance-bill-manage/detailReport.vue b/src/pages/finance-bill-manage/detailReport.vue index e25e79e..578b0b7 100644 --- a/src/pages/finance-bill-manage/detailReport.vue +++ b/src/pages/finance-bill-manage/detailReport.vue @@ -29,6 +29,9 @@

报表明细

+ + 导出报表明细 + { const refresh = () => { tableList(); }; + +// 导出excel +const exportExcel = () => { + const title = "报表明细excel"; + const titleFile = "报表明细"; + const columns = [ + { header: "部门", key: "1", width: 20 }, + { header: "入库量", key: "2", width: 20 }, + { header: "退库量", key: "3", width: 20 }, + { header: "领用量", key: "4", width: 20 }, + { header: "报损量", key: "5", width: 20 }, + { header: "核销量", key: "6", width: 20 }, + { header: "总票据比例", key: "7", width: 20 }, + ]; + const addRow = []; + tableData.value.forEach((item) => { + addRow.push({ + 1: item.branch, + 2: item.stockNum, + 3: item.cancelNum, + 4: item.receiveNum, + 5: item.breakNum, + 6: item.destoryNum, + 7: item.grossBillRatio, + }); + }); + ExcelUtils(title, titleFile, columns, addRow); +}; onMounted(() => { tableList(); }); diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index e95ce92..a987da9 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -55,7 +55,7 @@ import { MessagePlugin } from "tdesign-vue-next"; import { reactive, ref, onMounted } from "vue"; import { reqUser } from "@/api/login"; import { useRouter } from "vue-router"; -import axios from 'axios'; +// import axios from 'axios'; // import { TForm, TFormItem, TInput, TButton } from "tdesign-vue-next"; // import { DesktopIcon, LockOnIcon } from "tdesign-icons-vue"; @@ -103,7 +103,11 @@ onMounted(() => { const onSubmit = async () => { try { - const validateResult = await from.value?.validate(); + if (!form || !form.value) { + console.warn("form 或 form.value 不存在,无法进行表单验证"); + return; + } + const validateResult = await form.value?.validate(); if (validateResult?.result) { await reqUser(formData.account, formData.password); MessagePlugin.success("提交成功"); diff --git a/src/pages/students/student.vue b/src/pages/students/student.vue index dad652e..af3d510 100644 --- a/src/pages/students/student.vue +++ b/src/pages/students/student.vue @@ -1,146 +1,295 @@ diff --git a/src/utils/excel.js b/src/utils/excel.js new file mode 100644 index 0000000..17e7935 --- /dev/null +++ b/src/utils/excel.js @@ -0,0 +1,24 @@ +import ExcelJS from "exceljs"; +import saveAs from "file-saver"; // 引入FileSaver.js以使用saveAs函数 + +const ExcelUtils = (title, titleFile, columns, addRow) => { + // 创建一个新的工作簿 + const workbook = new ExcelJS.Workbook(); + // 添加一个新的工作表 + const worksheet = workbook.addWorksheet(title); + // 添加表头 + worksheet.columns = columns; + // 添加数据行 + for (const row of addRow) { + worksheet.addRow(row); + } + // 写入文件并下载 + workbook.xlsx.writeBuffer().then((buffer) => { + const blob = new Blob([buffer], { + type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + }); + saveAs(blob, `${titleFile}.xlsx`); + }); +}; + +export { ExcelUtils };