酷炫直播运营系统小程序版本

util.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var rootDocment = 'https://center.wenxingshuju.com';//域名
  2. // var rootDocment = 'https://oms.wenxingshuju.com'; //域名
  3. function req (url, method, data, cb, fail_cb, selfHeader) {
  4. var dataes = {
  5. 'admin_id': uni.getStorageSync('admin_id'),
  6. 'ttl': uni.getStorageSync('ttl'),
  7. 'sign': uni.getStorageSync('sign')
  8. }
  9. var header = {
  10. 'sessionKey': uni.getStorageSync('session_key') ? uni.getStorageSync('session_key') : false
  11. }
  12. const app = getApp()
  13. uni.request({
  14. url: rootDocment + url,
  15. data: data ? Object.assign(data, dataes) : dataes,
  16. method: method,
  17. header: selfHeader ? Object.assign(selfHeader, header) : header,
  18. success: function (res) {
  19. if ((res.data.errno == '4002') && url.indexOf('verified') == -1 && url.indexOf('login') == -1) {
  20. if (wx.getStorageSync('isLogin')) {
  21. wx.clearStorage()
  22. uni.redirectTo({
  23. url: '/pages/login/login'
  24. })
  25. }
  26. } else {
  27. return typeof cb == "function" && cb(res.data)
  28. }
  29. },
  30. fail: function (err) {
  31. return typeof fail_cb == "function" && fail_cb(err)
  32. }
  33. })
  34. }
  35. module.exports = {
  36. req: req,
  37. rootDocment: rootDocment
  38. }