1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-12 22:29:59 +08:00

fix: Relations in context menu. (#553)

This commit is contained in:
Elsio Sanchez 2020-12-02 12:59:54 -04:00 committed by GitHub
parent 2802e06030
commit 0384ab8568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 26 deletions

View File

@ -29,7 +29,7 @@ export default {
// uuid of the component where it is called // uuid of the component where it is called
containerUuid: { containerUuid: {
type: String, type: String,
required: true default: undefined
}, },
panelType: { panelType: {
type: String, type: String,

View File

@ -8,13 +8,14 @@ export default {
menuUuid = this.menuParentUuid menuUuid = this.menuParentUuid
} }
const relations = this.$store.getters.getRelations(menuUuid) const relations = this.$store.getters.getRelations(menuUuid)
if (!this.isEmptyValue(relations)) {
if (!this.isEmptyValue(relations.children)) { if (!this.isEmptyValue(relations.children)) {
return relations.children return relations.children
} }
if (relations.meta && !this.isEmptyValue(relations.meta.childs)) { if (relations.meta && !this.isEmptyValue(relations.meta.childs)) {
return relations.meta.childs return relations.meta.childs
} }
}
return [] return []
}, },
isEmptyChilds() { isEmptyChilds() {

View File

@ -6,6 +6,7 @@ import Layout from '@/layout'
/** /**
* Get Menu from server * Get Menu from server
* @author Elsio Sanchez <elsiosanches@gmail.com>
* @author Edwin Betancourt <EdwinBetanc0urt@outlook.com> * @author Edwin Betancourt <EdwinBetanc0urt@outlook.com>
* @param {string} sessionUuid * @param {string} sessionUuid
* @param {string} roleUuid * @param {string} roleUuid
@ -63,6 +64,7 @@ export function loadMainMenu({
/** /**
* Get Only Child * Get Only Child
* @author Elsio Sanchez <elsiosanches@gmail.com>
* @author Edwin Betancourt <EdwinBetanc0urt@outlook.com> * @author Edwin Betancourt <EdwinBetanc0urt@outlook.com>
* @param {object} menu * @param {object} menu
* @param {number} index * @param {number} index

View File

@ -188,24 +188,20 @@ export const recursiveTreeSearch = ({
treeData, treeData,
attributeValue, attributeValue,
attributeName = 'id', attributeName = 'id',
secondAttributeName = '', secondAttribute = false,
attributeChilds = 'childsList', attributeChilds = 'childsList',
isParent = false isParent = false
}) => { }) => {
if (Array.isArray(treeData)) { if (Array.isArray(treeData)) {
// search in childs attribute
let index = 0 let index = 0
const length = treeData.length const length = treeData.length
while (index < length) { while (index < length) {
let value = treeData[index] let value = treeData[index]
if (!isEmptyValue(value) && if (!isEmptyValue(value) && Object.prototype.hasOwnProperty.call(value, attributeName)) {
Object.prototype.hasOwnProperty.call(value, attributeName)) {
value = value[attributeName] value = value[attributeName]
} }
if (!isEmptyValue(value) && if (!isEmptyValue(value) && secondAttribute && Object.prototype.hasOwnProperty.call(value, secondAttribute)) {
secondAttributeName && value = value[secondAttribute]
Object.prototype.hasOwnProperty.call(value, secondAttributeName)) {
value = value[secondAttributeName]
} }
// compare item to search // compare item to search
@ -214,12 +210,11 @@ export const recursiveTreeSearch = ({
} }
if (treeData[index] && treeData[index][attributeChilds]) { if (treeData[index] && treeData[index][attributeChilds]) {
const newTree = treeData[index][attributeChilds]
const found = recursiveTreeSearch({ const found = recursiveTreeSearch({
treeData: newTree, treeData: treeData[index][attributeChilds],
attributeValue, attributeValue,
attributeName, attributeName,
secondAttributeName, secondAttribute,
attributeChilds, attributeChilds,
isParent isParent
}) })
@ -230,16 +225,12 @@ export const recursiveTreeSearch = ({
index++ index++
} }
} else { } else {
// search into meta attribute
let value = treeData let value = treeData
if (!isEmptyValue(value) && if (!isEmptyValue(value) && Object.prototype.hasOwnProperty.call(value, attributeName)) {
Object.prototype.hasOwnProperty.call(value, attributeName)) {
value = value[attributeName] value = value[attributeName]
} }
if (!isEmptyValue(value) && if (!isEmptyValue(value) && secondAttribute && Object.prototype.hasOwnProperty.call(value, secondAttribute)) {
secondAttributeName && value = value[secondAttribute]
Object.prototype.hasOwnProperty.call(value, secondAttributeName)) {
value = value[secondAttributeName]
} }
// compare item to search // compare item to search
@ -251,7 +242,7 @@ export const recursiveTreeSearch = ({
treeData: treeData[attributeChilds], treeData: treeData[attributeChilds],
attributeValue, attributeValue,
attributeName, attributeName,
secondAttributeName, secondAttribute,
attributeChilds attributeChilds
}) })
return found return found