蓝色 贷款产品助手

app.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //app.js
  2. var appInstance = getApp()
  3. // console.log(appInstance.onShow())
  4. App({
  5. data:{
  6. },
  7. globalData: {
  8. common: {
  9. source: 0,
  10. app_type: 3
  11. },
  12. userInfo: null,
  13. HOST: 'https://chaoshi.henhaojie.com',
  14. platform: 0,
  15. title: '',
  16. img: ''
  17. },
  18. // 在这个app里面this就是app实例
  19. // 监听小程序初始化
  20. onLaunch: function (){
  21. let system = '', app = this;
  22. const shareInfo = wx.getStorageSync('shareInfo');
  23. if (shareInfo) {
  24. app.globalData.title = shareInfo.title;
  25. app.globalData.img = shareInfo.img;
  26. }else{
  27. wx.redirectTo({url: '/pages/login/login'})
  28. }
  29. wx.getSystemInfo({
  30. success: function(res) {
  31. system = res.system
  32. console.log(system)
  33. if (system.indexOf('iOS') == -1) {
  34. app.globalData.platform = 1;
  35. }else{
  36. app.globalData.platform = 2;
  37. }
  38. console.log(app.globalData.platform);
  39. }
  40. })
  41. },
  42. // 监听小程序显示
  43. onShow: function (options) {
  44. },
  45. // 监听小程序隐藏
  46. onHide: function () {
  47. },
  48. onUnload () {
  49. wx.clearStorage();
  50. },
  51. // 错误监听函数
  52. onError: function (msg) {
  53. console.log(msg)
  54. },
  55. login: function (that, func) {
  56. let obj = {}, app = this, user = '', source = '';
  57. if (that.data.source) {
  58. source = that.data.source
  59. }
  60. wx.login({
  61. success: function(res) {
  62. if (res.code) {
  63. wx.request({
  64. url: app.globalData.HOST + '/user/wx/login',
  65. method: "POST",
  66. data: {
  67. code: res.code,
  68. iv: app.globalData.userInfo.iv,
  69. encryptedData: app.globalData.userInfo.encryptedData,
  70. source: source,
  71. app_type: 3
  72. },
  73. success: function (resLogin) {
  74. if (resLogin.data.errno == 0) {
  75. user = resLogin.data.rst;
  76. wx.setStorageSync("user", user)
  77. app.globalData.common['token'] = user.token
  78. wx.switchTab({'url': '/pages/index/index'})
  79. if (func) {
  80. func();
  81. }
  82. app.initShare();
  83. }
  84. }
  85. })
  86. } else {
  87. console.log('登录失败!' + res.errMsg)
  88. }
  89. }
  90. });
  91. },
  92. initShare () {
  93. var app = this;
  94. var title='', img = '';
  95. wx.request({
  96. url: app.globalData.HOST + '/user/wx/share',
  97. method: 'POST',
  98. data: app.globalData.common,
  99. success: function (res) {
  100. if (res.data.errno == '0'){
  101. title = res.data.rst.title;
  102. img = res.data.rst.pic;
  103. }
  104. app.globalData.title = title;
  105. app.globalData.img = img;
  106. wx.setStorage({
  107. key: 'shareInfo',
  108. data: {
  109. title: title,
  110. img: img
  111. }
  112. })
  113. }
  114. });
  115. },
  116. confirmModal (content, func) {
  117. wx.showModal({
  118. title: '小提示',
  119. content: content,
  120. success: function(res) {
  121. if (res.confirm) {
  122. func();
  123. } else if (res.cancel) {
  124. }
  125. }
  126. })
  127. },
  128. noticeModal (content, func) {
  129. wx.showModal({
  130. title: '小提示',
  131. content: content,
  132. showCancel: false,
  133. confirmText: '我知道了',
  134. success: function(res) {
  135. if (res.confirm) {
  136. if (func) {
  137. func();
  138. }
  139. }
  140. }
  141. })
  142. }
  143. })