recursion(stores.power,permissions) //调用
function recursion(list,button?: string[],count=0,arr=[]) :boolean {
list.forEach(v1=>{
if (count < button?.length-1 && button[count] == v1.name && v1.children && v1.children.length> 0) {
count++
return recursion(v1.children,button,count,arr)
}
if (count == button?.length-1 && v1.children == null) {
button[count] == v1.name ? arr.push('对了') : arr.push('错了')
}
})
return arr.includes('对了')
}
//处理数据
function getTreeData(data: any): UserPowerTreeItem[] {
if (data instanceof Array) {
return [...data.map((item) => ({
name: item
}))];
} else {
return Object.keys(data).map(key => {
const items = data[key]
const child = getTreeData(items)
return {
name: key,
children: child
}
})
}
}
处理前:
"微信客服": {
"关键词回复": ["编辑", "新增", "详情-关联", "列表", "详情-删除", "删除", "详情"],
"欢迎语设置": ["详情", "新增", "详情-关联", "删除", "编辑", "列表", "详情-删除"],
"回传配置": {
"腾讯回传": ["回传明细-列表", "配置客服-批量删除", "回传明细-删除", "回传明细-导出", "配置客服-关联", "配置客服-删除", "配置token", "配置客服-列表", "配置客服-修改", "配置token-列表"],
"百度回传": ["回传明细-列表", "配置客服-批量删除", "回传明细-删除", "回传明细-导出", "配置客服-关联", "配置客服-删除", "配置客服-列表", "配置客服-修改"],
"头条回传": ["回传明细-列表", "配置客服-批量删除", "回传明细-删除", "回传明细-导出", "配置客服-关联", "配置客服-删除", "配置客服-列表", "配置客服-修改"]
},
"客服账号": ["列表", "新增", "编辑", "详情", "删除"]
}
数据处理后:
{
"name": "推广管理",
"children": [{
"name": "线索管理",
"children": [{
"name": "线索公海",
"children": [{
"name": "去重用户导出"
}, {
"name": "去重用户列表"
}, {
"name": "去重用户删除/批量删除"
}, {
"name": "全部用户列表"
}, {
"name": "全部用户删除/批量删除"
}, {
"name": "全部用户导出"
}]
}, {
"name": "线索渠道",
"children": [{
"name": "添加"
}, {
"name": "删除/批量删除"
}, {
"name": "列表"
}]
}, {
"name": "线索回传",
"children": [{
"name": "百度回传",
"children": [{
"name": "导出"
}, {
"name": "列表"
}]
}]
}]
}, {
"name": "微信客服",
"children": [{
"name": "关键词回复",
"children": [{
"name": "编辑"
}, {
"name": "新增"
}, {
"name": "详情-关联"
}, {
"name": "列表"
}, {
"name": "详情-删除"
}, {
"name": "删除"
}, {
"name": "详情"
}]
}, {
"name": "欢迎语设置",
"children": [{
"name": "详情"
}, {
"name": "新增"
}, {
"name": "详情-关联"
}, {
"name": "删除"
}, {
"name": "编辑"
}, {
"name": "列表"
}, {
"name": "详情-删除"
}]
}, {
"name": "回传配置",
"children": [{
"name": "腾讯回传",
"children": [{
"name": "回传明细-列表"
}, {
"name": "配置客服-批量删除"
}, {
"name": "回传明细-删除"
}, {
"name": "回传明细-导出"
}, {
"name": "配置客服-关联"
}, {
"name": "配置客服-删除"
}, {
"name": "配置token"
}, {
"name": "配置客服-列表"
}, {
"name": "配置客服-修改"
}, {
"name": "配置token-列表"
}]
}, {
"name": "百度回传",
"children": [{
"name": "回传明细-列表"
}, {
"name": "配置客服-批量删除"
}, {
"name": "回传明细-删除"
}, {
"name": "回传明细-导出"
}, {
"name": "配置客服-关联"
}, {
"name": "配置客服-删除"
}, {
"name": "配置客服-列表"
}, {
"name": "配置客服-修改"
}]
}, {
"name": "头条回传",
"children": [{
"name": "回传明细-列表"
}, {
"name": "配置客服-批量删除"
}, {
"name": "回传明细-删除"
}, {
"name": "回传明细-导出"
}, {
"name": "配置客服-关联"
}, {
"name": "配置客服-删除"
}, {
"name": "配置客服-列表"
}, {
"name": "配置客服-修改"
}]
}]
}, {
"name": "客服账号",
"children": [{
"name": "列表"
}, {
"name": "新增"
}, {
"name": "编辑"
}, {
"name": "详情"
}, {
"name": "删除"
}]
}]
}]
}
findAuthNew(str, strBtn) {
const authRouter = JSON.parse(localStorage.getItem('menu'))
let isAuth = false
for (const i in authRouter) {
if (str === i) {
isAuth = true
} else {
for (const x in authRouter[i]) {
if (str === x) {
isAuth = true
} else {
for (const m in authRouter[i][x]) {
if (str === m) {
isAuth = true
if (strBtn) {
isAuth = authRouter[i][x][str].indexOf(strBtn) !== -1 ? true : ''
}
}
}
}
}
}
}
return isAuth
},
authRouter
{
"合规系统": {
"合规管理": {
"合同列表": [
"下载",
"合同日志",
"详情",
"列表"
],
"风险测评": [
"评级表编辑",
"编辑",
"风险测评",
"风测开关",
"删除"
]
}
},
"成长体系": {
"财豆管理": {
"财豆策略": [
"财豆策略",
"编辑",
"开启/关闭"
],
"财豆记录": [
"财豆记录",
"赠送"
]
}
}
}