http.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const ip = 'http://192.168.0.251/obpm';
  2. //const ip = 'https://tdmtest.liugong.com/obpm';
  3. /**
  4. * 全部接口
  5. */
  6. const urls = {
  7. ip: ip,
  8. home: ip + '/app/home/index', //首页数据
  9. login: ip + '/runtime/login/loginWithCiphertext2', //用户登陆
  10. myprofile: ip + '/runtime/users/myprofile', //用户登陆
  11. user_register: ip + '/app/user/register', //用户注册
  12. accessToken: ip + '/rest/accessToken?secret=11ec-db2f-ca248770-8df3-890eb68cafa4', //用户注册
  13. // wt_list:ip + '/runtime/__gAPYBW4YxB3UePM3lqO/views/__km3aURKW95BHxp12XVt/documents?parentId=&sortCol=&sortStatus=&lines=10&treedocid=&parentNodeId=&_docid=&_fieldid=&isRelate=&startDate=&endDate=&parentParam=&isQueryButton=false',
  14. wt_list: ip +
  15. '/runtime/__gAPYBW4YxB3UePM3lqO/views/__km3aURKW95BHxp12XVt/documents?lines=10&isQueryButton=false', //获取列表数据、更换viewID
  16. wt_xqsh: ip +
  17. '/runtime/__gAPYBW4YxB3UePM3lqO/views/__MhHakFCgVJAm81MFUnt/documents?lines=10&isQueryButton=false',
  18. wt_sysh: ip +
  19. '/runtime/__gAPYBW4YxB3UePM3lqO/views/__r4IN5HOqV4HIips1s0Q/documents?lines=10&isQueryButton=false',
  20. wt_xqpz: ip +
  21. '/runtime/__gAPYBW4YxB3UePM3lqO/views/__yoOF16IOiZdmrbDOujU/documents?lines=10&isQueryButton=false',
  22. wt_sypz: ip +
  23. '/runtime/__gAPYBW4YxB3UePM3lqO/views/__b6gD17cP1g4gFdTq0Ox/documents?lines=10&isQueryButton=false',
  24. wt_rwfp: ip +
  25. '/runtime/__gAPYBW4YxB3UePM3lqO/views/__m9w03S06KHbg3KioRIh/documents?lines=10&isQueryButton=false',
  26. documents: ip + '/runtime/__gAPYBW4YxB3UePM3lqO/documents/', //获取文档详情
  27. empty: ip +
  28. '/runtime/__gAPYBW4YxB3UePM3lqO/forms/__0FLGNncOS1lz0T9jsFn/empty?formId=__0FLGNncOS1lz0T9jsFn&appId=__gAPYBW4YxB3UePM3lqO', //创建委托单文档
  29. validate: ip + '/runtime/__gAPYBW4YxB3UePM3lqO/documents/__79Wtw03ya4dJUDGPyAN/validate', //保存文档
  30. borr_empty: ip +
  31. '/runtime/__gAPYBW4YxB3UePM3lqO/forms/__w9J1gxcIWgXmNw6pE1F/empty?formId=__w9J1gxcIWgXmNw6pE1F&appId=__gAPYBW4YxB3UePM3lqO', //创建设备借用
  32. return_empty: ip +
  33. '/runtime/__gAPYBW4YxB3UePM3lqO/forms/__LcDaGhYHt5xOSeHMCs0/empty?formId=__LcDaGhYHt5xOSeHMCs0&appId=__gAPYBW4YxB3UePM3lqO', //创建设备归还
  34. }
  35. /**
  36. * 封装的http请求wt_
  37. */
  38. const request = (opt) => {
  39. opt = opt || {};
  40. opt.url = opt.url || '';
  41. opt.data = opt.data || null;
  42. opt.method = opt.method || 'GET';
  43. opt.contentType = opt.contentType || 'application/json;charset=UTF-8'
  44. opt.header = opt.header || {
  45. "Content-Type": opt.contentType,
  46. //"Authorization": getUser().token ? getUser().token : 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NzAxMzYzMjEsInN1YiI6IkFpNmhsbGhOalMydWxsOVRLR2IiLCJleHAiOjE2NzAxMzk5MjEsIm5iZiI6MTY3MDEzNjMyMX0.cNQpCWUwVjA2jkrKCnybIfxl6iQQJ-xj3S8dmQSmQ3A',
  47. "accessToken": getUser().accessToken || ''
  48. };
  49. opt.loading = opt.loading || 'true';
  50. opt.success = opt.success || function() {};
  51. console.log("**************************************参数调式***************************************************");
  52. console.log("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data));
  53. console.log("************************************************************************************************");
  54. if (opt.loading == 'true') {
  55. uni.showLoading({
  56. title: '正在加载',
  57. mask: true
  58. });
  59. }
  60. uni.request({
  61. url: opt.url,
  62. data: opt.data,
  63. method: opt.method,
  64. header: opt.header,
  65. dataType: 'json',
  66. success: res => {
  67. setTimeout(() => {
  68. uni.hideLoading();
  69. }, 500)
  70. /*******************系统内部错误***************************/
  71. if (res.data.code === 500) {
  72. uni.showModal({
  73. content: res.data.msg,
  74. showCancel: false
  75. });
  76. return;
  77. }
  78. if (res.statusCode === 401) {
  79. uni.removeStorageSync('user');
  80. uni.showModal({
  81. title: '提示',
  82. content: '登录超时,请先登陆!',
  83. success: res => {
  84. if (res.confirm) {
  85. uni.navigateTo({
  86. url: '/pages/login'
  87. })
  88. }
  89. }
  90. });
  91. return;
  92. }
  93. opt.success(res);
  94. },
  95. fail: e => {
  96. uni.hideLoading();
  97. uni.getNetworkType({
  98. success: res => {
  99. if (res.networkType == 'none') {
  100. uni.showModal({
  101. content: '当前网络不可用,请检查网络稍后重试',
  102. showCancel: false
  103. });
  104. } else {
  105. uni.showModal({
  106. content: '服务异常,请稍后重试',
  107. showCancel: false
  108. })
  109. }
  110. }
  111. });
  112. }
  113. })
  114. }
  115. const getUser = () => {
  116. return uni.getStorageSync('user');
  117. }
  118. module.exports = {
  119. urls,
  120. request,
  121. getUser
  122. };