app.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. App({
  2. data: {
  3. userId: '',
  4. userBalance: '',
  5. refreshFlag:false,
  6. // host: '192.168.0.200:8180',
  7. // baseUrl: 'http://192.168.0.200:8180',
  8. host: '121.236.175.200:8180',
  9. baseUrl: 'http://121.236.175.200:8180',
  10. },
  11. onLaunch(options) {
  12. //获取用户信息
  13. var that = this
  14. var app = getApp()
  15. dd.getAuthCode({
  16. success: function (res) {
  17. app.requestHps('/system/dingLogin/login', { code: res.authCode }).then(res => {
  18. if (res.data.code == 0) {
  19. that.data.userId = res.data.data
  20. } else {
  21. dd.alert({
  22. content: res.msg,
  23. buttonText: '我知道了',
  24. });
  25. }
  26. })
  27. },
  28. fail: function (err) {
  29. console.log(err)
  30. dd.alert({
  31. content: err.message,
  32. buttonText: '我知道了',
  33. });
  34. }
  35. })
  36. },
  37. requestHp(url, data = {}) {
  38. var that = this
  39. return new Promise((resolve, reject) => {
  40. dd.showLoading({
  41. content: '加载中...',
  42. });
  43. dd.httpRequest({
  44. url: that.data.baseUrl + url,
  45. method: 'POST',
  46. data: data,
  47. dataType: 'json',
  48. headers: {
  49. "Content-Type": "application/json"
  50. },
  51. success: function (res) {
  52. // 请求成功
  53. dd.hideLoading()
  54. resolve(res)
  55. var msg = res.data.msg
  56. if (res.data.code == 0 || res.data.code == 200) {
  57. resolve(res)
  58. } else {
  59. dd.alert({
  60. content: msg,
  61. buttonText: '我知道了',
  62. });
  63. }
  64. },
  65. fail: function (res) {
  66. console.log(res)
  67. // 请求失败
  68. dd.alert({
  69. content: res.message,
  70. buttonText: '我知道了',
  71. });
  72. dd.hideLoading()
  73. reject(res)
  74. },
  75. complete: function (res) {
  76. // 请求调用结束 都会执行
  77. }
  78. });
  79. })
  80. },
  81. requestHps(url, data = {}) {
  82. var that = this
  83. return new Promise((resolve, reject) => {
  84. dd.showLoading({
  85. content: '加载中...',
  86. });
  87. dd.httpRequest({
  88. url: that.data.baseUrl + url,
  89. method: 'GET',
  90. data: data,
  91. dataType: 'json',
  92. headers: {
  93. "Content-Type": "application/json"
  94. },
  95. success: function (res) {
  96. dd.hideLoading()
  97. // 请求成功
  98. resolve(res)
  99. var msge = res.data.msg
  100. if (res.data.code == 0 || res.data.code == 200) {
  101. resolve(res)
  102. } else {
  103. dd.alert({
  104. content: msge,
  105. buttonText: '我知道了',
  106. });
  107. }
  108. },
  109. fail: function (res) {
  110. console.log(res)
  111. dd.hideLoading()
  112. // 请求失败
  113. dd.alert({
  114. content: res.message,
  115. buttonText: '我知道了',
  116. });
  117. reject(res)
  118. },
  119. complete: function (res) {
  120. // 请求调用结束 都会执行
  121. }
  122. });
  123. })
  124. },
  125. });