绿满眶商城微信小程序-uniapp
peng
16 小时以前 818fbcd2dc3073ab4dacdff2b19cea56552f32fc
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
88
89
90
91
92
93
94
95
96
97
98
99
100
<template>
  <view>
    <view class="my-tab-warp" :class="[`my-tab-${type}`]">
      <text class="my-tab-text" @click="clickTab">{{text}}</text>
      <view 
        v-if="closeable" 
        @click="close" 
        class="iconfont my-tab-close"
      >
        <text v-if="type == 'error'">&#xe6ea;</text>
        <text v-else-if="type == 'primary'">&#xe7f9;</text>
        <text v-else-if="type == 'success'">&#xe7fa;</text>
        <text v-else-if="type == 'warning'">&#xe7fb;</text>
      </view>
    </view>
  </view>
</template>
 
<script>
export default {
  name: "my-tag",
  props: {
    text: {
      type: String
    },
    // 关闭、点击时的回传参数
    index: {
      type: Number
    },
    closeable: {
      type: Boolean,
      default: true
    },
    type: {
      type: String,
      default: 'error',
      validator: (value) => ['primary', 'success', 'error', 'warning'].includes(value)
    }
  },
  methods: {
    close() {
      this.$emit('close', this.index)
    },
    clickTab() {
      this.$emit('click', this.index)
    }
  }
}
</script>
 
<style>
.my-tab-warp {
  display: inline-flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  height: 22px;
  line-height: 22px;
  border-radius: 3px;
  padding: 0 8px;
  font-size: 12px;
  margin-right: 3px;
  border: 1px solid;
}
 
.my-tab-text {
  color: inherit;
}
 
.my-tab-close {
  font-size: 12px !important;
  margin-left: 4px;
  cursor: pointer;
}
 
/* 不同类型样式 */
.my-tab-primary {
  color: #2d8cf0;
  border-color: #2d8cf0;
  background-color: rgba(45, 140, 240, 0.1);
}
 
.my-tab-success {
  color: #19be6b;
  border-color: #19be6b;
  background-color: rgba(25, 190, 107, 0.1);
}
 
.my-tab-error {
  color: #ed4014;
  border-color: #ed4014;
  background-color: rgba(237, 64, 20, 0.1);
}
 
.my-tab-warning {
  color: #ff9900;
  border-color: #ff9900;
  background-color: rgba(255, 153, 0, 0.1);
}
</style>