http.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 + '/runtime/__gAPYBW4YxB3UePM3lqO/views/__km3aURKW95BHxp12XVt/documents?lines=10&isQueryButton=false',//获取列表数据、更换viewID
  15. wt_xqsh:ip + '/runtime/__gAPYBW4YxB3UePM3lqO/views/__MhHakFCgVJAm81MFUnt/documents?lines=10&isQueryButton=false',
  16. wt_sysh:ip + '/runtime/__gAPYBW4YxB3UePM3lqO/views/__r4IN5HOqV4HIips1s0Q/documents?lines=10&isQueryButton=false',
  17. wt_xqpz:ip + '/runtime/__gAPYBW4YxB3UePM3lqO/views/__yoOF16IOiZdmrbDOujU/documents?lines=10&isQueryButton=false',
  18. wt_sypz:ip + '/runtime/__gAPYBW4YxB3UePM3lqO/views/__b6gD17cP1g4gFdTq0Ox/documents?lines=10&isQueryButton=false',
  19. wt_rwfp:ip + '/runtime/__gAPYBW4YxB3UePM3lqO/views/__m9w03S06KHbg3KioRIh/documents?lines=10&isQueryButton=false',
  20. documents: ip + '/runtime/__gAPYBW4YxB3UePM3lqO/documents/', //获取文档详情
  21. empty: ip + '/runtime/__gAPYBW4YxB3UePM3lqO/forms/__0FLGNncOS1lz0T9jsFn/empty?formId=__0FLGNncOS1lz0T9jsFn&appId=__gAPYBW4YxB3UePM3lqO', //创建委托单文档
  22. }
  23. /**
  24. * 封装的http请求wt_
  25. */
  26. const request = (opt) => {
  27. opt = opt || {};
  28. opt.url = opt.url || '';
  29. opt.data = opt.data || null;
  30. opt.method = opt.method || 'GET';
  31. opt.contentType = opt.contentType || 'application/json;charset=UTF-8'
  32. opt.header = opt.header || {
  33. "Content-Type": opt.contentType,
  34. //"Authorization": getUser().token ? getUser().token : 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NzAxMzYzMjEsInN1YiI6IkFpNmhsbGhOalMydWxsOVRLR2IiLCJleHAiOjE2NzAxMzk5MjEsIm5iZiI6MTY3MDEzNjMyMX0.cNQpCWUwVjA2jkrKCnybIfxl6iQQJ-xj3S8dmQSmQ3A',
  35. "accessToken": getUser().accessToken || ''
  36. };
  37. opt.loading = opt.loading || 'true';
  38. opt.success = opt.success || function() {};
  39. console.log("**************************************参数调式***************************************************");
  40. console.log("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data));
  41. console.log("************************************************************************************************");
  42. if (opt.loading == 'true') {
  43. uni.showLoading({
  44. title: '正在加载',
  45. mask: true
  46. });
  47. }
  48. uni.request({
  49. url: opt.url,
  50. data: opt.data,
  51. method: opt.method,
  52. header: opt.header,
  53. dataType: 'json',
  54. success: res => {
  55. setTimeout(() => {
  56. uni.hideLoading();
  57. }, 500)
  58. /*******************系统内部错误***************************/
  59. if (res.data.code === 500) {
  60. uni.showModal({
  61. content: res.data.msg,
  62. showCancel: false
  63. });
  64. return;
  65. }
  66. if (res.statusCode === 401) {
  67. uni.removeStorageSync('user');
  68. uni.showModal({
  69. title: '提示',
  70. content: '登录超时,请先登陆!',
  71. success: res => {
  72. if (res.confirm) {
  73. uni.navigateTo({
  74. url: '/pages/login'
  75. })
  76. }
  77. }
  78. });
  79. return;
  80. }
  81. opt.success(res);
  82. },
  83. fail: e => {
  84. uni.hideLoading();
  85. uni.getNetworkType({
  86. success: res => {
  87. if (res.networkType == 'none') {
  88. uni.showModal({
  89. content: '当前网络不可用,请检查网络稍后重试',
  90. showCancel: false
  91. });
  92. } else {
  93. uni.showModal({
  94. content: '服务异常,请稍后重试',
  95. showCancel: false
  96. })
  97. }
  98. }
  99. });
  100. }
  101. })
  102. }
  103. const getUser = () => {
  104. return uni.getStorageSync('user');
  105. }
  106. module.exports = {
  107. urls,
  108. request,
  109. getUser
  110. };