http.js 3.9 KB

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