Browse Source

权限管理部分完成

lrf402788946 6 years ago
parent
commit
e8df2446e2

+ 1 - 0
src/components/SideBar.vue

@@ -16,6 +16,7 @@
         <el-menu-item index="/group">群组管理</el-menu-item>
         <el-menu-item index="/resources">资源管理</el-menu-item>
         <el-menu-item index="/role">角色管理</el-menu-item>
+        <el-menu-item index="/right">权限管理</el-menu-item>
         <el-menu-item index="/confer">权限授予</el-menu-item>
       </el-submenu>
     </el-menu>

+ 6 - 1
src/router.js

@@ -55,7 +55,12 @@ export default new Router({
         {
           path: '/confer',
           name: 'confer',
-          component: () => import('./views/role/group.vue'),
+          component: () => import('./views/role/confers.vue'),
+        },
+        {
+          path: '/right',
+          name: 'right',
+          component: () => import('./views/role/right.vue'),
         },
       ],
     },

+ 213 - 0
src/views/role/confer/group_role.vue

@@ -0,0 +1,213 @@
+<template lang="html">
+  <div id="group_role">
+    <el-row>
+      <el-col :span="24" class="search">
+        <el-col :span="5" class="searchInp"><el-input v-model="input" placeholder="请输入内容"></el-input></el-col>
+        <el-col :span="2" class="searchBtn"><el-button icon="el-icon-search"></el-button></el-col>
+      </el-col>
+      <el-col :span="24" class="list">
+        <el-table :data="tableData" style="width: 100%" border stripe>
+          <el-table-column prop="name" align="center" :label="`${type}名称`"> </el-table-column>
+          <el-table-column label="操作" align="center">
+            <template v-slot="scoped">
+              <el-row type="flex" justify="center">
+                <el-col :span="6">
+                  <el-button size="mini" type="text" @click="openDialog(scoped.$index, 'right')">分配权限</el-button>
+                </el-col>
+                <el-col :span="6">
+                  <el-button size="mini" type="text" @click="openDialog(scoped.$index, 'resources')">分配资源</el-button>
+                </el-col>
+              </el-row>
+            </template>
+          </el-table-column>
+        </el-table>
+        <el-col class="paging">
+          <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination>
+        </el-col>
+      </el-col>
+    </el-row>
+    <el-dialog title="权限管理" :visible.sync="dialogRight">
+      <el-row>
+        <el-col :span="24" style="padding-left:4rem;">
+          <el-transfer v-model="form.rightList" :data="rightList" :titles="['未添加', '已添加']" :button-texts="['删除', '添加']"></el-transfer>
+        </el-col>
+      </el-row>
+      <div slot="footer" class="dialog-footer">
+        <el-button @click="handleCancel">取 消</el-button>
+        <el-button type="primary" @click="handleEdit">确 定</el-button>
+      </div>
+    </el-dialog>
+    <el-dialog title="资源管理" :visible.sync="dialogRes">
+      <el-row>
+        <el-col :span="24" style="padding-left:4rem;">
+          <el-transfer v-model="form.resourcesList" :data="resourcesList" :titles="['未添加', '已添加']" :button-texts="['删除', '添加']"></el-transfer>
+        </el-col>
+      </el-row>
+      <div slot="footer" class="dialog-footer">
+        <el-button @click="handleCancel">取 消</el-button>
+        <el-button type="primary" @click="handleEdit">确 定</el-button>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'group_role',
+  props: {
+    type: { type: String, default: '群组' },
+  },
+  components: {},
+  data: () => ({
+    input: '',
+    tableData: [],
+    rightList: [],
+    resourcesList: [],
+    dialogRight: false,
+    dialogRes: false,
+    form: {},
+    assignFrom: {},
+  }),
+  created() {
+    this.initData();
+  },
+  computed: {},
+  methods: {
+    handleEdit() {
+      let chData = this.form;
+      const { index, ...form } = chData;
+      console.log(index, form);
+      if (index !== undefined) {
+        this.$set(this.tableData, `${index}`, form);
+        this.$message.success('修改成功');
+      } else {
+        this.tableData.push(form);
+      }
+      this.handleCancel();
+    },
+    handleCancel() {
+      this.form = {};
+      this.dialogRight = false;
+      this.dialogRes = false;
+    },
+    openDialog(index, type) {
+      if (index !== undefined) {
+        let data = JSON.parse(JSON.stringify(this.tableData[index]));
+        data[`index`] = index;
+        this.personProccess('unlock');
+        if (this.type === '人员') {
+          this.personProccess('lock', data);
+        }
+        this.$set(this, `form`, data);
+      } else {
+        this.form = {};
+      }
+      if (type === 'right') {
+        this.dialogRight = true;
+      } else {
+        this.dialogRes = true;
+      }
+    },
+    personProccess(type, data) {
+      if (type === 'lock') {
+        let lockRightList = this.rightList.map(right => {
+          data.originalRight.map(self => {
+            if (self === right.key) {
+              right['disabled'] = true;
+            }
+          });
+          return right;
+        });
+        let lockResList = this.resourcesList.map(res => {
+          data.originalResources.map(self => {
+            if (self === res.key) {
+              res['disabled'] = true;
+            }
+          });
+          return res;
+        });
+      } else {
+        this.rightList.map(item => {
+          delete item.disabled;
+          return item;
+        });
+        this.resourcesList.map(item => {
+          delete item.disabled;
+          return item;
+        });
+        console.log(this.rightList);
+      }
+    },
+    initData() {
+      let list = [];
+      let resourcesList = [];
+      let tableList = [];
+      for (let i = 0; i < 10; i++) {
+        list.push({
+          key: i,
+          label: `权限${i + 1}`,
+        });
+        resourcesList.push({
+          key: i,
+          label: `${i % 3 === 1 ? '文档' : i % 3 === 2 ? '应用' : '数据'}${i + 1}`,
+        });
+        if (i < 5) {
+          tableList.push({
+            name: `${this.type}${i + 1}`,
+            rightList: [i, i + 1],
+            originalRight: [i, i + 1],
+            resourcesList: [i, i + 1],
+            originalResources: [i, i + 1],
+          });
+        }
+      }
+      this.$set(this, `rightList`, list);
+      this.$set(this, `resourcesList`, resourcesList);
+      this.$set(this, `tableData`, tableList);
+    },
+  },
+};
+</script>
+
+<style lang="scss" scoped>
+h1,
+h2,
+h3,
+h4,
+h5,
+h6 {
+  margin: 0;
+  padding: 0;
+}
+.register {
+  width: 100%;
+  padding: 20px;
+}
+.btn {
+  width: 100%;
+  height: 40px;
+  line-height: 40px;
+  margin: 20px 0;
+}
+.search {
+  height: 40px;
+  line-height: 40px;
+  margin: 0 0 20px 0;
+}
+.searchSel .el-select {
+  border-radius: 0;
+}
+/deep/.searchInp .el-input__inner {
+  border-radius: 0;
+}
+.searchBtn .el-button {
+  border-radius: 0;
+}
+.paging {
+  text-align: right;
+  margin: 10px 0;
+}
+.sizeA {
+  padding: 30px;
+}
+</style>

