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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {
  2. appId,
  3. envs
  4. } from "./api";
  5. import {
  6. encryption
  7. } from "./encryption";
  8. import {
  9. getItem,
  10. StorageKeys
  11. } from "../storage";
  12. import {
  13. sm4Key
  14. } from "../network/api.js";
  15. import {
  16. SM4Util
  17. } from '../util/sm4.js'
  18. const s4 = new SM4Util()
  19. //请求
  20. export function request(code, options = {}) {
  21. //公参
  22. const Common = {
  23. agentId: "52010106004",
  24. channelId: "5201010200601130001",
  25. channelType: "1",
  26. staffId: "54623263cb4d4a289dccbc983b22a4af",
  27. terminalId: "999999999999",
  28. loginSource: "69af303ba2eb4608a099163f0d2a5dbd",
  29. rbacSource: 'MINI_PROGRAM'
  30. }
  31. //Url 地址 /api/interfaceMidGroundIn
  32. options.url = 'http://' + envs[process.env.NODE_ENV].baseUrl + '/ifzt/api/interfaceMidGroundIn'
  33. //判断baseUri是否为空
  34. if (options.baseUrl) {
  35. options.url = options.baseUrl
  36. }
  37. //默认json数据格式提交`
  38. let contentType = 'application/x-www-form-urlencoded'
  39. //根据type判断数据传输格式
  40. if (options.type && options.type === 2) {
  41. contentType = 'application/json;charset=UTF-8'
  42. }
  43. options.header = {
  44. 'content-type': contentType,
  45. 'Access-Token': getItem(StorageKeys.Token)
  46. }
  47. //默认POST提交
  48. options.method = options.method ? options.method : 'POST'
  49. //设置请求超时时间
  50. options.timeout = 60000
  51. //判断code不为空
  52. if (code) {
  53. options.data = encryption(code, Object.assign(Common, {
  54. ...options.data,
  55. 'appId': appId
  56. }), 2);
  57. }
  58. //是否显示加载中
  59. if (options.showLoading) {
  60. wx.showLoading({
  61. title: '请稍后',
  62. mask: true
  63. });
  64. }
  65. console.log('请求参数:', options.data)
  66. //参数返回
  67. return new Promise((resolve, reject) => {
  68. options.success = (res) => {
  69. console.log('请求成功返回参数:', res)
  70. // 请求返回后,隐藏loading(如果请求返回快的话,可能会没有loading)
  71. wx.hideLoading()
  72. if (res.data.statusCode !== 0) {
  73. if (res.data.statusCode == 600) {
  74. resolve(res.data)
  75. } else if (res.data.statusCode == 401) {
  76. wx.showModal({
  77. title: '提示',
  78. content: res.data.errorMsg,
  79. confirmText: '去登录',
  80. showCancel: false,
  81. success: function(res) {
  82. if (res.confirm) {
  83. uni.navigateTo({
  84. url: '/login/login',
  85. })
  86. }
  87. }
  88. });
  89. } else {
  90. wx.showModal({
  91. title: '提示',
  92. content: res.data.errorMsg,
  93. success: function(res) {
  94. if (res.confirm) {
  95. console.log('用户点击确定');
  96. } else if (res.cancel) {
  97. console.log('用户点击取消');
  98. }
  99. }
  100. });
  101. }
  102. reject(res.data.errorMsg)
  103. return
  104. }
  105. let content = res
  106. // let content = s4.decryptData_CBC(res, sm4Key)
  107. // console.log(content);
  108. // content.data.bizContent = JSON.stringify(content.data.bizContent)
  109. // console.log(content.data);
  110. resolve(content.data)
  111. }
  112. options.fail = (err) => {
  113. console.log('请求失败返回参数:', res)
  114. wx.hideLoading()
  115. console.log('请求错误', err)
  116. //处理请求错误
  117. reject(err)
  118. }
  119. wx.request(options)
  120. });
  121. }