
import { UserState, UserInfo } from './types'
const useUserStore = defineStore('user', {
    state: (): UserState => ({
        // 用户名
        userInfo: null,
        token: undefined,
        permissionsList: [], // 用户职务接口权限列表
        info_status:{
            mobile: false,
            user_info: false
        }
    }),
   
    getters: {
        getToken(): string | undefined {
            return this.token || uni.getStorageSync('token')
        },
        getPermissionsList(): string[] {
            return this.permissionsList || uni.getStorageSync('permission') || []
        },
        getAuthorize(): {
            mobile: boolean,
            user_info: boolean
        } {
            return  uni.getStorageSync('info_status')
        }
    },

    actions: {
        setLoginInfo(info_status: {mobile: boolean, user_info: boolean}, token?: string) {
            uni.setStorageSync('token', token)
            uni.setStorageSync('info_status', info_status)
            this.token = token  
            this.info_status = info_status
        },
        setAuthorize(info_status: {mobile: boolean, user_info: boolean}) {
            uni.setStorageSync('info_status', info_status)
            this.info_status = info_status
        },
        setPermissionsList(list: string[]) {
            uni.setStorageSync('permission', list)
            this.permissionsList = list
        },
    }
})

export default useUserStore
