index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <work-bench-layout>
  3. <template v-slot:nav>
  4. <router-view name="nav">
  5. <template v-slot:nav-user-info="{ info }">
  6. <slot name="nav-user-info" v-bind:info="info"></slot>
  7. </template>
  8. </router-view>
  9. </template>
  10. <template v-slot:menu>
  11. <router-view v-show="$route.query.aside !== '0'" name="menu" :before-select="onBeforeSelect"
  12. @open="onOpenMenu"></router-view>
  13. </template>
  14. <router-view id="work-bench-container"></router-view>
  15. </work-bench-layout>
  16. </template>
  17. <script>
  18. import WorkBenchLayout from './layout'
  19. import { mapActions, mapGetters } from 'vuex'
  20. import { checkCanNextMenu } from '../../utils/menu'
  21. export default {
  22. name: 'work-bench',
  23. components: {
  24. [WorkBenchLayout.name]: WorkBenchLayout
  25. },
  26. computed: {
  27. ...mapGetters('work-bench/dialog', [
  28. 'dialogOptions'
  29. ])
  30. },
  31. async beforeRouteEnter (to, from, next) {
  32. next(async (vm) => {
  33. await vm.getMenus()
  34. await vm.checkNextMenu(to)
  35. })
  36. },
  37. async beforeRouteUpdate (to, from, next) {
  38. await this.checkNextMenu(to)
  39. next()
  40. },
  41. methods: {
  42. ...mapActions('work-bench', [
  43. 'getMenus'
  44. ]),
  45. ...mapActions('work-bench/menu', [
  46. 'tryMatchMenu',
  47. 'tryFindMenu'
  48. ]),
  49. ...mapActions('work-bench/dialog', [
  50. 'openDialog'
  51. ]),
  52. /**
  53. * 更新路由时检验菜单
  54. * @param to
  55. * @returns {Promise<void>}
  56. */
  57. async checkNextMenu (to) {
  58. const findMenuInfo = await this.tryFindMenu({
  59. link: to.query.link || to.fullPath
  60. })
  61. const canNext = checkCanNextMenu.apply(this, [findMenuInfo.findMenu])
  62. if (canNext) {
  63. this.tryMatchMenu({
  64. link: to.query.link || to.fullPath,
  65. find: findMenuInfo
  66. })
  67. }
  68. },
  69. /**
  70. * 默认前置校验
  71. * @param menu
  72. * @returns {boolean}
  73. */
  74. beforeSelect (menu) {
  75. return checkCanNextMenu.apply(this, [menu])
  76. },
  77. /**
  78. * 打开菜单前置校验钩子
  79. * @param menu
  80. * @returns {Promise<boolean>}
  81. */
  82. async onBeforeSelect (menu) {
  83. let canNext = true
  84. const spareFn = this.beforeSelect.bind(this)
  85. canNext = await new Promise((resolve) => {
  86. const next = (result) => {
  87. resolve(Boolean(result))
  88. }
  89. this.$BRACE.$emit({
  90. fKey: 'onBeforeSelect',
  91. spareFn: (menu, next) => {
  92. next(spareFn(menu))
  93. }
  94. }, menu, next)
  95. })
  96. return canNext
  97. },
  98. /**
  99. * 调用公共函数打开页面
  100. * @param menu
  101. */
  102. openMenu (menu) {
  103. this.$BRACE.methods.open({
  104. route: menu
  105. })
  106. },
  107. /**
  108. * 打开菜单事件发布
  109. * @param menu
  110. */
  111. onOpenMenu (menu) {
  112. this.$BRACE.$emit({
  113. fKey: 'onOpenMenu',
  114. spareFn: (menu, next) => {
  115. next(menu)
  116. }
  117. }, menu, this.openMenu.bind(this))
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="scss">
  123. @import "../../style/index";
  124. .content-shadow {
  125. background: #FFFFFF;
  126. box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.0800);
  127. border-radius: 5px 5px 5px 5px;
  128. }
  129. .abnormal-tip {
  130. margin: $padding-lg;
  131. padding: $padding-xl;
  132. @extend .content-shadow;
  133. }
  134. .custom-message-box {
  135. width: 380px !important;
  136. border-radius: 8px;
  137. .custom-confirm-btn {
  138. margin-top: 12px;
  139. width: 132px;
  140. height: 36px;
  141. background: #2cb7ca;
  142. border-radius: 6px;
  143. border: 0;
  144. font-size: 16px;
  145. }
  146. .el-message-box__message {
  147. font-size: 14px;
  148. color: #686868;
  149. }
  150. }
  151. </style>