lrf402788946 4 سال پیش
والد
کامیت
e46696f722
3فایلهای تغییر یافته به همراه61 افزوده شده و 18 حذف شده
  1. 19 18
      src/router/index.js
  2. 2 0
      src/store/index.js
  3. 40 0
      src/store/service.js

+ 19 - 18
src/router/index.js

@@ -91,24 +91,25 @@ const router = new VueRouter({
 });
 
 router.beforeEach(async (to, form, next) => {
-  if (to.name == 'account_user') {
-    let res = await store.dispatch('login/toGetUser');
-    if (res && res.uid) {
-      next();
-    } else {
-      let key = sessionStorage.getItem('token');
-      let user = jwt.decode(key);
-      if (user && user.uid) {
-        store.commit('setUser', user, { root: true });
-        next();
-      } else {
-        next({ name: 'login' });
-      }
-    }
-  } else {
-    let res = await store.dispatch('login/toGetUser');
-    next();
-  }
+  next();
+  // if (to.name == 'account_user') {
+  //   let res = await store.dispatch('login/toGetUser');
+  //   if (res && res.uid) {
+  //     next();
+  //   } else {
+  //     let key = sessionStorage.getItem('token');
+  //     let user = jwt.decode(key);
+  //     if (user && user.uid) {
+  //       store.commit('setUser', user, { root: true });
+  //       next();
+  //     } else {
+  //       next({ name: 'login' });
+  //     }
+  //   }
+  // } else {
+  //   let res = await store.dispatch('login/toGetUser');
+  //   next();
+  // }
 });
 const originalPush = VueRouter.prototype.push;
 VueRouter.prototype.push = function push(location, onResolve, onReject) {

+ 2 - 0
src/store/index.js

@@ -4,6 +4,7 @@ import login from './login';
 import upload from './upload';
 import refute from './refute';
 import topic from './topic';
+import service from './service';
 
 Vue.use(Vuex);
 
@@ -26,5 +27,6 @@ export default new Vuex.Store({
     upload,
     refute,
     topic,
+    service,
   },
 });

+ 40 - 0
src/store/service.js

@@ -0,0 +1,40 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  service: `/api/article/service`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(api.service, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.service}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.service}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...info } = {}) {
+    const res = await this.$axios.$post(`${api.service}/update/${id}`, {
+      ...info,
+    });
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.service}/${payload}`);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};