Bläddra i källkod

Merge branch 'master' of http://git.cc-lotus.info/service-platform/web-test

guhongwei 4 år sedan
förälder
incheckning
b25149e709

+ 2 - 2
src/components/data-table.vue

@@ -92,7 +92,7 @@
       <el-col :span="24" style="text-align:right;">
         <el-pagination
           background
-          layout="sizes, total, prev, pager, next"
+          layout=" total, prev, pager, next"
           :page-sizes="[10, 15, 20, 50, 100]"
           :total="total"
           :page-size="limit"
@@ -129,7 +129,7 @@ export default {
   data: () => ({
     pageSelected: [],
     currentPage: 1,
-    limit: _.get(this, `$limit`, undefined) !== undefined ? this.$limit : process.env.VUE_APP_LIMIT * 1,
+    limit: _.get(this, `$limit`, undefined) !== undefined ? this.$limit : process.env.VUE_APP_LIMIT * 1 || 10,
     searchInfo: {},
     useFilter: true,
     filterList: [],

+ 4 - 0
src/store/index.js

@@ -34,6 +34,9 @@ import dockLogin from './user/dockLogin';
 import * as ustate from './user/state';
 import * as umutations from './user/mutations';
 import place from './place';
+
+import role from './user/role';
+
 Vue.use(Vuex);
 
 export default new Vuex.Store({
@@ -71,5 +74,6 @@ export default new Vuex.Store({
     dockLogin,
     newsguidance,
     newsroadshow,
+    role,
   },
 });

+ 40 - 0
src/store/user/role.js

@@ -0,0 +1,40 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+//用户的菜单选项增删改查
+Vue.use(Vuex);
+const api = {
+  interface: `/api/auth/role`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit = undefined, ...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, ...info } = {}) {
+    const res = await this.$axios.$post(`${api.interface}/update/${id}`, { ...info });
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
+    return res;
+  },
+};
+
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 130 - 0
src/views/superAdminCenter/adminUser/index.vue

@@ -0,0 +1,130 @@
+<template>
+  <div id="adminUser">
+    <el-row>
+      <el-col :span="24" class="add" style="text-align:right;padding: 10px 20px;">
+        <el-button size="mini" type="primary" @click="toAdd" icon="el-icon-plus">添加{{ theme }}</el-button>
+      </el-col>
+      <el-col :span="24" class="main">
+        <data-table :fields="fields" @delete="toDelete" :data="list" :opera="opera" @edit="toEdit" :total="total" @query="search"></data-table>
+      </el-col>
+      <el-dialog :title="theme" width="60%" :visible.sync="dialog" @closed="handleClose" :destroy-on-close="true">
+        <data-form :data="form" :fields="formFields" @save="toSave" :isNew="dialogIsNew" :rules="rules"></data-form>
+      </el-dialog>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import dataForm from '@/components/form.vue';
+import dataTable from '@/components/data-table.vue';
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: users } = createNamespacedHelpers('users');
+const { mapActions: authUser } = createNamespacedHelpers('authUser');
+export default {
+  name: 'adminUser',
+  props: {},
+  components: { dataTable, dataForm },
+  data: function() {
+    return {
+      theme: '机构管理员',
+      dialog: false,
+      form: {},
+      dialogIsNew: true,
+      opera: [
+        {
+          label: '编辑',
+          icon: 'el-icon-edit',
+          method: 'edit',
+        },
+        {
+          label: '删除',
+          icon: 'el-icon-delete',
+          method: 'delete',
+          confirm: true,
+        },
+      ],
+      fields: [
+        { label: '机构代码或邀请码', prop: 'code' },
+        { label: '用户名', prop: 'name', filter: 'input' },
+        { label: '机构名称', prop: 'deptname', filter: 'input' },
+        { label: '电话', prop: 'phone', filter: 'input' },
+      ],
+      list: [],
+      total: 0,
+
+      formFields: [
+        { label: '机构代码或邀请码', prop: 'code', model: 'code' },
+        { label: '姓名', prop: 'name', model: 'name' },
+        { label: '机构名称', prop: 'deptname', model: 'deptname' },
+        { label: '手机号', prop: 'phone', model: 'phone', options: { maxLength: 11, minLength: 11, type: 'number' } },
+        { label: '密码', prop: 'password', model: 'password', type: 'password' },
+      ],
+      rules: {
+        code: [{ required: true, message: '请输入推荐码' }],
+      },
+    };
+  },
+  created() {
+    this.search();
+  },
+  methods: {
+    ...users(['query', 'fetch', 'create', 'update', 'delete']),
+    ...authUser({ authUserDelete: 'delete' }),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      const res = await this.query({ skip, limit, pid: this.user.uid, ...info });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data);
+        this.$set(this, `total`, res.total);
+      }
+    },
+    // 添加
+    toAdd() {
+      this.dialog = true;
+    },
+    toEdit({ data }) {
+      this.$set(this, 'form', data);
+      this.dialog = true;
+      this.dialogIsNew = false;
+    },
+    async toSave({ isNew, data }) {
+      let res;
+      let msg;
+      if (isNew) {
+        data.pid = this.user.uid;
+        data.status = '1';
+        data.role = '1';
+        res = await this.create(data);
+        msg = '创建成功';
+      } else {
+        res = await this.update(data);
+        msg = '修改成功';
+      }
+      if (this.$checkRes(res, msg, res.errmsg)) {
+        this.handleClose();
+        this.search();
+      }
+    },
+    async toDelete({ data }) {
+      const res = await this.delete(data.id);
+      const arr = await this.authUserDelete(data.id);
+      if (this.$checkRes(arr, '删除成功', res.errmsg || '删除失败')) this.search();
+    },
+    handleClose() {
+      this.dialog = false;
+      this.form = {};
+      this.dialogIsNew = true;
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+};
+</script>
+
+<style lang="less" scoped></style>

