import { defineStore } from 'pinia'

const useUserStore = defineStore('user', {
    state: () => {
        return {
            token: '',
            user_info: {
                id: '',
                username: '',
                nickname: '',
                status: 0,
                token: '',
                tokenHead: ' ',
                videoGroup: 0,
                autoRecord: false
            }
        }
    },

    getters: {},

    actions: {
        //用户登录
        setUserInfo() {
            this.token = res.token
            this.user_info = res
            this.router.push('/').then(function () {
                wsShouldOpen.value = true
            })
        },
        //退出登录
        handleLogOut() {
            this.token = ''
            this.user_info = {
                id: '',
                username: '',
                nickname: '',
                status: 0,
                token: '',
                tokenHead: ' ',
                videoGroup: 0,
                autoRecord: false
            }
        }
    },
    // 配置持久化
    persist: {
        // 调整为兼容多端的API
        storage: {
            setItem(key, value) {
                uni.setStorageSync(key, value)
            },
            getItem(key) {
                return uni.getStorageSync(key)
            },
        },
    },
})
export default useUserStore
