guhongwei 2 سال پیش
والد
کامیت
83b6514649
3فایلهای تغییر یافته به همراه40 افزوده شده و 28 حذف شده
  1. 1 0
      .gitignore
  2. 3 3
      src/router/index.ts
  3. 36 25
      src/stores/counter.ts

+ 1 - 0
.gitignore

@@ -26,3 +26,4 @@ coverage
 *.njsproj
 *.sln
 *.sw?
+.history

+ 3 - 3
src/router/index.ts

@@ -1,5 +1,6 @@
 import { createRouter, createWebHistory } from 'vue-router';
-import { store } from '@/stores/counter';
+import store from '@/stores/counter';
+
 // 公共
 import common from './module/common';
 // 管理员
@@ -76,8 +77,7 @@ router.beforeEach((to, from, next) => {
       exp: 1679206471,
     };
     console.log(store);
-
-    // store.commit('setUser', user, { root: true });
+    store.commit('setUser', user, { root: true });
     next();
   } else {
     window.alert('无登录信息,无法打开');

+ 36 - 25
src/stores/counter.ts

@@ -1,28 +1,39 @@
-import { ref, computed } from 'vue';
-import { defineStore } from 'pinia';
+// import { ref, computed } from 'vue';
+// import { defineStore } from 'pinia';
+// import * as ustate from '@common/src/stores/user/state';
+// import * as umutations from '@common/src/stores/user/mutations';
+// export const store = defineStore('counter', () => {
+//   const count = ref(0);
+//   const doubleCount = computed(() => count.value * 2);
+//   function increment() {
+//     count.value++;
+//   }
+//   const state = { ...ustate, isInAct: false };
+
+//   const getters = {};
+//   const mutations = {
+//     umutations,
+//     setIsInAct(state: { isInAct: object }, payload: { isInAct: object }) {
+//       state.isInAct = payload;
+//     },
+//   };
+//   return {
+//     state,
+//     getters,
+//     mutations,
+//     count,
+//     doubleCount,
+//     increment,
+//   };
+// });
+
 import * as ustate from '@common/src/stores/user/state';
 import * as umutations from '@common/src/stores/user/mutations';
-export const store = defineStore('counter', () => {
-  const count = ref(0);
-  const doubleCount = computed(() => count.value * 2);
-  function increment() {
-    count.value++;
-  }
-  const state = { ...ustate, isInAct: false };
-
-  const getters = {};
-  const mutations = {
-    umutations,
-    setIsInAct(state: { isInAct: object }, payload: { isInAct: object }) {
-      state.isInAct = payload;
-    },
-  };
-  return {
-    state,
-    getters,
-    mutations,
-    count,
-    doubleCount,
-    increment,
-  };
+import { createStore } from 'vuex';
+const store = createStore({
+  state: { ...ustate },
+  mutations: { ...umutations },
+  actions: {},
+  modules: {},
 });
+export default store;