import { reactive } from 'vue'

type status = 'init' | 'login' | 'logout' | 'error'

export const state = reactive({
  user: {
    status: 'init' as status,
    data: {} as any
  }
})

// 预览上传到oss的地址
export const getOssUploadUrl = (bucket: string) => {
  const tmpBucket = bucket || 'daya'
  return `https://${tmpBucket}.ks3-cn-beijing.ksyuncs.com/`
}

export const setLoginInit = () => {
  state.user.status = 'init'
  state.user.data = null
}

export const setLogin = (data: any) => {
  state.user.status = 'login'
  state.user.data = data
}

export const setLogout = () => {
  state.user.status = 'logout'
  state.user.data = null
}

export const setLoginError = () => {
  state.user.status = 'error'
  state.user.data = null
}
