guhongwei %!s(int64=3) %!d(string=hai) anos
pai
achega
3b2d438e80

+ 5 - 1
src/router/index.js

@@ -29,10 +29,14 @@ const web = [
       },
       {
         path: '/adminCenter/test/index',
-        name: 'admin_test',
         meta: { title: '测试菜单' },
         component: () => import('../views/adminCenter/test/index.vue'),
       },
+      {
+        path: '/adminCenter/test/detail',
+        meta: { title: '测试菜单-信息管理' },
+        component: () => import('../views/adminCenter/test/detail.vue'),
+      },
     ],
   },
 ];

+ 2 - 1
src/store/index.js

@@ -2,6 +2,7 @@ import Vue from 'vue';
 import Vuex from 'vuex';
 import * as ustate from '@common/src/store/user/state';
 import * as umutations from '@common/src/store/user/mutations';
+import test from '@common/src/store/test';
 
 Vue.use(Vuex);
 
@@ -9,5 +10,5 @@ export default new Vuex.Store({
   state: { ...ustate },
   mutations: { ...umutations },
   actions: {},
-  modules: {},
+  modules: { test },
 });

+ 72 - 0
src/views/adminCenter/test/detail.vue

@@ -0,0 +1,72 @@
+<template>
+  <div id="detail">
+    <el-row>
+      <el-col :span="24" class="main">
+        <el-col :span="24" class="one">
+          <data-form :fields="fields" :data="form" @save="toSave" returns="/adminCenter/test/index"> </data-form>
+        </el-col>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: maptest } = createNamespacedHelpers('test');
+export default {
+  name: 'detail',
+  props: {},
+  components: {},
+  data: function () {
+    return {
+      form: {},
+      fields: [
+        { label: '标题', model: 'title' },
+        { label: '内容', model: 'content', type: 'editor', url: '/files/cysci/news_editor/upload' },
+      ],
+    };
+  },
+  created() {
+    if (this.id) this.search();
+  },
+  methods: {
+    ...maptest(['fetch', 'create', 'update']),
+    async search() {
+      let res = await this.fetch(this.id);
+      if (this.$checkRes(res)) {
+        this.$set(this, `form`, res.data);
+      }
+    },
+    async toSave({ data }) {
+      let dup = _.cloneDeep(data);
+      let res;
+      if (_.get(dup, 'id')) {
+        res = await this.update(dup);
+      } else {
+        res = await this.create(dup);
+      }
+      if (this.$checkRes(res, '保存成功', '保存失败')) {
+        if (this.$dev_mode) this.$router.push('/adminCenter/test/index');
+      }
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+    id() {
+      return this.$route.query.id;
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+  watch: {
+    test: {
+      deep: true,
+      immediate: true,
+      handler(val) {},
+    },
+  },
+};
+</script>
+
+<style lang="less" scoped></style>

+ 50 - 4
src/views/adminCenter/test/index.vue

@@ -1,22 +1,68 @@
 <template>
   <div id="index">
     <el-row>
-      <el-col :span="24" class="main"> test </el-col>
+      <el-col :span="24" class="main">
+        <el-col :span="24" class="one">
+          <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @edit="toEdit" @delete="toDelete">
+            <template #selfbtn>
+              <el-button type="primary" size="mini" @click="toAdd">添加</el-button>
+            </template>
+          </data-table>
+        </el-col>
+      </el-col>
     </el-row>
   </div>
 </template>
 
 <script>
 import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: maptest } = createNamespacedHelpers('test');
 export default {
   name: 'index',
   props: {},
   components: {},
   data: function () {
-    return {};
+    return {
+      list: [],
+      total: 0,
+      opera: [
+        { label: '修改', method: 'edit' },
+        { label: '删除', method: 'delete', type: 'danger' },
+      ],
+      fields: [
+        { label: '标题', prop: 'title', filter: 'input' },
+        { label: '信息', prop: 'content' },
+      ],
+    };
+  },
+  created() {
+    this.search();
+  },
+  methods: {
+    ...maptest(['query', 'delete']),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      let res = await this.query({ skip, limit, ...info });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data);
+        this.$set(this, `total`, res.total);
+      }
+    },
+    // 添加
+    toAdd() {
+      this.$router.push({ path: '/adminCenter/test/detail' });
+    },
+    // 修改
+    toEdit({ data }) {
+      this.$router.push({ path: '/adminCenter/test/detail', query: { id: data.id } });
+    },
+    // 删除
+    async toDelete({ data }) {
+      const res = await this.delete(data._id);
+      if (this.$checkRes(res, '删除成功', '删除失败')) {
+        this.search();
+      }
+    },
   },
-  created() {},
-  methods: {},
   computed: {
     ...mapState(['user']),
   },