大数据平台的小程序版本

util.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var rootDocment = 'https://data.kuxuan.com';//域名
  2. // var rootDocment = 'http://47.93.151.217:8006';//测试域名
  3. // var rootDocment = 'http://apitbk.726p.com';//预发域名
  4. var md5 = require('./md5.js');
  5. var count = 0;
  6. wx.setStorageSync('doneLogin',false)
  7. function req(url, method, data, cb, fail_cb, selfHeader) {
  8. var dataes = {'admin_id':wx.getStorageSync('admin_id'),
  9. 'ttl':wx.getStorageSync('ttl'),
  10. 'sign':wx.getStorageSync('sign')}
  11. var header = {
  12. 'sessionKey':wx.getStorageSync('session_key')?wx.getStorageSync('session_key'):false
  13. }
  14. wx.request({
  15. url: rootDocment + url,
  16. data: data ? Object.assign(data, dataes) : dataes,
  17. method: method,
  18. header: selfHeader ? Object.assign(selfHeader,header) : header,
  19. success: function (res) {
  20. if(res.data.errno == '4002' || res.data.errno == '4001'){
  21. if(wx.getStorageSync('isLogin')){
  22. wx.clearStorage()
  23. wx.showToast({
  24. title: res.data.err,
  25. icon: 'none',
  26. duration: 2000
  27. })
  28. wx.redirectTo({
  29. url: '/pages/welcome/welcome',
  30. })
  31. }
  32. }else{
  33. count = 0;
  34. return typeof cb == "function" && cb(res.data)
  35. }
  36. },
  37. fail: function (err) {
  38. return typeof fail_cb == "function" && fail_cb(err)
  39. }
  40. })
  41. }
  42. module.exports = {
  43. req: req
  44. }