FarmWorkPlanTimeline.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. <template>
  2. <div class="timeline-container" ref="timelineContainerRef">
  3. <div class="timeline-list" ref="timelineListRef">
  4. <div class="timeline-middle-line"></div>
  5. <div
  6. v-for="(t, tIdx) in solarTerms"
  7. :key="`term-${uniqueTimestamp}-${tIdx}`"
  8. class="timeline-term"
  9. :style="getTermStyle(t, tIdx)"
  10. >
  11. <span class="term-name">{{ t.displayName }}</span>
  12. </div>
  13. <div v-for="(p, idx) in phenologyList" :key="`phenology-${uniqueTimestamp}-${idx}`" class="phenology-bar">
  14. <div class="start-time">
  15. <div class="time-text">起始时间</div>
  16. <span>{{ p.startDate }}</span>
  17. </div>
  18. <div
  19. v-for="(r, rIdx) in Array.isArray(p.reproductiveList) ? p.reproductiveList : []"
  20. :key="`reproductive-${uniqueTimestamp}-${idx}-${rIdx}`"
  21. class="reproductive-item"
  22. >
  23. <div class="arranges" :style="p.startDate && rIdx === 0 ? 'padding-top: 30px;' : ''">
  24. <div
  25. v-for="(fw, aIdx) in Array.isArray(r.farmWorkArrangeList) ? r.farmWorkArrangeList : []"
  26. :key="`arrange-${uniqueTimestamp}-${idx}-${rIdx}-${aIdx}`"
  27. class="arrange-card"
  28. :style="
  29. shouldShowIncompleteStatus(fw.farmWorkId)
  30. ? 'padding-bottom: 25px;'
  31. : 'padding-bottom: 10px'
  32. "
  33. :class="getArrangeStatusClass(fw)"
  34. @click="handleRowClick(fw)"
  35. >
  36. <div class="card-header">
  37. <div class="header-left">
  38. <span class="farm-work-name van-ellipsis">{{ fw.farmWorkName || "--" }}</span>
  39. <span class="tag-standard">{{ farmWorkType[fw.type] }}</span>
  40. </div>
  41. <div class="header-right" v-if="!isStandard">
  42. {{ fw.isFollow == 1 ? "已关注" : fw.isFollow == 2 ? "托管农事" : "" }}
  43. </div>
  44. </div>
  45. <div class="card-content">
  46. <span>{{ fw.interactionQuestion || "暂无提示" }}</span>
  47. <span
  48. v-if="!disableClick"
  49. :class="shouldShowIncompleteStatus(fw.farmWorkId) ? 'link-warning' : 'edit-link'"
  50. @click.stop="handleEdit(fw)"
  51. >点击编辑</span
  52. >
  53. </div>
  54. <div class="card-status" v-if="shouldShowIncompleteStatus(fw.farmWorkId)">
  55. <el-icon color="#FF953D" size="13"><WarningFilled /></el-icon>
  56. <span>未完善</span>
  57. </div>
  58. </div>
  59. </div>
  60. <template v-if="r.name === r.phenologyName">
  61. <div
  62. class="phenology-name single"
  63. :style="r.phenologyName === getNextPhenologyName(idx, rIdx) ? 'padding: 6px 0;' : ''"
  64. >
  65. {{ r.name }}
  66. </div>
  67. </template>
  68. <template v-else>
  69. <div class="phenology-name">{{ r.name }}</div>
  70. <div
  71. class="phenology-name mr"
  72. :style="r.phenologyName === getNextPhenologyName(idx, rIdx) ? 'padding: 6px 0;' : ''"
  73. >
  74. {{ r.phenologyName }}
  75. </div>
  76. </template>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. <!-- 互动设置弹窗 -->
  82. <interact-popup ref="interactPopupRef" @handleSaveSuccess="updateFarmWorkPlan"></interact-popup>
  83. </template>
  84. <script setup>
  85. import { ref, nextTick, watch, onMounted, onUnmounted } from "vue";
  86. import interactPopup from "@/components/popup/interactPopup.vue";
  87. import { ElMessage } from "element-plus";
  88. import { WarningFilled } from "@element-plus/icons-vue";
  89. const props = defineProps({
  90. // 农场 ID,用于请求农事规划数据
  91. farmId: {
  92. type: [String, Number],
  93. default: null,
  94. },
  95. // 页面类型:种植方案 / 农事规划,用来控制高度样式
  96. pageType: {
  97. type: String,
  98. default: "",
  99. },
  100. // 是否禁用所有点击事件(用于只读展示)
  101. disableClick: {
  102. type: Boolean,
  103. default: false,
  104. },
  105. containerId: {
  106. type: [Number, String],
  107. default: null,
  108. },
  109. // 是否是标准农事
  110. isStandard: {
  111. type: Boolean,
  112. default: false,
  113. },
  114. // 方案ID
  115. schemeId: {
  116. type: [Number, String],
  117. default: null,
  118. },
  119. });
  120. const farmWorkType = {
  121. 0: "预警农事",
  122. 1: "标准农事",
  123. 2: "建议农事",
  124. 3: "自建农事",
  125. };
  126. const emits = defineEmits(["row-click"]);
  127. const solarTerms = ref([]);
  128. const phenologyList = ref([]);
  129. const timelineContainerRef = ref(null);
  130. const timelineListRef = ref(null);
  131. // 标记是否为首次加载
  132. const isInitialLoad = ref(true);
  133. // 存储timeline-list的实际渲染高度
  134. const timelineListHeight = ref(0);
  135. // 生成唯一的时间戳,用于确保key的唯一性
  136. const uniqueTimestamp = ref(Date.now());
  137. // ResizeObserver 实例,用于监听高度变化
  138. let resizeObserver = null;
  139. // 获取当前季节
  140. const getCurrentSeason = () => {
  141. const month = new Date().getMonth() + 1; // 1-12
  142. if (month >= 3 && month <= 5) {
  143. return "spring"; // 春季:3-5月
  144. } else if (month >= 6 && month <= 8) {
  145. return "summer"; // 夏季:6-8月
  146. } else if (month >= 9 && month <= 10) {
  147. return "autumn"; // 秋季:9-10月
  148. } else {
  149. return "winter"; // 冬季:11-2月
  150. }
  151. };
  152. // 安全解析时间到时间戳(ms)
  153. const safeParseDate = (val) => {
  154. if (!val) return NaN;
  155. if (val instanceof Date) return val.getTime();
  156. if (typeof val === "number") return val;
  157. if (typeof val === "string") {
  158. // 兼容 "YYYY-MM-DD HH:mm:ss" -> Safari
  159. const s = val.replace(/-/g, "/").replace("T", " ");
  160. const d = new Date(s);
  161. return isNaN(d.getTime()) ? NaN : d.getTime();
  162. }
  163. return NaN;
  164. };
  165. const batchValidateData = ref({});
  166. const allTrue = ref(false);
  167. const invalidIds = ref([]);
  168. const invalidArr = ref([]);
  169. // 验证农事卡片药肥报价信息是否完整
  170. const batchValidatePesticideFertilizerQuotes = (ids, items) => {
  171. if (props.isStandard) {
  172. return;
  173. }
  174. VE_API.monitor
  175. .batchValidatePesticideFertilizerQuotes({ ids, schemeId: props.schemeId })
  176. .then(({ data, code }) => {
  177. if (code === 0) {
  178. batchValidateData.value = data || {};
  179. allTrue.value = Object.values(data).every((value) => value === true);
  180. invalidIds.value = Object.keys(data).filter((key) => data[key] !== true);
  181. // 清空之前的arrangeIds
  182. invalidArr.value = [];
  183. // 遍历items,判断farmWorkId是否在invalidIds中,如果对应上了就把item.id push进去
  184. items.forEach((item) => {
  185. // 判断item.farmWorkId是否在invalidIds数组中(需要转换为字符串进行比较)
  186. const farmWorkIdStr = String(item.farmWorkId);
  187. if (invalidIds.value.includes(farmWorkIdStr)) {
  188. invalidArr.value.push({
  189. arrangeId: item.id,
  190. farmWorkId: item.farmWorkId,
  191. });
  192. }
  193. });
  194. }
  195. })
  196. .catch(() => {});
  197. };
  198. // 判断是否应该显示"未完善"状态
  199. // 如果batchValidateData中对应的farmWorkId验证结果为true(已完善),则不显示
  200. // 如果验证结果为false(未完善)或不存在,则显示
  201. const shouldShowIncompleteStatus = (farmWorkId) => {
  202. if (!farmWorkId || !batchValidateData.value || typeof batchValidateData.value !== "object") {
  203. // 如果没有验证数据,默认不显示
  204. return false;
  205. }
  206. // 从对象中直接获取验证结果,支持字符串和数字类型的key
  207. const isValid =
  208. batchValidateData.value[farmWorkId] !== undefined
  209. ? batchValidateData.value[farmWorkId]
  210. : batchValidateData.value[String(farmWorkId)] !== undefined
  211. ? batchValidateData.value[String(farmWorkId)]
  212. : undefined;
  213. // 如果找到了验证结果
  214. if (isValid !== undefined) {
  215. // 如果验证结果为true(已完善),返回false(不显示)
  216. // 如果验证结果为false(未完善),返回true(显示)
  217. return !isValid;
  218. }
  219. // 如果没有找到验证结果,默认不显示
  220. return false;
  221. };
  222. // 获取下一个reproductive-item的phenologyName
  223. const getNextPhenologyName = (currentPhenologyIdx, currentReproductiveIdx) => {
  224. const currentPhenology = phenologyList.value[currentPhenologyIdx];
  225. if (!currentPhenology || !Array.isArray(currentPhenology.reproductiveList)) {
  226. return null;
  227. }
  228. // 如果当前reproductive-item不是最后一个,获取同一个物候期的下一个
  229. if (currentReproductiveIdx < currentPhenology.reproductiveList.length - 1) {
  230. const nextReproductive = currentPhenology.reproductiveList[currentReproductiveIdx + 1];
  231. return nextReproductive?.phenologyName || null;
  232. }
  233. // 如果当前reproductive-item是最后一个,获取下一个物候期的第一个reproductive-item
  234. if (currentPhenologyIdx < phenologyList.value.length - 1) {
  235. const nextPhenology = phenologyList.value[currentPhenologyIdx + 1];
  236. if (nextPhenology && Array.isArray(nextPhenology.reproductiveList) && nextPhenology.reproductiveList.length > 0) {
  237. const firstReproductive = nextPhenology.reproductiveList[0];
  238. return firstReproductive?.phenologyName || null;
  239. }
  240. }
  241. return null;
  242. };
  243. // 计算物候期需要的实际高度(基于农事数量)
  244. const getPhenologyRequiredHeight = (item) => {
  245. // 统计该物候期内的农事数量
  246. let farmWorkCount = 0;
  247. if (Array.isArray(item.reproductiveList)) {
  248. item.reproductiveList.forEach((reproductive) => {
  249. if (Array.isArray(reproductive.farmWorkArrangeList)) {
  250. farmWorkCount += reproductive.farmWorkArrangeList.length;
  251. }
  252. });
  253. }
  254. // 如果没有农事,给一个最小高度
  255. if (farmWorkCount === 0) {
  256. return 50; // 最小50px
  257. }
  258. // 每个农事卡片的高度(根据实际内容,卡片高度可能因内容而异)
  259. // 卡片包含:padding(8px*2) + header(约25px) + content margin(4px+2px) + content(约25-30px) = 约72-77px
  260. // 考虑到内容可能换行,实际高度可能更高,设置为120px更安全,避免卡片重叠
  261. const farmWorkCardHeight = 120; // 卡片高度估算,确保能容纳内容且不重叠
  262. // 卡片之间的间距(与CSS中的gap保持一致)
  263. const cardGap = 12;
  264. // 计算总高度:卡片数量 * 卡片高度 + (卡片数量 - 1) * 间距
  265. // 如果有多个卡片,需要加上它们之间的间距
  266. const totalHeight = farmWorkCount * farmWorkCardHeight + (farmWorkCount > 1 ? (farmWorkCount - 1) * cardGap : 0);
  267. // 返回精确的总高度,只保留最小高度限制,不添加额外余量
  268. return Math.max(totalHeight, 50); // 最小50px,精确匹配农事卡片高度
  269. };
  270. // 计算所有物候期的累积位置和总高度
  271. const calculatePhenologyPositions = () => {
  272. let currentTop = 10; // 起始位置,留出顶部间距
  273. const positions = new Map();
  274. // 按progress排序物候期,确保按时间顺序排列
  275. const sortedPhenologyList = [...phenologyList.value].sort((a, b) => {
  276. const aProgress = Math.min(Number(a?.progress) || 0, Number(a?.progress2) || 0);
  277. const bProgress = Math.min(Number(b?.progress) || 0, Number(b?.progress2) || 0);
  278. return aProgress - bProgress;
  279. });
  280. sortedPhenologyList.forEach((phenology) => {
  281. const height = getPhenologyRequiredHeight(phenology);
  282. // 使用与数据生成时相同的ID生成逻辑
  283. const itemId =
  284. phenology.id ?? phenology.phenologyId ?? phenology.name ?? `${phenology.progress}-${phenology.progress2}`;
  285. positions.set(itemId, {
  286. top: currentTop,
  287. height: height,
  288. });
  289. currentTop += height; // 紧挨着下一个物候期,不留间距
  290. });
  291. return {
  292. positions,
  293. totalHeight: currentTop, // 总高度 = 最后一个物候期的底部位置,不添加额外间距
  294. };
  295. };
  296. // 计算所有农事的总高度(基于物候期紧挨排列)
  297. const calculateTotalHeightByFarmWorks = () => {
  298. const { totalHeight } = calculatePhenologyPositions();
  299. // 如果有物候期数据,直接使用计算出的总高度
  300. // totalHeight 已经包含了从 10 开始的起始位置和所有物候期的高度
  301. if (totalHeight > 10) {
  302. // 确保总高度至少能容纳所有节气(每个节气至少50px)
  303. const baseHeight = (solarTerms.value?.length || 0) * 50;
  304. // 返回物候期总高度和基础高度的较大值,确保节气能正常显示
  305. return Math.max(totalHeight, baseHeight);
  306. }
  307. // 如果没有物候期数据,返回基础高度
  308. const baseHeight = (solarTerms.value?.length || 0) * 50;
  309. return baseHeight || 100; // 至少返回100px,避免为0
  310. };
  311. const getTermStyle = (t, index) => {
  312. // 优先使用实际测量的timeline-list高度,如果没有测量到则使用计算值作为后备
  313. const totalHeight = timelineListHeight.value > 0 ? timelineListHeight.value : calculateTotalHeightByFarmWorks();
  314. // 获取节气总数
  315. const termCount = solarTerms.value?.length || 1;
  316. // 等分高度:总高度 / 节气数量
  317. const termHeight = totalHeight / termCount;
  318. // 计算top位置:索引 * 每个节气的高度
  319. const top = index * termHeight;
  320. return {
  321. position: "absolute",
  322. top: `${top}px`,
  323. left: 0,
  324. width: "30px",
  325. height: `${termHeight}px`, // 高度等分,使用实际测量的高度
  326. display: "flex",
  327. alignItems: "center",
  328. };
  329. };
  330. // 点击季节 → 滚动到对应节气(立春/立夏/立秋/立冬)
  331. const handleSeasonClick = (seasonValue) => {
  332. const mapping = {
  333. spring: "立春",
  334. summer: "立夏",
  335. autumn: "立秋",
  336. winter: "立冬",
  337. };
  338. const targetName = mapping[seasonValue];
  339. if (!targetName) return;
  340. // 查找对应的节气
  341. const targetIndex = solarTerms.value.findIndex((t) => (t?.displayName || "") === targetName);
  342. if (targetIndex === -1) return;
  343. // 计算目标节气的top位置
  344. const totalHeight = timelineListHeight.value > 0 ? timelineListHeight.value : calculateTotalHeightByFarmWorks();
  345. const termCount = solarTerms.value?.length || 1;
  346. const termHeight = totalHeight / termCount;
  347. const targetTop = targetIndex * termHeight;
  348. // 滚动到目标位置
  349. const wrap = timelineContainerRef.value;
  350. if (!wrap) return;
  351. const viewH = wrap.clientHeight || 0;
  352. const maxScroll = Math.max(0, wrap.scrollHeight - viewH);
  353. // 将目标位置稍微靠上(使用 0.1 视口高度做偏移)
  354. let scrollTop = Math.max(0, targetTop - viewH * 0.1);
  355. if (scrollTop > maxScroll) scrollTop = maxScroll;
  356. wrap.scrollTo({ top: scrollTop, behavior: "smooth" });
  357. };
  358. // 农事状态样式映射(0:取消关注,1:关注,2:托管农事,)
  359. const getArrangeStatusClass = (fw) => {
  360. const t = fw?.isFollow;
  361. const warningStatus = shouldShowIncompleteStatus(fw.farmWorkId);
  362. if (t == 0) return "normal-style";
  363. if (warningStatus) return "status-warning";
  364. // if (t >= 0 && t <= 4) return "status-normal";
  365. // if (t === 5) return "status-complete";
  366. return "status-normal";
  367. };
  368. const handleRowClick = (item) => {
  369. item.isEdit = shouldShowIncompleteStatus(item.farmWorkId);
  370. item.invalidIds = invalidIds.value;
  371. item.invalidArr = invalidArr.value;
  372. emits("row-click", item);
  373. };
  374. const interactPopupRef = ref(null);
  375. const handleEdit = (item) => {
  376. if (props.disableClick) return;
  377. if (interactPopupRef.value) {
  378. interactPopupRef.value.showPopup(item);
  379. }
  380. };
  381. // 获取农事规划数据
  382. const getFarmWorkPlan = () => {
  383. if (!props.farmId && !props.containerId) return;
  384. // 更新时间戳,确保key变化,触发DOM重新渲染
  385. uniqueTimestamp.value = Date.now();
  386. // 重置测量高度,等待重新测量
  387. timelineListHeight.value = 0;
  388. let savedScrollTop = 0;
  389. if (!isInitialLoad.value && timelineContainerRef.value) {
  390. savedScrollTop = timelineContainerRef.value.scrollTop || 0;
  391. }
  392. VE_API.monitor
  393. .farmWorkPlan({ farmId: props.farmId, containerId: props.containerId, schemeId: props.schemeId })
  394. .then(({ data, code }) => {
  395. if (code === 0) {
  396. const list = Array.isArray(data?.solarTermsList) ? data.solarTermsList : [];
  397. const filtered = list
  398. .filter((t) => t && t.type === 1)
  399. .map((t) => ({
  400. id:
  401. t.id ??
  402. t.solarTermsId ??
  403. t.termId ??
  404. `${t.name || t.solarTermsName || t.termName || "term"}-${t.createDate || ""}`,
  405. displayName: t.name || t.solarTermsName || t.termName || "节气",
  406. createDate: t.createDate || null,
  407. progress: Number(t.progress) || 0,
  408. }));
  409. solarTerms.value = filtered;
  410. // 物候期数据
  411. phenologyList.value = Array.isArray(data?.phenologyList)
  412. ? data.phenologyList.map((it) => {
  413. const reproductiveList = Array.isArray(it.reproductiveList)
  414. ? it.reproductiveList.map((r) => {
  415. const farmWorkArrangeList = Array.isArray(r.farmWorkArrangeList)
  416. ? r.farmWorkArrangeList.map((fw) => ({
  417. ...fw,
  418. containerSpaceTimeId: it.containerSpaceTimeId,
  419. }))
  420. : [];
  421. return {
  422. ...r,
  423. farmWorkArrangeList,
  424. };
  425. })
  426. : [];
  427. return {
  428. id: it.id ?? it.phenologyId ?? it.name ?? `${it.progress}-${it.progress2}`,
  429. progress: Number(it.progress) || 0, // 起点 %
  430. progress2: Number(it.progress2) || 0, // 终点 %
  431. startDate: it.startDate,
  432. startTimeMs: safeParseDate(
  433. it.startDate || it.beginDate || it.startTime || it.start || it.start_at
  434. ),
  435. reproductiveList,
  436. };
  437. })
  438. : [];
  439. // 使用多次 nextTick 和 requestAnimationFrame 确保DOM完全渲染
  440. nextTick(() => {
  441. requestAnimationFrame(() => {
  442. nextTick(() => {
  443. requestAnimationFrame(() => {
  444. // 测量timeline-list的实际渲染高度
  445. if (timelineListRef.value) {
  446. const height =
  447. timelineListRef.value.offsetHeight || timelineListRef.value.clientHeight;
  448. if (height > 0) {
  449. timelineListHeight.value = height;
  450. // 如果是首次加载,滚动到当前季节对应的节气
  451. if (isInitialLoad.value) {
  452. const currentSeason = getCurrentSeason();
  453. handleSeasonClick(currentSeason);
  454. isInitialLoad.value = false;
  455. }
  456. }
  457. }
  458. if (isInitialLoad.value) {
  459. // 如果测量失败,延迟一下再尝试滚动
  460. setTimeout(() => {
  461. if (timelineListRef.value) {
  462. const height =
  463. timelineListRef.value.offsetHeight ||
  464. timelineListRef.value.clientHeight;
  465. if (height > 0) {
  466. timelineListHeight.value = height;
  467. }
  468. }
  469. const currentSeason = getCurrentSeason();
  470. handleSeasonClick(currentSeason);
  471. isInitialLoad.value = false;
  472. }, 200);
  473. } else if (timelineContainerRef.value && savedScrollTop > 0) {
  474. timelineContainerRef.value.scrollTop = savedScrollTop;
  475. }
  476. });
  477. });
  478. });
  479. });
  480. // 收集所有farmWorkId
  481. const farmWorkIds = [];
  482. const farmWorks = [];
  483. phenologyList.value.forEach((phenology) => {
  484. if (Array.isArray(phenology.reproductiveList)) {
  485. phenology.reproductiveList.forEach((reproductive) => {
  486. if (Array.isArray(reproductive.farmWorkArrangeList)) {
  487. reproductive.farmWorkArrangeList.forEach((farmWork) => {
  488. if (farmWork.farmWorkId && farmWork.isFollow !== 0) {
  489. farmWorkIds.push(farmWork.farmWorkId);
  490. farmWorks.push(farmWork);
  491. }
  492. });
  493. }
  494. });
  495. }
  496. });
  497. // 调用验证方法,传入所有ids
  498. if (farmWorkIds.length > 0) {
  499. batchValidatePesticideFertilizerQuotes(farmWorkIds, farmWorks);
  500. }
  501. }
  502. })
  503. .catch((error) => {
  504. console.error("获取农事规划数据失败:", error);
  505. ElMessage.error("获取农事规划数据失败");
  506. });
  507. };
  508. const updateFarmWorkPlan = () => {
  509. solarTerms.value = [];
  510. phenologyList.value = [];
  511. getFarmWorkPlan();
  512. };
  513. watch(
  514. () => props.farmId || props.containerId,
  515. (val) => {
  516. if (val) {
  517. isInitialLoad.value = true;
  518. updateFarmWorkPlan();
  519. }
  520. },
  521. { immediate: true }
  522. );
  523. watch(
  524. () => props.schemeId,
  525. (val) => {
  526. if (val) {
  527. updateFarmWorkPlan();
  528. }
  529. }
  530. );
  531. // 使用 ResizeObserver 监听高度变化,确保在DOM完全渲染后获取准确高度
  532. const setupResizeObserver = () => {
  533. if (!timelineListRef.value || typeof ResizeObserver === "undefined") {
  534. return;
  535. }
  536. // 如果已经存在观察者,先断开
  537. if (resizeObserver) {
  538. resizeObserver.disconnect();
  539. }
  540. // 创建新的观察者
  541. resizeObserver = new ResizeObserver((entries) => {
  542. for (const entry of entries) {
  543. const height = entry.contentRect.height;
  544. if (height > 0 && height !== timelineListHeight.value) {
  545. timelineListHeight.value = height;
  546. }
  547. }
  548. });
  549. // 开始观察
  550. resizeObserver.observe(timelineListRef.value);
  551. };
  552. // 组件挂载后设置 ResizeObserver
  553. onMounted(() => {
  554. nextTick(() => {
  555. requestAnimationFrame(() => {
  556. setupResizeObserver();
  557. });
  558. });
  559. });
  560. // 组件卸载前清理 ResizeObserver
  561. onUnmounted(() => {
  562. if (resizeObserver) {
  563. resizeObserver.disconnect();
  564. resizeObserver = null;
  565. }
  566. });
  567. // 在数据更新后重新设置 ResizeObserver
  568. watch(
  569. () => phenologyList.value.length,
  570. () => {
  571. nextTick(() => {
  572. requestAnimationFrame(() => {
  573. setupResizeObserver();
  574. });
  575. });
  576. }
  577. );
  578. </script>
  579. <style scoped lang="scss">
  580. .timeline-container {
  581. height: 100%;
  582. overflow: auto;
  583. position: relative;
  584. box-sizing: border-box;
  585. .timeline-list {
  586. position: relative;
  587. }
  588. .timeline-middle-line {
  589. position: absolute;
  590. left: 15px; /* 位于节气文字列中间(列宽约30px) */
  591. top: 0;
  592. bottom: 0;
  593. width: 2px;
  594. background: #e8e8e8;
  595. z-index: 1;
  596. }
  597. .phenology-bar {
  598. align-items: stretch;
  599. justify-content: center;
  600. box-sizing: border-box;
  601. position: relative;
  602. .start-time{
  603. position: absolute;
  604. left: 88px;
  605. z-index: 1;
  606. letter-spacing: 0px;
  607. writing-mode: initial;
  608. line-height: normal;
  609. display: flex;
  610. align-items: center;
  611. gap: 10px;
  612. font-size: 12px;
  613. .time-text{
  614. padding: 2px 6px;
  615. color: #2199f8;
  616. background: rgba(33, 153, 248, 0.1);
  617. }
  618. }
  619. .reproductive-item {
  620. font-size: 12px;
  621. text-align: center;
  622. word-break: break-all;
  623. writing-mode: vertical-rl;
  624. text-orientation: upright;
  625. letter-spacing: 3px;
  626. width: 100%;
  627. line-height: 23px;
  628. color: inherit;
  629. position: relative;
  630. .phenology-name {
  631. width: 20px;
  632. line-height: 20px;
  633. height: 100%;
  634. background: #2199f8;
  635. color: #fff;
  636. padding: 4px 0;
  637. font-size: 12px;
  638. &.mr{
  639. margin-right: 3px;
  640. }
  641. &.single{
  642. width: 43px;
  643. line-height: 43px;
  644. }
  645. }
  646. .arranges {
  647. display: flex;
  648. max-width: calc(100vw - 92px);
  649. min-width: calc(100vw - 92px);
  650. gap: 10px;
  651. letter-spacing: 0px;
  652. .arrange-card {
  653. width: 93%;
  654. border: 0.5px solid #2199f8;
  655. border-radius: 8px;
  656. background: #fff;
  657. box-sizing: border-box;
  658. position: relative;
  659. padding: 8px;
  660. writing-mode: horizontal-tb;
  661. .card-header {
  662. display: flex;
  663. justify-content: space-between;
  664. align-items: center;
  665. width: 100%;
  666. .header-left {
  667. display: flex;
  668. align-items: center;
  669. gap: 8px;
  670. width: calc(100% - 50px);
  671. .farm-work-name {
  672. font-size: 14px;
  673. font-weight: 500;
  674. color: #1d2129;
  675. max-width: calc(100% - 74px);
  676. }
  677. .tag-standard {
  678. padding: 0 8px;
  679. background: rgba(119, 119, 119, 0.1);
  680. border-radius: 25px;
  681. font-weight: 400;
  682. font-size: 12px;
  683. color: #000;
  684. }
  685. }
  686. .header-right {
  687. font-size: 12px;
  688. color: #808080;
  689. border-radius: 25px;
  690. }
  691. }
  692. .card-content {
  693. color: #909090;
  694. text-align: left;
  695. line-height: 1.55;
  696. margin: 4px 0 2px 0;
  697. .edit-link {
  698. color: #2199f8;
  699. margin-left: 5px;
  700. }
  701. .link-warning {
  702. color: #ff953d;
  703. margin-left: 5px;
  704. }
  705. }
  706. .card-status {
  707. position: absolute;
  708. bottom: 0;
  709. right: 0;
  710. background: rgba(255, 149, 61, 0.1);
  711. border-radius: 3px;
  712. color: #ff953d;
  713. padding: 0 6px;
  714. display: flex;
  715. align-items: center;
  716. gap: 4px;
  717. font-size: 12px;
  718. }
  719. &::before {
  720. content: "";
  721. position: absolute;
  722. left: -5px;
  723. top: 50%;
  724. transform: translateY(-50%);
  725. width: 0;
  726. height: 0;
  727. border-top: 5px solid transparent;
  728. border-bottom: 5px solid transparent;
  729. border-right: 5px solid #2199f8;
  730. }
  731. }
  732. .arrange-card.normal-style {
  733. opacity: 0.3;
  734. }
  735. .arrange-card.status-warning {
  736. border-color: #ff953d;
  737. &::before {
  738. border-right-color: #ff953d;
  739. }
  740. }
  741. .arrange-card.status-complete {
  742. border-color: #1ca900;
  743. &::before {
  744. border-right-color: #1ca900;
  745. }
  746. }
  747. .arrange-card.status-normal {
  748. border-color: #2199f8;
  749. &::before {
  750. border-right-color: #2199f8;
  751. }
  752. }
  753. }
  754. }
  755. }
  756. .reproductive-item + .reproductive-item {
  757. padding-top: 11px;
  758. }
  759. .phenology-bar + .phenology-bar {
  760. padding-top: 11px;
  761. }
  762. .timeline-term {
  763. position: absolute;
  764. width: 30px;
  765. display: flex;
  766. align-items: flex-start;
  767. z-index: 2; /* 置于中线之上 */
  768. .term-name {
  769. display: inline-block;
  770. width: 100%;
  771. min-height: 35px;
  772. line-height: 30px;
  773. background: #f5f7fb;
  774. font-size: 13px;
  775. word-break: break-all;
  776. writing-mode: vertical-rl;
  777. text-orientation: upright;
  778. color: rgba(174, 174, 174, 0.6);
  779. text-align: center;
  780. }
  781. }
  782. }
  783. </style>