import { queryAccountMenu } from '@/services/api/account'
import { createStore } from '../base'
import { sessionData } from '../storage'

export const menuStore = createStore({
    state() {
        return {
            loading: false,
            userRoutes: sessionData.getRef('userRoutes'),
        }
    },
    actions: {
        /** 获取用户菜单列表 */
        async getUserMenuList() {
            try {
                this.state.loading = true
                const res = await queryAccountMenu()
                this.state.userRoutes = res.data
            } finally {
                this.state.loading = false
            }
        },
        /** 重置数据 */
        reset() {
            this.state.userRoutes = []
        }
    }
})