Forráskód Böngészése

将user提取出来

aaa 4 éve
szülő
commit
2e10bea09d

+ 3 - 1
src/store/index.js

@@ -4,6 +4,7 @@ import createPersistedState from "vuex-persistedstate"; // 持久化存储插件
 
 import exam from "./modules/exam";
 import answer from "./modules/answer";
+import user from "./modules/user";
 
 Vue.use(Vuex);
 
@@ -48,6 +49,7 @@ export default new Vuex.Store({
   },
   modules: {
     exam,
-    answer
+    answer,
+    user
   }
 });

+ 19 - 0
src/store/modules/user.js

@@ -0,0 +1,19 @@
+const user = {
+  state: {
+    userName: "testuser-ztdxxDGdNj",
+    email: "test@gmail.com",
+    firstName: "一",
+    lastName: "张",
+    studyId: "U00000",
+    phone: "13060901234",
+    nickName: "小强"
+  },
+  mutations: {
+    updateExamStore(state, { field, value }) {
+      state[field] = value;
+    }
+  },
+  actions: {}
+};
+
+export default user;

+ 7 - 1
src/views/home/person/collection.vue

@@ -29,6 +29,7 @@
 </template>
 
 <script>
+import { mapState } from "vuex";
 export default {
   name: "collection",
   components: {},
@@ -43,10 +44,15 @@ export default {
     console.log("--收藏--");
     this.getFavorites();
   },
+  computed: {
+    ...mapState({
+      user: state => state.user
+    })
+  },
   methods: {
     getFavorites() {
       let path = {
-        userName: "testuser-zirKBELIlg"
+        userName: this.user.userName
       };
       this.$_http
         .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))

+ 7 - 1
src/views/home/person/exam-history.vue

@@ -32,6 +32,7 @@
 </template>
 
 <script>
+import { mapState } from "vuex";
 export default {
   name: "exam-history",
   components: {},
@@ -52,10 +53,15 @@ export default {
   mounted() {
     this.getExamHistory();
   },
+  computed: {
+    ...mapState({
+      user: state => state.user
+    })
+  },
   methods: {
     getExamHistory() {
       let params = {
-        user: "testuser-ztdxxDGdNj"
+        user: this.user.userName
       };
       this.$_http
         .get(this.$_API.JTXT_GET_USER_EXAMS_HISTORY, { params })

+ 8 - 3
src/views/home/person/page-person.vue

@@ -52,6 +52,7 @@
 
 <script>
 import maleAvatar from "@/assets/image/maleAvatar.jpg";
+import { mapState } from "vuex";
 export default {
   name: "page-personal",
   components: {},
@@ -68,7 +69,6 @@ export default {
         "margin-right": "0.2rem"
       },
       faceUrl: "",
-      userName: "test@test.com",
       menus: [
         { title: "考试成绩", icon: "photo-o", to: "exam-history" },
         { title: "收藏", icon: "photo-o", to: "collection" },
@@ -78,6 +78,11 @@ export default {
       ]
     };
   },
+  computed: {
+    ...mapState({
+      user: state => state.user
+    })
+  },
   mounted() {
     this.getDailyPoints();
     this.getAllPoints();
@@ -86,7 +91,7 @@ export default {
     //   获取今日分数
     getDailyPoints() {
       let path = {
-        userName: "testuser-zirKBELIlg"
+        userName: this.user.userName
       };
       this.$_http
         .get(this.$pathParams(this.$_API.JTXT_GET_USER_DAIYL_POINTS, path))
@@ -101,7 +106,7 @@ export default {
     //   查询总积分
     getAllPoints() {
       let path = {
-        userName: "testuser-zirKBELIlg"
+        userName: this.user.userName
       };
       this.$_http
         .get(this.$pathParams(this.$_API.JTXT_GET_USER_ALL_POINTS, path))

+ 7 - 1
src/views/home/person/rank.vue

@@ -39,6 +39,7 @@
 
 <script>
 import maleAvatar from "@/assets/image/maleAvatar.jpg";
+import { mapState } from "vuex";
 export default {
   name: "collection",
   components: {},
@@ -55,10 +56,15 @@ export default {
     console.log("--收藏--");
     this.getFavorites();
   },
+  computed: {
+    ...mapState({
+      user: state => state.user
+    })
+  },
   methods: {
     getFavorites() {
       let path = {
-        userName: "testuser-zirKBELIlg"
+        userName: this.user.userName
       };
       this.$_http
         .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))