¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <el-dialog |
| | | v-dialogDrag |
| | | :close-on-click-modal="false" |
| | | :visible.sync="isShowDialog" |
| | | append-to-body |
| | | class="avue-dialog avue-dialog--top" |
| | | title="æ°æ®ææ" |
| | | top="-45px" @close="closeDialog"> |
| | | <el-table |
| | | ref="dataTable" |
| | | v-loading="isLoading" |
| | | :data="classifyAuthData" |
| | | :header-cell-style="{ background: '#FAFAFA', color: '#505050' }" |
| | | :height="tableHeight" |
| | | border |
| | | class="cus-table" |
| | | @select="handleSelection" |
| | | @row-click="handleRowClick" |
| | | @select-all="handleSelectionAll" |
| | | @selection-change="handleSelectionChange" |
| | | @sort-change="sortChange" |
| | | > |
| | | <el-table-column |
| | | type="selection" |
| | | width="55" |
| | | ></el-table-column> |
| | | <el-table-column |
| | | v-for="(item, index) in classifyAuthHeader" |
| | | v-if="classifyAuthHeader.length !== 0" |
| | | :key="index" |
| | | :label="item.label" |
| | | :prop="item.prop" |
| | | :show-overflow-tooltip="true" |
| | | :width="item.width" |
| | | align="center" |
| | | > |
| | | <template slot-scope="{ row }"> |
| | | <el-select |
| | | v-if="item.type === 'select'" |
| | | slot="prepend" |
| | | v-model="row[item.prop]" |
| | | @change="roleChange(row.roleData,row)" |
| | | > |
| | | <el-option |
| | | v-for="optionItem in roleList" |
| | | :key="optionItem.id" |
| | | :label="optionItem.roleName" |
| | | :value="optionItem.id" |
| | | > |
| | | </el-option> |
| | | </el-select> |
| | | <el-input |
| | | v-if="item.type === 'text'" |
| | | v-model="row[item.prop]" |
| | | readonly |
| | | type="text" |
| | | > |
| | | </el-input> |
| | | <el-checkbox |
| | | v-if="item.type === 'checkbox'" |
| | | v-model="row[item.prop]" |
| | | :disabled="row.authButton.allDisabled ? true : row.authButton[item.code]"> |
| | | </el-checkbox> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button plain type="info" @click="selectAllButton">æé®å
¨é</el-button> |
| | | <el-button class="el-icon-plus" plain type="success" @click="addClassifyAuth"></el-button> |
| | | <el-button class="el-icon-minus" plain type="warning" @click="subClassifyAuth"></el-button> |
| | | <el-button plain type="primary" @click="submit">æ 交</el-button> |
| | | <el-button plain type="danger" @click="isShowDialog = false">å
³ é</el-button> |
| | | </div> |
| | | </el-dialog> |
| | | </template> |
| | | |
| | | <script> |
| | | import {getButtonByParentCode} from "@/api/system/menu" |
| | | import {getPage} from "@/api/system/role" |
| | | import {saveOrUpdate, getClassifyAuthList, getButtonsByRoleId} from "@/api/system/classifyAuth" |
| | | import {v4 as uuidv4} from 'uuid'; |
| | | |
| | | export default { |
| | | name: "dataAuthDialog.vue", |
| | | props: { |
| | | classifyData: { |
| | | type: "Object", |
| | | default: "", |
| | | }, |
| | | /**å¯¹è¯æ¡æ¾ç¤ºéèæ§å¶*/ |
| | | visible: { |
| | | type: "Boolean", |
| | | default: false, |
| | | }, |
| | | TreeNode:{ |
| | | type:Object |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | // å¯¹è¯æ¡æ¾ç¤ºæ§å¶ |
| | | isShowDialog: this.visible, |
| | | isLoading: false, |
| | | tableHeight: 'calc(100vh - 550px)', |
| | | classifyAuthData: [], |
| | | //å头 |
| | | classifyAuthHeader: [], |
| | | //æé®æ°æ® |
| | | classifyAuthButton: [], |
| | | //è§è²å表 |
| | | roleList: [], |
| | | //å½åéä¸çè¡¨æ ¼è¡ |
| | | selectList: [], |
| | | itemKey: '', |
| | | addIndex: Number, |
| | | currentRow: {} |
| | | }; |
| | | }, |
| | | watch: { |
| | | // çå¬ç¶ç»ä»¶ä¼ ççªå£æ¾ç¤ºéèçå¼ |
| | | 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) |
| | | }) |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | }, |
| | | }, |
| | | computed: {}, |
| | | mounted() { |
| | | }, |
| | | created() { |
| | | }, |
| | | methods: { |
| | | // å
³éå¯¹è¯æ¡ |
| | | closeDialog() { |
| | | this.$emit('update:visible', false); |
| | | this.classifyAuthData = []; |
| | | }, |
| | | roleHandlerMethods(id, type, index) { |
| | | if (this.classifyAuthData.length === 0) { |
| | | return; |
| | | } |
| | | //filteredItems æªæææ°ç» |
| | | getButtonsByRoleId({roleId: id, code: this.TreeNode.id}).then(res => { |
| | | const filteredItems = this.classifyAuthButton.filter(item => |
| | | !res.data.data.some(x => x.id === item.id) |
| | | ); |
| | | //åè¡¨æ ¼åè¿è¡å¯¹æ¯ |
| | | this.classifyAuthHeader.forEach((item) => { |
| | | const isMatched = filteredItems.some((x) => x.id === item.prop); |
| | | this.$nextTick(() => { |
| | | if (this.classifyAuthData[index]) { |
| | | if (isMatched) { |
| | | Object.keys(this.classifyAuthData[index]).forEach((key) => { |
| | | this.$set(this.classifyAuthData[index].authButton,item.code,true); |
| | | }); |
| | | } else { |
| | | Object.keys(this.classifyAuthData[index]).forEach((key) => { |
| | | this.$set(this.classifyAuthData[index].authButton,item.code,false); |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | //æ·»å âæ¥çâç¦ç¨ |
| | | if (this.classifyAuthData.authButton) { |
| | | this.classifyAuthData.forEach((classkey, classIndex) => { |
| | | if (classkey.authButton.classify_view) { |
| | | this.$set(this.classifyAuthData[classIndex].authButton,"allDisabled",true); |
| | | } else { |
| | | this.classifyAuthData[classIndex].authButton.allDisabled = false; |
| | | } |
| | | }); |
| | | } |
| | | //强å¶å·æ°è¡¨æ ¼ |
| | | this.itemKey = uuidv4(); |
| | | }); |
| | | }, |
| | | // è§è²æ¹åæ¶ |
| | | async roleChange(row, currentRow) { |
| | | try { |
| | | this.currentRow = currentRow; |
| | | const res = await getButtonsByRoleId({roleId: row, code: this.TreeNode.id}); |
| | | |
| | | const filteredItems = this.classifyAuthButton.filter(item => { |
| | | return !res.data.data.find(x => x.id === item.id); |
| | | }); |
| | | |
| | | this.classifyAuthHeader.forEach(item => { |
| | | const isMatched = filteredItems.some(x => x.id === item.prop); |
| | | this.$nextTick(() => { |
| | | if (currentRow) { |
| | | if (isMatched) { |
| | | Object.keys(currentRow).forEach((key) => { |
| | | currentRow.authButton[item.code] = true; |
| | | if (!currentRow.authButton.classify_view) { |
| | | currentRow.authButton.allDisabled = false; |
| | | } |
| | | }); |
| | | } else { |
| | | Object.keys(currentRow).forEach((key) => { |
| | | currentRow.authButton[item.code] = false; |
| | | if (!currentRow.authButton.classify_view) { |
| | | currentRow.authButton.allDisabled = false; |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | this.itemKey = uuidv4(); // 强å¶å·æ°è¡¨æ ¼ |
| | | }); |
| | | }); |
| | | } catch (error) { |
| | | console.error(error); |
| | | } |
| | | }, |
| | | // å¢å è¡ |
| | | addClassifyAuth() { |
| | | if (this.roleList.length <= 0) { |
| | | this.$message.warning("å½åç§æ·ä¸åå¨è§è²ä¿¡æ¯ï¼"); |
| | | return; |
| | | } |
| | | this.addIndex++; //èªå®ä¹çææ·»å è¡ä¸æ |
| | | let item = { |
| | | roleData: this.roleList[0].id, |
| | | classifyItem: this.classifyData.label, |
| | | authButton:{}, |
| | | uuid: uuidv4(),//çæå¯ä¸çid, |
| | | index: this.addIndex, |
| | | } |
| | | //å°æé®è®¾ç½®è¿å» |
| | | this.classifyAuthButton.forEach(data => { |
| | | Vue.set(item, data.id, false); |
| | | }) |
| | | //console.log(item) |
| | | this.classifyAuthData.push(item) |
| | | this.roleHandlerMethods(this.roleList[0].id, 'add', this.addIndex) |
| | | }, |
| | | // å é¤è¡ |
| | | subClassifyAuth() { |
| | | for (let item of this.selectList) { |
| | | let index = this.classifyAuthData.findIndex(data => data.index === item.index); |
| | | if (index !== -1) { |
| | | this.classifyAuthData.splice(index, 1); |
| | | } |
| | | } |
| | | }, |
| | | handleRowClick(row, column) { |
| | | this.selectList.push(row); |
| | | this.$refs.dataTable.toggleRowSelection(row); |
| | | }, |
| | | // å¤é |
| | | handleSelectionChange(list) { |
| | | this.selectList = list; |
| | | //console.log("å¤é"); |
| | | }, |
| | | // éæ©å
¨é¨ |
| | | handleSelectionAll(list) { |
| | | this.selectList = list; |
| | | }, |
| | | // ä¿ååç±»ææä¿¡æ¯ |
| | | submit() { |
| | | if (this.classifyAuthData.length <= 0) { |
| | | this.$message.warning('ææå表为空ï¼') |
| | | return; |
| | | } |
| | | 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; |
| | | 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; |
| | | 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, |
| | | }); |
| | | // this.isShowDialog = false |
| | | }, (error) => { |
| | | window.console.log(error); |
| | | }) |
| | | }, |
| | | // å
¨éæé® |
| | | selectAllButton() { |
| | | if (this.selectList.length !== 1) { |
| | | this.$message.warning("请åªéæ©ä¸è¡éè¦å
¨éçæé®çæ°æ®è¡ï¼"); |
| | | return; |
| | | } |
| | | this.classifyAuthButton.forEach(item => { |
| | | //console.log("item",item); |
| | | Vue.set(this.selectList[0], item.id, true); |
| | | }); |
| | | //console.log("this.selectList",this.selectList); |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | |
| | | // æ»å¨æ¡æ ·å¼ä¿®æ¹ |
| | | // æ»å¨æ¡ç宽度 |
| | | /deep/ .el-table__body-wrapper::-webkit-scrollbar { |
| | | height: 15px; // çºµåæ»å¨æ¡ å¿
å |
| | | background: white; |
| | | border: white; |
| | | width: 10px; |
| | | |
| | | } |
| | | |
| | | // æ»å¨æ¡çæ»å |
| | | /deep/ .el-table__body-wrapper::-webkit-scrollbar-thumb { |
| | | background-color: #ececec; |
| | | border-radius: 20px; |
| | | border: #ececec; |
| | | } |
| | | |
| | | /deep/ .el-table__body-wrapper { |
| | | height: calc(100% - 50px) !important; |
| | | } |
| | | |
| | | </style> |