jinx 7 місяців тому
батько
коміт
682f9b8bf7
3 змінених файлів з 22 додано та 7 видалено
  1. 11 3
      src/stores/line.js
  2. 6 2
      src/views/line/index.vue
  3. 5 2
      src/views/map/index.vue

+ 11 - 3
src/stores/line.js

@@ -2,7 +2,15 @@
 import { nextTick, onMounted, ref } from "vue";
 import { defineStore } from "pinia";
 
-export const useCounterStore = defineStore("counter", () => {
-  const lines = ref([]);
-  return { lines };
+export const useLineStore = defineStore("line", {
+  state: () => {
+    return { lineTime: null };
+  },
+  // 也可以定义为
+  // state: () => ({ count: 0 })
+  actions: {
+    initLineTime(payload) {
+      this.lineTime = payload;
+    },
+  },
 });

+ 6 - 2
src/views/line/index.vue

@@ -14,7 +14,7 @@
         </div>
         <div class="time">
           <span class="num">{{ lineData.length }}个景点</span>
-          <span>预计用时:{{ Math.round(overTime / 3600) }}小时</span>
+          <span>预计用时:{{ lineStore.lineTime ? Math.round(lineStore.lineTime / 3600) : Math.round(overTime / 3600) }}小时</span>
         </div>
       </div>
       <div class="bottom">
@@ -49,9 +49,13 @@ import tagIcon5 from "@/assets/images/tag-5.png";
 import tagIcon6 from "@/assets/images/tag-6.png";
 import tagIcon from "@/assets/images/tagIcon.png";
 import router from "@/router/index.js";
+import { useLineStore } from "@/stores/line";
+
 import axios from "axios";
 const route = useRoute();
 const lineId = ref(route.params.id || 1);
+const lineStore = useLineStore();
+
 let iconList = {
   tagIcon1,
   tagIcon2,
@@ -281,8 +285,8 @@ const createdLine = () => {
   driving.search(startLngLat, endLngLat, opts, function (status, result) {
     if (status === "complete") {
       if (result.routes && result.routes.length) {
-        drawRoute(result);
         overTime.value = result.routes[0].time;
+        drawRoute(result);
         // log.success('绘制步行路线完成')
       }
     } else {

+ 5 - 2
src/views/map/index.vue

@@ -125,11 +125,13 @@ import OpenAI from "openai";
 import Swiper from "swiper";
 import AMapLoader from "@amap/amap-jsapi-loader";
 import axios from "axios";
+
+import { useLineStore } from "@/stores/line";
 // import jsonp from "jsonp";
-import { useCounterStore } from "@/stores/line";
+// import { useCounterStore } from "@/stores/line";
 // const counter = useCounterStore()
 // console.error(counter.lines)
-
+const lineStore = useLineStore();
 const mapData = ref(null);
 const typeData = ref(null);
 
@@ -260,6 +262,7 @@ const scrollRef = ref(null);
 
 const goLine = (i) => {
   router.replace(`/line/${i.id}`);
+  lineStore.initLineTime(i.time);
 };
 const messages = ref([]);
 if (sessionStorage.getItem("messages")) {