大数据平台的小程序版本

app.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // app.js
  2. var http = require('utils/util.js');
  3. var md5 = require('utils/md5.js');
  4. var commonJs = require('utils/common.js')
  5. var api = require('utils/api.js')
  6. App({
  7. data:{
  8. windowWidth:0,//屏幕的宽度
  9. windowHeight:0,//屏幕的高度
  10. systemInfo:{isIpx:false},
  11. safeAreaTop:30,//距离上面的安全距离
  12. isOnshow:false,
  13. loginCount:0,
  14. statusNavBarHeight:0
  15. },
  16. onLaunch() {
  17. this.data.isOnshow = true
  18. var _this = this;
  19. this.getNavBarHeight()
  20. wx.getSystemInfo({
  21. success (res) {
  22. _this.data.systemInfo = res
  23. _this.data.windowWidth = res.windowWidth
  24. _this.data.windowHeight = res.windowHeight
  25. if(_this.data.systemInfo.platform == "ios"){
  26. _this.data.safeAreaTop = _this.data.systemInfo.statusBarHeight + 10
  27. }else if(_this.data.systemInfo.platform == "android"){
  28. _this.data.safeAreaTop = _this.data.systemInfo.statusBarHeight + 10
  29. }else{
  30. _this.data.safeAreaTop = _this.data.systemInfo.statusBarHeight + 10
  31. }
  32. let modelmes = res.model; //手机品牌
  33. var fringeScreenModels = [
  34. "iPhone 12","iPhone 11","iPhone X", "iPhone x", "vivo X21A", "ASUS Zenfone 5",
  35. "Ulefone T2 Pro", "Leagoo S9", "HUAWEI P20", "DooGee V",
  36. "OPPO R15", "LG G7", "SAMSUNG S9", "COR-AL00",
  37. "vivo Y83A", "LLD-AL20", "vivo Z1", "PACM00", "PAAM00"]
  38. fringeScreenModels.forEach((item)=>{
  39. if (modelmes.indexOf(item) != -1) {
  40. _this.data.systemInfo.isIpx = true
  41. }
  42. })
  43. }
  44. })
  45. this.verified();//版本控制(过审用)
  46. },
  47. onShow:function(){
  48. if(!wx.getStorageSync('isLogin')){//解决未登录情况下,点击左上角home
  49. if(this.data.isOnshow){
  50. this.data.isOnshow = false
  51. }else{
  52. this.verified();//版本控制(过审用)
  53. }
  54. }
  55. },
  56. getNavBarHeight(){
  57. // 获取状态栏高度
  58. const { statusBarHeight } = wx.getSystemInfoSync();
  59. // 得到右上角菜单的位置尺寸
  60. const menuButtonObject = wx.getMenuButtonBoundingClientRect();
  61. const { top, height } = menuButtonObject;
  62. // 计算导航栏的高度
  63. // 此高度基于右上角菜单在导航栏位置垂直居中计算得到
  64. const navBarHeight = height + (top - statusBarHeight) * 2;
  65. // 计算状态栏与导航栏的总高度
  66. this.data.statusNavBarHeight = statusBarHeight + navBarHeight
  67. },
  68. verified(cb){//版本控制
  69. var _this = this;
  70. http.req(api.api.verified, 'get', {
  71. version: 'v1.2'
  72. }, function (res) {
  73. if(res && res.errno == 0){
  74. wx.setStorageSync('isLogin',false)
  75. wx.setStorageSync('admin_id',res.rst.data.id)
  76. if(!wx.getStorageSync('ttl')||wx.setStorageSync('ttl')!=res.rst.data.ttl) {
  77. wx.setStorageSync('ttl',res.rst.data.ttl)
  78. var sign=md5.hex_md5("random="+res.rst.data.random+"&ttl="+res.rst.data.ttl+"&user_id="+res.rst.data.id);
  79. wx.setStorageSync('sign',sign)
  80. }
  81. wx.setStorageSync('doneLogin', false)
  82. if (getCurrentPages().length != 0) {
  83. //刷新当前页面的数据
  84. getCurrentPages()[getCurrentPages().length - 1].onLoad()
  85. }
  86. }else{
  87. _this.login({})
  88. }
  89. },(err)=>{
  90. })
  91. },
  92. // 登录
  93. login({encryptedData,iv,cb}){
  94. var _this = this;
  95. wx.login({
  96. success (res) {
  97. if (res.code) {
  98. var params = {code: res.code,}
  99. if(encryptedData){
  100. params.encrypted_data = encryptedData;
  101. params.iv = iv;
  102. }
  103. http.req(api.api.Login, 'get', params, function (res) {
  104. wx.hideLoading()
  105. if(res && res.errno == 0){
  106. var session_key = res.rst.session_key;
  107. wx.setStorageSync('session_key',session_key)
  108. wx.setStorageSync('userInfo',res.rst.info)
  109. wx.setStorageSync('admin_id',res.rst.info.id)
  110. wx.setStorageSync('ttl',res.rst.ttl)
  111. var sign=md5.hex_md5("random="+res.rst.random+"&ttl="+res.rst.ttl+"&user_id="+res.rst.info.id);
  112. wx.setStorageSync('sign',sign)
  113. wx.setStorageSync('isLogin',true)
  114. cb?cb():''
  115. let pages = getCurrentPages(); //页面对象
  116. let currentPage = pages[0];
  117. if(Object.keys(currentPage.options).length>0) {
  118. currentPage.onShow();
  119. }else {
  120. currentPage.onLoad();
  121. }
  122. }else if(res.errno == 1303){//新用户
  123. wx.redirectTo({
  124. url: '/pages/welcome/welcome',
  125. })
  126. }else{
  127. if(_this.data.loginCount==0){//第一次请求失败,再来一次
  128. setTimeout(()=>{
  129. _this.login({})
  130. _this.data.loginCount = 1
  131. },500)
  132. }
  133. }
  134. },()=>{
  135. wx.hideLoading()
  136. })
  137. } else {
  138. console.log('登录失败!' + res.errMsg)
  139. }
  140. }
  141. })
  142. },
  143. shareEvent(res){//分享
  144. if(res.from === 'button'){
  145. //来自页面内转发按钮
  146. }
  147. return{
  148. title:'问星赚赚-帮助视频号创业者更快变现的服务平台',
  149. imageUrl:'https://kx-bigdata.oss-cn-beijing.aliyuncs.com/Applet/recevice/recevice_share.png',
  150. path: '/pages/index/index'
  151. }
  152. },
  153. shareTimeline(res){//分享到朋友圈
  154. let img = 'https://kx-bigdata.oss-cn-beijing.aliyuncs.com/Applet/recevice/recevice_share.png'
  155. return {
  156. title: '问星赚赚-帮助视频号创业者更快变现的服务平台', //字符串 自定义标题
  157. query: `source=pyq`, //页面携带参数
  158. imageUrl:img //图片地址
  159. }
  160. },
  161. func: {
  162. req: http.req,
  163. md5: md5.hex_md5,
  164. getDay: commonJs.getDay,
  165. NumberHandle: commonJs.NumberHandle,
  166. api:api.api
  167. }
  168. })