index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div class="pa-3 white">
  3. <el-tabs v-model="activeName" @tab-click="handleClick">
  4. <el-tab-pane
  5. v-for="item in items"
  6. :key="item.name"
  7. :label="item.label"
  8. :name="item.name"
  9. >
  10. <component :is="item.component" :ref="item.name" :label="item.label" @hook:mounted="onComponentMounted"></component>
  11. </el-tab-pane>
  12. </el-tabs>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. name: 'ProcessIndex',
  18. data () {
  19. return {
  20. activeName: '',
  21. items: []
  22. }
  23. },
  24. created () {
  25. console.log(this.$route.meta.roles)
  26. this.items = this.$route.meta.roles.filter(e => e.hidden === 1).sort((a, b) => a.sort - b.sort).map(e => {
  27. return {
  28. name: e.name,
  29. label: e.label,
  30. component: () => import(`./${e.component}/index.vue`)
  31. }
  32. })
  33. if (this.$route.query.name) {
  34. this.activeName = this.$route.query.name
  35. } else {
  36. this.activeName = this.items[0].name
  37. }
  38. },
  39. computed: {
  40. name () {
  41. return this.items.find(e => e.name === this.activeName)?.label ?? ''
  42. }
  43. },
  44. methods: {
  45. onComponentMounted () {
  46. this.$nextTick(() => {
  47. if (!this.$refs[this.activeName]) {
  48. return
  49. }
  50. this.$refs[this.activeName][0].onInit && this.$refs[this.activeName][0].onInit(this.name)
  51. })
  52. },
  53. handleClick () {
  54. this.$router.push(`${this.$route.path}?name=${this.activeName}`)
  55. this.$nextTick(() => {
  56. this.$refs[this.activeName][0].onInit && this.$refs[this.activeName][0].onInit(this.name)
  57. })
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. /* 自定义样式 */
  64. ::v-deep .el-tabs__content {
  65. overflow: visible !important;
  66. }
  67. </style>