+ 63 - 0
src/views/role/confers.vue

@@ -0,0 +1,63 @@
+<template lang="html">
+  <div id="confers">
+    <el-row class="register">
+      <el-col :span="24" class="btn">
+        <el-row :gutter="10">
+          <el-col :span="20"><h3>权限管理</h3></el-col>
+        </el-row>
+      </el-col>
+      <el-col :span="24" style="background:#fff;">
+        <el-tabs v-model="activeName" type="card">
+          <el-tab-pane label="群组-权限/资源管理" name="first">
+            <group-role type="群组"></group-role>
+          </el-tab-pane>
+          <el-tab-pane label="角色-权限/资源管理" name="second">
+            <group-role type="角色"></group-role>
+          </el-tab-pane>
+          <el-tab-pane label="人员-权限/资源管理" name="third">
+            <group-role type="人员"></group-role>
+          </el-tab-pane>
+        </el-tabs>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import groupRole from './confer/group_role.vue';
+export default {
+  name: 'confers',
+  props: {},
+  components: {
+    groupRole,
+  },
+  data: () => ({
+    activeName: 'first',
+  }),
+  created() {},
+  computed: {},
+  methods: {},
+};
+</script>
+
+<style lang="scss" scoped>
+h1,
+h2,
+h3,
+h4,
+h5,
+h6 {
+  margin: 0;
+  padding: 0;
+}
+.register {
+  width: 100%;
+  padding: 20px;
+}
+.btn {
+  width: 100%;
+  height: 40px;
+  line-height: 40px;
+  margin: 20px 0;
+}
+</style>

+ 14 - 11
src/views/role/group.vue

@@ -5,7 +5,7 @@
         <el-row :gutter="10">
           <el-col :span="20"><h3>群组管理</h3></el-col>
           <!-- 批量导入按钮没加 -->
