http.js 4.8 KB

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