Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {
  2. encryption
  3. } from "./encryption"
  4. /**
  5. * 配置信息,针对不同的平台进行配置
  6. */
  7. export const envs = {
  8. //开发环境配置
  9. development: {
  10. // baseUrl: "222.85.144.89:19002",
  11. baseUrl: "192.168.100.63:8087",
  12. },
  13. //生产环境配置
  14. production: {
  15. baseUrl: "192.168.100.63:8087",
  16. }
  17. }
  18. export function request(code, options = {}) {
  19. //公参
  20. const Common = {
  21. }
  22. //Url 地址
  23. options.url = 'http://' + envs['development'].baseUrl + '/ifzt/api/interfaceMidGroundIn'
  24. // options.url = 'https://' + 'skx.mynatapp.cc' + '/ifzt/api/interfaceMidGroundIn'
  25. //判断baseUri是否为空
  26. if (options.baseUrl) {
  27. options.url = options.baseUrl
  28. }
  29. //默认json数据格式提交`
  30. let contentType = 'application/json;charset=UTF-8'
  31. //根据type判断数据传输格式
  32. if (options.type && options.type === 2) {
  33. contentType = 'application/x-www-form-urlencoded '
  34. }
  35. options.header = {
  36. 'content-type': contentType
  37. }
  38. //默认POST提交
  39. options.method = options.method ? options.method : 'POST'
  40. //设置请求超时时间
  41. options.timeout = 60000
  42. //判断code不为空
  43. if (code) {
  44. options.data = encryption(code, Object.assign(Common, {
  45. ...options.data,
  46. 'appId': '52030131'
  47. }), 2);
  48. }
  49. //是否显示加载中
  50. if (!options.showLoading) {
  51. uni.showLoading({
  52. title: options.showTitle ? options.showTitle : '加载中',
  53. mask: true
  54. });
  55. }
  56. //参数返回
  57. return new Promise((resolve, reject) => {
  58. options.success = (res) => {
  59. // 请求返回后,隐藏loading(如果请求返回快的话,可能会没有loading)
  60. uni.hideLoading()
  61. if (res.data.statusCode !== 0) {
  62. uni.showModal({
  63. title: '提示',
  64. content: res.data.errorMsg,
  65. success: function(res) {
  66. if (res.confirm) {
  67. console.log('用户点击确定');
  68. } else if (res.cancel) {
  69. console.log('用户点击取消');
  70. }
  71. }
  72. });
  73. }
  74. //请求成功
  75. resolve(res.data)
  76. }
  77. options.fail = (err) => {
  78. uni.hideLoading()
  79. console.log('请求错误', err)
  80. //处理请求错误
  81. reject(err)
  82. }
  83. uni.request(options)
  84. });
  85. }