import {
  request
} from '~/services/_utils/request'
import {
  removeStorage
} from '~/utils/storage'

/** 登出 */
export function logout() {
  return new Promise((resolve, reject) => {
    request({
      url: `WeChatLogin/logout`,
      method: 'POST',
      success: function (res) {

        // 清空登录信息缓存
        removeStorage('userInfo')
        removeStorage('Authorization')

        // 回到首页
        wx.showToast({
          icon: 'success',
          title: '登出成功',
        });
        wx.reLaunch({
          url: '/pages/home/home'
        })
        resolve(res);
      },
      fail: function (error) {
        reject(error);
      }
    });
  });
}