http.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //const ip = 'http://192.168.0.101:8080';
  2. //const ip = 'https://qfnj.gaswkj.com/prod-api';
  3. //const ip = 'http://192.168.2.102:8080';
  4. const ip = 'http://139.159.189.40/prod-api';
  5. /**
  6. * 全部接口(集中管理)
  7. */
  8. const urls = {
  9. ip: ip,
  10. home: ip + '/app/home/index', //首页数据
  11. wxLogin: ip + '/api/login/wxLogin/', //游客微信小程序登录
  12. getPageContent: ip + '/api/index/getPageContent', //分页获取主要内容信息
  13. getContentInfo: ip + '/api/index/getContentInfo/', //获取主要内容详细信息
  14. getAboutUs: ip + '/api/index/getAboutUs/', //获取关于我们的信息
  15. pushRecord: ip + '/api/index/pushRecord', //门店数据上报
  16. shopApply: ip + '/api/index/shopApply', //商铺开通申请
  17. getShopList: ip + '/api/index/getShopList', //获取商铺列表
  18. updateShop: ip + '/api/index/updateShop', //更新门店信息
  19. getPageMarker: ip + '/api/index/getPageMarker', //根据标记物类型分页获取标记物信息
  20. pushHelp: ip + '/api/index/pushHelp', //上传会员拨打记录
  21. }
  22. /**
  23. * 封装的http请求
  24. */
  25. const request = (opt) => {
  26. opt = opt || {};
  27. opt.url = opt.url || '';
  28. opt.data = opt.data || null;
  29. opt.method = opt.method || 'GET';
  30. opt.header = opt.header || {
  31. "Content-Type": "application/json;charset=UTF-8",
  32. "apiToken": getUser().apiToken || ''
  33. };
  34. opt.loading = opt.loading || 'true';
  35. opt.success = opt.success || function() {};
  36. console.log("**************************************参数调式***************************************************");
  37. console.log("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data));
  38. console.log("************************************************************************************************");
  39. if (opt.loading == 'true') {
  40. uni.showLoading({
  41. title: '正在加载',
  42. mask: true
  43. });
  44. }
  45. uni.request({
  46. url: opt.url,
  47. data: opt.data,
  48. method: opt.method,
  49. header: opt.header,
  50. dataType: 'json',
  51. success: res => {
  52. setTimeout(() => {
  53. uni.hideLoading();
  54. }, 500)
  55. if (res.data.code == 200) {
  56. opt.success(res);
  57. } else {
  58. uni.showModal({
  59. content: res.data.msg,
  60. showCancel: false
  61. });
  62. return;
  63. }
  64. },
  65. fail: e => {
  66. uni.hideLoading();
  67. uni.getNetworkType({
  68. success: res => {
  69. if (res.networkType == 'none') {
  70. uni.showModal({
  71. content: '当前网络不可用,请检查网络稍后重试',
  72. showCancel: false
  73. });
  74. } else {
  75. uni.showModal({
  76. content: '服务异常,请稍后重试',
  77. showCancel: false
  78. })
  79. }
  80. }
  81. });
  82. }
  83. })
  84. }
  85. const getUser = () => {
  86. return uni.getStorageSync('user');
  87. }
  88. module.exports = {
  89. urls,
  90. request,
  91. getUser
  92. };