12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- var rootDocment = 'http://zhitou.wenxingshuju.com';//域名
- function req (url, method, data, cb, fail_cb, selfHeader) {
- var params = {
- 'admin_id': uni.getStorageSync('admin_id'),
- 'ttl': uni.getStorageSync('ttl'),
- 'sign': uni.getStorageSync('sign')
- }
- var header = {
- // 'sessionKey': uni.getStorageSync('session_key') ? uni.getStorageSync('session_key') : false
- }
- const app = getApp()
- uni.request({
- url: rootDocment + url,
- data: data ? Object.assign(data, params) : params,
- method: method,
- header: selfHeader ? Object.assign(selfHeader, header) : header,
- success: function (res) {
- // url.indexOf('verified') == -1 &&
- if ((res.data.code == '4002') && url.indexOf('login') == -1) {
- wx.clearStorage()
- uni.redirectTo({
- url: '/pages/login/login'
- })
- } else {
- return typeof cb == "function" && cb(res.data)
- }
- },
- fail: function (err) {
- // if(url.indexOf('login') == -1){
- // wx.clearStorage()
- // uni.redirectTo({
- // url: '/pages/login/login'
- // })
- // }
- return typeof fail_cb == "function" && fail_cb(err)
- }
- })
- }
- module.exports = {
- req: req,
- rootDocment: rootDocment
- }
|