http.js 4.9 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. myPending: ip +'/runtime/widget/myPending?pageNo=1&linesPerPage=5&workflowOrder=true',
  40. runViewDialogConfirmScript: ip + '/runtime/views/selectbox/runViewDialogConfirmScript?',
  41. eq_list: ip + '/runtime/__gAPYBW4YxB3UePM3lqO/views/__WLVxKX6e0Pq0cTwdNUQ/documents?',
  42. }
  43. /**
  44. * 封装的http请求wt_
  45. */
  46. const request = (opt) => {
  47. opt = opt || {};
  48. opt.url = opt.url || '';
  49. opt.data = opt.data || null;
  50. opt.method = opt.method || 'GET';
  51. opt.contentType = opt.contentType || 'application/json;charset=UTF-8'
  52. opt.header = opt.header || {
  53. "Content-Type": opt.contentType,
  54. //"Authorization": getUser().token ? getUser().token : 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NzAxMzYzMjEsInN1YiI6IkFpNmhsbGhOalMydWxsOVRLR2IiLCJleHAiOjE2NzAxMzk5MjEsIm5iZiI6MTY3MDEzNjMyMX0.cNQpCWUwVjA2jkrKCnybIfxl6iQQJ-xj3S8dmQSmQ3A',
  55. "accessToken": getUser().accessToken || ''
  56. };
  57. opt.loading = opt.loading || 'true';
  58. opt.success = opt.success || function() {};
  59. console.log("**************************************参数调式***************************************************");
  60. console.log("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data));
  61. console.log("************************************************************************************************");
  62. if (opt.loading == 'true') {
  63. uni.showLoading({
  64. title: '正在加载',
  65. mask: true
  66. });
  67. }
  68. uni.request({
  69. url: opt.url,
  70. data: opt.data,
  71. method: opt.method,
  72. header: opt.header,
  73. dataType: 'json',
  74. success: res => {
  75. setTimeout(() => {
  76. uni.hideLoading();
  77. }, 500)
  78. /*******************系统内部错误***************************/
  79. if (res.data.code === 500) {
  80. uni.showModal({
  81. content: res.data.msg,
  82. showCancel: false
  83. });
  84. return;
  85. }
  86. if (res.statusCode === 401) {
  87. uni.removeStorageSync('user');
  88. uni.showModal({
  89. title: '提示',
  90. content: '登录超时,请先登陆!',
  91. success: res => {
  92. if (res.confirm) {
  93. uni.navigateTo({
  94. url: '/pages/login'
  95. })
  96. }
  97. }
  98. });
  99. return;
  100. }
  101. opt.success(res);
  102. },
  103. fail: e => {
  104. uni.hideLoading();
  105. uni.getNetworkType({
  106. success: res => {
  107. if (res.networkType == 'none') {
  108. uni.showModal({
  109. content: '当前网络不可用,请检查网络稍后重试',
  110. showCancel: false
  111. });
  112. } else {
  113. uni.showModal({
  114. content: '服务异常,请稍后重试',
  115. showCancel: false
  116. })
  117. }
  118. }
  119. });
  120. }
  121. })
  122. }
  123. const getUser = () => {
  124. return uni.getStorageSync('user');
  125. }
  126. module.exports = {
  127. urls,
  128. request,
  129. getUser
  130. };