diff --git a/pages/my/index.js b/pages/my/index.js index 3f20428..fd9362c 100644 --- a/pages/my/index.js +++ b/pages/my/index.js @@ -1,6 +1,6 @@ -import { alertInfo } from "../../utils/index"; +import { alertInfo, alertSuccess } from "../../utils/index"; import Dialog from '@vant/weapp/dialog/dialog'; -import { getUserInfo } from "../../service/user"; +import { getUserInfo, logout } from "../../service/user"; import { getDot } from "../../utils/system"; import request from "../../utils/request" const { OK } = request; @@ -78,7 +78,12 @@ Page({ dot }) }, - logout() { + async logout() { + const { code, message } = await logout() + if (code !== OK) { + alertInfo(message) + return; + } wx.clearStorageSync() wx.switchTab({ url: '/pages/home/index', diff --git a/service/user.js b/service/user.js index a96c7f7..e82612a 100644 --- a/service/user.js +++ b/service/user.js @@ -54,4 +54,8 @@ export const getUserParksAndTenementsList = async function() { // 获取所有未阅读的用户数 export const getUnReadApproveNumber = async function() { return await GET('/wx/getApproveNumber'); +} +// 退出登录 +export const logout = async function() { + return await POST('/wx/logout'); } \ No newline at end of file diff --git a/utils/request.js b/utils/request.js index 9e65452..b831914 100644 --- a/utils/request.js +++ b/utils/request.js @@ -20,6 +20,7 @@ const requestWithoutCookie = promisify(wx.request); // 考虑了Cookie的请求 const request = async function (options, config = {}) { console.log('请求参数', 'options', options, 'config', config) + console.log('token', wx.getStorageSync('token'), 'user', wx.getStorageSync('user')) let token = wx.getStorageSync('token'); const result = wx.getAccountInfoSync(); const { envVersion } = result.miniProgram;