Browse Source

权限控制

Lijy 3 years ago
parent
commit
325e62abef

+ 19 - 0
fhKeeper/formulahousekeeper/timesheet/config/index.js

@@ -34,6 +34,23 @@ module.exports = {
     assetsSubDirectory: 'static',
     assetsSubDirectory: 'static',
     assetsPublicPath: '/',
     assetsPublicPath: '/',
     proxyTable: {
     proxyTable: {
+        // '/api/permission': {
+        //   target: 'http://' + ip + ':2022',
+        //   pathRewrite: {'^api': '/'}
+        // },
+        // '/api/user': {
+        //   target: 'http://' + ip + ':10010',
+        //   pathRewrite: {'^api': '/'}
+        // }
+        '/api/permission': {    
+            target: 'http://'+ ip +':2022',
+            secure: true,
+            changeOrigin: true,
+            pathRewrite: {
+                '^/api': '/' 
+            }
+        },
+
         '/api': {    
         '/api': {    
             target: 'http://'+ ip +':10010',
             target: 'http://'+ ip +':10010',
             secure: true,
             secure: true,
@@ -43,6 +60,8 @@ module.exports = {
             }
             }
         },
         },
 
 
+
+
         // '/ips': {    
         // '/ips': {    
         //     target: 'http://'+ ip +':8080',
         //     target: 'http://'+ ip +':8080',
         //     secure: true,
         //     secure: true,

+ 29 - 4
fhKeeper/formulahousekeeper/timesheet/src/routes.js

@@ -68,6 +68,9 @@ import customData from './views/project/custom_data';
 // 研究中心
 // 研究中心
 // import research from './views/research/list';
 // import research from './views/research/list';
 
 
+// 角色权限
+import quanx from './views/quanx/quanx'
+
 Vue.use(Router)
 Vue.use(Router)
 
 
 export const fixedRouter = [
 export const fixedRouter = [
@@ -315,15 +318,37 @@ export const allRouters = [//组织架构
         ]
         ]
     },
     },
     //设置时间类型
     //设置时间类型
-    {
+    // {
         
         
+    //     path: '/',
+    //     component: Home,
+    //     name: '',
+    //     iconCls: 'iconfont firerock-iconsetting',
+    //     leaf: true,//只有一个节点
+    //     children: [
+    //         { path: '/timetype', component: timetype, name: '系统基础设置' },
+    //     ]
+    // },
+    // {
+    //     path: '/',
+    //     component: Home,
+    //     name: '基础数据管理',
+    //     iconCls: 'iconfont firerock-iconsetting',
+    //     leaf: false,//只有一个节点
+    //     children: [
+    //         { path: '/timetype', component: infrastructure, name: '系统基础设置', iconCls: 'iconfont firerock-iconsetting' },
+    //         { path: '/quanx', component: quanx, name: '角色权限管理', iconCls: 'iconfont firerock-iconsetting' }
+    //     ]
+    // },
+    {
         path: '/',
         path: '/',
         component: Home,
         component: Home,
-        name: '',
+        name: '基础数据管理',
         iconCls: 'iconfont firerock-iconsetting',
         iconCls: 'iconfont firerock-iconsetting',
-        leaf: true,//只有一个节点
+        leaf: false,//只有一个节点
         children: [
         children: [
-            { path: '/timetype', component: timetype, name: '系统基础设置' },
+            { path: '/timetype', component: timetype, name: '系统基础设置', iconCls: 'iconfont firerock-iconsetting'},
+            { path: '/quanx', component: quanx, name: '角色权限管理', iconCls: 'iconfont firerock-iconsetting' }
         ]
         ]
     },
     },
     {
     {

+ 2 - 2
fhKeeper/formulahousekeeper/timesheet/src/views/Home.vue

@@ -43,7 +43,7 @@
                                 <el-link type="primary" :underline="false" @click="locationHerf(scope.row.id,scope.row.content, scope.row.type)">
                                 <el-link type="primary" :underline="false" @click="locationHerf(scope.row.id,scope.row.content, scope.row.type)">
                                     <span style="font-size:13px;">{{scope.row.msg==null?msgTypeTxt[scope.row.type]:scope.row.msg}}</span>
                                     <span style="font-size:13px;">{{scope.row.msg==null?msgTypeTxt[scope.row.type]:scope.row.msg}}</span>
                                 </el-link>
                                 </el-link>
-                            </template>
+                            </template> 
                         </el-table-column>
                         </el-table-column>
                         <el-table-column property="type" label="状态" align="center" width="60">
                         <el-table-column property="type" label="状态" align="center" width="60">
                             <template slot-scope="scope">
                             <template slot-scope="scope">
@@ -81,7 +81,7 @@
                                 <i :class="item.iconCls"></i>
                                 <i :class="item.iconCls"></i>
                                 <span class="itemName">{{item.name}}</span>
                                 <span class="itemName">{{item.name}}</span>
                             </template>
                             </template>
-                            <el-menu-item v-for="child in item.children" :index="child.path" :key="child.path" v-if="!child.hidden">{{child.name}}</el-menu-item>
+                            <el-menu-item v-for="child in item.children" :index="child.path" :key="child.path" v-if="!child.hidden"><i :class="item.iconCls"></i>{{child.name}}</el-menu-item>
                         </el-submenu>
                         </el-submenu>
                         <el-menu-item v-if="item.leaf && item.children.length > 0" :index="item.children[0].path">
                         <el-menu-item v-if="item.leaf && item.children.length > 0" :index="item.children[0].path">
                             <i :class="item.iconCls"></i> {{item.children[0].name}}
                             <i :class="item.iconCls"></i> {{item.children[0].name}}

+ 348 - 0
fhKeeper/formulahousekeeper/timesheet/src/views/quanx/quanx.vue

@@ -0,0 +1,348 @@
+<template>
+  <div>
+      <!-- 表头 -->
+      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
+          <el-form :inline="true">
+              <el-form-item label="角色权限">
+              </el-form-item>
+              <el-form-item >
+                  <div>
+                  <el-input style="float:left;" v-model="keyword" class="input-with-select" placeholder="请输入关键字查询" clearable="true">
+                      <el-button slot="append" @click="mohu" @clear="mohus" icon="el-icon-search"></el-button>
+                  </el-input>
+                  </div>
+              </el-form-item>
+              <el-form-item>
+                  <el-link type="primary" :underline="false" @click="handleAdd('添加角色', '立即添加')">添加角色</el-link>
+              </el-form-item>
+          </el-form>
+      </el-col>
+      <!-- 表格 -->
+      <el-table :data="tableData" style="width: 100%" height="615">
+        <el-table-column prop="rolename" label="角色"></el-table-column>
+        <el-table-column prop="roleDescribe" label="描述"></el-table-column>
+        <el-table-column prop="date" label="操作">
+            <template slot-scope="scope">
+                <div>
+                    <el-button type="primary" size="small" @click="handleAdd('编辑角色', '立即修改', scope.row)">编辑角色</el-button>
+                    <el-button type="primary" size="small" @click="shisha(scope.row.companyId),dialogVisible = true">分配权限</el-button>
+                    <el-button type="danger" size="small" @click="deteHand(scope.row)">删除</el-button>
+                </div>
+            </template>
+        </el-table-column>
+      </el-table>
+      <!--工具条-->
+        <!-- <el-col :span="24" class="toolbar">
+            <el-pagination
+                @size-change="handleSizeChange"
+                @current-change="handleCurrentChange"
+                :page-sizes="[20 , 50 , 80 , 100]"
+                :page-size="20"
+                layout="total, sizes, prev, pager, next"
+                :total="total"
+                style="float:right;"
+            ></el-pagination>
+        </el-col> -->
+        <!-- 分配权限弹窗 -->
+        <el-dialog title="分配权限" :visible.sync="dialogVisible" width="600" :before-close="handleClose">
+            <div>
+                <!-- <el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input> -->
+                <!-- <el-tree :data="data" show-checkbox node-key="id" :filter-node-method="filterNode" ref="tree" :default-expanded-keys="[2, 3]" :default-checked-keys="[5]" :props="defaultProps"> </el-tree> -->
+                <el-form ref="form" :model="form" label-width="80px">
+                <!-- 分模块展示功能项 -->
+                <el-form-item>
+                  <ul>
+                    <li v-for="mainMenu in moduleList" :key="mainMenu.id">
+                      <el-checkbox :label="mainMenu.name" name="type" v-model="mainMenu.checked" style="font-weight:bold;" @change="mainChange(mainMenu)"></el-checkbox>
+                      <ul v-if="mainMenu.children">
+                        <li v-for="subMenu in mainMenu.children" :key="subMenu.id">
+                        <el-checkbox :label="subMenu.name" name="type" v-model="subMenu.checked" style="font-weight:bold;" @change="subChange(subMenu)"></el-checkbox>
+                            <span v-if="subMenu.functionList && subMenu.functionList.length > 0" style="margin-right:10px;margin-left:10px;">(功能:  
+                              <el-checkbox v-for="fun in subMenu.functionList" :key="fun.id" :label="fun.name" name="type" v-model="fun.checked" @change="funChange(fun)"></el-checkbox>)</span>
+                        </li>
+                      </ul>
+                    </li>
+                  </ul>
+                </el-form-item>
+                </el-form>
+                <el-button type="primary" size="small" @click="saveList()">保存</el-button>
+            </div>
+        </el-dialog>
+        <!-- 添加角色弹窗 -->
+        <el-dialog :title="titles" :visible.sync="addDialogVisible" width="600" :before-close="handleClose">
+            <div>
+                <el-form ref="form" :model="form" label-width="80px">
+                    <el-form-item label="角色名称">
+                        <el-input v-model="form.rolename" clearable></el-input>
+                    </el-form-item>
+                    <el-form-item label="描述">
+                        <el-input type="textarea" v-model="form.roleDescribe" clearable></el-input>
+                    </el-form-item>
+                    <el-form-item>
+                        <el-button type="primary" @click="onSubmit()">{{addTil}}</el-button>
+                    </el-form-item>
+                </el-form>
+            </div>
+        </el-dialog>
+  </div>
+</template>
+
+<script>
+export default {
+  props: {},
+  components: {},
+  watch: {
+      filterText(val) {
+        this.$refs.tree.filter(val);
+      }
+  },
+  data() {
+    return {
+        user: JSON.parse(sessionStorage.getItem("user")),
+        tableData: [],
+        total: 0,
+        dialogVisible: false,
+        filterText: '',
+        addDialogVisible: false,
+        form: {
+            rolename: '',
+            roleDescribe: '',
+            id: ''
+        },
+        moduleList: [],
+        roles: '',
+        titles: '',
+        addTil: '立即添加',
+        keyword: '',
+        auseList: []
+    };
+  },
+  computed: {},
+  watch: {
+      filterText(val) {
+        this.$refs.tree.filter(val);
+      },
+      keyword(val) {
+        if(val == '') {
+          this.mohu()
+        }
+      }
+  },
+  created() {},
+  mounted() {
+    this.getRole()
+    // this.shisha()
+  },
+  methods: {
+      // 模糊匹配
+      mohu() {
+        console.log(this.keyword)
+        if(this.keyword == '') {
+          this.tableData = this.auseList
+          return
+        }
+        var len = this.auseList.length;
+        var arr = []
+        for(var i = 0; i < len; i++){
+            if(this.auseList[i].rolename.indexOf(this.keyword)>=0){
+                arr.push(this.auseList[i]);
+            }
+        }
+        this.tableData = arr
+      },
+      // 还不知道是啥
+      shisha(id) {
+        this.roles = id
+        this.http.post('/permission/getAuthority', {
+          companyId: this.user.companyId,
+          role: id
+        },
+        res => {
+            if (res.code == "ok") {
+              console.log(res.data, '数据来源(990)')
+              this.moduleList = res.data
+            } else {
+                this.$message({
+                    message: res.msg,
+                    type: "error"
+                });
+            }
+        },
+        error => {
+            this.$message({
+                message: error,
+                type: "error"
+            });
+        });
+      },
+      // 获取权限列表
+      getRole() {
+        this.http.post('/permission/getRoleList', {
+          companyId: this.user.companyId
+        },
+        res => {
+            if (res.code == "ok") {
+              console.log(res.data, '数据来源')
+              this.tableData = res.data
+              this.auseList = res.data
+            } else {
+                this.$message({
+                    message: res.msg,
+                    type: "error"
+                });
+            }
+        },
+        error => {
+            this.$message({
+                message: error,
+                type: "error"
+            });
+        });
+      },
+      handleSizeChange() {},
+      handleCurrentChange() {},
+      filterNode(value, data) {
+        if (!value) return true;
+        return data.label.indexOf(value) !== -1;
+      },
+        handleAdd(tex, tel, id) {
+          this.titles = tex
+          this.addTil = tel
+          this.addDialogVisible = true
+          // var ss = {rolename: '', roleDescribe: '',id: ''}
+          var ss = {}
+          id ? ss.id = id.id : ss.id = ''
+          id ? ss.rolename = id.rolename : ss.rolename = ''
+          id ? ss.roleDescribe = id.roleDescribe : ss.roleDescribe = ''
+          this.form = ss
+      },
+      // 添加角色
+      onSubmit() {
+          // var ss = this.form
+          this.http.post('/permission/editRole', {
+            id: this.form.id,
+            name: this.form.rolename,
+            description: this.form.roleDescribe,
+            companyId: this.user.companyId
+          },
+          res => {
+              if (res.code == "ok") {
+                console.log(res.data, '数据来源(123)')
+                this.addDialogVisible = false
+                this.getRole()
+              } else {
+                  this.$message({
+                      message: res.msg,
+                      type: "error"
+                  });
+              }
+          },
+          error => {
+              this.$message({
+                  message: error,
+                  type: "error"
+              });
+          });
+      },
+      deteHand(item) {
+        this.$confirm('此操作将删除('+item.rolename+')角色, 是否继续?', '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }).then(() => {
+          this.http.post('/permission/deleteRole', {
+            id: item.id,
+          },
+          res => {
+              if (res.code == "ok") {
+                this.$message({
+                      message: '删除成功',
+                      type: "success"
+                  });
+                this.getRole()
+              } else {
+                  this.$message({
+                      message: res.msg,
+                      type: "error"
+                  });
+              }
+          },
+          error => {
+              this.$message({
+                  message: error,
+                  type: "error"
+              });
+          });
+        }).catch(() => {});
+      },
+      mainChange(mainMenu) {
+        //一级选中,全部选中,一级取消全部取消
+        console.log(mainMenu);
+        mainMenu.children.forEach(c=>{
+            c.checked = mainMenu.checked;
+            c.functionList.forEach(f=>{
+                f.checked = mainMenu.checked;
+            });
+        });
+      },
+      subChange(subMenu) {
+        //二级选中,自动勾选对应的一级
+        console.log(subMenu);
+        let mainMenuList = this.moduleList;
+        mainMenuList.forEach(m=>{
+          //检测子菜单
+          if (m.id == subMenu.parentId) {
+            //找到父菜单了
+            var hasChecked = false;
+            m.children.forEach(c=>{
+                if (c.checked) {
+                    hasChecked = true;
+                }
+            })
+            //当前点击的子菜单所有同级菜单是否有点中的,如果没有需要把父级取消勾选
+            m.checked = hasChecked;
+          }
+        });
+
+        //子功能全部勾上,取消
+        subMenu.functionList.forEach(f=>{
+          f.checked = subMenu.checked;
+        })
+      },
+      saveList() {
+        this.dialogVisible = false
+        console.log(this.moduleList)
+        this.http.post('/permission/savePermission', {
+            role: this.roles,
+            moduleList: JSON.stringify(this.moduleList),
+          },
+          res => {
+              if (res.code == "ok") {
+                this.$message({
+                      message: '操作成功',
+                      type: "success"
+                  });
+                this.getRole()
+              } else {
+                  this.$message({
+                      message: res.msg,
+                      type: "error"
+                  });
+              }
+          },
+          error => {
+              this.$message({
+                  message: error,
+                  type: "error"
+              });
+          });
+      }
+  },
+};
+</script>
+
+<style scoped>
+  li {
+    list-style: none;
+  }
+</style>