123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520 |
- <template>
- <div>
- <!-- 表头 -->
- <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
- <el-form :inline="true" style="width: 87%">
- <el-form-item :label="$t('roleauthorization')">
- </el-form-item>
- <el-form-item >
- <div>
- <el-input style="float:left;" v-model="keyword" class="input-with-select" @keyup.enter.native="mohu()" :placeholder="$t('pleaseenterakeyworforquery')" 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 style="float: right">
- <el-link type="primary" :underline="false" @click="handleAdd($t('addingroles'), $t('Immediatelyadd'))">{{ $t('addingroles') }}</el-link>
- <el-link type="primary" :underline="false" @click="modify()" style="margin-left: 20px;">{{ $t('modifyingDefaultRole') }}</el-link>
- <!-- <el-link type="primary" :underline="false" @click="exportAuthority()" style="margin-left:20px">导出所有权限</el-link> -->
- </el-form-item>
- </el-form>
- </el-col>
- <!-- 表格 -->
- <el-table :data="tableData" style="width: 100%" :height="tableHeight">
- <el-table-column prop="rolename" :label="$t('jiao-se')" align="center">
- <template slot-scope="scope">
- {{scope.row.rolename}} <span v-if="scope.row.isDefault == 1" style="color: #909399;"> {{ $t('mo-ren-jiao-se') }}</span>
- </template>
- </el-table-column>
- <el-table-column prop="roleDescribe" :label="$t('other.describe')"></el-table-column>
- <el-table-column prop="date" :label="$t('operation')">
- <template slot-scope="scope">
- <div>
- <el-button size="small" @click="handleAdd($t('editingtherole'), $t('Immediatelychange'), scope.row)" :style="scope.row.rolename != $t('role.superAdministrator') ? '' : 'visibility:hidden;'">{{ $t('editingtherole') }}</el-button>
- <el-button type="primary" size="small" @click="shisha(scope.row.id), roleName = scope.row.rolename" v-if="scope.row.rolename !=$t('role.superAdministrator') || (scope.row.rolename ==$t('role.superAdministrator') && user.roleName == $t('role.superAdministrator'))">{{ $t('assignpermissions') }}</el-button>
- <el-button size="small" @click="exportAuthority(scope.row)" >{{ $t('exportpermission') }}</el-button>
- <el-button type="danger" size="small" @click="deteHand(scope.row)" v-if="scope.row.rolename != $t('role.superAdministrator')">{{ $t('btn.delete') }}</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="$t('assignpermissions') +' - '+roleName" :visible.sync="dialogVisible" width="900px" :before-close="handleClose">
- <div class="quanxians">
- <!-- <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="0px">
- <!-- 分模块展示功能项 -->
- <el-form-item>
- <ul>
- <!-- <li v-for="mainMenu in moduleList" :key="mainMenu.id" style="display: flex;"> -->
- <li v-for="mainMenu in moduleList" :key="mainMenu.id">
- <!-- <div style="width: 20px; display: inline-block;height: 10px"> -->
- <div style="display: inline-block; float: left;width: 20px;height: 10px">
- <span v-if="mainMenu.children.length > 0" @click="dianji(mainMenu)" style="cursor:pointer;"><i :class="mainMenu.useState ? 'el-icon-caret-bottom' : 'el-icon-caret-right'"></i></span>
- </div>
- <span style="display: flex;">
- <el-checkbox :label="mainMenu.name" name="type" v-model="mainMenu.checked" style="font-weight:bold;width: 160px" @change="mainChange(mainMenu)"></el-checkbox>
- <span v-if="mainMenu.functionList && mainMenu.functionList.length > 0" style="margin-right:10px;margin-left:10px;">
- <!-- <div></div>(功能: <el-checkbox v-for="fun in mainMenu.functionList" :key="fun.id" :label="fun.name" name="type" v-model="fun.checked" @change="subChanges(fun, mainMenu.id)"></el-checkbox>) -->
- <span class="gongn"><el-checkbox v-for="fun in mainMenu.functionList" :key="fun.id" :label="fun.name" name="type" v-model="fun.checked" style="width: 170px" @change="subChanges(fun, mainMenu.id)"></el-checkbox></span>
- </span>
- </span>
- <ul v-if="mainMenu.children && mainMenu.useState">
- <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;">({{ $t('gong-neng') }} :
- <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>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button type="primary" @click="saveList()" :loading="saveListDialogVisible">{{ $t('save') }}</el-button>
- </span>
- </el-dialog>
- <!-- 添加角色弹窗 -->
- <el-dialog :title="titles" :visible.sync="addDialogVisible" width="600px" :before-close="handleClose">
- <div>
- <el-form ref="form" :rules="rules" :model="form" label-width="80px">
- <el-form-item :label="$t('charactername')" prop="rolename">
- <el-input v-model="form.rolename" clearable></el-input>
- </el-form-item>
- <el-form-item :label="$t('other.describe')">
- <el-input type="textarea" v-model="form.roleDescribe" maxlength="25" show-word-limit clearable></el-input>
- </el-form-item>
- <el-form-item>
- <el-button style="float: right" type="primary" @click="onSubmit('form')">{{ $t('btn.determine') }}</el-button>
- </el-form-item>
- </el-form>
- </div>
- </el-dialog>
- <!-- 修改默认角色弹窗 -->
- <el-dialog :title="$t('defaultrole')" :visible.sync="defaultRole" width="400px" :before-close="handleClose">
- <div>
- <el-form label-width="80px">
- <el-form-item :label="$t('defaultrole')">
- <el-select v-model="roleId" :placeholder="$t('defaultText.pleaseChoose')">
- <el-option v-for="item in auseList" :key="item.id" :label="item.rolename" :value="item.id"></el-option>
- </el-select>
- </el-form-item>
- <div class="daoru"><span type="info" style="color:#999">{{ $t('defaultroleforimportingpeople') }}</span></div>
- </el-form>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button type="primary" @click="determine()">{{ $t('btn.determine') }}</el-button>
- </span>
- </el-dialog>
- </div>
- </template>
- <script>
- export default {
- props: {},
- components: {},
- watch: {
- filterText(val) {
- this.$refs.tree.filter(val);
- }
- },
- data() {
- return {
- saveListDialogVisible: false,
- user: JSON.parse(sessionStorage.getItem("user")),
- tableData: [],
- total: 0,
- dialogVisible: false,
- filterText: '',
- addDialogVisible: false,
- form: {
- rolename: '',
- roleDescribe: '',
- id: ''
- },
- moduleList: [],
- roles: '',
- titles: '',
- addTil: this.$t('Immediatelyadd'),
- keyword: '',
- auseList: [],
- defaultRole: false,
- roleId: '',
- roleName: '',
- rules: {
- rolename: [{
- required: true, message: this.$t('peaseenterthe'), trigger: 'blur'
- }]
- },
- tableHeight: 0
- };
- },
- computed: {},
- watch: {
- filterText(val) {
- this.$refs.tree.filter(val);
- },
- keyword(val) {
- if(val == '') {
- this.mohu()
- }
- }
- },
- created() {
- let height = window.innerHeight;
- this.tableHeight = height - 125;
- },
- mounted() {
- this.getRole()
- // this.shisha()
- },
- methods: {
- // 默认角色点击确定
- determine() {
- this.http.post('/permission/setDefaultRole', {
- companyId: this.user.companyId,
- id: this.roleId
- },
- res => {
- if (res.code == "ok") {
- this.$message({
- message: this.$t('operationissuccessful'),
- type: "success"
- });
- this.defaultRole = false
- this.getRole()
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- // 默认角色
- modify() {
- for(var i in this.auseList) {
- if(this.auseList[i].isDefault == '1') {
- this.roleId = this.auseList[i].id
- }
- }
- this.defaultRole = true
- },
- // 模糊匹配
- 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)')
- for(var i in res.data) {
- res.data[i].useState = true
- }
- this.moduleList = res.data
- this.dialogVisible = true
- } 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) {
- if(id && id.rolename == this.$t('role.superAdministrator')){
- this.$message(this.$t('administratorcannotbeedited'));
- return
- }
- 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(formName) {
- // var ss = this.form
- this.$refs[formName].validate((valid) => {
- if (valid) {
- 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"
- });
- });
- } else {
- console.log('error submit!!');
- return false;
- }
- });
-
- },
- deteHand(item) {
- this.$confirm(this.$t('operationwilldelete')+'('+item.rolename+')'+this.$t('shifujuxu'), this.$t('other.prompts'), {
- confirmButtonText: this.$t('btn.determine'),
- cancelButtonText: this.$t('btn.cancel'),
- type: 'warning'
- }).then(() => {
- this.http.post('/permission/deleteRole', {
- id: item.id,
- },
- res => {
- if (res.code == "ok") {
- this.$message({
- message: this.$t('message.successfullyDeleted'),
- 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;
- });
- });
- if(mainMenu.functionList) {
- mainMenu.functionList.forEach(c=>{
- c.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;
- }
- });
- },
- subChanges(subMenu, id) {
- let mainMenuList = this.moduleList
- mainMenuList.forEach(m=>{
- if(m.id == id) {
- //找到父菜单了
- var hasChecked = false;
- m.functionList.forEach(c=>{
- if (c.checked) {
- hasChecked = true;
- }
- })
- console.log(hasChecked, '事件')
- // m.checked = hasChecked;
- if(hasChecked) {
- console.log('执行')
- m.checked = hasChecked;
- }
- }
- });
- },
- dianji(item) {
- console.log(item)
- let mainMenuList = this.moduleList
- mainMenuList.forEach(m=>{
- if(m.id == item.id) {
- m.useState = !m.useState
- }
- });
- },
- saveList() {
- this.dialogVisible = false
- this.saveListDialogVisible = true
- this.http.post('/permission/savePermission', {
- role: this.roles,
- moduleList: JSON.stringify(this.moduleList),
- },
- res => {
- this.saveListDialogVisible = false
- if (res.code == "ok") {
- this.$message({
- message: this.$t('operationissuccessful'),
- type: "success"
- });
- this.getRole()
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.saveListDialogVisible = false
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- exportAuthority(row){ // 导出权限
- this.http.post('/permission/exportData',{
- role: row.id,
- companyId: this.user.companyId
- },res => {
- if(res.code == 'ok'){
- var a = document.createElement('a');
- a.download = this.$t('quanxianshuju')+ ".xls";
- a.href = res.data;
- a.click();
- }else{
- this.$message({
- message: res.msg,
- type: 'error'
- })
- }
- },err => {
- this.$message({
- message: err,
- type: 'error'
- })
- })
- }
- },
- };
- </script>
- <style scoped>
- ul {
- padding: 0 0 0 30px;
- margin: 0;
- }
- li {
- list-style: none;
- }
- .quanxians {
- height: 400px;
- width: 100%;
- overflow: auto;
- }
- .gongn {
- display: inline-block;
- width: 620px;
- }
- .daoru {
- margin-left: 10px;
- }
- </style>
|