소스 검색

feat:修改剩下的没有转换完成的逻辑

wangsisi 2 주 전
부모
커밋
3571158518
3개의 변경된 파일84개의 추가작업 그리고 28개의 파일을 삭제
  1. 26 16
      src/components/pageComponents/ArchivesFarmTimeLine.vue
  2. 40 0
      src/i18n/messages.js
  3. 18 12
      src/views/old_mini/work_detail/index.vue

+ 26 - 16
src/components/pageComponents/ArchivesFarmTimeLine.vue

@@ -74,10 +74,13 @@
 </template>
 
 <script setup>
-import { ref, nextTick, watch, onMounted, onUnmounted, onActivated, onDeactivated } from "vue";
+import { ref, computed, nextTick, watch, onMounted, onUnmounted, onActivated, onDeactivated } from "vue";
 import { useRouter, useRoute, onBeforeRouteLeave } from "vue-router";
 import { ElMessage } from "element-plus";
 import { Empty } from "vant";
+import { useI18n } from "@/i18n";
+
+const { locale, t } = useI18n();
 
 const router = useRouter();
 const route = useRoute();
@@ -205,10 +208,12 @@ const uniqueTimestamp = ref(Date.now());
 const isEmpty = ref(false);
 // 标记是否正在请求数据,防止重复请求
 const isRequesting = ref(false);
-// 记录上一次请求作用域,避免相同参数重复请求
-const lastRequestedFarmId = ref(null);
+// 记录上一次请求作用域(含语言),避免相同参数重复请求
+const lastRequestedScopeKey = ref(null);
+const lastFetchedLocale = ref(null);
 