+ 48 - 3
src/views/superAdminCenter/index.vue

@@ -7,7 +7,15 @@
         </el-col>
         <el-col :span="24" class="main">
           <div class="w_1200">
-            管理中心
+            <el-col :span="4" class="mainMenu">
+              <menus @setRight="setRight"></menus>
+            </el-col>
+            <el-col :span="19" class="mainMess">
+              <top :title="topTitle"></top>
+              <div style="padding:10px">
+                <component :is="cpt"></component>
+              </div>
+            </el-col>
           </div>
         </el-col>
         <el-col :span="24" class="foot">
@@ -19,6 +27,12 @@
 </template>
 
 <script>
+/* eslint-disable vue/no-unused-components */
+import menus from './menuInfo.vue';
+import top from './lefttop.vue';
+import role from './role/index.vue';
+import permission from './permission/index.vue';
+import adminUser from './adminUser/index.vue';
 import heads from '@/layout/userCenter/heads.vue';
 import foot from '@/layout/live/foot.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
@@ -28,12 +42,26 @@ export default {
   components: {
     heads,
     foot,
+    role,
+    permission,
+    adminUser,
+    menus,
+    top,
   },
   data: function() {
-    return {};
+    return {
+      cpt: 'role',
+      topTitle: '',
+    };
   },
   created() {},
-  methods: {},
+  methods: {
+    setRight(menu) {
+      let { name, cpt } = menu;
+      this.$set(this, `topTitle`, name);
+      // this.$set(this, `cpt`, cpt);
+    },
+  },
   computed: {
     ...mapState(['user']),
     pageTitle() {
@@ -51,4 +79,21 @@ export default {
   width: 80%;
   margin: 0 auto;
 }
+.info {
+  background-color: #e9edf6;
+}
+.main {
+  min-height: 666px;
+  margin: 15px 0;
+}
+.mainMenu {
+  width: 20%;
+  min-height: 666px;
+  background-color: #fff;
+}
+.mainMess {
+  float: right;
+  min-height: 666px;
+  background-color: #fff;
+}
 </style>

+ 49 - 0
src/views/superAdminCenter/lefttop.vue

@@ -0,0 +1,49 @@
+<template>
+  <div id="lefttop">
+    <el-row>
+      <el-col :span="24" class="leftTop">
+        <span>|</span> <span>{{ title }}</span>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import { mapState, createNamespacedHelpers } from 'vuex';
+export default {
+  name: 'lefttop',
+  props: {
+    title: { type: String, default: 'title' },
+  },
+  components: {},
+  data: function() {
+    return {};
+  },
+  created() {},
+  methods: {},
+  computed: {
+    ...mapState(['user']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.leftTop {
+  font-size: 18px;
+  width: 96%;
+  height: 41px;
+  line-height: 35px;
+  border-bottom: 1px solid #e5e5e5;
+  position: relative;
+  bottom: 1px;
+  margin: 10px;
+  font-weight: 600;
+  color: #22529a;
+}
+</style>

+ 111 - 0
src/views/superAdminCenter/menuInfo.vue

@@ -0,0 +1,111 @@
+<template>
+  <div id="menuInfo">
+    <el-row>
+      <el-col :span="24">
+        <el-col :span="24" class="top">
+          <el-image :src="topUrl"></el-image>
+          <span>个人中心</span>
+        </el-col>
+        <el-col :span="24">
+          <el-menu :default-active="active" @select="setRight" text-color="#999" active-text-color="#044b79">
+            <template v-for="(i, index) in menuList">
+              <el-menu-item :key="index" :index="`${index}`" v-if="i.cpt">
+                <template slot="title">
+                  <!-- <i class="el-icon-pie-chart"></i> -->
+                  <span>{{ i.name }}</span>
+                </template>
+              </el-menu-item>
+            </template>
+          </el-menu>
+        </el-col>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('role');
+export default {
+  name: 'menuInfo',
+  props: {},
+  components: {},
+  data: function() {
+    return {
+      topUrl: require('@/assets/live/square_big.png'),
+      active: '0',
+      haveMsg: false,
+      menuList: [],
+    };
+  },
+  created() {
+    //TODO 子管理员需要查询对应的权限表
+    this.search();
+  },
+  methods: {
+    ...mapActions(['query', 'create', 'update', 'delete']),
+    async search() {
+      const res = await this.query();
+      if (this.$checkRes(res)) {
+        let data = res.data.reverse();
+        data = data.map(i => {
+          let { role_name: name, url: cpt } = i;
+          return { name, cpt };
+        });
+        this.$set(this, `menuList`, data);
+        this.setRight(this.active);
+      }
+    },
+    // 菜单跳转
+    setRight(index) {
+      let r = this.menuList[index];
+      if (r) this.$emit('setRight', r);
+    },
+  },
+  watch: {
+    active: {
+      handler(val) {
+        this.setRight(val);
+      },
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.top {
+  height: 50px;
+  line-height: 50px;
+  text-align: center;
+  border-bottom: 1px solid #2d64b3;
+  .el-image {
+    float: left;
+    padding: 10px 40px;
+    width: 30px;
+    height: 30px;
+  }
+  span {
+    font-size: 24px;
+    color: #92959a;
+    font-weight: 600;
+    float: left;
+    text-align: left;
+  }
+}
+/deep/.el-menu-item {
+  font-weight: bold;
+  font-size: 20px;
+  text-align: center;
+  border-bottom: 1px solid #2d64b3;
+  margin: 0 20px;
+}
+</style>

+ 142 - 0
src/views/superAdminCenter/permission/index.vue

@@ -0,0 +1,142 @@
+<template>
+  <div id="adminUser">
+    <el-row>
+      <el-col :span="24" class="add" style="text-align:right;padding: 10px 20px;">
+        <!-- <el-button size="mini" type="primary" @click="toAdd" icon="el-icon-plus">添加{{ theme }}</el-button> -->
+      </el-col>
+      <el-col :span="24" class="main">
+        <data-table :fields="fields" @delete="toDelete" :data="list" :opera="opera" @edit="toEdit" :total="total" @query="search"></data-table>
+      </el-col>
+      <el-dialog :title="theme" width="60%" :visible.sync="dialog" @closed="handleClose" :destroy-on-close="true">
+        <data-form :fields="formFields" :data="form" :rules="{}" @save="toSave" :isNew="dialogIsNew">
+          <template #custom="{item, form}">
+            <el-checkbox-group v-model="form.menus">
+              <el-checkbox v-for="(i, index) in menuList" :key="index" :label="i.id">{{ i.role_name }}</el-checkbox>
+            </el-checkbox-group>
+          </template>
+        </data-form>
+      </el-dialog>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import dataForm from '@/components/form.vue';
+import dataTable from '@/components/data-table.vue';
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: authUser } = createNamespacedHelpers('authUser');
+const { mapActions: role } = createNamespacedHelpers('role');
+const { mapActions: loginMenu } = createNamespacedHelpers('login');
+export default {
+  name: 'permission',
+  props: {},
+  components: { dataTable, dataForm },
+  data: function() {
+    return {
+      theme: '权限',
+      dialog: false,
+      form: {},
+      dialogIsNew: true,
+      opera: [
+        {
+          label: '分配权限',
+          icon: 'el-icon-edit',
+          method: 'edit',
+        },
+        {
+          label: '删除',
+          icon: 'el-icon-delete',
+          method: 'delete',
+          confirm: true,
+        },
+      ],
+      fields: [
+        { label: '用户名', prop: 'name' },
+        { label: '机构名称', prop: 'deptname' },
+      ],
+      formFields: [
+        { label: '用户名', model: 'name', type: 'text' },
+        { label: '机构名称', model: 'deptname', type: 'text' },
+        { label: '权限', model: 'menus', custom: true },
+      ],
+      list: [],
+      menuList: [],
+      total: 0,
+    };
+  },
+  created() {
+    this.search();
+    this.getOtherList();
+  },
+  methods: {
+    ...authUser(['fetch', 'query', 'update']),
+    ...role({ getRoleList: 'query' }),
+    ...loginMenu(['toGetMenu']),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      const res = await this.query({ skip, limit, role: '1', pid: this.user.uid, ...info });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data);
+        this.$set(this, `total`, res.total);
+      }
+    },
+    // 添加
+    toAdd() {
+      this.dialog = true;
+    },
+    async toEdit({ data }) {
+      const res = await this.fetch({ id: data.id });
+      if (this.$checkRes(res)) {
+        let menus = res.data.menus;
+        this.$set(this, 'form', { ...data, menus: menus.map(i => i.id) });
+      }
+      this.dialog = true;
+      this.dialogIsNew = false;
+    },
+    async toSave({ isNew, data }) {
+      let res;
+      let msg;
+      data.type = 1;
+      if (isNew) {
+        res = await this.create(data);
+        msg = '创建成功';
+      } else {
+        res = await this.update(data);
+        msg = '修改成功';
+      }
+      if (this.$checkRes(res, msg, res.errmsg)) {
+        this.handleClose();
+        this.search();
+      }
+    },
+    async toDelete({ data }) {
+      const res = await this.delete(data.id);
+      if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) this.search();
+    },
+    handleClose() {
+      this.dialog = false;
+      this.form = { menus: [] };
+      this.dialogIsNew = true;
+    },
+    async getOtherList() {
+      if (this.user.role == '0') {
+        const res = await this.getRoleList({ id: this.user.uid });
+        if (this.$checkRes(res)) this.$set(this, `menuList`, res.data.reverse());
+      } else if (this.user.role == '1') {
+        const res = await this.toGetMenu({ id: this.user.uid });
+        if (this.$checkRes(res)) this.$set(this, `menuList`, res.data.menus.reverse());
+      }
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+};
+</script>
+
+<style lang="less" scoped></style>

+ 112 - 0
src/views/superAdminCenter/role/index.vue

@@ -0,0 +1,112 @@
+<template>
+  <div id="role">
+    <el-row>
+      <el-col :span="24" class="add" style="text-align:right;padding: 10px 20px;">
+        <el-button size="mini" type="primary" @click="toAdd" icon="el-icon-plus">添加{{ theme }}</el-button>
+      </el-col>
+      <el-col :span="24" class="main">
+        <data-table :fields="fields" :usePage="false" @delete="toDelete" :data="list" :opera="opera" @edit="toEdit" :total="total" @query="search"></data-table>
+      </el-col>
+      <el-dialog :title="theme" width="60%" :visible.sync="dialog" @closed="handleClose" :destroy-on-close="true">
+        <data-form :data="form" :fields="fields" @save="toSave" :isNew="dialogIsNew"></data-form>
+      </el-dialog>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import dataForm from '@/components/form.vue';
+import dataTable from '@/components/data-table.vue';
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('role');
+export default {
+  name: 'role',
+  props: {},
+  components: { dataTable, dataForm },
+  data: function() {
+    return {
+      theme: '菜单',
+      dialog: false,
+      form: {},
+      dialogIsNew: true,
+      opera: [
+        {
+          label: '编辑',
+          icon: 'el-icon-edit',
+          method: 'edit',
+        },
+        {
+          label: '删除',
+          icon: 'el-icon-delete',
+          method: 'delete',
+          confirm: true,
+        },
+      ],
+      fields: [
+        { label: '名称', prop: 'role_name', model: 'role_name' },
+        { label: '路由', prop: 'url', model: 'url' },
+      ],
+      list: [],
+      total: 0,
+    };
+  },
+  created() {
+    this.search();
+  },
+  methods: {
+    ...mapActions(['query', 'create', 'update', 'delete']),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      const res = await this.query({ ...info });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data.reverse());
+        this.$set(this, `total`, res.total);
+      }
+    },
+    // 添加
+    toAdd() {
+      this.dialog = true;
+    },
+    toEdit({ data }) {
+      this.$set(this, 'form', data);
+      this.dialog = true;
+      this.dialogIsNew = false;
+    },
+    async toSave({ isNew, data }) {
+      let res;
+      let msg;
+      data.type = 1;
+      if (isNew) {
+        res = await this.create(data);
+        msg = '创建成功';
+      } else {
+        res = await this.update(data);
+        msg = '修改成功';
+      }
+      if (this.$checkRes(res, msg, res.errmsg)) {
+        this.handleClose();
+        this.search();
+      }
+    },
+    async toDelete({ data }) {
+      const res = await this.delete(data.id);
+      if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) this.search();
+    },
+    handleClose() {
+      this.dialog = false;
+      this.form = {};
+      this.dialogIsNew = true;
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+    pageTitle() {
+      return `${this.$route.meta.title}`;
+    },
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+};
+</script>
+
+<style lang="less" scoped></style>