Blame view

components/thorui/tui-badge/tui-badge.vue 2.86 KB
46b6767c   刘淇   init 提交到库
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
  <template>
  	<view :class="[dot ? 'tui-badge-dot' : 'tui-badge', !dot ? 'tui-badge-scale' : '']"
  		:style="{ top: top, right: right, position: absolute ? 'absolute' : 'static', transform: getStyle, margin: margin,background:getBackground,color:getColor }"
  		@tap="handleClick">
  		<slot></slot>
  	</view>
  </template>
  
  <script>
  	export default {
  		name: 'tuiBadge',
  		emits: ['click'],
  		props: {
  			//primary,warning,green,danger,white,black,gray,white_red
  			type: {
  				type: String,
  				default: 'primary'
  			},
  			//是否是圆点
  			dot: {
  				type: Boolean,
  				default: false
  			},
  			margin: {
  				type: String,
  				default: '0'
  			},
  			//是否绝对定位
  			absolute: {
  				type: Boolean,
  				default: false
  			},
  			top: {
  				type: String,
  				default: '-8rpx'
  			},
  			right: {
  				type: String,
  				default: '0'
  			},
  			//缩放比例
  			scaleRatio: {
  				type: Number,
  				default: 1
  			},
  			//水平方向移动距离
  			translateX: {
  				type: String,
  				default: '0'
  			}
  		},
  		computed: {
  			getStyle() {
  				return `scale(${this.scaleRatio}) translateX(${this.translateX})`;
  			},
  			getBackground() {
  				const global = uni && uni.$tui && uni.$tui.color;
  				let color = {
  					'primary': (global && global.primary) || '#5677fc',
  					'green': (global && global.success) || '#07c160',
  					'warning': (global && global.warning) || '#ff7900',
  					'danger': (global && global.danger) || '#EB0909',
  					'white': '#fff',
  					'black': '#000',
  					'gray': '#ededed',
  					'red': (global && global.pink) || '#f74d54',
  					'pink': (global && global.pink) || '#f74d54',
  					'white_red': '#fff',
  					'white_primary': '#fff',
  					'white_green': '#fff',
  					'white_warning': '#fff',
  					'white_pink': '#fff'
  				} [this.type]
  				return color
  			},
  			getColor() {
  				const global = uni && uni.$tui && uni.$tui.color;
  				let color = {
  					'primary': '#fff',
  					'green': '#fff',
  					'warning': '#fff',
  					'danger': '#fff',
  					'white': '#333',
  					'black': '#fff',
  					'gray': '#999',
  					'red': '#fff',
  					'pink': (global && global.pink) || '#f74d54',
  					'white_red': (global && global.danger) || '#EB0909',
  					'white_primary': (global && global.primary) || '#5677fc',
  					'white_green': (global && global.success) || '#07c160',
  					'white_warning': (global && global.warning) || '#ff7900',
  					'white_pink': (global && global.pink) || '#f74d54',
  				} [this.type]
  				return color
  			}
  		},
  		methods: {
  			handleClick() {
  				this.$emit('click', {});
  			}
  		}
  	};
  </script>
  
  <style scoped>
  	.tui-badge-dot {
  		height: 8px;
  		width: 8px;
  		border-radius: 50%;
  	}
  
  	.tui-badge {
  		font-size: 24rpx;
  		line-height: 24rpx;
  		height: 36rpx;
  		min-width: 36rpx;
  		padding: 0 10rpx;
  		box-sizing: border-box;
  		border-radius: 100rpx;
  		display: flex;
  		align-items: center;
  		justify-content: center;
  		z-index: 10;
  	}
  
  	.tui-badge-scale {
  		transform-origin: center center;
  	}
  </style>