-const farmWorkPlanScopeKey = () => JSON.stringify([props.farmId ?? null]);
+const farmWorkPlanScopeKey = () =>
+    JSON.stringify([props.farmId ?? null, locale.value ?? "zh"]);
 
 const resetTimelineData = () => {
     phenologyList.value = [];
@@ -240,15 +245,9 @@ const shouldShowPhenologyBarTitle = (idx) => {
     return list[idx]?.phenologyName !== list[idx - 1]?.phenologyName;
 };
 
-const workStatusObj = {
-    0: "待校准",
-    1: "机动执行",
-    2: "待执行",
-    3: "未激活",
-    4: "已认证",
-    5: "已失效",
-    6: "已执行",
-};
+const workStatusObj = computed(() =>
+    Object.fromEntries([0, 1, 2, 3, 4, 5, 6].map((s) => [s, t(`agriRecord.workStatus.${s}`)]))
+);
 
 const statusColorObj = {
     2: {
@@ -383,9 +382,9 @@ const getFarmWorkPlan = () => {
     resetTimelineData();
     if (!props.farmId) return;
     const scopeKey = farmWorkPlanScopeKey();
-    if (isRequesting.value || lastRequestedFarmId.value === scopeKey) return;
+    if (isRequesting.value || lastRequestedScopeKey.value === scopeKey) return;
     isRequesting.value = true;
-    lastRequestedFarmId.value = scopeKey;
+    lastRequestedScopeKey.value = scopeKey;
     uniqueTimestamp.value = Date.now();
     isEmpty.value = false;
 
@@ -397,6 +396,7 @@ const getFarmWorkPlan = () => {
         .then(({ data, code }) => {
             const ok = code === 200 || code === 0;
             if (ok) {
+                lastFetchedLocale.value = locale.value;
                 phenologyList.value = normalizeFarmWorksPhenologyList(data);
                 isEmpty.value = phenologyList.value.length === 0;
                 if (!isEmpty.value) {
@@ -428,13 +428,19 @@ watch(
         if (!props.farmId) return;
         const changed = oldVal == null || val !== oldVal;
         if (changed) {
-            lastRequestedFarmId.value = null;
+            lastRequestedScopeKey.value = null;
         }
         updateFarmWorkPlan();
     },
     { immediate: true }
 );
 
+watch(locale, () => {
+    if (!props.farmId) return;
+    lastRequestedScopeKey.value = null;
+    updateFarmWorkPlan();
+});
+
 const handleStatusDetail = (fw) => {
     saveTimelineScrollTop();
     emits('card-click');
@@ -492,6 +498,10 @@ onUnmounted(() => {
 });
 
 onActivated(() => {
+    if (props.farmId && lastFetchedLocale.value != null && lastFetchedLocale.value !== locale.value) {
+        lastRequestedScopeKey.value = null;
+        updateFarmWorkPlan();
+    }
     nextTick(() => {
         requestAnimationFrame(() => {
             restoreTimelineScrollTopWithRetry();

+ 40 - 0
src/i18n/messages.js

@@ -146,6 +146,26 @@ export default {
             phenologyWorkName: "物候跟踪记录",
             phenologyReason: "预计到达病虫防控关键期",
             phenologyIssue: "是否有60%的荔枝进入转色期",
+            workStatus: {
+                0: "待校准",
+                1: "机动执行",
+                2: "待执行",
+                3: "未激活",
+                4: "已认证",
+                5: "已失效",
+                6: "已执行",
+            },
+        },
+        workDetail: {
+            title: "农事详情",
+            certifiedSuccess: "已认证成功",
+            ownedPlot: "权属田块1:",
+            executionArea: "执行区域",
+            verified: "已认证",
+            purpose: "农事目的",
+            notes: "注意事项",
+            prescription: "药物处方",
+            executionMethod: "执行方式",
         },
     },
     en: {
@@ -293,6 +313,26 @@ export default {
             phenologyWorkName: "Phenology Tracking",
             phenologyReason: "Expected critical pest control period",
             phenologyIssue: "Have 60% of lychee trees entered color-change stage?",
+            workStatus: {
+                0: "Calib",
+                1: "Flex",
+                2: "Pending",
+                3: "Off",
+                4: "Cert",
+                5: "Void",
+                6: "Done",
+            },
+        },
+        workDetail: {
+            title: "Work Details",
+            certifiedSuccess: "Certified",
+            ownedPlot: "Plot 1: ",
+            executionArea: "Area",
+            verified: "Cert",
+            purpose: "Purpose",
+            notes: "Notes",
+            prescription: "Rx",
+            executionMethod: "Method",
         },
     },
 };

+ 18 - 12
src/views/old_mini/work_detail/index.vue

@@ -1,6 +1,6 @@
 <template>
     <div class="work-detail">
-        <custom-header :name="$t('农事详情')" v-if="!miniJson?.hideDraw" :showClose="false" isGoBack @goback="handleBack" />
+        <custom-header :name="$t('workDetail.title')" v-if="!miniJson?.hideDraw" :showClose="false" isGoBack @goback="handleBack" />
 
         <div class="work-detail-content">
             <!-- 顶部状态 -->
@@ -17,7 +17,7 @@
                         预计{{ detail?.executeDate || "--" }}执行,执行时间需巡园校准
                     </div> -->
                     <div class="status-sub">
-                        已认证成功
+                        {{ $t('workDetail.certifiedSuccess') }}
                     </div>
                 </div>
             </div>
@@ -39,7 +39,7 @@
 
                         <div class="stage-info">
                             <div class="form-item">
-                                <div class="item-name">{{ $t('农事目的') }}</div>
+                                <div class="item-name">{{ $t('workDetail.purpose') }}</div>
                                 <div class="item-text">
                                     {{ prescription.purpose || prescription.purposeName || "--" }}
                                 </div>
@@ -59,7 +59,7 @@
                                 </div>
                             </div>
                             <div class="form-item">
-                                <div class="item-name">{{ $t('注意事项') }}</div>
+                                <div class="item-name">{{ $t('workDetail.notes') }}</div>
                                 <div class="item-text">
                                     {{ detail.remark || "--" }}
                                 </div>
@@ -138,15 +138,15 @@
                 <div class="box-wrap stage-card">
                     <div class="work-info">
                         <div class="map-box">
-                            <div class="map-title">{{ $t('执行区域') }}</div>
+                            <div class="map-title">{{ $t('workDetail.executionArea') }}</div>
                             <div class="map-container" ref="mapContainer"></div>
                         </div>
                         <div class="area-list">
                             <div class="area-item">
                                 <div class="area-l">
-                                    权属田块1:{{ farmData.work_time }}
+                                    {{ $t('workDetail.ownedPlot') }}{{ farmData.work_time }}
                                     <span class="area-tag"
-                                        style="background: rgba(55, 193, 27, 0.1); color: #37C11B;">{{ $t('已认证') }}</span>
+                                        style="background: rgba(55, 193, 27, 0.1); color: #37C11B;">{{ $t('workDetail.verified') }}</span>
                                     <!-- <span class="area-tag">{{ $t('未激活') }}</span> -->
                                 </div>
                                 <!-- <div class="area-r">{{ $t('我已完成') }}</div> -->
@@ -172,19 +172,19 @@
                 <div class="box-wrap stage-card">
                     <div class="work-info">
                         <div class="info-item">
-                            <div class="info-title"><span class="title-block"></span>{{ $t('农事目的') }}</div>
+                            <div class="info-title"><span class="title-block"></span>{{ $t('workDetail.purpose') }}</div>
                             <div class="info-value">{{ farmData.work_purpose }}</div>
                         </div>
                         <div class="info-item">
-                            <div class="info-title"><span class="title-block"></span>{{ $t('注意事项') }}</div>
+                            <div class="info-title"><span class="title-block"></span>{{ $t('workDetail.notes') }}</div>
                             <div class="info-value">{{ farmData.precautions }}</div>
                         </div>
                         <div class="info-item">
-                            <div class="info-title"><span class="title-block"></span>{{ $t('药物处方') }}</div>
+                            <div class="info-title"><span class="title-block"></span>{{ $t('workDetail.prescription') }}</div>
                             <div class="info-value">{{ farmData.drug_prescription }}</div>
                         </div>
                         <div class="info-item">
-                            <div class="info-title"><span class="title-block"></span>{{ $t('执行方式') }}</div>
+                            <div class="info-title"><span class="title-block"></span>{{ $t('workDetail.executionMethod') }}</div>
                             <div class="info-value">{{ farmData.execution_method }}</div>
                         </div>
                     </div>
@@ -228,7 +228,8 @@
 import { ElMessage } from "element-plus";
 import wx from "weixin-js-sdk";
 import customHeader from "@/components/customHeader.vue";
-import { ref, computed, onMounted, onActivated, nextTick } from "vue";
+import { ref, computed, watch, onMounted, onActivated, nextTick } from "vue";
+import { useI18n } from "@/i18n";
 import { useRouter } from "vue-router";
 import { formatDate } from "@/common/commonFun";
 import ExecutePopup from "./components/executePopup.vue";
@@ -248,6 +249,7 @@ import imgJf1 from "@/assets/img/common/jf-1.png";
 import imgJf2 from "@/assets/img/common/jf-2.png";
 
 const route = useRoute();
+const { locale } = useI18n();
 const showUploadTipsPopup = ref(false);
 const headerTitle = ref('');
 const router = useRouter();
@@ -357,6 +359,7 @@ onActivated(() => {
 
 const farmData = ref({})
 const getDetail = () => {
+    if (!route.query.id) return;
     VE_API.monitor.getWorkDetail({ id: route.query.id }).then(res => {
         if (res.code === 200 && res.data.length) {
             farmData.value = res.data[0]
@@ -385,6 +388,9 @@ const getDetail = () => {
     //     });
 };
 
+watch(locale, () => {
+    getDetail();
+});
 
 // 计算距离执行时间的天数差
 const daysDiff = computed(() => {