Blame view

src/views/demo/feat/tabs/index.vue 2.12 KB
陈文彬 authored
1
<template>
2
  <PageWrapper title="标签页操作示例">
3
    <CollapseContainer title="在下面输入框输入文本,切换后回来内容会保存">
4
      <a-alert banner message="该操作不会影响页面标题,仅修改Tab标题" />
5
      <div class="mt-2 flex flex-grow-0">
6
7
        <a-button class="mr-2" @click="setTabTitle" type="primary"> 设置Tab标题 </a-button>
        <a-input placeholder="请输入" v-model:value="title" class="mr-4 w-12" />
8
      </div>
陈文彬 authored
9
10
    </CollapseContainer>
11
    <CollapseContainer class="mt-4" title="标签页操作">
12
13
14
15
16
17
      <a-button class="mr-2" @click="closeAll"> 关闭所有 </a-button>
      <a-button class="mr-2" @click="closeLeft"> 关闭左侧 </a-button>
      <a-button class="mr-2" @click="closeRight"> 关闭右侧 </a-button>
      <a-button class="mr-2" @click="closeOther"> 关闭其他 </a-button>
      <a-button class="mr-2" @click="closeCurrent"> 关闭当前 </a-button>
      <a-button class="mr-2" @click="refreshPage"> 刷新当前 </a-button>
陈文彬 authored
18
    </CollapseContainer>
19
  </PageWrapper>
陈文彬 authored
20
21
</template>
<script lang="ts">
22
  import { defineComponent, ref } from 'vue';
陈文彬 authored
23
24
  import { CollapseContainer } from '/@/components/Container/index';
  import { useTabs } from '/@/hooks/web/useTabs';
25
  import { PageWrapper } from '/@/components/Page';
26
27
  import { Input, Alert } from 'ant-design-vue';
  import { useMessage } from '/@/hooks/web/useMessage';
vben authored
28
陈文彬 authored
29
30
  export default defineComponent({
    name: 'TabsDemo',
31
    components: { CollapseContainer, PageWrapper, [Input.name]: Input, [Alert.name]: Alert },
陈文彬 authored
32
    setup() {
33
34
35
36
37
38
39
40
41
42
43
      const title = ref<string>('');
      const { closeAll, closeLeft, closeRight, closeOther, closeCurrent, refreshPage, setTitle } =
        useTabs();
      const { createMessage } = useMessage();
      function setTabTitle() {
        if (title.value) {
          setTitle(title.value);
        } else {
          createMessage.error('请输入要设置的Tab标题!');
        }
      }
44
45
46
47
48
49
50
      return {
        closeAll,
        closeLeft,
        closeRight,
        closeOther,
        closeCurrent,
        refreshPage,
51
52
        setTabTitle,
        title,
53
      };
陈文彬 authored
54
55
56
    },
  });
</script>