我的溯源,查看溯源码,查看检测报告,表格组件完成
This commit is contained in:
parent
53cdca5961
commit
6b05924fc4
@ -26,18 +26,18 @@
|
||||
<div class="_label" style="font-size: 30px">溯源信息</div>
|
||||
<div class="traceability_info_box">
|
||||
<div class="traceability_info_box_image">
|
||||
<img v-if="info.productType === '番茄'" src="../../../assets/images/entities/tomatoImg.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '芹菜'" src="../../../assets/images/entities/芹菜.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '白菜'" src="../../../assets/images/entities/白菜.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '石斛'" src="../../../assets/images/entities/石斛.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '铁皮石斛'" src="../../../assets/images/entities/石斛.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '紫皮石斛'" src="../../../assets/images/entities/石斛.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '甘蔗'" src="../../../assets/images/entities/3.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '黑皮甘蔗'" src="../../../assets/images/entities/3.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '黄皮甘蔗'" src="../../../assets/images/entities/3.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '红茶'" src="../../../assets/images/entities/红茶.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '核桃'" src="../../../assets/images/entities/核桃.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productType === '核桃仁'" src="../../../assets/images/entities/核桃.png" style="width: 100%; height: 100%" />
|
||||
<img v-if="info.productName === '番茄'" src="../../../assets/images/entities/tomatoImg.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '芹菜'" src="../../../assets/images/entities/芹菜.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '白菜'" src="../../../assets/images/entities/白菜.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '石斛'" src="../../../assets/images/entities/石斛.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '铁皮石斛'" src="../../../assets/images/entities/石斛.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '紫皮石斛'" src="../../../assets/images/entities/石斛.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '甘蔗'" src="../../../assets/images/entities/3.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '黑皮甘蔗'" src="../../../assets/images/entities/3.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '黄皮甘蔗'" src="../../../assets/images/entities/3.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '红茶'" src="../../../assets/images/entities/红茶.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '核桃'" src="../../../assets/images/entities/核桃.png" style="width: 100%; height: 100%" />
|
||||
<img v-else-if="info.productName === '核桃仁'" src="../../../assets/images/entities/核桃.png" style="width: 100%; height: 100%" />
|
||||
</div>
|
||||
<div class="traceability_info_box_title">
|
||||
<div class="traceability_info_right">新鲜{{ info.productType }}</div>
|
||||
|
BIN
sub-operation-service/src/assets/images/userCenter/weweima.png
Normal file
BIN
sub-operation-service/src/assets/images/userCenter/weweima.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.5 KiB |
BIN
sub-operation-service/src/assets/images/userCenter/检测报告.png
Normal file
BIN
sub-operation-service/src/assets/images/userCenter/检测报告.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 417 KiB |
@ -73,6 +73,12 @@ export const constantRoutes = [
|
||||
name: 'userLands',
|
||||
meta: { title: '我的土地' },
|
||||
},
|
||||
{
|
||||
path: '/sub-operation-service/mySource',
|
||||
component: () => import('@/views/userCenter/mySource.vue'),
|
||||
name: 'userLands',
|
||||
meta: { title: '我的溯源' },
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
@import '@/assets/fonts/aliiconfont.css';
|
||||
|
||||
#app {
|
||||
position: relative;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-family: Avenir, sans-serif;
|
||||
|
@ -24,7 +24,10 @@ const props = defineProps({
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.ecommerce-common-warp {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
height: 100%;
|
||||
|
||||
// height: calc(100vh - 230px);
|
||||
text-align: center;
|
||||
@ -37,6 +40,7 @@ const props = defineProps({
|
||||
.left-menu,
|
||||
.common-content {
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 8px;
|
||||
|
||||
// height: calc(100% - 16px);
|
||||
|
@ -33,7 +33,8 @@ const props = defineProps({
|
||||
const leftMenu = reactive([
|
||||
{ name: 'agricultural', title: '我的购物车', icon: 'menu1.png', path: '/sub-operation-service/userCenter' },
|
||||
{ name: 'supplier', title: '我的订单', icon: 'menu2-1.png', path: '/sub-operation-service/userOrders' },
|
||||
{ name: 'purchaser', title: '我的土地', icon: 'menu3-1.png', path: '/sub-operation-service/userLands' },
|
||||
// { name: 'purchaser', title: '我的土地', icon: 'menu3-1.png', path: '/sub-operation-service/userLands' },
|
||||
{ name: 'purchaser', title: '我的溯源', icon: 'menu3-1.png', path: '/sub-operation-service/mySource' },
|
||||
]);
|
||||
|
||||
let currentIndex = ref(0);
|
||||
@ -101,7 +102,7 @@ const toLink = (n, index) => {
|
||||
width: 100%;
|
||||
display: inline-flex;
|
||||
justify-content: flex-start;
|
||||
padding: 16px 0;
|
||||
padding: 16px 0 16px 16px;
|
||||
cursor: pointer;
|
||||
&.active {
|
||||
color: $color-main;
|
||||
|
@ -0,0 +1,335 @@
|
||||
<template>
|
||||
<div class="custom-table-container">
|
||||
<div class="custom-table-tool">
|
||||
<el-form :inline="true" class="demo-form-inline" :label-width="'auto'">
|
||||
<el-form-item label="每页显示">
|
||||
<el-select v-model="internalPageSize" placeholder="请选择" style="width: 100px" @change="pageSizeChange($event)">
|
||||
<el-option v-for="item in pageSizes" :key="item" :label="item" :value="item" />
|
||||
</el-select>
|
||||
<span style="padding: 0 10px">条</span>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<el-table
|
||||
style="flex: 1; display: flex; flex-direction: column"
|
||||
:max-height="tableMaxHeight"
|
||||
:data="pagedTableData"
|
||||
:border="showBorder"
|
||||
:stripe="showStripe"
|
||||
v-bind="$attrs"
|
||||
:header-cell-class-name="headerCellClassName"
|
||||
:cell-class-name="cellClassName"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<!-- 首列多选框 -->
|
||||
<el-table-column v-if="showSelection" type="selection" width="55" align="center" />
|
||||
|
||||
<template v-for="column in columns" :key="column.prop">
|
||||
<el-table-column
|
||||
:prop="column.prop"
|
||||
:label="column.label"
|
||||
:width="column.width"
|
||||
:align="column.align || 'center'"
|
||||
:sortable="column.sortable"
|
||||
:header-class-name="column.headerClassName"
|
||||
>
|
||||
<!-- 支持插槽 -->
|
||||
<template v-if="column.slotName" #default="scope">
|
||||
<slot :name="column.slotName" :row="scope.row"></slot>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</template>
|
||||
</el-table>
|
||||
|
||||
<div v-if="showPagination" class="pagination-container">
|
||||
<span class="custom-pagination-text">
|
||||
第{{ internalPage }}页,共{{ Math.ceil(internalTotal / internalPageSize) }}页,共{{ internalTotal }}条
|
||||
</span>
|
||||
<div style="flex: 1; display: flex; justify-content: end; text-align: right">
|
||||
<el-pagination
|
||||
v-model:current-page="internalPage"
|
||||
v-model:page-size="internalPageSize"
|
||||
:page-sizes="pageSizes"
|
||||
:small="small"
|
||||
:disabled="disabled"
|
||||
:background="background"
|
||||
layout="prev, pager, next"
|
||||
:total="internalTotal"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
<span class="custom-pagination-size"> {{ internalPageSize }}条/页 </span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch, computed, onMounted, onBeforeUnmount } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
// 表格数据
|
||||
tableData: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
// 列配置
|
||||
columns: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
// 是否显示分页
|
||||
showPagination: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
// 是否显示边框
|
||||
showBorder: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 是否显示斑马纹
|
||||
showStripe: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 是否显示首列多选框
|
||||
showSelection: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 每页显示条数选项
|
||||
pageSizes: {
|
||||
type: Array,
|
||||
default: () => [10, 20, 30, 50],
|
||||
},
|
||||
// 是否使用小型分页样式
|
||||
small: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 是否禁用
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 是否为分页按钮添加背景色
|
||||
background: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 自定义表头类名函数
|
||||
headerCellClassName: {
|
||||
type: Function,
|
||||
default: () => '',
|
||||
},
|
||||
// 自定义单元格类名函数
|
||||
cellClassName: {
|
||||
type: Function,
|
||||
default: () => '',
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['page-change', 'selection-change']);
|
||||
|
||||
// 内部管理的分页状态
|
||||
const internalPage = ref(1);
|
||||
const internalPageSize = ref(props.pageSizes?.[0] || 10);
|
||||
const internalTotal = ref(0);
|
||||
|
||||
// 计算当前页显示的数据
|
||||
const pagedTableData = computed(() => {
|
||||
const start = (internalPage.value - 1) * internalPageSize.value;
|
||||
const end = start + internalPageSize.value;
|
||||
return props.tableData.slice(start, end);
|
||||
});
|
||||
|
||||
// 计算总页数(可根据实际需求调整)
|
||||
watch(
|
||||
() => props.tableData,
|
||||
(newData) => {
|
||||
internalTotal.value = newData.length; // 示例:假设总数据量是当前显示的3倍
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// 分页大小改变
|
||||
const pageSizeChange = (val) => {
|
||||
console.log(`每页 ${val} 条`);
|
||||
internalPageSize.value = val;
|
||||
internalPage.value = 1; // 重置为第一页
|
||||
console.log(internalPage.value, internalPageSize.value);
|
||||
emitPageChange();
|
||||
};
|
||||
|
||||
// 当前页改变
|
||||
const handleCurrentChange = (val) => {
|
||||
console.log(`当前页改变 ${val} 页`);
|
||||
internalPage.value = val;
|
||||
emitPageChange();
|
||||
};
|
||||
|
||||
// 触发分页变化事件
|
||||
const emitPageChange = () => {
|
||||
emit('page-change', {
|
||||
page: internalPage.value,
|
||||
pageSize: internalPageSize.value,
|
||||
});
|
||||
};
|
||||
|
||||
// 多选框变化
|
||||
const handleSelectionChange = (selection) => {
|
||||
emit('selection-change', selection);
|
||||
};
|
||||
|
||||
const tableRef = ref(null);
|
||||
const tableMaxHeight = ref(null); // 使用max-height而不是height
|
||||
|
||||
// 自动计算最大高度(预留分页器空间)
|
||||
const calculateMaxHeight = () => {
|
||||
const paginationHeight = 60; // 分页器固定高度
|
||||
const container = tableRef.value?.$el?.parentElement;
|
||||
if (container) {
|
||||
const containerHeight = container.clientHeight;
|
||||
tableMaxHeight.value = containerHeight - paginationHeight;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
calculateMaxHeight();
|
||||
window.addEventListener('resize', calculateMaxHeight);
|
||||
|
||||
// 添加MutationObserver监听父容器尺寸变化
|
||||
const observer = new MutationObserver(calculateMaxHeight);
|
||||
if (tableRef.value?.$el?.parentElement) {
|
||||
observer.observe(tableRef.value.$el.parentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ['style', 'class'],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('resize', calculateMaxHeight);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.custom-table-container {
|
||||
// position: relative;
|
||||
padding: 10px 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%; /* 关键:继承父容器高度 */
|
||||
overflow: hidden; /* 防止内容溢出 */
|
||||
}
|
||||
/* 表格弹性布局 */
|
||||
:deep(.el-table) {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
/* 表头固定 */
|
||||
.el-table__header-wrapper {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* 表体可滚动 */
|
||||
.el-table__body-wrapper {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.demo-form-inline {
|
||||
text-align: left;
|
||||
padding-left: 20px;
|
||||
}
|
||||
.pagination-container {
|
||||
margin-top: 10px;
|
||||
padding: 0 16px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
color: #999;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.custom-pagination-text {
|
||||
flex: 1;
|
||||
text-align: left;
|
||||
line-height: 32px;
|
||||
}
|
||||
|
||||
.custom-pagination-size {
|
||||
text-align: right;
|
||||
line-height: 32px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
/* 去除表格边框 */
|
||||
:deep(.el-table) {
|
||||
--el-table-border-color: transparent;
|
||||
}
|
||||
|
||||
/* 自定义鼠标悬停颜色 */
|
||||
:deep(.el-table__body tr:hover > td) {
|
||||
background-color: rgba(37, 191, 130, 0.1) !important;
|
||||
}
|
||||
|
||||
/* 自定义表头样式 */
|
||||
:deep(.custom-header) {
|
||||
background-color: #fff !important;
|
||||
color: #999;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
:deep(.el-pagination) {
|
||||
/* 整体分页样式 */
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
|
||||
/* 页码按钮容器 */
|
||||
.el-pager {
|
||||
/* 所有页码项 */
|
||||
li {
|
||||
font-weight: 400; /* 普通页码字体不加粗 */
|
||||
color: #606266; /* 普通页码颜色 */
|
||||
background: transparent;
|
||||
font-size: 14px;
|
||||
|
||||
/* 当前选中页码 */
|
||||
&.active,
|
||||
&.is-active {
|
||||
font-weight: 400 !important; /* 当前页不加粗 */
|
||||
color: #25bf82 !important; /* 自定义当前页颜色 - 橙色示例 */
|
||||
}
|
||||
|
||||
/* 悬停状态 */
|
||||
&:hover {
|
||||
color: #409eff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 上一页/下一页按钮 */
|
||||
.btn-prev,
|
||||
.btn-next {
|
||||
font-weight: 400;
|
||||
|
||||
&:disabled {
|
||||
color: #c0c4cc;
|
||||
}
|
||||
}
|
||||
|
||||
/* 每页条数选择器 */
|
||||
.el-pagination__sizes {
|
||||
.el-input__inner {
|
||||
font-weight: 400;
|
||||
}
|
||||
}
|
||||
|
||||
/* 跳页输入框 */
|
||||
.el-pagination__jump {
|
||||
font-weight: 400;
|
||||
}
|
||||
}
|
||||
</style>
|
488
sub-operation-service/src/views/userCenter/mySource.vue
Normal file
488
sub-operation-service/src/views/userCenter/mySource.vue
Normal file
@ -0,0 +1,488 @@
|
||||
<template>
|
||||
<div>
|
||||
<common current-name="agricultural">
|
||||
<template #main>
|
||||
<div class="container">
|
||||
<userHeader ref="titleRef" :title="'我的溯源'"></userHeader>
|
||||
<!-- 搜索栏 -->
|
||||
<div ref="searchBarRef" class="search-bar">
|
||||
<div class="search-bar-left">
|
||||
<el-form ref="searchForm" :inline="true" :model="formInline" class="demo-form-inline" :label-width="'auto'">
|
||||
<el-form-item label="产品名称" prop="productName">
|
||||
<el-input v-model="formInline.productName" placeholder="请输入产品名称" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="溯源码" prop="sourceCode">
|
||||
<el-input v-model="formInline.sourceCode" placeholder="请输入编号" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="申请状态" prop="status">
|
||||
<el-select v-model="formInline.status" placeholder="请选择">
|
||||
<el-option label="全部" value="99" />
|
||||
<el-option label="待检测" value="0" />
|
||||
<el-option label="已检测" value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="申请日期" prop="startDate" style="margin-right: 0">
|
||||
<el-date-picker v-model="formInline.startDate" type="date" placeholder="请选择起始日期" clearable style="width: 160px" />
|
||||
</el-form-item>
|
||||
<el-form-item style="margin-right: 0">
|
||||
<span style="width: 30px; text-align: center; display: inline-block"> - </span>
|
||||
</el-form-item>
|
||||
<el-form-item prop="endDate">
|
||||
<el-date-picker v-model="formInline.endDate" type="date" placeholder="请选择截止日期" clearable style="width: 160px" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<div class="search-bar-right">
|
||||
<el-button type="primary" icon="Search" @click="onSubmit">搜索</el-button>
|
||||
<el-button icon="Refresh" style="margin: 24px 0 0 0" @click="resetForm">重置</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 表格 -->
|
||||
<div class="table-cont" :style="{ height: tableViewportHeight + 'px' }">
|
||||
<tableComponent
|
||||
:table-data="tableData"
|
||||
:columns="columns"
|
||||
:show-border="false"
|
||||
:show-selection="true"
|
||||
:header-cell-class-name="getHeaderClass"
|
||||
@page-change="handlePaginationChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<!-- 自定义-状态 -->
|
||||
<template #status="slotProps">
|
||||
<span :style="{ color: slotProps.row.status == 1 ? 'green' : 'red' }">
|
||||
{{ slotProps.row.status === 1 ? '已检测' : '待检测' }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<!-- 自定义-检测报告 -->
|
||||
<template #report="slotProps">
|
||||
<el-icon v-if="slotProps.row.report == 1" color="#25bf82" size="20px" class="el-icon-custom" @click="seeReportImg(slotProps.row)"
|
||||
><Memo style="width: 2em; height: 2em"
|
||||
/></el-icon>
|
||||
<el-icon v-else color="#999" size="20px" class="el-icon-custom"><Memo style="width: 2em; height: 2em" /></el-icon>
|
||||
</template>
|
||||
|
||||
<!-- 自定义-溯源码 -->
|
||||
<template #sourceCode="slotProps">
|
||||
<el-icon v-if="slotProps.row.sourceCode == 1" color="#25bf82" size="20px" class="el-icon-custom" @click="seeCodeImg(slotProps.row)"
|
||||
><Film style="width: 2em; height: 2em"
|
||||
/></el-icon>
|
||||
<el-icon v-else color="#999" size="20px" class="el-icon-custom"><Film style="width: 2em; height: 2em" /></el-icon>
|
||||
</template>
|
||||
|
||||
<!-- 自定义-操作 -->
|
||||
<template #action="slotProps">
|
||||
<el-dropdown>
|
||||
<span class="el-dropdown-link">
|
||||
<el-icon><More /></el-icon>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="handleEdit(slotProps.row, 1)">Action 1</el-dropdown-item>
|
||||
<el-dropdown-item @click="handleEdit(slotProps.row, 2)">Action 2</el-dropdown-item>
|
||||
<el-dropdown-item @click="handleEdit(slotProps.row, 3)">Action 3</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
</tableComponent>
|
||||
</div>
|
||||
|
||||
<!-- 图片预览组件 -->
|
||||
<el-image-viewer v-if="showPreview" :url-list="[previewImageUrl]" :initial-index="0" @close="closePreview" />
|
||||
|
||||
<!-- 查看溯源码 -->
|
||||
<el-dialog v-model="dialogVisible" :show-close="false" width="450px" custom-class="traceability-dialog" :before-close="handleClose">
|
||||
<!-- 主要内容区域 -->
|
||||
<div class="dialog-content">
|
||||
<!-- 二维码图片 -->
|
||||
<img :src="codeUrl" alt="溯源码" class="qrcode-image" />
|
||||
|
||||
<!-- 下载区域 -->
|
||||
<div class="download-section" @click="handleDownload">
|
||||
<el-icon class="download-icon"><Download /></el-icon>
|
||||
<span style="margin-left: 5px">下载溯源码</span>
|
||||
</div>
|
||||
|
||||
<!-- 遗传编码区域 -->
|
||||
<div class="code-section">
|
||||
<span class="genetic-code">10.5488754215478XE254.1040201</span>
|
||||
<el-tooltip content="复制溯源码" placement="top">
|
||||
<el-button color="#25bf82" style="color: #fff; font-weight: 400; height: 100%" @click="copyCode">复制</el-button>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 自定义关闭按钮 -->
|
||||
<el-icon class="close-button" @click="dialogVisible = false">
|
||||
<CircleCloseFilled />
|
||||
</el-icon>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
</common>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import common from './components/common.vue';
|
||||
import { ref, reactive, computed, onMounted, onBeforeUnmount } from 'vue';
|
||||
import { isEmpty, getAssetsFile } from '@/utils';
|
||||
import userHeader from './components/userHeader.vue';
|
||||
import tableComponent from './components/tableComponent.vue';
|
||||
import Mock from 'mockjs';
|
||||
import { Close, Download, DocumentCopy, Loading } from '@element-plus/icons-vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
const formInline = reactive({
|
||||
productName: '',
|
||||
sourceCode: '',
|
||||
status: '99',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
});
|
||||
|
||||
const searchForm = ref(null);
|
||||
const onSubmit = () => {
|
||||
console.log('submit!');
|
||||
};
|
||||
const resetForm = () => {
|
||||
searchForm.value.resetFields();
|
||||
};
|
||||
|
||||
// 表格数据
|
||||
const tableData = ref([]);
|
||||
// 列配置
|
||||
const columns = ref([
|
||||
{ prop: 'id', label: 'ID', width: '80' },
|
||||
{ prop: 'productName', label: '产品名称' },
|
||||
{ prop: 'applyTime', label: '申请时间', width: '180px' },
|
||||
{ prop: 'status', label: '申请状态', slotName: 'status' },
|
||||
{ prop: 'report', label: '检测报告', slotName: 'report' },
|
||||
{ prop: 'sourceCode', label: '溯源码', slotName: 'sourceCode' },
|
||||
{ prop: 'action', label: '操作', slotName: 'action', width: '180' },
|
||||
]);
|
||||
// 生成模拟数据
|
||||
const generateMockData = () => {
|
||||
return Mock.mock({
|
||||
'list|30': [
|
||||
{
|
||||
'id|+1': 1,
|
||||
productName: '@cname', //产品名称 水果 蔬菜
|
||||
applyTime: '@datetime',
|
||||
'status|1': [1, 1, 1, 0], //0待检测 1已检测
|
||||
'report|1': [1, 1, 1, 0], //0无报告 1有报告
|
||||
reportUrl: '@url',
|
||||
'sourceCode|1': [1, 1, 1, 0], //0无溯源码 1有溯源码
|
||||
code: '@guid',
|
||||
codeUrl: '@url',
|
||||
},
|
||||
],
|
||||
}).list;
|
||||
};
|
||||
// 加载数据
|
||||
const loadData = () => {
|
||||
// 模拟API请求延迟
|
||||
setTimeout(() => {
|
||||
tableData.value = generateMockData();
|
||||
}, 500);
|
||||
};
|
||||
// 自定义表头类名,也可以在columns指定列中添加headerClassName: 'custom-header'
|
||||
const getHeaderClass = ({ column }) => {
|
||||
return 'custom-header';
|
||||
};
|
||||
// 分页变化
|
||||
const handlePaginationChange = ({ page, pageSize }) => {
|
||||
console.log('分页变化:', page, pageSize);
|
||||
// 这里可以调用API获取新数据
|
||||
// fetchData(page, limit,pageSize)
|
||||
};
|
||||
// 多选框变化
|
||||
const handleSelectionChange = (selection) => {
|
||||
console.log('选中项:', selection);
|
||||
};
|
||||
|
||||
let nowClickRow = ref(null);
|
||||
const dialogVisible = ref(false);
|
||||
let codeUrl = ref('');
|
||||
codeUrl.value = getAssetsFile('images/userCenter/检测报告.png').href ?? '';
|
||||
// 编辑操作
|
||||
const handleEdit = (row, num) => {
|
||||
nowClickRow.value = row;
|
||||
console.log('编辑的行:', row);
|
||||
console.log('第几个按钮:', num);
|
||||
};
|
||||
|
||||
// 图片预览相关状态
|
||||
const showPreview = ref(false);
|
||||
const previewImageUrl = ref('');
|
||||
// 查看检测报告
|
||||
const seeReportImg = (row) => {
|
||||
nowClickRow.value = row;
|
||||
console.log('查看检测报告:', row);
|
||||
if (row.reportUrl) {
|
||||
// 支持相对路径处理
|
||||
// const imgUrl = row.reportUrl.startsWith('http') ? row.reportUrl : `${import.meta.env.VITE_API_BASE}${row.reportUrl}`;
|
||||
const imgUrl = codeUrl.value;
|
||||
|
||||
previewImageUrl.value = imgUrl;
|
||||
showPreview.value = true;
|
||||
} else {
|
||||
ElMessage.warning('该记录没有检测报告');
|
||||
}
|
||||
};
|
||||
const closePreview = () => {
|
||||
showPreview.value = false;
|
||||
};
|
||||
|
||||
// 查看溯源码
|
||||
const seeCodeImg = (row) => {
|
||||
nowClickRow.value = row;
|
||||
console.log('查看溯源码:', row);
|
||||
// codeUrl.value = getAssetsFile(row.codeUrl);
|
||||
codeUrl.value = getAssetsFile('images/userCenter/weweima.png').href ?? '';
|
||||
dialogVisible.value = true;
|
||||
};
|
||||
|
||||
const handleClose = (done) => {
|
||||
dialogVisible.value = false;
|
||||
};
|
||||
|
||||
const handleDownload = async () => {
|
||||
console.log('下载溯源码:', nowClickRow.value);
|
||||
try {
|
||||
if (!nowClickRow.value.codeUrl) {
|
||||
ElMessage.error('图片链接无效');
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加加载状态提示
|
||||
const loading = ElMessage({
|
||||
message: '正在准备下载...',
|
||||
duration: 0,
|
||||
icon: Loading,
|
||||
});
|
||||
|
||||
// 使用fetch获取图片Blob数据
|
||||
const response = await fetch(codeUrl.value);
|
||||
if (!response.ok) throw new Error('网络响应不正常');
|
||||
|
||||
const blob = await response.blob();
|
||||
const blobUrl = window.URL.createObjectURL(blob);
|
||||
|
||||
// 创建隐藏的下载链接
|
||||
const link = document.createElement('a');
|
||||
link.href = blobUrl;
|
||||
link.download = `${new Date().toISOString().slice(0, 10)}.png`;
|
||||
link.style.display = 'none';
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
// 清理
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
loading.close();
|
||||
ElMessage.success('下载完成');
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
console.error('下载失败:', error);
|
||||
ElMessage.error('下载失败: ' + error.message);
|
||||
}
|
||||
};
|
||||
|
||||
const copyCode = () => {
|
||||
const code = '10.5488754215478XE254.1040201';
|
||||
navigator.clipboard
|
||||
.writeText(code)
|
||||
.then(() => ElMessage.success('复制成功'))
|
||||
.catch(() => ElMessage.error('复制失败'));
|
||||
};
|
||||
|
||||
const titleRef = ref(null);
|
||||
const searchBarRef = ref(null);
|
||||
const tableViewportHeight = ref(0);
|
||||
// 精确计算可用高度
|
||||
const calculateTableHeight = () => {
|
||||
// 获取窗口总高度
|
||||
const windowHeight = window.innerHeight;
|
||||
|
||||
// 获取各组件高度
|
||||
const headerHeight = titleRef.value?.$el?.offsetHeight || 0;
|
||||
const searchBarHeight = searchBarRef.value?.offsetHeight || 0;
|
||||
|
||||
// 计算容器内边距补偿(根据实际样式调整)
|
||||
const paddingCompensation = 60;
|
||||
|
||||
// 最终计算
|
||||
tableViewportHeight.value = windowHeight - headerHeight - searchBarHeight - paddingCompensation;
|
||||
// console.log(tableViewportHeight.value);
|
||||
};
|
||||
// 组件挂载时加载数据
|
||||
onMounted(() => {
|
||||
loadData();
|
||||
|
||||
calculateTableHeight();
|
||||
|
||||
// 添加响应式监听
|
||||
window.addEventListener('resize', calculateTableHeight);
|
||||
|
||||
// 监听DOM变化(适用于动态变化的header/searchbar)
|
||||
const observer = new ResizeObserver(calculateTableHeight);
|
||||
if (titleRef.value?.$el) observer.observe(titleRef.value.$el);
|
||||
if (searchBarRef.value) observer.observe(searchBarRef.value);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('resize', calculateTableHeight);
|
||||
});
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.container {
|
||||
width: 100%;
|
||||
overflow: hidden; /* 防止全局滚动条 */
|
||||
|
||||
.search-bar {
|
||||
overflow: hidden;
|
||||
margin: 16px 0;
|
||||
padding: 16px 8px 0 16px;
|
||||
border-radius: 16px;
|
||||
background: #fff;
|
||||
display: flex;
|
||||
flex-shrink: 0; /* 禁止收缩 */
|
||||
min-height: 100px;
|
||||
|
||||
.search-bar-left {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.search-bar-right {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
.demo-form-inline {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.el-form--inline .el-form-item {
|
||||
margin-right: 30px;
|
||||
}
|
||||
|
||||
.demo-form-inline .el-input {
|
||||
--el-input-width: 160px;
|
||||
}
|
||||
|
||||
.demo-form-inline .el-select {
|
||||
--el-select-width: 160px;
|
||||
}
|
||||
|
||||
.demo-form-inline .el-date-picker {
|
||||
--el-select-width: 160px;
|
||||
}
|
||||
}
|
||||
.table-cont {
|
||||
min-height: 300px;
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
background-color: #fff;
|
||||
position: relative;
|
||||
.el-icon-custom {
|
||||
vertical-align: middle;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
/* 自定义弹窗样式 */
|
||||
.traceability-dialog {
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
border-radius: 16px !important;
|
||||
}
|
||||
|
||||
/* 主要内容区域 */
|
||||
.dialog-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 0 0 20px 0;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* 产品信息 */
|
||||
.product-info {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* 二维码图片 */
|
||||
.qrcode-image {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
/* 下载区域 */
|
||||
.download-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 0 0 10px 0;
|
||||
color: #25bf82;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
.download-icon {
|
||||
margin-left: 8px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
/* 遗传编码区域 */
|
||||
.code-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 10px 0;
|
||||
background: rgba(37, 191, 130, 0.1);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.genetic-code {
|
||||
font-family: monospace;
|
||||
font-size: 14px;
|
||||
color: #25bf82;
|
||||
display: inline-block;
|
||||
max-width: 250px;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.copy-icon {
|
||||
margin-left: 10px;
|
||||
color: #409eff;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
/* 关闭按钮 */
|
||||
.close-button {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
bottom: -60px;
|
||||
color: white;
|
||||
font-size: 30px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
}
|
||||
</style>
|
Loading…
x
Reference in New Issue
Block a user