index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <script lang="ts" setup>
  2. import { ref } from 'vue';
  3. import { useRouter } from 'vue-router';
  4. import { useTabs } from '@vben/hooks';
  5. import { Input as AInput, Button } from 'ant-design-vue';
  6. defineOptions({ name: 'FeatureTabsDemo' });
  7. const router = useRouter();
  8. const newTabTitle = ref('');
  9. const {
  10. closeAllTabs,
  11. closeCurrentTab,
  12. closeLeftTabs,
  13. closeOtherTabs,
  14. closeRightTabs,
  15. closeTabByKey,
  16. refreshTab,
  17. resetTabTitle,
  18. setTabTitle,
  19. } = useTabs();
  20. function openTab() {
  21. // 这里就是路由跳转,也可以用path
  22. router.push({ name: 'VbenAbout' });
  23. }
  24. function openTabWithParams(id: number) {
  25. // 这里就是路由跳转,也可以用path
  26. router.push({ name: 'FeatureTabDetailDemo', params: { id } });
  27. }
  28. function reset() {
  29. newTabTitle.value = '';
  30. resetTabTitle();
  31. }
  32. </script>
  33. <template>
  34. <div class="p-5">
  35. <div class="card-box p-5">
  36. <h1 class="text-xl font-semibold">标签页</h1>
  37. <div class="text-foreground/80 mt-2">用于需要操作标签页的场景</div>
  38. </div>
  39. <div class="card-box mt-5 p-5">
  40. <div class="text-lg font-semibold">打开/关闭标签页</div>
  41. <div class="text-foreground/80 my-3">
  42. 如果标签页存在,直接跳转切换。如果标签页不存在,则打开新的标签页。
  43. </div>
  44. <div class="flex flex-wrap gap-3">
  45. <Button type="primary" @click="openTab"> 打开 "关于" 标签页 </Button>
  46. <Button type="primary" @click="closeTabByKey('/vben-admin/about')">
  47. 关闭 "关于" 标签页
  48. </Button>
  49. </div>
  50. </div>
  51. <div class="card-box mt-5 p-5">
  52. <div class="text-lg font-semibold">标签页操作</div>
  53. <div class="text-foreground/80 my-3">用于动态控制标签页的各种操作</div>
  54. <div class="flex flex-wrap gap-3">
  55. <Button type="primary" @click="closeCurrentTab()">
  56. 关闭当前标签页
  57. </Button>
  58. <Button type="primary" @click="closeLeftTabs()">
  59. 关闭左侧标签页
  60. </Button>
  61. <Button type="primary" @click="closeRightTabs()">
  62. 关闭右侧标签页
  63. </Button>
  64. <Button type="primary" @click="closeAllTabs()"> 关闭所有标签页 </Button>
  65. <Button type="primary" @click="closeOtherTabs()">
  66. 关闭其他标签页
  67. </Button>
  68. <Button type="primary" @click="refreshTab()"> 刷新当前标签页 </Button>
  69. </div>
  70. </div>
  71. <div class="card-box mt-5 p-5">
  72. <div class="text-lg font-semibold">动态标题</div>
  73. <div class="text-foreground/80 my-3">
  74. 该操作不会影响页面标题,仅修改Tab标题
  75. </div>
  76. <div class="flex flex-wrap items-center gap-3">
  77. <AInput
  78. v-model:value="newTabTitle"
  79. class="w-40"
  80. placeholder="请输入新标题"
  81. />
  82. <Button type="primary" @click="() => setTabTitle(newTabTitle)">
  83. 修改
  84. </Button>
  85. <Button @click="reset"> 重置 </Button>
  86. </div>
  87. </div>
  88. <div class="card-box mt-5 p-5">
  89. <div class="text-lg font-semibold">最大打开数量</div>
  90. <div class="text-foreground/80 my-3">
  91. 限制带参数的tab打开的最大数量,由 `route.meta.maxNumOfOpenTab` 控制
  92. </div>
  93. <div class="flex flex-wrap items-center gap-3">
  94. <template v-for="item in 5" :key="item">
  95. <Button type="primary" @click="openTabWithParams(item)">
  96. 打开{{ item }}详情页
  97. </Button>
  98. </template>
  99. </div>
  100. </div>
  101. </div>
  102. </template>