| | |
| | | visible() { |
| | | if (this.visible) { |
| | | this.isShowDialog = this.visible; |
| | | return new Promise((resolve, reject) => { |
| | | getButtonByParentCode({code: this.classifyData.attributes.id}).then(res => { |
| | | // 记录按钮数据 |
| | | this.classifyAuthButton = res.data.data; |
| | | const list = res.data.data; |
| | | let tempData = []; |
| | | // 角色列 |
| | | tempData.push({ |
| | | label: "角色", |
| | | prop: "roleData", |
| | | type: "select", |
| | | width: 150, |
| | | }); |
| | | // 编码项分类授权 |
| | | tempData.push({ |
| | | label: "编码项数据授权", |
| | | prop: "classifyItem", |
| | | type: "text", |
| | | width: 180, |
| | | }); |
| | | list.forEach(item => { |
| | | let columnItem = { |
| | | label: item.name, |
| | | prop: item.id, |
| | | code: item.code, |
| | | type: "checkbox", |
| | | width: 180, |
| | | }; |
| | | tempData.push(columnItem); |
| | | }) |
| | | this.classifyAuthHeader = tempData |
| | | resolve(); |
| | | }).catch(err => { |
| | | reject(err) |
| | | }); |
| | | // 获取角色列表 |
| | | getPage(1, -1, null).then(res => { |
| | | this.roleList = res.data.data.records; |
| | | }); |
| | | // 获取该分类下已授权的分类授权信息 |
| | | getClassifyAuthList({classifyId: this.classifyData.oid, authType: "data_auth"}).then(res => { |
| | | //console.log(res.data.data); |
| | | let authDatas = res.data.data; |
| | | if (authDatas.length > 0) { |
| | | authDatas.forEach((authData, index) => { |
| | | let item = { |
| | | oid: authData.oid, |
| | | roleData: authData.roleId, |
| | | classifyItem: this.classifyData.label, |
| | | index: index, |
| | | authButton:{}, |
| | | uuid: uuidv4(),//生成唯一的id |
| | | } |
| | | //将按钮设置进去 |
| | | authData.buttonIdList.forEach(data => { |
| | | Vue.set(item, data, true); |
| | | }); |
| | | this.classifyAuthData.push(item); |
| | | this.addIndex = this.classifyAuthData.length - 1; //添加行下标等于classifyAuthData的长度-1 |
| | | this.roleHandlerMethods(authData.roleId, 'create', index) |
| | | }) |
| | | } |
| | | }); |
| | | }); |
| | | this.loadAuthPage(); |
| | | } |
| | | }, |
| | | }, |
| | |
| | | this.selectList = list; |
| | | }, |
| | | // 保存分类授权信息 |
| | | submit() { |
| | | if (this.classifyAuthData.length <= 0) { |
| | | this.$message.warning('授权列表为空!') |
| | | return; |
| | | } |
| | | async submit() { |
| | | let form = { |
| | | classifyAuthList: [], |
| | | isCLear: false, //默认是清空 |
| | | classifyId: this.classifyData.oid, |
| | | }; |
| | | let isRepeat = false; |
| | | // 遍历数组,比较后面的对象的roleData是否与前面的对象相等 |
| | | for (let i = 0; i < this.classifyAuthData.length - 1; i++) { |
| | | let currentRoleId = this.classifyAuthData[i].roleData; |
| | | for (let j = i + 1; j < this.classifyAuthData.length; j++) { |
| | | if (currentRoleId === this.classifyAuthData[j].roleData) { |
| | | isRepeat = true; |
| | | if (this.classifyAuthData.length > 0) { |
| | | // 遍历数组,比较后面的对象的roleData是否与前面的对象相等 |
| | | for (let i = 0; i < this.classifyAuthData.length - 1; i++) { |
| | | let currentRoleId = this.classifyAuthData[i].roleData; |
| | | for (let j = i + 1; j < this.classifyAuthData.length; j++) { |
| | | if (currentRoleId === this.classifyAuthData[j].roleData) { |
| | | isRepeat = true; |
| | | break; |
| | | } |
| | | } |
| | | if (isRepeat) { |
| | | break; |
| | | } |
| | | } |
| | | if (isRepeat) { |
| | | break; |
| | | } |
| | | } |
| | | if (isRepeat) { |
| | | this.$message.warning("角色和分类已经存在,请重新配置!"); |
| | | return; |
| | | } |
| | | let form = []; |
| | | let flag = false; |
| | | this.classifyAuthData.forEach(item => { |
| | | let itemButtonList = []; |
| | | //筛选出按钮勾选为true的列 |
| | | for (let key in item) { |
| | | if (item[key] === true) { |
| | | itemButtonList.push(key); |
| | | } |
| | | } |
| | | /**如果itemButtonList为空证明是, |
| | | 添加了角色但是没勾选任何的按钮*/ |
| | | if (itemButtonList.length <= 0) { |
| | | flag = true; |
| | | this.$message.warning("角色和分类已经存在,请重新配置!"); |
| | | return; |
| | | } |
| | | let data = { |
| | | oid: item.oid, |
| | | roleId: item.roleData, |
| | | classifyId: this.classifyData.oid, |
| | | buttonIds: itemButtonList.join(","), |
| | | authType: "data_auth", |
| | | } |
| | | form.push(data); |
| | | }); |
| | | if (flag) { |
| | | this.$message.warning('有未勾选操作的权限,不允许授权') |
| | | return; |
| | | } |
| | | // console.log(form) |
| | | // 调用保存分类授权的接口 |
| | | saveOrUpdate(form).then(res => { |
| | | this.$message({ |
| | | type: "success", |
| | | message: res.data.msg, |
| | | let flag = false; |
| | | this.classifyAuthData.forEach(item => { |
| | | let itemButtonList = []; |
| | | //筛选出按钮勾选为true的列 |
| | | for (let key in item) { |
| | | if (item[key] === true) { |
| | | itemButtonList.push(key); |
| | | } |
| | | } |
| | | /**如果itemButtonList为空证明是, |
| | | 添加了角色但是没勾选任何的按钮*/ |
| | | if (itemButtonList.length <= 0) { |
| | | flag = true; |
| | | return; |
| | | } |
| | | let data = { |
| | | oid: item.oid, |
| | | roleId: item.roleData, |
| | | classifyId: this.classifyData.oid, |
| | | buttonIds: itemButtonList.join(","), |
| | | authType: "data_auth", |
| | | } |
| | | form.classifyAuthList.push(data); |
| | | }); |
| | | // this.isShowDialog = false |
| | | }, (error) => { |
| | | window.console.log(error); |
| | | }) |
| | | if (flag) { |
| | | this.$message.warning('有未勾选操作的权限,不允许授权') |
| | | return; |
| | | } |
| | | // console.log(form) |
| | | // 调用保存分类授权的接口 |
| | | await saveOrUpdate(form).then(res => { |
| | | this.$message({ |
| | | type: "success", |
| | | message: res.data.msg, |
| | | }); |
| | | // this.isShowDialog = false |
| | | }, (error) => { |
| | | window.console.log(error); |
| | | }) |
| | | }else{ |
| | | // 为空证明是清空授权列表 |
| | | form.isCLear = true; |
| | | } |
| | | this.classifyAuthData = []; |
| | | this.loadAuthPage(); |
| | | }, |
| | | // 全选按钮 |
| | | selectAllButton() { |
| | |
| | | }); |
| | | //console.log("this.selectList",this.selectList); |
| | | }, |
| | | loadAuthPage() { |
| | | return new Promise((resolve, reject) => { |
| | | console.log(this.classifyData); |
| | | getButtonByParentCode({code: this.classifyData.attributes.id}).then(res => { |
| | | // 记录按钮数据 |
| | | this.classifyAuthButton = res.data.data; |
| | | const list = res.data.data; |
| | | let tempData = []; |
| | | // 角色列 |
| | | tempData.push({ |
| | | label: "角色", |
| | | prop: "roleData", |
| | | type: "select", |
| | | width: 150, |
| | | }); |
| | | // 编码项分类授权 |
| | | tempData.push({ |
| | | label: "编码项数据授权", |
| | | prop: "classifyItem", |
| | | type: "text", |
| | | width: 180, |
| | | }); |
| | | list.forEach(item => { |
| | | let columnItem = { |
| | | label: item.name, |
| | | prop: item.id, |
| | | code: item.code, |
| | | type: "checkbox", |
| | | width: 180, |
| | | }; |
| | | tempData.push(columnItem); |
| | | }) |
| | | this.classifyAuthHeader = tempData |
| | | resolve(); |
| | | }).catch(err => { |
| | | reject(err) |
| | | }); |
| | | // 获取角色列表 |
| | | getPage(1, -1, null).then(res => { |
| | | this.roleList = res.data.data.records; |
| | | }); |
| | | // 获取该分类下已授权的分类授权信息 |
| | | getClassifyAuthList({classifyId: this.classifyData.oid, authType: "data_auth"}).then(res => { |
| | | //console.log(res.data.data); |
| | | let authDatas = res.data.data; |
| | | if (authDatas.length > 0) { |
| | | authDatas.forEach((authData, index) => { |
| | | let item = { |
| | | oid: authData.oid, |
| | | roleData: authData.roleId, |
| | | classifyItem: this.classifyData.label, |
| | | index: index, |
| | | authButton:{}, |
| | | uuid: uuidv4(),//生成唯一的id |
| | | } |
| | | //将按钮设置进去 |
| | | authData.buttonIdList.forEach(data => { |
| | | Vue.set(item, data, true); |
| | | }); |
| | | this.classifyAuthData.push(item); |
| | | this.addIndex = this.classifyAuthData.length - 1; //添加行下标等于classifyAuthData的长度-1 |
| | | this.roleHandlerMethods(authData.roleId, 'create', index) |
| | | }) |
| | | } |
| | | }); |
| | | }); |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |