2024-07-20 08:31:05 +08:00
|
|
|
|
<script lang="ts" setup>
|
2024-07-20 09:36:10 +08:00
|
|
|
|
import { ref } from 'vue';
|
2024-07-20 08:31:05 +08:00
|
|
|
|
import { useRouter } from 'vue-router';
|
|
|
|
|
|
|
|
|
|
import { useTabs } from '@vben/hooks';
|
|
|
|
|
|
2024-07-20 09:36:10 +08:00
|
|
|
|
import { Input as AInput, Button } from 'ant-design-vue';
|
2024-07-20 08:31:05 +08:00
|
|
|
|
|
|
|
|
|
const router = useRouter();
|
2024-07-20 09:36:10 +08:00
|
|
|
|
const newTabTitle = ref('');
|
|
|
|
|
|
2024-07-20 08:31:05 +08:00
|
|
|
|
const {
|
|
|
|
|
closeAllTabs,
|
|
|
|
|
closeCurrentTab,
|
|
|
|
|
closeLeftTabs,
|
|
|
|
|
closeOtherTabs,
|
|
|
|
|
closeRightTabs,
|
|
|
|
|
closeTabByKey,
|
|
|
|
|
refreshTab,
|
2024-07-20 09:36:10 +08:00
|
|
|
|
resetTabTitle,
|
|
|
|
|
setTabTitle,
|
2024-07-20 08:31:05 +08:00
|
|
|
|
} = useTabs();
|
|
|
|
|
|
|
|
|
|
function openTab() {
|
|
|
|
|
// 这里就是路由跳转,也可以用path
|
|
|
|
|
router.push({ name: 'VbenAbout' });
|
|
|
|
|
}
|
2024-07-20 09:36:10 +08:00
|
|
|
|
|
2024-07-20 11:14:32 +08:00
|
|
|
|
function openTabWithParams(id: number) {
|
|
|
|
|
// 这里就是路由跳转,也可以用path
|
|
|
|
|
router.push({ name: 'FeatureTabDetailDemo', params: { id } });
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-20 09:36:10 +08:00
|
|
|
|
function reset() {
|
|
|
|
|
newTabTitle.value = '';
|
|
|
|
|
resetTabTitle();
|
|
|
|
|
}
|
2024-07-20 08:31:05 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="p-5">
|
|
|
|
|
<div class="card-box p-5">
|
|
|
|
|
<h1 class="text-xl font-semibold">标签页</h1>
|
|
|
|
|
<div class="text-foreground/80 mt-2">用于需要操作标签页的场景</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="card-box mt-5 p-5">
|
|
|
|
|
<div class="text-lg font-semibold">打开/关闭标签页</div>
|
|
|
|
|
<div class="text-foreground/80 my-3">
|
|
|
|
|
如果标签页存在,直接跳转切换。如果标签页不存在,则打开新的标签页。
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex flex-wrap gap-3">
|
|
|
|
|
<Button type="primary" @click="openTab"> 打开 "关于" 标签页 </Button>
|
|
|
|
|
<Button type="primary" @click="closeTabByKey('/vben-admin/about')">
|
|
|
|
|
关闭 "关于" 标签页
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="card-box mt-5 p-5">
|
|
|
|
|
<div class="text-lg font-semibold">标签页操作</div>
|
|
|
|
|
<div class="text-foreground/80 my-3">用于动态控制标签页的各种操作</div>
|
|
|
|
|
<div class="flex flex-wrap gap-3">
|
|
|
|
|
<Button type="primary" @click="closeCurrentTab()">
|
|
|
|
|
关闭当前标签页
|
|
|
|
|
</Button>
|
|
|
|
|
<Button type="primary" @click="closeLeftTabs()">
|
|
|
|
|
关闭左侧标签页
|
|
|
|
|
</Button>
|
|
|
|
|
<Button type="primary" @click="closeRightTabs()">
|
|
|
|
|
关闭右侧标签页
|
|
|
|
|
</Button>
|
2024-07-20 09:36:10 +08:00
|
|
|
|
<Button type="primary" @click="closeAllTabs()"> 关闭所有标签页 </Button>
|
2024-07-20 08:31:05 +08:00
|
|
|
|
<Button type="primary" @click="closeOtherTabs()">
|
|
|
|
|
关闭其他标签页
|
|
|
|
|
</Button>
|
|
|
|
|
<Button type="primary" @click="refreshTab()"> 刷新当前标签页 </Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="card-box mt-5 p-5">
|
|
|
|
|
<div class="text-lg font-semibold">动态标题</div>
|
|
|
|
|
<div class="text-foreground/80 my-3">
|
|
|
|
|
该操作不会影响页面标题,仅修改Tab标题
|
|
|
|
|
</div>
|
2024-07-20 09:36:10 +08:00
|
|
|
|
<div class="flex flex-wrap items-center gap-3">
|
|
|
|
|
<AInput
|
|
|
|
|
v-model:value="newTabTitle"
|
|
|
|
|
class="w-40"
|
|
|
|
|
placeholder="请输入新标题"
|
2024-07-20 08:31:05 +08:00
|
|
|
|
/>
|
2024-07-20 09:36:10 +08:00
|
|
|
|
<Button type="primary" @click="() => setTabTitle(newTabTitle)">
|
|
|
|
|
修改
|
2024-07-20 08:31:05 +08:00
|
|
|
|
</Button>
|
2024-07-20 09:36:10 +08:00
|
|
|
|
<Button @click="reset"> 重置 </Button>
|
|
|
|
|
</div>
|
2024-07-20 08:31:05 +08:00
|
|
|
|
</div>
|
2024-07-20 11:14:32 +08:00
|
|
|
|
|
|
|
|
|
<div class="card-box mt-5 p-5">
|
|
|
|
|
<div class="text-lg font-semibold">最大打开数量</div>
|
|
|
|
|
<div class="text-foreground/80 my-3">
|
|
|
|
|
限制带参数的tab打开的最大数量,由 `route.meta.maxNumOfOpenTab` 控制
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex flex-wrap items-center gap-3">
|
|
|
|
|
<template v-for="item in 5" :key="item">
|
|
|
|
|
<Button type="primary" @click="openTabWithParams(item)">
|
|
|
|
|
打开{{ item }}详情页
|
|
|
|
|
</Button>
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-07-20 08:31:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|