App.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <script>
  2. export default {
  3. onLaunch: function(option) {
  4. // #ifdef APP-PLUS
  5. uni.getSystemInfo({
  6. success: res => {
  7. let fontsize = ((res.windowWidth * 16) / 1200) * 5.5 + 'px';
  8. this.$store.commit('setRootSize', fontsize);
  9. }
  10. });
  11. // #endif
  12. this.$store.dispatch('getAddonIsExit');
  13. this.$store.dispatch('getDefautlImg');
  14. if (uni.getStorageSync('cashier_token')) {
  15. this.$store.dispatch('getStoreInfo');
  16. this.$store.dispatch('getUserInfo');
  17. this.$store.dispatch('getUserGroup');
  18. }
  19. this.$store.commit('setCurrRoute', '/' + option.path);
  20. // #ifdef APP-PLUS
  21. plus.webview.open(this.$config.baseUrl + '/cashier/pages/index/loading', 'loading');
  22. uni.switchTab({
  23. url: '/pages/reserve/index',
  24. success: () => {
  25. uni.switchTab({
  26. url: '/pages/recharge/index',
  27. success: () => {
  28. uni.switchTab({
  29. url: '/pages/verify/index',
  30. success: () => {
  31. if (!uni.getStorageSync('cashier_token')) {
  32. uni.navigateTo({ url: '/pages/login/login' });
  33. } else {
  34. uni.switchTab({ url: '/pages/billing/index' });
  35. }
  36. plus.webview.close('loading');
  37. }
  38. });
  39. }
  40. });
  41. }
  42. });
  43. // #endif
  44. },
  45. onShow: function(option) {
  46. if (!uni.getStorageSync('cashier_token')) {
  47. // #ifdef H5
  48. if (location.href.indexOf('pages/index/loading') == -1) {
  49. this.$util.redirectTo('/pages/login/login', {}, 'redirectTo');
  50. }
  51. // #endif
  52. // #ifndef H5
  53. this.$util.redirectTo('/pages/login/login', {}, 'redirectTo');
  54. // #endif
  55. }
  56. },
  57. onHide: function() {},
  58. methods: {
  59. initRoute(route) {
  60. const search = function(menu, route, arr = []) {
  61. menu.find((item, index) => {
  62. if (item.path == route) {
  63. arr.push(index);
  64. return true;
  65. } else if (item.children) {
  66. arr = search(item.children, route, arr);
  67. if (arr.length) {
  68. arr.push(index);
  69. return true;
  70. } else {
  71. return false;
  72. }
  73. }
  74. return false;
  75. });
  76. return arr;
  77. };
  78. let menuIndex = search(this.menu, route).reverse();
  79. this.$store.commit('setMemuIndex', { level: 'first', index: menuIndex[0] });
  80. this.$store.commit('setMemuIndex', { level: 'second', index: menuIndex[1] ?? -1 });
  81. this.$store.commit('setMemuIndex', { level: 'third', index: menuIndex[2] ?? -1 });
  82. },
  83. /**
  84. * 检测页面是否有权限
  85. */
  86. checkPageAuth() {
  87. this.$api.sendRequest({
  88. url: '/cashier/storeapi/store/checkpageauth',
  89. data: {
  90. page: this.currRoute
  91. },
  92. success: res => {
  93. if (res.code && res.code == -10012) {
  94. this.$util.redirectTo('/pages/index/no_permission', {}, 'redirectTo');
  95. }
  96. }
  97. });
  98. }
  99. },
  100. computed: {
  101. currRoute() {
  102. return this.$store.state.currRoute;
  103. },
  104. menu() {
  105. let menu = require('@/common/menu/store.js');
  106. return menu.default ?? [];
  107. }
  108. },
  109. watch: {
  110. currRoute: function(nVal, oVal) {
  111. if (nVal) {
  112. this.initRoute(nVal);
  113. this.checkPageAuth();
  114. }
  115. },
  116. menu: function(nVal) {
  117. if (nVal.length) {
  118. this.initRoute(this.currRoute);
  119. }
  120. }
  121. }
  122. };
  123. </script>
  124. <style lang="scss">
  125. /*每个页面公共css */
  126. @import url('/common/css/iconfont.css');
  127. @import '/common/css/common.scss';
  128. @import '/common/css/form.scss';
  129. uni-toast .uni-toast__content {
  130. font-size: 0.16rem !important;
  131. }
  132. </style>