Compare commits
No commits in common. "0ff925515062945e5d2d2514ed6db49c10a7ac10" and "304daec79f6e588407435d0ca3aa05f2c752650b" have entirely different histories.
0ff9255150
...
304daec79f
@ -25,7 +25,7 @@
|
|||||||
"echarts": "5.5.1",
|
"echarts": "5.5.1",
|
||||||
"element-china-area-data": "^6.1.0",
|
"element-china-area-data": "^6.1.0",
|
||||||
"element-plus": "^2.7.6",
|
"element-plus": "^2.7.6",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "2.0.5",
|
||||||
"fuse.js": "6.6.2",
|
"fuse.js": "6.6.2",
|
||||||
"js-beautify": "1.14.11",
|
"js-beautify": "1.14.11",
|
||||||
"js-cookie": "3.0.5",
|
"js-cookie": "3.0.5",
|
||||||
@ -37,8 +37,7 @@
|
|||||||
"vue-cropper": "1.1.1",
|
"vue-cropper": "1.1.1",
|
||||||
"vue-router": "4.4.0",
|
"vue-router": "4.4.0",
|
||||||
"vuedraggable": "4.1.0",
|
"vuedraggable": "4.1.0",
|
||||||
"vuex": "^4.0.2",
|
"vuex": "^4.0.2"
|
||||||
"xlsx": "^0.18.5"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "5.0.5",
|
"@vitejs/plugin-vue": "5.0.5",
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// src/api/dairyProducts/sheepMilkAnalysis/sheepMilkAnalysis.js
|
||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
// 查询羊奶产量分析列表(分页 + 条件)
|
// 查询羊奶产量分析列表(分页 + 条件)
|
||||||
@ -16,3 +17,13 @@ export function getSheepMilkAnalysis(sheepId) {
|
|||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 导出羊奶产量分析 Excel
|
||||||
|
export function exportSheepMilkAnalysis(query) {
|
||||||
|
return request({
|
||||||
|
url: '/dairyProducts/sheepMilkAnalysis/export',
|
||||||
|
method: 'get',
|
||||||
|
params: query,
|
||||||
|
responseType: 'blob' // 返回二进制流
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -291,9 +291,6 @@
|
|||||||
import { ref, reactive, onMounted } from 'vue';
|
import { ref, reactive, onMounted } from 'vue';
|
||||||
import { listFreshMilkTest, getFreshMilkTest, delFreshMilkTest, addFreshMilkTest, updateFreshMilkTest } from "@/api/dairyProducts/freshMilkTest/freshMilkTest.js";
|
import { listFreshMilkTest, getFreshMilkTest, delFreshMilkTest, addFreshMilkTest, updateFreshMilkTest } from "@/api/dairyProducts/freshMilkTest/freshMilkTest.js";
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||||
// 导入xlsx库和file-saver
|
|
||||||
import * as XLSX from 'xlsx';
|
|
||||||
import { saveAs } from 'file-saver';
|
|
||||||
|
|
||||||
const freshMilkTestList = ref([]);
|
const freshMilkTestList = ref([]);
|
||||||
const open = ref(false);
|
const open = ref(false);
|
||||||
@ -307,27 +304,6 @@ const title = ref("");
|
|||||||
const columnShowDialogVisible = ref(false);
|
const columnShowDialogVisible = ref(false);
|
||||||
const freshMilkTestRef = ref(null);
|
const freshMilkTestRef = ref(null);
|
||||||
|
|
||||||
// 列配置映射
|
|
||||||
const columnConfig = [
|
|
||||||
{ prop: 'source', label: '来源' },
|
|
||||||
{ prop: 'datetime', label: '检测日期' },
|
|
||||||
{ prop: 'fat', label: '脂肪g/100g' },
|
|
||||||
{ prop: 'protein', label: '蛋白质g/100g' },
|
|
||||||
{ prop: 'nonFat', label: '非脂g/100g' },
|
|
||||||
{ prop: 'acidity', label: '酸度oT' },
|
|
||||||
{ prop: 'bacterialColony1', label: '菌落总数1' },
|
|
||||||
{ prop: 'bacterialColony2', label: '菌落总数2' },
|
|
||||||
{ prop: 'bacterialColony3', label: '菌落总数3' },
|
|
||||||
{ prop: 'bacterialColony4', label: '菌落总数4' },
|
|
||||||
{ prop: 'bacterialColony5', label: '菌落总数5' },
|
|
||||||
{ prop: 'coli', label: '大肠菌群(CFU/ml)' },
|
|
||||||
{ prop: 'lactoferrin', label: '乳铁蛋白(mg/L)' },
|
|
||||||
{ prop: 'ig', label: '免疫球蛋白(mg/L)' },
|
|
||||||
{ prop: 'commnet', label: '备注' },
|
|
||||||
{ prop: 'createBy', label: '创建人' },
|
|
||||||
{ prop: 'createTime', label: '创建时间' }
|
|
||||||
];
|
|
||||||
|
|
||||||
// 默认显示的列
|
// 默认显示的列
|
||||||
const selectedColumns = ref([
|
const selectedColumns = ref([
|
||||||
'source', 'datetime', 'fat', 'protein', 'nonFat', 'acidity',
|
'source', 'datetime', 'fat', 'protein', 'nonFat', 'acidity',
|
||||||
@ -569,42 +545,17 @@ function handleDelete(row) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 导出按钮操作 - 前端实现 */
|
/** 导出按钮操作 */
|
||||||
function handleExport() {
|
function handleExport() {
|
||||||
// 获取当前显示的列配置
|
const params = new URLSearchParams();
|
||||||
const visibleColumnsConfig = columnConfig.filter(
|
for (const key in queryParams) {
|
||||||
col => selectedColumns.value.includes(col.prop)
|
if (queryParams[key] !== null && queryParams[key] !== undefined) {
|
||||||
);
|
params.append(key, queryParams[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 准备导出数据
|
const url = `/freshMilkTest/freshMilkTest/export?${params.toString()}`;
|
||||||
const exportData = freshMilkTestList.value.map(item => {
|
window.location.href = url;
|
||||||
const rowData = {};
|
|
||||||
visibleColumnsConfig.forEach(col => {
|
|
||||||
// 特殊处理日期字段
|
|
||||||
if (col.prop === 'datetime') {
|
|
||||||
rowData[col.label] = formatDate(item[col.prop]);
|
|
||||||
} else if (col.prop === 'createTime') {
|
|
||||||
rowData[col.label] = formatDateTime(item[col.prop]);
|
|
||||||
} else {
|
|
||||||
rowData[col.label] = item[col.prop];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return rowData;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 创建工作簿和工作表
|
|
||||||
const worksheet = XLSX.utils.json_to_sheet(exportData);
|
|
||||||
const workbook = XLSX.utils.book_new();
|
|
||||||
XLSX.utils.book_append_sheet(workbook, worksheet, '鲜奶检验记录');
|
|
||||||
|
|
||||||
// 生成Excel文件并下载
|
|
||||||
const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
|
|
||||||
const blob = new Blob([excelBuffer], {
|
|
||||||
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
||||||
});
|
|
||||||
|
|
||||||
// 使用file-saver保存文件
|
|
||||||
saveAs(blob, `鲜奶检验记录_${new Date().getTime()}.xlsx`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化加载
|
// 初始化加载
|
||||||
|
|||||||
@ -1,24 +1,16 @@
|
|||||||
<!-- index.vue (前端视图,仅保留单日查询功能) -->
|
<!-- index.vue (前端视图,修改 resetQuery 以匹配正确字段) -->
|
||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<el-form ref="queryRef" :model="queryParams" inline label-width="80px">
|
<el-form ref="queryRef" :model="queryParams" inline label-width="80px">
|
||||||
<!-- 单日查询 -->
|
<el-form-item label="日期范围">
|
||||||
<el-form-item label="查询日期">
|
<el-date-picker v-model="dateRange" type="daterange" range-separator="至"
|
||||||
<el-date-picker
|
start-placeholder="开始日期" end-placeholder="结束日期" value-format="YYYY-MM-DD" />
|
||||||
v-model="queryDate"
|
|
||||||
type="date"
|
|
||||||
placeholder="选择查询日期"
|
|
||||||
value-format="YYYY-MM-DD"
|
|
||||||
format="YYYY-MM-DD"
|
|
||||||
clearable />
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<!-- 管理耳号变成输入框 -->
|
||||||
<!-- 管理耳号输入框 -->
|
|
||||||
<el-form-item label="管理耳号">
|
<el-form-item label="管理耳号">
|
||||||
<el-input v-model="queryParams.manageEarNo" placeholder="请输入管理耳号" clearable />
|
<el-input v-model="queryParams.manageEarNo" placeholder="请输入管理耳号" clearable />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<!-- 厂区下拉框,数据源来自字典 da_ranch -->
|
||||||
<!-- 厂区下拉框 -->
|
|
||||||
<el-form-item label="厂区">
|
<el-form-item label="厂区">
|
||||||
<el-select v-model="queryParams.factory" clearable placeholder="请选择">
|
<el-select v-model="queryParams.factory" clearable placeholder="请选择">
|
||||||
<el-option
|
<el-option
|
||||||
@ -28,15 +20,13 @@
|
|||||||
:value="d.value" />
|
:value="d.value" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<!-- 班次只有 1、2 -->
|
||||||
<!-- 班次下拉框 -->
|
|
||||||
<el-form-item label="班次">
|
<el-form-item label="班次">
|
||||||
<el-select v-model="queryParams.classes" clearable placeholder="请选择">
|
<el-select v-model="queryParams.classes" clearable placeholder="请选择">
|
||||||
<el-option :value="1" label="1" />
|
<el-option :value="1" label="1" />
|
||||||
<el-option :value="2" label="2" />
|
<el-option :value="2" label="2" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" @click="getList">查询</el-button>
|
<el-button type="primary" @click="getList">查询</el-button>
|
||||||
<el-button @click="resetQuery">重置</el-button>
|
<el-button @click="resetQuery">重置</el-button>
|
||||||
@ -66,7 +56,7 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="correctedMilk" label="班次校正奶量" >
|
<el-table-column prop="correctedMilk" label="班次校正奶量" >
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
{{ row.correctedMilk ? Number(row.correctedMilk).toFixed(2) : '-' }}
|
{{ row.milk ? Number(row.milk).toFixed(2) : '-' }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@ -92,7 +82,6 @@ import { ref, reactive, onMounted } from 'vue'
|
|||||||
import { listMilkProdclasses, importMilkProdclasses, exportMilkProdclasses } from '@/api/dairyProducts/milkProdclasses/milkProdclasses'
|
import { listMilkProdclasses, importMilkProdclasses, exportMilkProdclasses } from '@/api/dairyProducts/milkProdclasses/milkProdclasses'
|
||||||
import { getToken } from '@/utils/auth'
|
import { getToken } from '@/utils/auth'
|
||||||
import { getRanchList } from '@/api/dairyProducts/ranch/ranch.js'
|
import { getRanchList } from '@/api/dairyProducts/ranch/ranch.js'
|
||||||
import { ElMessage } from 'element-plus'
|
|
||||||
import { Upload, Download, UploadFilled } from '@element-plus/icons-vue';
|
import { Upload, Download, UploadFilled } from '@element-plus/icons-vue';
|
||||||
|
|
||||||
const ranchOptions = ref([])
|
const ranchOptions = ref([])
|
||||||
@ -111,36 +100,25 @@ onMounted(() => {
|
|||||||
const queryParams = reactive({
|
const queryParams = reactive({
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
datetimeStart: null, // 开始日期
|
manageEarNo: '', // 管理耳号
|
||||||
datetimeEnd: null, // 结束日期
|
factory: null,
|
||||||
manageEarNo: '', // 管理耳号
|
classes: null
|
||||||
factory: null, // 厂区
|
|
||||||
classes: null // 班次
|
|
||||||
})
|
})
|
||||||
const queryDate = ref(null) // 查询日期
|
const dateRange = ref([])
|
||||||
const tableData = ref([]) // 表格数据
|
const tableData = ref([])
|
||||||
const total = ref(0) // 总数据条数
|
const total = ref(0)
|
||||||
const loading = ref(false) // 加载状态
|
const loading = ref(false)
|
||||||
const openImport = ref(false) // 导入弹窗显示状态
|
const openImport = ref(false)
|
||||||
|
|
||||||
const uploadUrl = import.meta.env.VITE_APP_BASE_API + '/milkProdclasses/milkProdclasses/import';
|
const uploadUrl = import.meta.env.VITE_APP_BASE_API + '/milkProdclasses/milkProdclasses/import';
|
||||||
const headers = { Authorization: 'Bearer ' + getToken() };
|
const headers = { Authorization: 'Bearer ' + getToken() };
|
||||||
|
|
||||||
function getList() {
|
function getList() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
const [start, end] = dateRange.value || []
|
||||||
// 设置查询参数
|
|
||||||
if (queryDate.value) {
|
|
||||||
queryParams.datetimeStart = queryDate.value;
|
|
||||||
queryParams.datetimeEnd = queryDate.value;
|
|
||||||
} else {
|
|
||||||
queryParams.datetimeStart = null;
|
|
||||||
queryParams.datetimeEnd = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
listMilkProdclasses({
|
listMilkProdclasses({
|
||||||
datetimeStart: queryParams.datetimeStart,
|
datetimeStart: start,
|
||||||
datetimeEnd: queryParams.datetimeEnd,
|
datetimeEnd: end,
|
||||||
manageEarNo: queryParams.manageEarNo,
|
manageEarNo: queryParams.manageEarNo,
|
||||||
factory: queryParams.factory,
|
factory: queryParams.factory,
|
||||||
classes: queryParams.classes,
|
classes: queryParams.classes,
|
||||||
@ -157,15 +135,8 @@ function getList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resetQuery() {
|
function resetQuery() {
|
||||||
Object.assign(queryParams, {
|
Object.assign(queryParams, { pageNum: 1, manageEarNo: '', factory: null, classes: null });
|
||||||
pageNum: 1,
|
dateRange.value = [];
|
||||||
datetimeStart: null,
|
|
||||||
datetimeEnd: null,
|
|
||||||
manageEarNo: '',
|
|
||||||
factory: null,
|
|
||||||
classes: null
|
|
||||||
});
|
|
||||||
queryDate.value = null;
|
|
||||||
getList();
|
getList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,57 +148,20 @@ function uploadSuccess(response) {
|
|||||||
console.log('上传成功:', response);
|
console.log('上传成功:', response);
|
||||||
openImport.value = false;
|
openImport.value = false;
|
||||||
getList();
|
getList();
|
||||||
ElMessage.success('导入成功');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadError(err) {
|
function uploadError(err) {
|
||||||
console.error('上传失败:', err);
|
console.error('上传失败:', err);
|
||||||
ElMessage.error('导入失败');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleExport() {
|
function handleExport() {
|
||||||
// 设置查询参数
|
const [start, end] = dateRange.value || [];
|
||||||
if (queryDate.value) {
|
|
||||||
queryParams.datetimeStart = queryDate.value;
|
|
||||||
queryParams.datetimeEnd = queryDate.value;
|
|
||||||
} else {
|
|
||||||
queryParams.datetimeStart = null;
|
|
||||||
queryParams.datetimeEnd = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
exportMilkProdclasses({
|
exportMilkProdclasses({
|
||||||
datetimeStart: queryParams.datetimeStart,
|
datetimeStart: start,
|
||||||
datetimeEnd: queryParams.datetimeEnd,
|
datetimeEnd: end,
|
||||||
manageEarNo: queryParams.manageEarNo,
|
manageEarNo: queryParams.manageEarNo, // 与后台参数统一
|
||||||
factory: queryParams.factory,
|
factory: queryParams.factory,
|
||||||
classes: queryParams.classes
|
classes: queryParams.classes
|
||||||
}).then(response => {
|
|
||||||
// 创建Blob对象,用于文件下载
|
|
||||||
const blob = new Blob([response], {
|
|
||||||
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
||||||
});
|
|
||||||
|
|
||||||
// 创建下载链接
|
|
||||||
const downloadElement = document.createElement('a');
|
|
||||||
const href = window.URL.createObjectURL(blob);
|
|
||||||
downloadElement.href = href;
|
|
||||||
|
|
||||||
// 设置下载文件名,包含当前日期
|
|
||||||
const now = new Date();
|
|
||||||
const dateStr = `${now.getFullYear()}${(now.getMonth()+1).toString().padStart(2, '0')}${now.getDate().toString().padStart(2, '0')}`;
|
|
||||||
downloadElement.download = `班次产奶数据_${dateStr}.xlsx`;
|
|
||||||
|
|
||||||
document.body.appendChild(downloadElement);
|
|
||||||
// 触发点击下载
|
|
||||||
downloadElement.click();
|
|
||||||
// 释放URL对象
|
|
||||||
document.body.removeChild(downloadElement);
|
|
||||||
window.URL.revokeObjectURL(href);
|
|
||||||
|
|
||||||
ElMessage.success('导出成功');
|
|
||||||
}).catch(error => {
|
|
||||||
console.error('导出失败:', error);
|
|
||||||
ElMessage.error('导出失败: ' + (error.message || '未知错误'));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -236,10 +236,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="RawMilkTest">
|
<script setup name="RawMilkTest">
|
||||||
// 导入xlsx库
|
|
||||||
import * as XLSX from 'xlsx';
|
|
||||||
// 导入file-saver用于文件下载
|
|
||||||
import { saveAs } from 'file-saver';
|
|
||||||
import { listRawMilkTest, getRawMilkTest, delRawMilkTest, addRawMilkTest, updateRawMilkTest } from "@/api/dairyProducts/rawMilkTest/rawMilkTest.js"
|
import { listRawMilkTest, getRawMilkTest, delRawMilkTest, addRawMilkTest, updateRawMilkTest } from "@/api/dairyProducts/rawMilkTest/rawMilkTest.js"
|
||||||
import { getCurrentInstance, ref, reactive, toRefs, onMounted } from 'vue'
|
import { getCurrentInstance, ref, reactive, toRefs, onMounted } from 'vue'
|
||||||
import { parseTime } from '@/utils/ruoyi'
|
import { parseTime } from '@/utils/ruoyi'
|
||||||
@ -500,38 +496,9 @@ function handleDelete(row) {
|
|||||||
|
|
||||||
/** 导出按钮操作 */
|
/** 导出按钮操作 */
|
||||||
function handleExport() {
|
function handleExport() {
|
||||||
// 获取当前显示的列配置
|
proxy.download('rawMilkTest/rawMilkTest/export', {
|
||||||
const visibleColumnsConfig = allColumns.value.filter(
|
...queryParams.value
|
||||||
col => visibleColumns.value[col.prop]
|
}, `rawMilkTest_${new Date().getTime()}.xlsx`)
|
||||||
);
|
|
||||||
|
|
||||||
// 准备导出数据
|
|
||||||
const exportData = rawMilkTestList.value.map(item => {
|
|
||||||
const rowData = {};
|
|
||||||
visibleColumnsConfig.forEach(col => {
|
|
||||||
// 特殊处理日期字段
|
|
||||||
if (col.prop === 'datetime' || col.prop === 'createTime') {
|
|
||||||
rowData[col.label] = parseTime(item[col.prop]);
|
|
||||||
} else {
|
|
||||||
rowData[col.label] = item[col.prop];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return rowData;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 创建工作簿和工作表
|
|
||||||
const worksheet = XLSX.utils.json_to_sheet(exportData);
|
|
||||||
const workbook = XLSX.utils.book_new();
|
|
||||||
XLSX.utils.book_append_sheet(workbook, worksheet, '生乳检验记录');
|
|
||||||
|
|
||||||
// 生成Excel文件并下载
|
|
||||||
const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
|
|
||||||
const blob = new Blob([excelBuffer], {
|
|
||||||
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
||||||
});
|
|
||||||
|
|
||||||
// 使用file-saver保存文件
|
|
||||||
saveAs(blob, `生乳检验记录_${new Date().getTime()}.xlsx`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@ -16,16 +16,16 @@
|
|||||||
|
|
||||||
<!-- 操作按钮行 -->
|
<!-- 操作按钮行 -->
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
|
<el-button type="success" @click="handleExport">导出</el-button>
|
||||||
|
|
||||||
<el-popover placement="bottom" width="400" trigger="click">
|
<el-popover placement="bottom" width="400" trigger="click">
|
||||||
<el-checkbox-group v-model="selectedFields" class="checkbox-columns">
|
<el-checkbox-group v-model="selectedFields" class="checkbox-columns">
|
||||||
<!-- 使用 :value 替代 :label -->
|
<el-checkbox v-for="col in allColumns" :key="col.prop" :label="col.prop">{{ col.label }}</el-checkbox>
|
||||||
<el-checkbox v-for="col in allColumns" :key="col.prop" :value="col.prop">{{ col.label }}</el-checkbox>
|
|
||||||
</el-checkbox-group>
|
</el-checkbox-group>
|
||||||
<template #reference>
|
<template #reference>
|
||||||
<el-button type="info">展示列</el-button>
|
<el-button type="info">展示列</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-popover>
|
</el-popover>
|
||||||
<el-button type="success" @click="handleExport">导出</el-button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 数据表格 -->
|
<!-- 数据表格 -->
|
||||||
@ -55,9 +55,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { listSheepMilkAnalysis } from "@/api/dairyProducts/sheepMilkAnalysis/sheepMilkAnalysis.js";
|
import { listSheepMilkAnalysis, exportSheepMilkAnalysis } from "@/api/dairyProducts/sheepMilkAnalysis/sheepMilkAnalysis.js";
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import * as XLSX from 'xlsx'; // 导入xlsx库
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "SheepMilkAnalysis",
|
name: "SheepMilkAnalysis",
|
||||||
@ -127,6 +126,7 @@ export default {
|
|||||||
getList() {
|
getList() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
listSheepMilkAnalysis(this.queryParams).then(response => {
|
listSheepMilkAnalysis(this.queryParams).then(response => {
|
||||||
|
// 兼容可能的 axios wrapper:有的返回 { data: { rows, total } }, 有的直接返回 { rows, total }
|
||||||
const res = response && response.data ? response.data : response;
|
const res = response && response.data ? response.data : response;
|
||||||
this.list = res.rows || res;
|
this.list = res.rows || res;
|
||||||
this.total = res.total || (Array.isArray(this.list) ? this.list.length : 0);
|
this.total = res.total || (Array.isArray(this.list) ? this.list.length : 0);
|
||||||
@ -155,33 +155,21 @@ export default {
|
|||||||
this.queryParams.pageSize = pageSize;
|
this.queryParams.pageSize = pageSize;
|
||||||
this.getList();
|
this.getList();
|
||||||
},
|
},
|
||||||
// 前端导出方法
|
|
||||||
handleExport() {
|
handleExport() {
|
||||||
// 准备导出数据
|
exportSheepMilkAnalysis(this.queryParams).then(response => {
|
||||||
const exportData = this.list.map(item => {
|
const data = response && response.data ? response.data : response;
|
||||||
const row = {};
|
const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
||||||
this.visibleColumns.forEach(col => {
|
const url = window.URL.createObjectURL(blob);
|
||||||
let value = item[col.prop];
|
const link = document.createElement('a');
|
||||||
// 处理日期格式化
|
link.href = url;
|
||||||
if (col.formatter && typeof col.formatter === 'function') {
|
link.setAttribute('download', '羊奶分析数据.xlsx');
|
||||||
value = col.formatter(item);
|
document.body.appendChild(link);
|
||||||
} else if (value instanceof Date) {
|
link.click();
|
||||||
value = format(new Date(value), 'yyyy-MM-dd');
|
document.body.removeChild(link);
|
||||||
}
|
window.URL.revokeObjectURL(url);
|
||||||
row[col.label] = value;
|
}).catch(err => {
|
||||||
});
|
this.$message.error('导出失败,请检查后端是否正确返回文件流');
|
||||||
return row;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 创建工作簿和工作表
|
|
||||||
const worksheet = XLSX.utils.json_to_sheet(exportData);
|
|
||||||
const workbook = XLSX.utils.book_new();
|
|
||||||
XLSX.utils.book_append_sheet(workbook, worksheet, "羊奶产量分析");
|
|
||||||
|
|
||||||
// 生成Excel文件并下载
|
|
||||||
XLSX.writeFile(workbook, "羊奶产量分析数据.xlsx");
|
|
||||||
|
|
||||||
this.$message.success('导出成功');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -287,9 +287,6 @@
|
|||||||
import { ref, reactive, onMounted } from 'vue';
|
import { ref, reactive, onMounted } from 'vue';
|
||||||
import { listYogurtTest, getYogurtTest, delYogurtTest, addYogurtTest, updateYogurtTest } from "@/api/dairyProducts/yogurtTest/yogurtTest.js";
|
import { listYogurtTest, getYogurtTest, delYogurtTest, addYogurtTest, updateYogurtTest } from "@/api/dairyProducts/yogurtTest/yogurtTest.js";
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||||
// 导入xlsx库和file-saver
|
|
||||||
import * as XLSX from 'xlsx';
|
|
||||||
import { saveAs } from 'file-saver';
|
|
||||||
|
|
||||||
// 响应式数据
|
// 响应式数据
|
||||||
const yogurtTestList = ref([]);
|
const yogurtTestList = ref([]);
|
||||||
@ -304,27 +301,6 @@ const title = ref("");
|
|||||||
const columnShowDialogVisible = ref(false);
|
const columnShowDialogVisible = ref(false);
|
||||||
const yogurtTestRef = ref(null);
|
const yogurtTestRef = ref(null);
|
||||||
|
|
||||||
// 列配置映射
|
|
||||||
const columnConfig = [
|
|
||||||
{ prop: 'source', label: '来源' },
|
|
||||||
{ prop: 'datetime', label: '检测日期' },
|
|
||||||
{ prop: 'fat', label: '脂肪g/100g' },
|
|
||||||
{ prop: 'protein', label: '蛋白质g/100g' },
|
|
||||||
{ prop: 'nonFat', label: '非脂g/100g' },
|
|
||||||
{ prop: 'acidity', label: '酸度oT' },
|
|
||||||
{ prop: 'bacterialColony1', label: '菌落总数1' },
|
|
||||||
{ prop: 'bacterialClony2', label: '菌落总数2' },
|
|
||||||
{ prop: 'bacterialClony3', label: '菌落总数3' },
|
|
||||||
{ prop: 'bacterialClony4', label: '菌落总数4' },
|
|
||||||
{ prop: 'bacterialClony5', label: '菌落总数5' },
|
|
||||||
{ prop: 'yeast', label: '酵母菌(CFU/g)' },
|
|
||||||
{ prop: 'mould', label: '霉菌(CFU/g)' },
|
|
||||||
{ prop: 'lacto', label: '乳酸菌(CFU/g)' },
|
|
||||||
{ prop: 'comment', label: '备注' },
|
|
||||||
{ prop: 'createBy', label: '创建人' },
|
|
||||||
{ prop: 'createTime', label: '创建时间' }
|
|
||||||
];
|
|
||||||
|
|
||||||
// 默认显示的列
|
// 默认显示的列
|
||||||
const selectedColumns = ref([
|
const selectedColumns = ref([
|
||||||
'source', 'datetime', 'fat', 'protein', 'nonFat', 'acidity',
|
'source', 'datetime', 'fat', 'protein', 'nonFat', 'acidity',
|
||||||
@ -567,42 +543,17 @@ function handleDelete(row) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 导出按钮操作 - 前端实现 */
|
/** 导出按钮操作 */
|
||||||
function handleExport() {
|
function handleExport() {
|
||||||
// 获取当前显示的列配置
|
const params = new URLSearchParams();
|
||||||
const visibleColumnsConfig = columnConfig.filter(
|
for (const key in queryParams) {
|
||||||
col => selectedColumns.value.includes(col.prop)
|
if (queryParams[key] !== null && queryParams[key] !== undefined) {
|
||||||
);
|
params.append(key, queryParams[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 准备导出数据
|
const url = `/yogurtTest/yogurtTest/export?${params.toString()}`;
|
||||||
const exportData = yogurtTestList.value.map(item => {
|
window.location.href = url;
|
||||||
const rowData = {};
|
|
||||||
visibleColumnsConfig.forEach(col => {
|
|
||||||
// 特殊处理日期字段
|
|
||||||
if (col.prop === 'datetime') {
|
|
||||||
rowData[col.label] = formatDate(item[col.prop]);
|
|
||||||
} else if (col.prop === 'createTime') {
|
|
||||||
rowData[col.label] = formatDateTime(item[col.prop]);
|
|
||||||
} else {
|
|
||||||
rowData[col.label] = item[col.prop];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return rowData;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 创建工作簿和工作表
|
|
||||||
const worksheet = XLSX.utils.json_to_sheet(exportData);
|
|
||||||
const workbook = XLSX.utils.book_new();
|
|
||||||
XLSX.utils.book_append_sheet(workbook, worksheet, '酸奶检疫记录');
|
|
||||||
|
|
||||||
// 生成Excel文件并下载
|
|
||||||
const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
|
|
||||||
const blob = new Blob([excelBuffer], {
|
|
||||||
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
||||||
});
|
|
||||||
|
|
||||||
// 使用file-saver保存文件
|
|
||||||
saveAs(blob, `酸奶检疫记录_${new Date().getTime()}.xlsx`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化加载
|
// 初始化加载
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user