wuhongyuq 5 years ago
parent
commit
db8835b286
4 changed files with 73 additions and 4 deletions
  1. 1 1
      src/store/classes.js
  2. 38 0
      src/store/dept.js
  3. 2 1
      src/store/index.js
  4. 32 2
      src/views/dept/detail.vue

+ 1 - 1
src/store/classes.js

@@ -3,7 +3,7 @@ import Vuex from 'vuex';
 import _ from 'lodash';
 Vue.use(Vuex);
 const api = {
-  interface: `/api/class`,
+  interface: `/api/dept`,
 };
 const state = () => ({});
 const mutations = {};

+ 38 - 0
src/store/dept.js

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

+ 2 - 1
src/store/index.js

@@ -1,11 +1,12 @@
 import Vue from 'vue';
 import Vuex from 'vuex';
 import classes from './classes';
+import dept from './dept';
 Vue.use(Vuex);
 
 export default new Vuex.Store({
   modules: {
-    classes,
+    dept,
   },
   state: {},
   mutations: {},

+ 32 - 2
src/views/dept/detail.vue

@@ -9,6 +9,9 @@
 <script>
 import detailFrame from '@frame/layout/admin/detail-frame';
 import dataForm from '@frame/components/form';
+import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: mapClass } = createNamespacedHelpers('dept');
+
 export default {
   metaInfo: { title: '部门信息' },
   name: 'detail',
@@ -26,14 +29,41 @@ export default {
   }),
   created() {},
   computed: {
+    id() {
+      return this.$route.query.id;
+    },
     isNew() {
       return this.$route.query.id ? false : true;
     },
   },
+  watch: {
+    isNew: {
+      immediate: true,
+      handler(val) {
+        if (val) this.loading = false;
+        else this.search();
+      },
+    },
+  },
   methods: {
+    ...mapClass(['fetch', 'create', 'update']),
+    async search() {
+      const res = await this.fetch(this.id);
+      console.log(res);
+      if (this.$checkRes(res)) this.$set(this, `info`, res.data);
+      this.loading = false;
+    },
     async handleSave({ isNew, data }) {
-      console.log(isNew);
-      console.log(data);
+      let res;
+      let msg;
+      if (isNew) {
+        res = this.create(data);
+        msg = '班级添加成功';
+      } else {
+        res = this.update(data);
+        msg = '班级修改成功';
+      }
+      if (this.$checkRes(res, msg)) this.$router.push({ path: '/classes/index' });
     },
   },
 };