// 用户权限
import { useRoute } from 'vue-router';
import { GetUserLimit } from "@/apis/user";

// const testData = {
//     "sysType": "MA==",
//     "userId": "NTIzMw==",
//     "type": "eXc="
// }


//userId=NTMwMw==&sysType=W29iamVjdCBPYmplY3Rd&digitalTwainType=eXM=


/**
 * @params nameList-按钮列表
 */
export function GetUserPrivilege(nameList) {
    // const router = useRoute()
    let userData = useRoute().query
    console.log(userData)
    if(userData.digitalTwainType){
        userData.type = userData.digitalTwainType
        delete userData.digitalTwainType
    }
    GetUserLimit(userData).then((res) => {
        console.log(res)
        let parentId = []
        let limitArr = []
        res.data.Rows.forEach((item) => {
            // if (item.name.includes('数字孪生')) {
                if (item.name.includes('数字孪生业务版') || item.name.includes('数字孪生演示版')) {
                    res.data.Rows.forEach((item) => {
                    // console.log(item)
                    parentId.push(item.id)
                })
                // console.log(parentId)
            }
            if (parentId.includes(item.parentId)) {
                limitArr.push(item.name)
                // console.log(limitArr)
            }

        })
        // console.log(nameList.data)
                console.log(limitArr)

        nameList.data = nameList.data.filter((i) => {
            if (limitArr.includes(i.name)) {
                return true
            }
        })
        // console.log(nameList.data)
    })
}