Selaa lähdekoodia

fix store init process

Michael Wang 3 vuotta sitten
vanhempi
commit
b277d111cc
4 muutettua tiedostoa jossa 25 lisäystä ja 19 poistoa
  1. 1 0
      .browserslistrc
  2. 8 10
      src/App.vue
  3. 12 8
      src/api/login.ts
  4. 4 1
      src/store/store.ts

+ 1 - 0
.browserslistrc

@@ -0,0 +1 @@
+chrome >= 58

+ 8 - 10
src/App.vue

@@ -1,17 +1,12 @@
 <script setup lang="ts">
 import { NConfigProvider, NMessageProvider, useMessage } from "naive-ui";
 import { zhCN, dateZhCN } from "naive-ui";
-import { defineComponent, watch, watchEffect } from "vue";
-import { store } from "./store/store";
+import { defineComponent, watchEffect } from "vue";
+import { useStore, setStore, store } from "./store/store";
 
-let spinning = $ref(false);
+setStore(useStore());
 
-setTimeout(() => {
-  watch(
-    () => store?.hasGlobalMask,
-    () => (spinning = store?.hasGlobalMask)
-  );
-});
+const spinning = $computed(() => store.hasGlobalMask);
 
 const DummyComp = defineComponent({
   setup() {
@@ -75,13 +70,16 @@ watchEffect(() => {
   animation-delay: 1.5s;
   animation-iteration-count: 1;
   animation-timing-function: ease-in;
-  animation-duration: 5s;
+  animation-duration: 60s;
 }
 
 @keyframes fadeInOpacity {
   0% {
     opacity: 0;
   }
+  10% {
+    opacity: 0.7;
+  }
   100% {
     opacity: 0.7;
   }

+ 12 - 8
src/api/login.ts

@@ -8,12 +8,16 @@ export async function loginApi(
   domain: string,
   rootOrgId: number
 ) {
-  return httpApp.post<{ content: any }>("/api/ecs_core/verifyCode/gt/login", {
-    accountType,
-    accountValue,
-    password,
-    domain,
-    rootOrgId,
-    alwaysOK: true,
-  });
+  return httpApp.post<{ content: any }>(
+    "/api/ecs_core/verifyCode/gt/login",
+    {
+      accountType,
+      accountValue,
+      password,
+      domain,
+      rootOrgId,
+      alwaysOK: true,
+    },
+    { setGlobalMask: true }
+  );
 }

+ 4 - 1
src/store/store.ts

@@ -58,8 +58,11 @@ export const useStore = defineStore("ecs", {
 
 export let store = null as unknown as ReturnType<typeof useStore>;
 
+export function setStore(s: ReturnType<typeof useStore>) {
+  store = s;
+}
 void Promise.resolve(0).then(() => {
-  store = useStore();
+  // store = useStore();
 
   store.$subscribe((_mutation, state) => {
     sessionStorage.setItem(