-          <el-col :span="4"><el-button type="success" icon="el-icon-plus" @click="dialog = true">群组添加</el-button></el-col>
+          <el-col :span="4"><el-button type="success" icon="el-icon-plus" @click="openDialog()">群组添加</el-button></el-col>
         </el-row>
       </el-col>
       <el-col :span="24" class="search">
@@ -52,7 +52,7 @@
         </el-row>
       </el-form>
       <div slot="footer" class="dialog-footer">
-        <el-button @click="dialog = false">取 消</el-button>
+        <el-button @click="handleCancel">取 消</el-button>
         <el-button type="primary" @click="handleEdit">确 定</el-button>
       </div>
     </el-dialog>
@@ -128,7 +128,6 @@ export default {
       } else {
         this.tableData.push(form);
       }
-
       this.handleCancel();
     },
     handleCancel() {
@@ -136,15 +135,19 @@ export default {
       this.dialog = false;
     },
     openDialog(index, type) {
-      let data = JSON.parse(JSON.stringify(this.tableData[index]));
-      data[`index`] = index;
-      if (type === 'update') {
-        this.dialog = true;
-        this.$set(this, `form`, data);
+      if (index !== undefined) {
+        let data = JSON.parse(JSON.stringify(this.tableData[index]));
+        data[`index`] = index;
+        if (type === 'update') {
+          this.dialog = true;
+          this.$set(this, `form`, data);
+        } else {
+          this.dialogAssign = true;
+          this.$set(this, `assignFrom`, data);
+        }
       } else {
-        this.dialogAssign = true;
-
-        this.$set(this, `assignFrom`, data);
+        this.form = {};
+        this.dialog = true;
       }
     },
     handleAssign() {

+ 1 - 8
src/views/role/resources.vue

@@ -74,7 +74,7 @@
         </el-row>
       </el-form>
       <div slot="footer" class="dialog-footer">
-        <el-button @click="dialog = false">取 消</el-button>
+        <el-button @click="handleCancel">取 消</el-button>
         <el-button type="primary" @click="handleEdit">确 定</el-button>
       </div>
     </el-dialog>
@@ -152,13 +152,6 @@ export default {
       this.$set(this.form, `state`, data.state);
       this.$set(this.tableData[index].children[itemIndex], `state`, data.state);
     },
-    handleClose(done) {
-      this.$confirm('确认关闭?')
-        .then(_ => {
-          done();
-        })
-        .catch(_ => {});
-    },
   },
 };
 </script>

+ 171 - 0
src/views/role/right.vue

@@ -0,0 +1,171 @@
+<template lang="html">
+  <div id="right">
+    <el-row class="register">
+      <el-col :span="24" class="btn">
+        <el-row :gutter="10">
+          <el-col :span="20"><h3>权限管理</h3></el-col>
+          <!-- 批量导入按钮没加 -->
+          <el-col :span="4"><el-button type="success" icon="el-icon-plus" @click="openDialog()">权限添加</el-button></el-col>
+        </el-row>
+      </el-col>
+      <el-col :span="24" class="search">
+        <el-col :span="5" class="searchInp"><el-input v-model="input" placeholder="请输入内容"></el-input></el-col>
+        <el-col :span="2" class="searchBtn"><el-button icon="el-icon-search"></el-button></el-col>
+      </el-col>
+      <el-col :span="24" class="list">
+        <el-table :data="tableData" style="width: 100%" border stripe>
+          <el-table-column prop="name" align="center" label="权限名称"> </el-table-column>
+          <el-table-column label="操作" align="center">
+            <template v-slot="scoped">
+              <el-row type="flex" justify="center">
+                <el-col :span="6">
+                  <el-button size="mini" type="text" @click="openDialog(scoped.$index)">修改</el-button>
+                </el-col>
+              </el-row>
+            </template>
+          </el-table-column>
+        </el-table>
+        <el-col class="paging">
+          <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination>
+        </el-col>
+      </el-col>
+    </el-row>
+    <el-dialog title="权限编辑" :visible.sync="dialog">
+      <el-form :model="form" label-position="left" label-width="auto" style="padding: 0 5px;">
+        <el-row>
+          <el-col :span="24">
+            <el-form-item label="权限名称">
+              <el-input v-model="form.name" clearable></el-input>
+            </el-form-item>
+          </el-col>
+        </el-row>
+      </el-form>
+      <el-row>
+        <el-col :span="24" style="padding-left:4rem;">
+          <el-transfer v-model="form.children" :data="rightList" :titles="['未添加', '已添加']" :button-texts="['删除', '添加']"></el-transfer>
+        </el-col>
+      </el-row>
+
+      <div slot="footer" class="dialog-footer">
+        <el-button @click="handleCancel">取 消</el-button>
+        <el-button type="primary" @click="handleEdit">确 定</el-button>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'right',
+  props: {},
+  components: {},
+  data: () => ({
+    input: '',
+    tableData: [
+      {
+        name: '权限1',
+        children: [1],
+      },
+      {
+        name: '权限2',
+        children: [2, 3],
+      },
+      {
+        name: '权限3',
+      },
+      {
+        name: '权限4',
+      },
+    ],
+    rightList: [],
+    value: '',
+    dialog: false,
+    form: {},
+    assignFrom: {},
+  }),
+  created() {
+    let list = [];
+    for (let i = 0; i < 10; i++) {
+      list.push({
+        key: i,
+        label: `能力${i}`,
+      });
+    }
+    this.$set(this, `rightList`, list);
+  },
+  computed: {},
+  methods: {
+    handleEdit() {
+      let chData = this.form;
+      const { index, ...form } = chData;
+      form['state'] = 1;
+      console.log(index, form);
+      if (index !== undefined) {
+        this.$set(this.tableData, `${index}`, form);
+        this.$message.success('修改成功');
+      } else {
+        this.tableData.push(form);
+      }
+
+      this.handleCancel();
+    },
+    handleCancel() {
+      this.form = {};
+      this.dialog = false;
+    },
+    openDialog(index) {
+      if (index !== undefined) {
+        let data = JSON.parse(JSON.stringify(this.tableData[index]));
+        data[`index`] = index;
+        this.$set(this, `form`, data);
+      } else {
+        this.form = {};
+      }
+      this.dialog = true;
+    },
+  },
+};
+</script>
+
+<style lang="scss" scoped>
+h1,
+h2,
+h3,
+h4,
+h5,
+h6 {
+  margin: 0;
+  padding: 0;
+}
+.register {
+  width: 100%;
+  padding: 20px;
+}
+.btn {
+  width: 100%;
+  height: 40px;
+  line-height: 40px;
+  margin: 20px 0;
+}
+.search {
+  height: 40px;
+  line-height: 40px;
+  margin: 0 0 20px 0;
+}
+.searchSel .el-select {
+  border-radius: 0;
+}
+/deep/.searchInp .el-input__inner {
+  border-radius: 0;
+}
+.searchBtn .el-button {
+  border-radius: 0;
+}
+.paging {
+  text-align: right;
+  margin: 10px 0;
+}
+.sizeA {
+  padding: 30px;
+}
+</style>

