config.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // let api = "https://passport.lrlz.com/mobile/index.php";
  2. let api = "http://192.168.1.200/mobile/index.php";
  3. function getReq(data, callback, method) {
  4. let options = {
  5. client_type: 'mini'
  6. }
  7. data = Object.assign({}, options, data);
  8. let session_id = wx.getStorageSync('session_id');
  9. if (!session_id && data['op'] != 'ministart') {
  10. setTimeout(() => {
  11. getReq(data, callback, method)
  12. }, 0);
  13. return;
  14. }
  15. let header = {
  16. 'content-type': 'application/json', // 默认值
  17. 'Cookie': 'MPHPSESSID=' + session_id
  18. }
  19. if (method == 'POST') {
  20. header = {
  21. 'content-type': 'application/x-www-form-urlencoded', // 数据转换成 query string
  22. 'Cookie': 'MPHPSESSID=' + session_id
  23. }
  24. }
  25. return wx.request({
  26. url: api,
  27. data,
  28. method: method || 'GET',
  29. header,
  30. success(res) {
  31. callback(res.data)
  32. },
  33. fail() {
  34. wx.showModal({
  35. confirmText: '重试',
  36. content: '网络错误',
  37. success: function (res) {
  38. if (res.confirm) {
  39. wx.reLaunch({
  40. url: "/pages/index/index"
  41. })
  42. } else if (res.cancel) {
  43. console.log('用户点击取消')
  44. }
  45. }
  46. })
  47. }
  48. })
  49. }
  50. module.exports = {
  51. getReq,
  52. host: api
  53. }