http.js 3.7 KB

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