浏览代码

移植hooks,useApp等

gemercheung 2 年之前
父节点
当前提交
7e96b6bbc8
共有 2 个文件被更改,包括 21 次插入25 次删除
  1. 16 23
      src/components/basic/loading.vue
  2. 5 2
      src/hooks/userApp.ts

+ 16 - 23
src/components/basic/loading.vue

@@ -54,10 +54,11 @@ import {
 } from "vue";
 import { useApp } from "/@/hooks/userApp";
 import { useSceneStore } from "/@/store/modules/scene";
+import loadLOGO from "/@/assets/images/loading.jpg";
 
 const sceneStore = useSceneStore();
 // import { useStore } from "vuex";
-// import { useApp } from "@/app";
+
 const props = defineProps({
   small: {
     type: Boolean,
@@ -71,8 +72,8 @@ const props = defineProps({
 // const store = useStore();
 const progres = ref(0);
 const enter = ref(false);
-const thumb = ref(null);
-const thumbStyle = ref(null);
+const thumb = ref<string>("");
+const thumbStyle = ref<string>("");
 const show = ref(true);
 const metadata = computed(() => sceneStore.metadata);
 // store.getters["scene/loadingLogoFile"]
@@ -87,28 +88,20 @@ watchEffect(async () => {
     // debugger
     onMounted(async () => {
       await nextTick();
-      const [app] = useApp();
-      console.log("app22", app);
-      app().then(async (sdk: any) => {
-        console.log("hey", sdk);
-        debugger;
+      const app = await useApp();
+
+      app.Scene.on("ready", () => {
+        show.value = false;
+      });
+      app.store.on("metadata", (metadata) => {
+        if (metadata.entry) {
+          thumb.value = app.resource.getUserResourceURL("thumb-2k.jpg");
+        } else {
+          thumb.value = loadLOGO;
+          thumbStyle.value = "default";
+        }
       });
     });
-
-    //   console.log("app", app);
-    //   useApp().then((app) => {
-    //     app.Scene.on("ready", () => {
-    //       show.value = false;
-    //     });
-    //     app.store.on("metadata", (metadata) => {
-    //       if (metadata.entry) {
-    //         thumb.value = app.resource.getUserResourceURL("thumb-2k.jpg");
-    //       } else {
-    //         thumb.value = require("@/assets/images/loading.jpg");
-    //         thumbStyle.value = "default";
-    //       }
-    //     });
-    //   });
   }
 });
 </script>

+ 5 - 2
src/hooks/userApp.ts

@@ -40,7 +40,10 @@ export function createApp(options: appOptions): Promise<KanKanInstance> {
     return Promise.resolve(app)
 }
 
-export function useApp(): Promise<KanKanInstance | null> {
-
+export function useApp(): Promise<KanKanInstance> {
+    if (app) {
+        return Promise.resolve(app)
+    }
+    return deferred
 }