+ 14 - 11
src/views/role/role.vue

@@ -5,7 +5,7 @@
         <el-row :gutter="10">
           <el-col :span="20"><h3>角色管理</h3></el-col>
           <!-- 批量导入按钮没加 -->
-          <el-col :span="4"><el-button type="success" icon="el-icon-plus" @click="dialog = true">角色添加</el-button></el-col>
+          <el-col :span="4"><el-button type="success" icon="el-icon-plus" @click="openDialog()">角色添加</el-button></el-col>
         </el-row>
       </el-col>
       <el-col :span="24" class="search">
@@ -44,7 +44,7 @@
         </el-row>
       </el-form>
       <div slot="footer" class="dialog-footer">
-        <el-button @click="dialog = false">取 消</el-button>
+        <el-button @click="handleCancel">取 消</el-button>
         <el-button type="primary" @click="handleEdit">确 定</el-button>
       </div>
     </el-dialog>
@@ -112,7 +112,6 @@ export default {
       } else {
         this.tableData.push(form);
       }
-
       this.handleCancel();
     },
     handleCancel() {
@@ -120,15 +119,19 @@ export default {
       this.dialog = false;
     },
     openDialog(index, type) {
-      let data = JSON.parse(JSON.stringify(this.tableData[index]));
-      data[`index`] = index;
-      if (type === 'update') {
-        this.dialog = true;
-        this.$set(this, `form`, data);
+      if (index !== undefined) {
+        let data = JSON.parse(JSON.stringify(this.tableData[index]));
+        data[`index`] = index;
+        if (type === 'update') {
+          this.dialog = true;
+          this.$set(this, `form`, data);
+        } else {
+          this.dialogAssign = true;
+          this.$set(this, `assignFrom`, data);
+        }
       } else {
-        this.dialogAssign = true;
-
-        this.$set(this, `assignFrom`, data);
+        this.form = {};
+        this.dialog = true;
       }
     },
     handleAssign() {