App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <script>
  2. import Vue from 'vue'
  3. export default {
  4. onLaunch: function() {
  5. //检查是否登录
  6. //this.$api.user.hasLogin();
  7. //字符串加密
  8. Vue.prototype.$strEncode = function($data) {
  9. if (typeof $data == 'object') {
  10. $data = JSON.stringify($data);
  11. }
  12. var key = CryptoJS.enc.Latin1.parse('BC1F5E3BAEE198AC');
  13. var iv = CryptoJS.enc.Latin1.parse('1F5E3BAEE198ACE1');
  14. var encoded = CryptoJS.AES.encrypt($data, key, {
  15. iv: iv,
  16. mode: CryptoJS.mode.CBC, //模式
  17. adding: CryptoJS.pad.ZeroPadding
  18. }).toString();
  19. if (!encoded) {
  20. return '';
  21. }
  22. return encoded
  23. },
  24. Vue.prototype.clientType = function() {
  25. let c = 1; //默认为电脑
  26. // #ifdef APP-PLUS
  27. switch (uni.getSystemInfoSync().platform) {
  28. case 'android':
  29. c = 3;
  30. break;
  31. case 'ios':
  32. c = 4;
  33. break;
  34. default:
  35. }
  36. // #endif
  37. // #ifdef h5
  38. c = 2;
  39. // #endif
  40. // #ifdef MP-WEIXIN
  41. c = 5;
  42. // #endif
  43. return c
  44. }
  45. uni.getSystemInfo({
  46. success: function(e) {
  47. // #ifndef MP
  48. Vue.prototype.StatusBar = e.statusBarHeight;
  49. if (e.platform == 'android') {
  50. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  51. } else {
  52. Vue.prototype.CustomBar = e.statusBarHeight + 45;
  53. };
  54. // #endif
  55. // #ifdef MP-WEIXIN
  56. Vue.prototype.StatusBar = e.statusBarHeight;
  57. let custom = wx.getMenuButtonBoundingClientRect();
  58. Vue.prototype.Custom = custom;
  59. Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
  60. // #endif
  61. // #ifdef MP-ALIPAY
  62. Vue.prototype.StatusBar = e.statusBarHeight;
  63. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  64. // #endif
  65. }
  66. })
  67. //关闭页面
  68. Vue.prototype.closePage = function() {
  69. console.log(getCurrentPages());
  70. if (getCurrentPages().length > 1) {
  71. uni.navigateBack();
  72. } else {
  73. // #ifdef H5
  74. history.back()
  75. // #endif
  76. // #ifndef H5
  77. uni.reLaunch({
  78. url: '/pages/index/index'
  79. });
  80. // #endif
  81. }
  82. }
  83. /**
  84. * 统一跳转接口,拦截未登录路由
  85. * navigator标签现在默认没有转场动画,所以用view
  86. */
  87. Vue.prototype.navTo = function(url) {
  88. // if(!this.hasLogin){
  89. // url = '/pages/user/login/login';
  90. // }
  91. uni.navigateTo({
  92. url: url
  93. })
  94. }
  95. },
  96. onShow: function() {
  97. try {
  98. const value = uni.getStorageSync('userData');
  99. if (value) {
  100. //有登录信息
  101. that.$store.dispatch("setUserData", value); //存入状态
  102. } else {
  103. //用户未登录
  104. /* uni.navigateTo({
  105. url: '/pages/user/login/login',
  106. }); */
  107. }
  108. } catch (e) {
  109. // error
  110. }
  111. },
  112. onHide: function() {
  113. console.log('App Hide')
  114. }
  115. }
  116. </script>
  117. <style>
  118. @import "/common/iconfont/iconfont.css";
  119. /* #ifndef APP-PLUS-NVUE */
  120. @import "/common/main.css";
  121. /* #endif */
  122. /* 骨架屏方案 */
  123. .Skeleton {
  124. background-color: #f3f3f3;
  125. padding: 20upx 0;
  126. border-radius: 6upx;
  127. }
  128. body {
  129. background: #F2F2F4;
  130. }
  131. </style>