帮你贷的小程序

app.js 3.1KB

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