/**
 * Created by JianJia.Zhou<jianjia.zhou> on 2022/8/14.
 */
import { getToken } from '../../utils/auth'

const request = uni.$u.http

export async function login() {
  console.log('-->data', 1)
  return new Promise(resolve => {
    uni.showLoading({
      title: '数据加载中...',
      mask: true
    })
    uni.login({
      provider: uni.$u.platform,
      success: loginRes => {
        console.log('-->data', loginRes)
        uni.hideLoading()
        const url = '/auth/kuaishou'

        return request.post(
          url,
          { code: loginRes.code, anonymousCode: loginRes.anonymousCode }
        ).then(res => {
          resolve(res)
        })
      }
    })
  })
}

export function update(data) {
  return request.post(
    'user/update',
    data
  )
}

export async function info() {
  return request.get(
    'user/info'
  )
}

export function isLogin() {
  return !!getToken()
}

export default {
  login,
  update,
  info,
  isLogin
}
