app.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import {
  2. Router
  3. } from "./utils/common";
  4. import {
  5. requst_post_login
  6. } from './pages/api/index.js'
  7. App({
  8. globalData: {
  9. employId:"",
  10. token: null,
  11. userInfo: null,
  12. flag: false,
  13. navHeight: null,
  14. navTop: null,
  15. windowHeight: null,
  16. navHeight: 0,
  17. navTop: 0,
  18. jnheight: 0,
  19. jnwidth: 0,
  20. screenHeight: 0,
  21. isInitialized: false
  22. },
  23. onLaunch: function () {
  24. var that = this;
  25. // 登录1 获取code
  26. wx.login({
  27. success: res => {
  28. // console.log(res.code+'我是登录中的')
  29. const code = res.code;
  30. if (code) {
  31. //将code发送到开发者服务器
  32. wx.getUserInfo({
  33. success: res => {
  34. // console.log(res,'getUserInfo')
  35. let encryptedData = res.encryptedData;
  36. let iv = res.iv;
  37. requst_post_login({
  38. encryptedData: encryptedData,
  39. iv: iv,
  40. code: code
  41. }).then(res => {
  42. that.globalData.token = res.data.data.token;
  43. this.globalData.isInitialized = true;
  44. // console.log( that.globalData.token ,' that.globalData.token ')
  45. if (res.data.data) {
  46. // 回调
  47. // this.globalData.employId= res.data.data;
  48. // let employId=res.data.data;
  49. //由于这里是网络请求,可能会在 Page.onLoad 之后才返回
  50. // 所以此处加入 callback 以防止这种情况
  51. wx.setStorage({
  52. key: 'access-token',
  53. data: res.data.data.token,
  54. })
  55. wx.setStorage({
  56. key: 'wx_name',
  57. data: res.data.data.nickName,
  58. })
  59. wx.setStorage({
  60. key: 'wx_img',
  61. data: res.data.data.avatarUrl,
  62. })
  63. setTimeout(function () {
  64. wx.switchTab({
  65. url: '/pages/scan/scan'
  66. })
  67. }, 400)
  68. if (this.employIdCallback){
  69. this.employIdCallback(employId);
  70. }
  71. } else {}
  72. }).catch(err => {
  73. console.log('ajax_err', err)
  74. })
  75. }
  76. })
  77. }
  78. }
  79. })
  80. //获取菜单按钮的布局位置信息
  81. let menuButtonObject = wx.getMenuButtonBoundingClientRect();
  82. //获取系统信息
  83. wx.getSystemInfo({
  84. success: res => {
  85. console.log('xxxx', res.screenWidth)
  86. //状态栏的高度
  87. let statusBarHeight = res.statusBarHeight,
  88. //胶囊按钮与顶部的距离
  89. navTop = menuButtonObject.top,
  90. navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2;
  91. let globalData = this.globalData;
  92. globalData.navHeight = navHeight;//导航栏高度
  93. globalData.navTop = navTop;//胶囊按钮与顶部的距离
  94. globalData.jnheight = menuButtonObject.height;//胶囊的高度
  95. globalData.jnwidth = menuButtonObject.width;//胶囊的宽度
  96. globalData.screenHeight = res.screenHeight;//屏幕高度
  97. globalData.screenWidth = res.screenWidth;
  98. },
  99. fail(err) {
  100. console.log(err);
  101. }
  102. });
  103. },
  104. //渐入,渐出实现
  105. show : function(that,param,opacity){
  106. var animation = wx.createAnimation({
  107. //持续时间800ms
  108. duration: 800,
  109. timingFunction: 'ease',
  110. });
  111. //var animation = this.animation
  112. animation.opacity(opacity).step()
  113. //将param转换为key
  114. var json = '{"' + param + '":""}'
  115. json = JSON.parse(json);
  116. json[param] = animation.export()
  117. //设置动画
  118. that.setData(json)
  119. },
  120. //滑动渐入渐出
  121. slideupshow:function(that,param,px,opacity){
  122. var animation = wx.createAnimation({
  123. duration: 800,
  124. timingFunction: 'ease',
  125. });
  126. animation.translateY(px).opacity(opacity).step()
  127. //将param转换为key
  128. var json = '{"' + param + '":""}'
  129. json = JSON.parse(json);
  130. json[param] = animation.export()
  131. //设置动画
  132. that.setData(json)
  133. },
  134. //向右滑动渐入渐出
  135. sliderightshow: function (that, param, px, opacity) {
  136. var animation = wx.createAnimation({
  137. duration: 800,
  138. timingFunction: 'ease',
  139. });
  140. animation.translateX(px).opacity(opacity).step()
  141. //将param转换为key
  142. var json = '{"' + param + '":""}'
  143. json = JSON.parse(json);
  144. json[param] = animation.export()
  145. //设置动画
  146. that.setData(json)
  147. }
  148. })