http.js 4.5 KB

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