|
@@ -4,7 +4,8 @@ class request {
|
|
static BASE_URL = 'https://llzlovesh.top/api/'
|
|
static BASE_URL = 'https://llzlovesh.top/api/'
|
|
static HEAD = {
|
|
static HEAD = {
|
|
"Content-Type": "application/json",
|
|
"Content-Type": "application/json",
|
|
- "token": 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2MTI5NTc0MDQsImV4cCI6NDA3MDg4MDAwMCwidXNlcklkIjoxMjM0NTY3ODksInZpc2l0b3IiOiJ2aXNpdG9yNjAyM2M2ZGNkZmIwNiIsImlzQWRtaW4iOjAsImFkbWluSWQiOjB9.ojdQ3bieXuJ5sKCesjVfutwDpp8f8oL0-fSJMP72XZc'
|
|
|
|
|
|
+ "defaultToken": 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2MTY5MDg3NjAsImV4cCI6MjQ4MDgyMjM2MCwidXNlcklkIjoxMjM0NTY3ODksInZpc2l0b3IiOiJ2aXNpdG9yNjA2MDExZDg4NTQwYyIsImlzQWRtaW4iOjAsImFkbWluSWQiOjB9.7XrRxA3WYMBlqJWIXEw-71AxOxQvCc4VVVN6rlqn3uc',
|
|
|
|
+ "token":'',
|
|
}
|
|
}
|
|
static constructor() {
|
|
static constructor() {
|
|
|
|
|
|
@@ -21,8 +22,12 @@ class request {
|
|
* GET类型的网络请求
|
|
* GET类型的网络请求
|
|
*/
|
|
*/
|
|
static getRequest(url, data, header = this.HEAD ) {
|
|
static getRequest(url, data, header = this.HEAD ) {
|
|
- if (!this.HEAD.token){
|
|
|
|
- header.token = wx.getStorageSync('token')
|
|
|
|
|
|
+
|
|
|
|
+ const token = wx.getStorageSync('token')
|
|
|
|
+ if (token) {
|
|
|
|
+ header.token = token
|
|
|
|
+ }else {
|
|
|
|
+ header.token = header.defaultToken
|
|
}
|
|
}
|
|
return this.requestAll(url, data, header, 'GET')
|
|
return this.requestAll(url, data, header, 'GET')
|
|
}
|
|
}
|
|
@@ -31,8 +36,11 @@ class request {
|
|
* DELETE类型的网络请求
|
|
* DELETE类型的网络请求
|
|
*/
|
|
*/
|
|
static deleteRequest(url, data, header = this.HEAD ) {
|
|
static deleteRequest(url, data, header = this.HEAD ) {
|
|
- if (!this.HEAD.token){
|
|
|
|
- header.token = wx.getStorageSync('token')
|
|
|
|
|
|
+ const token = wx.getStorageSync('token')
|
|
|
|
+ if (token) {
|
|
|
|
+ header.token = token
|
|
|
|
+ }else {
|
|
|
|
+ header.token = header.defaultToken
|
|
}
|
|
}
|
|
return this.requestAll(url, data, header, 'DELETE')
|
|
return this.requestAll(url, data, header, 'DELETE')
|
|
}
|
|
}
|
|
@@ -41,8 +49,11 @@ class request {
|
|
* PUT类型的网络请求
|
|
* PUT类型的网络请求
|
|
*/
|
|
*/
|
|
static putRequest(url, data, header = this.HEAD ) {
|
|
static putRequest(url, data, header = this.HEAD ) {
|
|
- if (!this.HEAD.token){
|
|
|
|
- header.token = wx.getStorageSync('token')
|
|
|
|
|
|
+ const token = wx.getStorageSync('token')
|
|
|
|
+ if (token) {
|
|
|
|
+ header.token = token
|
|
|
|
+ }else {
|
|
|
|
+ header.token = header.defaultToken
|
|
}
|
|
}
|
|
return this.requestAll(url, data, header, 'PUT')
|
|
return this.requestAll(url, data, header, 'PUT')
|
|
}
|
|
}
|
|
@@ -51,15 +62,21 @@ class request {
|
|
* POST类型的网络请求
|
|
* POST类型的网络请求
|
|
*/
|
|
*/
|
|
static postRequest(url, data, header = this.HEAD) {
|
|
static postRequest(url, data, header = this.HEAD) {
|
|
- if (!this.HEAD.token){
|
|
|
|
- header.token = wx.getStorageSync('token')
|
|
|
|
|
|
+ const token = wx.getStorageSync('token')
|
|
|
|
+ if (token) {
|
|
|
|
+ header.token = token
|
|
|
|
+ }else {
|
|
|
|
+ header.token = header.defaultToken
|
|
}
|
|
}
|
|
return this.requestAll(url, data, header, 'POST')
|
|
return this.requestAll(url, data, header, 'POST')
|
|
}
|
|
}
|
|
|
|
|
|
static upload(url, name, path, ortherData, header = this.HEAD){
|
|
static upload(url, name, path, ortherData, header = this.HEAD){
|
|
- if (!this.HEAD.token){
|
|
|
|
- header.token = wx.getStorageSync('token')
|
|
|
|
|
|
+ const token = wx.getStorageSync('token')
|
|
|
|
+ if (token) {
|
|
|
|
+ header.token = token
|
|
|
|
+ }else {
|
|
|
|
+ header.token = header.defaultToken
|
|
}
|
|
}
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
wx.uploadFile({
|
|
wx.uploadFile({
|
|
@@ -79,6 +96,9 @@ class request {
|
|
title: res.data.message,
|
|
title: res.data.message,
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+ if (res.data.code === 901) {
|
|
|
|
+ _self.HEAD.token = ''
|
|
|
|
+ }
|
|
//其它错误,提示用户错误信息
|
|
//其它错误,提示用户错误信息
|
|
if (this._errorHandler != null) {
|
|
if (this._errorHandler != null) {
|
|
//如果有统一的异常处理,就先调用统一异常处理函数对异常进行处理
|
|
//如果有统一的异常处理,就先调用统一异常处理函数对异常进行处理
|
|
@@ -123,8 +143,8 @@ class request {
|
|
title: res.data.message,
|
|
title: res.data.message,
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- if (res.data.code === 901){
|
|
|
|
- console.log(res.data)
|
|
|
|
|
|
+ if (res.data.code === 901) {
|
|
|
|
+ _self.HEAD.token = ''
|
|
}
|
|
}
|
|
//其它错误,提示用户错误信息
|
|
//其它错误,提示用户错误信息
|
|
if (this._errorHandler != null) {
|
|
if (this._errorHandler != null) {
|