songshankun
2023-11-20 3a3cc473c33cb4a97399ace76a1b35e9ffd68525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<template>
  <div class="task-tabs">
    <div
      v-for="tab in list"
      :key="tab.value"
      class="task-tab-item triangle-tip"
      :class="{ active: props.modelValue === tab.value }"
      @click="selectTab(tab)"
    >
      {{ tab.label }}
    </div>
  </div>
</template>
<script setup lang="ts">
import { useVModel } from '@vueuse/core'
 
export interface LabelValue {
  label: string
  value: any
}
 
const props = defineProps<{
  /** tab 列表*/
  list: LabelValue[]
  /** 当前选中的 tab*/
  modelValue?: any
}>()
const emit = defineEmits<{
  'update:modelValue': [tabName: string]
  change: [tab: LabelValue]
}>()
const data = useVModel(props, 'modelValue', emit)
 
function selectTab(tab: LabelValue) {
  data.value = tab.value
  emit('change', tab)
}
</script>
<style scoped lang="scss">
$active-bg: #6b83ff;
$tab-bg: #0b4694;
$tab-height: 50px;
.task-tabs {
  background-color: transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: $tab-height;
  font-size: 20px;
 
  .task-tab-item {
    background-color: $tab-bg;
    margin-right: 10px;
    flex: 1;
    height: $tab-height;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-radius: 4px;
    cursor: pointer;
    &:last-child {
      margin-right: 0;
    }
  }
  .active {
    background-color: $active-bg;
    font-weight: 600;
  }
  .triangle-tip:before {
    content: '';
    width: 0;
    height: 0;
    border-width: 10px 10px 0;
    border-style: solid;
    border-color: $active-bg transparent transparent;
    position: absolute;
    left: 50%;
    margin-left: -10px;
    bottom: -10px;
    display: none;
  }
  .active.triangle-tip:before {
    display: block;
  }
}
</style>