|
@@ -11,13 +11,12 @@
|
|
|
<template v-else>
|
|
<template v-else>
|
|
|
<div class="timeline-middle-line"></div>
|
|
<div class="timeline-middle-line"></div>
|
|
|
<div
|
|
<div
|
|
|
- v-for="(t, tIdx) in solarTerms"
|
|
|
|
|
|
|
+ v-for="(t, tIdx) in phenologyStartDates"
|
|
|
:key="`term-${uniqueTimestamp}-${tIdx}`"
|
|
:key="`term-${uniqueTimestamp}-${tIdx}`"
|
|
|
class="timeline-term"
|
|
class="timeline-term"
|
|
|
:style="getTermStyle(t, tIdx)"
|
|
:style="getTermStyle(t, tIdx)"
|
|
|
>
|
|
>
|
|
|
- <span class="term-name">{{ t.displayName }}</span>
|
|
|
|
|
- <span class="term-date">{{ formatDate(t.createDate) }}</span>
|
|
|
|
|
|
|
+ <span class="term-name">{{ formatDate(t.startDate) }}</span>
|
|
|
</div>
|
|
</div>
|
|
|
<div
|
|
<div
|
|
|
v-for="(p, idx) in phenologyList"
|
|
v-for="(p, idx) in phenologyList"
|
|
@@ -136,7 +135,7 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref, nextTick, watch, onMounted, onUnmounted } from "vue";
|
|
|
|
|
|
|
+import { ref, nextTick, watch, onMounted, onUnmounted, computed } from "vue";
|
|
|
import { ElMessage } from "element-plus";
|
|
import { ElMessage } from "element-plus";
|
|
|
import { Empty, Popup } from "vant";
|
|
import { Empty, Popup } from "vant";
|
|
|
import { base_img_url2 } from "@/api/config";
|
|
import { base_img_url2 } from "@/api/config";
|
|
@@ -185,6 +184,34 @@ const emits = defineEmits(["row-click"]);
|
|
|
|
|
|
|
|
const solarTerms = ref([]);
|
|
const solarTerms = ref([]);
|
|
|
const phenologyList = ref([]);
|
|
const phenologyList = ref([]);
|
|
|
|
|
+// 从物候期列表中提取起始时间,用于时间轴显示
|
|
|
|
|
+const phenologyStartDates = computed(() => {
|
|
|
|
|
+ if (!phenologyList.value || phenologyList.value.length === 0) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+ // 从每个物候期中提取起始时间,并去重排序
|
|
|
|
|
+ const startDatesMap = new Map();
|
|
|
|
|
+ phenologyList.value.forEach((phenology) => {
|
|
|
|
|
+ if (phenology.startDate) {
|
|
|
|
|
+ const dateKey = phenology.startDate;
|
|
|
|
|
+ // 如果该日期还没有添加过,或者需要更新信息
|
|
|
|
|
+ if (!startDatesMap.has(dateKey)) {
|
|
|
|
|
+ startDatesMap.set(dateKey, {
|
|
|
|
|
+ startDate: phenology.startDate,
|
|
|
|
|
+ id: phenology.id || `phenology-${dateKey}`,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ // 转换为数组并按时间排序
|
|
|
|
|
+ const result = Array.from(startDatesMap.values()).sort((a, b) => {
|
|
|
|
|
+ const timeA = safeParseDate(a.startDate);
|
|
|
|
|
+ const timeB = safeParseDate(b.startDate);
|
|
|
|
|
+ if (isNaN(timeA) || isNaN(timeB)) return 0;
|
|
|
|
|
+ return timeA - timeB;
|
|
|
|
|
+ });
|
|
|
|
|
+ return result;
|
|
|
|
|
+});
|
|
|
const timelineContainerRef = ref(null);
|
|
const timelineContainerRef = ref(null);
|
|
|
const timelineListRef = ref(null);
|
|
const timelineListRef = ref(null);
|
|
|
// 标记是否为首次加载
|
|
// 标记是否为首次加载
|
|
@@ -409,27 +436,27 @@ const calculateTotalHeightByFarmWorks = () => {
|
|
|
// 如果有物候期数据,直接使用计算出的总高度
|
|
// 如果有物候期数据,直接使用计算出的总高度
|
|
|
// totalHeight 已经包含了从 10 开始的起始位置和所有物候期的高度
|
|
// totalHeight 已经包含了从 10 开始的起始位置和所有物候期的高度
|
|
|
if (totalHeight > 10) {
|
|
if (totalHeight > 10) {
|
|
|
- // 确保总高度至少能容纳所有节气(每个节气至少50px)
|
|
|
|
|
- const baseHeight = (solarTerms.value?.length || 0) * 50;
|
|
|
|
|
- // 返回物候期总高度和基础高度的较大值,确保节气能正常显示
|
|
|
|
|
|
|
+ // 确保总高度至少能容纳所有物候期起始时间(每个至少50px)
|
|
|
|
|
+ const baseHeight = (phenologyStartDates.value?.length || 0) * 50;
|
|
|
|
|
+ // 返回物候期总高度和基础高度的较大值,确保物候期起始时间能正常显示
|
|
|
return Math.max(totalHeight, baseHeight);
|
|
return Math.max(totalHeight, baseHeight);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 如果没有物候期数据,返回基础高度
|
|
// 如果没有物候期数据,返回基础高度
|
|
|
- const baseHeight = (solarTerms.value?.length || 0) * 50;
|
|
|
|
|
|
|
+ const baseHeight = (phenologyStartDates.value?.length || 0) * 50;
|
|
|
return baseHeight || 100; // 至少返回100px,避免为0
|
|
return baseHeight || 100; // 至少返回100px,避免为0
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const getTermStyle = (t, index) => {
|
|
const getTermStyle = (t, index) => {
|
|
|
// 优先使用实际测量的timeline-list高度,如果没有测量到则使用计算值作为后备
|
|
// 优先使用实际测量的timeline-list高度,如果没有测量到则使用计算值作为后备
|
|
|
const totalHeight = timelineListHeight.value > 0 ? timelineListHeight.value : calculateTotalHeightByFarmWorks();
|
|
const totalHeight = timelineListHeight.value > 0 ? timelineListHeight.value : calculateTotalHeightByFarmWorks();
|
|
|
- // 获取节气总数
|
|
|
|
|
- const termCount = solarTerms.value?.length || 1;
|
|
|
|
|
|
|
+ // 获取物候期起始时间总数(使用新数组)
|
|
|
|
|
+ const termCount = phenologyStartDates.value?.length || 1;
|
|
|
|
|
|
|
|
- // 等分高度:总高度 / 节气数量
|
|
|
|
|
|
|
+ // 等分高度:总高度 / 物候期起始时间数量
|
|
|
const termHeight = totalHeight / termCount;
|
|
const termHeight = totalHeight / termCount;
|
|
|
|
|
|
|
|
- // 计算top位置:索引 * 每个节气的高度
|
|
|
|
|
|
|
+ // 计算top位置:索引 * 每个物候期起始时间的高度
|
|
|
const top = index * termHeight;
|
|
const top = index * termHeight;
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
@@ -939,7 +966,7 @@ watch(
|
|
|
color: #fff;
|
|
color: #fff;
|
|
|
font-size: 12px;
|
|
font-size: 12px;
|
|
|
position: absolute;
|
|
position: absolute;
|
|
|
- left: 32px;
|
|
|
|
|
|
|
+ left: 39px;
|
|
|
z-index: 10;
|
|
z-index: 10;
|
|
|
text-align: center;
|
|
text-align: center;
|
|
|
display: flex;
|
|
display: flex;
|
|
@@ -1002,11 +1029,11 @@ watch(
|
|
|
}
|
|
}
|
|
|
.arranges {
|
|
.arranges {
|
|
|
display: flex;
|
|
display: flex;
|
|
|
- max-width: calc(100vw - 111px);
|
|
|
|
|
- min-width: calc(100vw - 111px);
|
|
|
|
|
|
|
+ max-width: calc(100vw - 118px);
|
|
|
|
|
+ min-width: calc(100vw - 118px);
|
|
|
gap: 5px;
|
|
gap: 5px;
|
|
|
letter-spacing: 0px;
|
|
letter-spacing: 0px;
|
|
|
- min-height: 90px;
|
|
|
|
|
|
|
+ // min-height: 90px;
|
|
|
.arrange-card {
|
|
.arrange-card {
|
|
|
width: 95%;
|
|
width: 95%;
|
|
|
border: 0.5px solid #2199f8;
|
|
border: 0.5px solid #2199f8;
|
|
@@ -1177,15 +1204,10 @@ watch(
|
|
|
.term-name {
|
|
.term-name {
|
|
|
display: inline-block;
|
|
display: inline-block;
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
- min-height: 32px;
|
|
|
|
|
|
|
+ min-height: 20px;
|
|
|
line-height: 26px;
|
|
line-height: 26px;
|
|
|
background: #fff;
|
|
background: #fff;
|
|
|
font-size: 12px;
|
|
font-size: 12px;
|
|
|
- margin-top: -4px;
|
|
|
|
|
- }
|
|
|
|
|
- .term-date {
|
|
|
|
|
- font-size: 10px;
|
|
|
|
|
- margin: -11px 0 0 -6px;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
.empty-state {
|
|
.empty-state {
|