App.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <script>
  2. /**
  3. * vuex管理登陆状态,具体可以参考官方登陆模板示例
  4. */
  5. import Vue from 'vue'
  6. import { mapState,mapMutations} from 'vuex';
  7. import authorize from '@/common/config/authorize.js'
  8. export default {
  9. onLaunch: function() {
  10. let self = this
  11. //小程序热更新代码
  12. // if (wx.canIUse('getUpdateManager')) {
  13. // const updateManager = wx.getUpdateManager()
  14. // updateManager.onCheckForUpdate(function (res) {
  15. // console.log('onCheckForUpdate====', res)
  16. // // 请求完新版本信息的回调
  17. // if (res.hasUpdate) {
  18. // console.log('res.hasUpdate====')
  19. // updateManager.onUpdateReady(function () {// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  20. // self.$util.modal('更新提示','新版本已经准备好,是否重启应用?','确定','取消',true,() =>{
  21. // updateManager.applyUpdate()
  22. // })
  23. // })
  24. // updateManager.onUpdateFailed(function () { // 新的版本下载失败
  25. // self.$util.modal('已经有新版本了哟~','新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~','确定','取消',true,() =>{
  26. // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  27. // updateManager.applyUpdate()
  28. // })
  29. // })
  30. // }
  31. // })
  32. // }
  33. uni.getSystemInfo({
  34. success: function(e) {
  35. let modelmes = e.model;
  36. console.log(e);
  37. if (modelmes.search('iPhone 11') || modelmes.search('iPhone 11 Pro Max') ||modelmes.search('iPhone X') != -1) { //XS,XR,XS MAX均可以适配
  38. self.$store.dispatch('setVariableFun',true)
  39. }else{
  40. self.$store.dispatch('setVariableFun',false)
  41. }
  42. // #ifndef MP
  43. Vue.prototype.StatusBar = e.statusBarHeight;
  44. if (e.platform == 'android') {
  45. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  46. Vue.prototype.platformClass = true
  47. } else {
  48. Vue.prototype.CustomBar = e.statusBarHeight + 45;
  49. Vue.prototype.platformClass = false
  50. };
  51. // #endif
  52. // #ifdef MP-WEIXIN || MP-QQ
  53. console.log(e.platform)
  54. if (e.platform == 'android') {
  55. Vue.prototype.platformClass = 'left'
  56. self.$store.dispatch('setVariableFun',false)
  57. } else {
  58. Vue.prototype.platformClass = 'center'
  59. self.$store.dispatch('setIsIphoneFun',true)
  60. }
  61. Vue.prototype.StatusBar = e.statusBarHeight;
  62. Vue.prototype.fontSizeSetting = e.fontSizeSetting
  63. Vue.prototype.screenWidth = e.screenWidth
  64. let capsule = wx.getMenuButtonBoundingClientRect();
  65. Vue.prototype.capsule = capsule
  66. if (capsule) {
  67. Vue.prototype.Custom = capsule;
  68. // Vue.prototype.capsuleSafe = uni.upx2px(750) - capsule.left + uni.upx2px(750) - capsule.right;
  69. Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
  70. } else {
  71. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  72. }
  73. // #endif
  74. // #ifdef MP-ALIPAY
  75. Vue.prototype.StatusBar = e.statusBarHeight;
  76. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  77. // #endif
  78. }
  79. })
  80. this.refresh()
  81. if(uni.getStorageSync('isActivityStatus')){
  82. const lockTime = uni.getStorageSync('lockTime')
  83. const eTime = this.diffTime(lockTime)
  84. this.$store.dispatch('setActivityFn',eTime)
  85. }else{
  86. this.$store.dispatch('setActivityFn',true)
  87. }
  88. },
  89. methods:{
  90. ...mapMutations(['login','logout','isWxAuthorize']),
  91. async getWxAuthorize(){
  92. const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  93. const getUserInfo = await authorize.getUserInfo('weixin');
  94. this.UserService.UserLoginAuthApplets({
  95. code:wechatCode,
  96. encryptedData:getUserInfo.encryptedData,
  97. iv:getUserInfo.iv
  98. })
  99. .then(response =>{
  100. this.$store.commit('updateStatus',response.data)
  101. this.login(response.data);
  102. uni.setStorageSync('token',response.data.token)
  103. uni.setStorageSync('unionId',response.data.unionId)
  104. })
  105. .catch(error =>{
  106. this.logout(error.data)
  107. uni.setStorageSync('unionId',error.data.unionId)
  108. this.$store.commit('updateStatus',error.data)
  109. })
  110. },
  111. refresh(){
  112. let TIME = (20*60)*1000;
  113. setInterval(()=>{
  114. authorize.getSetting().then(res =>{
  115. console.log('用户是否授权过',res)
  116. if(res == 1){
  117. this.getWxAuthorize()
  118. }else{
  119. console.log(new Date +'用户未授权微信信息')
  120. this.$api.navigateTo('/pages/authorization/authorization')
  121. }
  122. })
  123. // if(uni.getStorageSync('_WX_State')){
  124. // this.getWxAuthorize()
  125. // }else{
  126. // console.log(new Date +'用户未授权微信信息')
  127. // this.$api.navigateTo('/pages/authorization/authorization')
  128. // }
  129. },TIME)
  130. },
  131. diffTime(t){
  132. let date = Date.now();
  133. return (date -t) < 2*60*1000 ? false : true
  134. }
  135. },
  136. onShow: function() {
  137. },
  138. onHide: function() {
  139. console.log('App Hide')
  140. },
  141. }
  142. </script>
  143. <style lang="scss">
  144. /*每个页面公共css */
  145. @import "@/common/css/common.scss";
  146. @import "@/common/css/iconfont.scss";
  147. @import "@/common/css/style/thorui.css";
  148. @import "@/common/css/style/icon.css";
  149. view,
  150. scroll-view,
  151. swiper,
  152. swiper-item,
  153. cover-view,
  154. cover-image,
  155. icon,
  156. text,
  157. rich-text,
  158. progress,
  159. button,
  160. checkbox,
  161. form,
  162. input,
  163. label,
  164. radio,
  165. slider,
  166. switch,
  167. textarea,
  168. navigator,
  169. audio,
  170. camera,
  171. image,
  172. video {
  173. // box-sizing: border-box;
  174. }
  175. // page {
  176. // width: 100%;
  177. // height: 100%;
  178. // background: #fff;
  179. // filter: grayscale(100%);
  180. // filter: gray;
  181. // filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
  182. // --toast-default-width: 114px;
  183. // }
  184. page{
  185. height: 100%;
  186. background-color: #FFFFFF;
  187. }
  188. /* 骨架屏替代方案 */
  189. .Skeleton {
  190. background: #f3f3f3;
  191. padding: 20upx 0;
  192. border-radius: 8upx;
  193. }
  194. .clamp {
  195. overflow: hidden;
  196. text-overflow: ellipsis;
  197. white-space: nowrap;
  198. display: block;
  199. }
  200. .common-hover {
  201. background: #f5f5f5;
  202. }
  203. /* input 样式 */
  204. .input-placeholder {
  205. color: #999999;
  206. }
  207. .placeholder {
  208. color: #999999;
  209. }
  210. </style>