app.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //app.js
  2. var app = getApp();
  3. // var wxh = require('../../utils/wxh.js');
  4. App({
  5. onLaunch: function () {
  6. // 展示本地存储能力
  7. var that = this;
  8. var logs = wx.getStorageSync('logs') || []
  9. logs.unshift(Date.now())
  10. wx.setStorageSync('logs', logs)
  11. that.getRoutineStyle();
  12. },
  13. globalData: {
  14. routineStyle:'#ffffff',
  15. uid: null,
  16. openPages:'',
  17. spid:0,
  18. urlImages: '',
  19. url: 'https://shop.crmeb.net/'
  20. },
  21. getRoutineStyle:function(){
  22. var that = this;
  23. wx.request({
  24. url: that.globalData.url + '/routine/login/get_routine_style',
  25. method: 'post',
  26. dataType  : 'json',
  27. success: function (res) {
  28. that.globalData.routineStyle = res.data.data.routine_style;
  29. that.setBarColor();
  30. }
  31. })
  32. },
  33. setBarColor:function(){
  34. var that = this;
  35. wx.setNavigationBarColor({
  36. frontColor: '#000000',
  37. backgroundColor: that.globalData.routineStyle,
  38. })
  39. },
  40. setUserInfo : function(){
  41. var that = this;
  42. if (that.globalData.uid == null) {//是否存在用户信息,如果不存在跳转到首页
  43. wx.showToast({
  44. title: '用户信息获取失败',
  45. icon: 'none',
  46. duration: 1500,
  47. })
  48. setTimeout(function () {
  49. wx.navigateTo({
  50. url: '/pages/enter/enter',
  51. })
  52. }, 2000)
  53. }
  54. },
  55. getUserInfo: function () {
  56. var that = this;
  57. wx.getUserInfo({
  58. lang: 'zh_CN',
  59. success: function (res) {
  60. var userInfo = res.userInfo
  61. wx.login({
  62. success: function (res) {
  63. if (res.code) {
  64. userInfo.code = res.code;
  65. userInfo.spid = that.globalData.spid;
  66. wx.request({
  67. url: that.globalData.url + '/routine/login/index',
  68. method: 'post',
  69. dataType  : 'json',
  70. data: {
  71. info: userInfo
  72. },
  73. success: function (res) {
  74. that.globalData.uid = res.data.data.uid;
  75. if (!res.data.data.status){
  76. wx.redirectTo({
  77. url: '/pages/login-status/login-status',
  78. })
  79. }
  80. if (that.globalData.openPages != '') {
  81. wx.navigateTo({
  82. url: that.globalData.openPages
  83. })
  84. } else {
  85. wx.switchTab({
  86. url: '/pages/index/index'
  87. })
  88. }
  89. },
  90. fail: function () {
  91. console.log('获取用户信息失败');
  92. wx.navigateTo({
  93. url: '/pages/enter/enter',
  94. })
  95. },
  96. })
  97. } else {
  98. console.log('登录失败!' + res.errMsg)
  99. }
  100. },
  101. fail: function () {
  102. console.log('获取用户信息失败');
  103. wx.navigateTo({
  104. url: '/pages/enter/enter',
  105. })
  106. },
  107. })
  108. },
  109. fail:function(){
  110. console.log('获取用户信息失败');
  111. wx.navigateTo({
  112. url: '/pages/enter/enter',
  113. })
  114. },
  115. })
  116. },
  117. getUserInfoEnter: function () {
  118. var that = this;
  119. wx.getUserInfo({
  120. lang: 'zh_CN',
  121. success: function (res) {
  122. var userInfo = res.userInfo
  123. wx.login({
  124. success: function (res) {
  125. if (res.code) {
  126. userInfo.code = res.code;
  127. userInfo.spid = that.globalData.spid;
  128. wx.request({
  129. url: that.globalData.url + '/routine/login/index',
  130. method: 'post',
  131. dataType  : 'json',
  132. data: {
  133. info: userInfo
  134. },
  135. success: function (res) {
  136. that.globalData.uid = res.data.data.uid;
  137. if (that.globalData.openPages != '') {
  138. wx.navigateTo({
  139. url: that.globalData.openPages
  140. })
  141. } else {
  142. wx.reLaunch({
  143. url: '/pages/index/index'
  144. })
  145. }
  146. }
  147. })
  148. } else {
  149. console.log('登录失败!' + res.errMsg)
  150. }
  151. },
  152. fail: function (res) {
  153. wx.showToast({
  154. title: '授权失败,请重新打开小程序',
  155. icon: 'none',
  156. duration: 1500,
  157. })
  158. }
  159. })
  160. },
  161. fail: function (res) {
  162. wx.showToast({
  163. title: '授权失败,请重新授权',
  164. icon: 'none',
  165. duration: 1500,
  166. })
  167. }
  168. })
  169. },
  170. })