任一存 1 anno fa
parent
commit
9acdb44cf0
5 ha cambiato i file con 33 aggiunte e 10 eliminazioni
  1. 15 4
      src/App.vue
  2. BIN
      src/assets/images/map-with-routes.jpg
  3. 3 3
      src/main.js
  4. 14 2
      src/message-center.js
  5. 1 1
      src/views/MapView.vue

+ 15 - 4
src/App.vue

@@ -86,10 +86,12 @@
 </template>
 
 <script setup>
-import { onMounted, ref, computed, watch } from "vue";
+import { onMounted, ref, computed, watch, onBeforeUnmount } from "vue";
 import { /* useRoute, */ useRouter } from "vue-router";
 import { poiList } from "@/config.js";
 
+console.log("init App.vue...");
+
 // const route = useRoute();
 const router = useRouter();
 
@@ -130,6 +132,7 @@ function onClickLocateBtn() {
   isShowText.value = false;
   isNavigating.value = true;
 }
+
 window.messageCenter.subscribe("nav-to-poi", (v) => {
   const poiPos = poiList[v].pos;
   window.SenseMain.startNavigationMicroApp({
@@ -143,11 +146,19 @@ window.messageCenter.subscribe("nav-to-poi", (v) => {
   isShowText.value = false;
   isNavigating.value = true;
 });
-window.SenseMain.emitter.on("NAVIGATE_SUB_APP_END", function () {
+onBeforeUnmount(() => {
+  window.messageCenter.unsubscribeAll();
+});
+
+function onNavEnd() {
   isNavigating.value = false;
   // console.log("[demo] 导航结束信息", JSON.stringify(msg));
   // 输出如下,是否为抵达终点后退出导航,可以查看 endType 字段是否为 0
   // [demo] 导航终点信息 {"endName":"会议室2002","endPos":{"x":48.59096,"y":-39.54175,"z":0},"floorId":"20200","type":"brand","navChannel":"Brand","nextApp":"qiankun-h5-standard","endType":-1,"floorName":"F20"}
+}
+window.SenseMain.emitter.on("NAVIGATE_SUB_APP_END", onNavEnd);
+onBeforeUnmount(() => {
+  window.SenseMain.emitter.off("NAVIGATE_SUB_APP_END", onNavEnd);
 });
 
 // audio相关
@@ -257,8 +268,8 @@ window.SenseMain.emitter.on("CLICK_POI", (e) => {
   > button.open-map {
     pointer-events: initial;
     position: absolute;
-    left: 21px;
-    bottom: 32%;
+    right: 11px;
+    bottom: 268px;
     width: 50px;
     height: 50px;
     background-image: url(@/assets/images/icon-locate-colorful.png);

BIN
src/assets/images/map-with-routes.jpg


+ 3 - 3
src/main.js

@@ -9,7 +9,9 @@ import "@/assets/style/reset.css";
 import "@/assets/style/my-reset.css";
 import { MessageCenter } from "@/message-center.js";
 
-console.log("build time: 20240511-1100");
+console.log("build time: 20240605-1052");
+
+window.messageCenter = new MessageCenter();
 
 const packageName = packageJson.name;
 const rootId = packageName + "__id";
@@ -102,5 +104,3 @@ export async function update(customProps) {
   // 假如没有相关需求,该生命周期可以删除
   console.log(`[${packageName}] app update`, customProps);
 }
-
-window.messageCenter = new MessageCenter();

+ 14 - 2
src/message-center.js

@@ -16,7 +16,7 @@ export class MessageCenter {
     console.error("MessageCenter: invalid parameter.");
   }
 
-  subscribe(message, callback) {
+  subscribe(message, callback, onlyOnce = true) {
     if (typeof message !== "string" || typeof callback !== "function") {
       this.logInvalidParam();
       return;
@@ -25,7 +25,15 @@ export class MessageCenter {
     if (!Object.prototype.hasOwnProperty.call(this._recorder, message)) {
       this._recorder[message] = [];
     }
-    this._recorder[message].push(callback);
+    if (onlyOnce) {
+      if (!this._recorder[message].includes(callback)) {
+        this._recorder[message].push(callback);
+      } else {
+        return
+      }
+    } else {
+      this._recorder[message].push(callback);
+    }
   }
 
   unsubscribe(message, callback) {
@@ -42,6 +50,10 @@ export class MessageCenter {
     }
   }
 
+  unsubscribeAll() {
+    this._recorder = {}
+  }
+
   publish(message, param) {
     if (Object.prototype.hasOwnProperty.call(this._recorder, message)) {
       this._recorder[message].forEach((callback) => {

+ 1 - 1
src/views/MapView.vue

@@ -2,7 +2,7 @@
   <div
     class="map-view"
     :style="{
-      backgroundImage: `url(${require(`@/assets/images/map.png`)})`,
+      backgroundImage: `url(${require(`@/assets/images/map-with-routes.jpg`)})`,
     }"
   >
     <button class="back" @click="router.go(-1)"></button>