import request from '@/utils/request';
import store from '@/store';

/**
 * 通过wx.login()获取登录code令牌
 * @returns
 */
export const getWxLoginCode = () => {
  return new Promise((resolve, reject) => {
    wx.login({
      success(res) {
        if (res.code) {
          //发起网络请求log
          resolve(res.code);
        }
      },
    });
  });
};

/**
 * 微信一键注册/登录
 * @param {*} data
 * @returns
 */
export function loginByWxLoginCode(data) {
  return request({
    url: '/maintain/login/wechat',
    method: 'post',
    data: data,
  });
}

/**
 *  通过手机号获取验证码
 * @param {string} phoneNumber 电话号码
 * @returns R
 */
export function getSmsCodeByPhone(data) {
  return request({
    url: '/maintain/sms/captcha',
    method: 'post',
    data: data
  });
}

/**
 *  通过手机号验证码登录
 * @param {*} data
 * @returns
 */
export function loginByPhoneAndSmsCode(data) {
  return request({
    url: '/maintain/login/sms',
    method: 'post',
    data: data,
  });
}

/**
 * 退出登录
 * @param {*} data
 * @returns
 */
export function logout(data) {
  return request({
    url: '/maintain/logoff',
    method: 'post',
    data: data
  })
}
