App.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div id="app">
  3. <router-view v-if="isRouterAlive" />
  4. <Setings ref="setingsRef" />
  5. </div>
  6. </template>
  7. <script>
  8. // +----------------------------------------------------------------------
  9. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  10. // +----------------------------------------------------------------------
  11. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  12. // +----------------------------------------------------------------------
  13. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  14. // +----------------------------------------------------------------------
  15. // | Author: CRMEB Team <admin@crmeb.com>
  16. // +----------------------------------------------------------------------
  17. import { Local } from '@/utils/storage.js';
  18. import Setings from '@/layout/navBars/breadcrumb/setings.vue';
  19. export default {
  20. name: 'App',
  21. components: { Setings },
  22. provide() {
  23. return {
  24. reload: this.reload,
  25. };
  26. },
  27. data() {
  28. return {
  29. isRouterAlive: true,
  30. };
  31. },
  32. watch: {
  33. // 监听路由 控制侧边栏显示 标记当前顶栏菜单(如需要)
  34. $route(to, from) {
  35. const onRoutes = to.meta.activeMenu ? to.meta.activeMenu : to.meta.path;
  36. this.$store.commit('menu/setActivePath', onRoutes);
  37. if (to.name == 'crud_crud') {
  38. this.$store.state.user.oneLvRoutes.map((e) => {
  39. if (e.path === to.path) {
  40. to.meta.title = e.title;
  41. }
  42. });
  43. }
  44. //商品添加、优惠券
  45. if (['creatProduct', 'coupon'].includes(to.name)) {
  46. let route = to.matched[1].path.split(':')[0];
  47. this.$store.state.user.oneLvRoutes.map((e) => {
  48. if (route.indexOf(e.path) != -1) {
  49. to.meta.title = `${e.title} ${to.params.id ? 'ID:' + to.params.id : ''}`;
  50. }
  51. });
  52. }
  53. //个人中心、修改密码
  54. if (['MaintainUser'].includes(to.name)) {
  55. let route = to.matched[1].path.split(':')[0];
  56. this.$store.state.user.oneLvRoutes.map((e) => {
  57. if (route.indexOf(e.path) != -1) {
  58. let params = to.params.type;
  59. to.meta.title = params === 'users' ? '个人中心' : '修改密码';
  60. }
  61. });
  62. }
  63. },
  64. },
  65. mounted() {
  66. this.openSetingsDrawer();
  67. this.getLayoutThemeConfig();
  68. },
  69. methods: {
  70. reload() {
  71. this.isRouterAlive = false;
  72. this.$nextTick(function () {
  73. this.isRouterAlive = true;
  74. });
  75. },
  76. // 布局配置弹窗打开
  77. openSetingsDrawer() {
  78. this.bus.$on('openSetingsDrawer', () => {
  79. this.$refs.setingsRef.openDrawer();
  80. });
  81. },
  82. // 获取缓存中的布局配置
  83. getLayoutThemeConfig() {
  84. if (Local.get('JavaMerThemeConfigPrev')) {
  85. this.$store.dispatch('themeConfig/setThemeConfig', Local.get('JavaMerThemeConfigPrev'));
  86. document.documentElement.style.cssText = Local.get('JavaMerThemeConfigStyle');
  87. } else {
  88. Local.set('JavaMerThemeConfigPrev', this.$store.state.themeConfig.themeConfig);
  89. }
  90. },
  91. },
  92. destroyed() {
  93. this.bus.$off('openSetingsDrawer');
  94. },
  95. };
  96. </script>
  97. <style></style>