Commit 6ad1666f by 李伟康

修改登录

1 parent 1a94f2e4
import http from '../request/http' import http from '../request/http'
// const { appId } = wx.getAccountInfoSync().miniProgram const { appId } = wx.getAccountInfoSync().miniProgram
import {
appId
} from '~/utils/constants'
let loginCount = null, let loginCount = null,
loginCache = null, loginCache = null,
loginTimer = null loginTimer = null
......
...@@ -5,7 +5,6 @@ import { ...@@ -5,7 +5,6 @@ import {
pathEnum, pathEnum,
domain, domain,
} from '../env/index' } from '../env/index'
let INTERRUPT = false
/**接口 */ /**接口 */
class Request { class Request {
get(params, returnAll = false) { get(params, returnAll = false) {
...@@ -14,16 +13,22 @@ class Request { ...@@ -14,16 +13,22 @@ class Request {
post(params, returnAll = false) { post(params, returnAll = false) {
return this.request('POST', params, returnAll) return this.request('POST', params, returnAll)
} }
fetch(method,data, returnAll = true){ fetch(method, data, returnAll = true) {
return this.post( return this.post({
{
method, method,
...data, ...data,
}, },
returnAll returnAll
); );
} }
wx_request({url,method='GET',data={},header={},dataType='json',responseType="text"}){ wx_request({
url,
method = 'GET',
data = {},
header = {},
dataType = 'json',
responseType = "text"
}) {
return new Promise((resolve) => { return new Promise((resolve) => {
wx.request({ wx.request({
url, url,
...@@ -46,7 +51,9 @@ class Request { ...@@ -46,7 +51,9 @@ class Request {
wx.showNavigationBarLoading() wx.showNavigationBarLoading()
let header = RequestMethods === 'POST' ? { let header = RequestMethods === 'POST' ? {
'content-type': 'application/x-www-form-urlencoded' 'content-type': 'application/x-www-form-urlencoded'
} : {'Cache-Control': 'no-cache'} } : {
'Cache-Control': 'no-cache'
}
header.merchantId = defaultMerchantId header.merchantId = defaultMerchantId
let projectName = this.getRopProject(params.method) let projectName = this.getRopProject(params.method)
if (!projectName) projectName = this.getRopProject(params.method) if (!projectName) projectName = this.getRopProject(params.method)
...@@ -74,21 +81,9 @@ class Request { ...@@ -74,21 +81,9 @@ class Request {
} }
if (code == 20 || code == 21) { if (code == 20 || code == 21) {
wx.hideLoading() wx.hideLoading()
const thisPage = wx.p.router.getPageInstance() return wx.reLaunch({
if (thisPage && thisPage.pageRefresh) thisPage.pageRefresh() url: '/pages/loading/loading'
if (!wx.p.authStatus) { })
if (INTERRUPT) return
INTERRUPT = true
wx.showLoading()
getApp().login().then(() => {
if (thisPage.init && thisPage.data.userInfo) thisPage.init()
if (thisPage.loginCallBack && thisPage.data.userInfo) thisPage.loginCallBack(thisPage.data.userInfo)
if (thisPage.onRoute) thisPage.onRoute()
thisPage.onLoad()
thisPage.onShow()
INTERRUPT = false
})
}
} else { } else {
if (code == '0') { if (code == '0') {
resolve(data.data) resolve(data.data)
......
...@@ -29,6 +29,9 @@ Page({ ...@@ -29,6 +29,9 @@ Page({
wx.p.storage.set('userInfo', data) wx.p.storage.set('userInfo', data)
wx.p.storage.set('sessionId', data.sessionId) wx.p.storage.set('sessionId', data.sessionId)
if (!data) throw message if (!data) throw message
} else {
wx.p.storage.rm('userInfo')
wx.p.storage.rm('sessionId')
} }
console.log(data, '=============') console.log(data, '=============')
//scenc获取页面参数并跳转 //scenc获取页面参数并跳转
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!