App.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. },TIME)
  124. },
  125. diffTime(t){
  126. let date = Date.now();
  127. return (date -t) < 2*60*1000 ? false : true
  128. }
  129. },
  130. onShow: function() {
  131. },
  132. onHide: function() {
  133. console.log('App Hide')
  134. },
  135. }
  136. </script>
  137. <style lang="scss">
  138. /*每个页面公共css */
  139. @import "@/common/css/common.scss";
  140. @import "@/common/css/iconfont.scss";
  141. @import "@/common/css/style/thorui.css";
  142. @import "@/common/css/style/icon.css";
  143. view,
  144. scroll-view,
  145. swiper,
  146. swiper-item,
  147. cover-view,
  148. cover-image,
  149. icon,
  150. text,
  151. rich-text,
  152. progress,
  153. button,
  154. checkbox,
  155. form,
  156. input,
  157. label,
  158. radio,
  159. slider,
  160. switch,
  161. textarea,
  162. navigator,
  163. audio,
  164. camera,
  165. image,
  166. video {
  167. // box-sizing: border-box;
  168. }
  169. // page {
  170. // width: 100%;
  171. // height: 100%;
  172. // background: #fff;
  173. // filter: grayscale(100%);
  174. // filter: gray;
  175. // filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
  176. // --toast-default-width: 114px;
  177. // }
  178. page{
  179. height: 100%;
  180. background-color: #FFFFFF;
  181. }
  182. /* 骨架屏替代方案 */
  183. .Skeleton {
  184. background: #f3f3f3;
  185. padding: 20upx 0;
  186. border-radius: 8upx;
  187. }
  188. .clamp {
  189. overflow: hidden;
  190. text-overflow: ellipsis;
  191. white-space: nowrap;
  192. display: block;
  193. }
  194. .common-hover {
  195. background: #f5f5f5;
  196. }
  197. /* input 样式 */
  198. .input-placeholder {
  199. color: #999999;
  200. }
  201. .placeholder {
  202. color: #999999;
  203. }
  204. </style>