import {departInterence} from '@/api/api.js';
import{doPageEventListener}from'@/utils/TimeOnPage.js';

// 权限配置按钮
const permissionButtons = {
    state:()=>({
        permissionButtons:[]
    }),
    mutations:{
     SET_PERMISSION_BUTTONS:(state,buttons)=>{
        state.permissionButtons = buttons
     }
    },
    actions:{
        getPermissionButtons({commit}){
            return new Promise((resolve,reject)=>{
                departInterence.getRoleBtnAuth().then(res=>{
                    const buttons = res.Data || []
                    // console.log(buttons.find(it => it.ButtonCode=="etaTable:excel:save"),'buttons');
                    commit('SET_PERMISSION_BUTTONS',buttons)
                    
                    let trialUserPermisson = !!buttons.find(item => item.ButtonCode =="trialUserAction")
                    commit('SET_ETRIAL',trialUserPermisson)

                    if(!this.state.hasDoPageListening && trialUserPermisson){
                        //有ETA用户行为记录权限 而且没有执行过页面监听
                        doPageEventListener()
                    }
                    resolve('获取权限按钮成功')
                })
/*                 const buttons = [
                    {ButtonCode: "system:menu:add"},
                ]
                commit('SET_PERMISSION_BUTTONS',buttons)
                resolve('获取权限按钮成功') */
            })
        }
    },
    getters:{}
  }
  export default permissionButtons;