|
1 | 1 | <template>
|
2 |
| - <view :style="[customStyle]" class="u-icon" @tap="click" :class="[labelPos == 'bottom' ? 'u-flex-col u-row-center' : 'u-flex u-col-center']"> |
| 2 | + <view :style="[customStyle]" class="u-icon" @tap="click" :class="['u-icon--' + labelPos]"> |
3 | 3 | <image class="u-icon__img" v-if="isImg" :src="name" :mode="imgMode" :style="[imgStyle]"></image>
|
4 | 4 | <text v-else class="u-icon__icon" :class="customClass" :style="[iconStyle]" :hover-class="hoverClass" @touchstart="touchstart"></text>
|
5 | 5 | <text v-if="label" class="u-icon__label" :style="{
|
6 | 6 | color: labelColor,
|
7 | 7 | fontSize: labelSize + 'rpx',
|
8 | 8 | marginLeft: labelPos == 'right' ? marginLeft + 'rpx' : 0,
|
9 | 9 | marginTop: labelPos == 'bottom' ? marginTop + 'rpx' : 0,
|
| 10 | + marginRight: labelPos == 'left' ? marginRight + 'rpx' : 0, |
| 11 | + marginBottom: labelPos == 'top' ? marginBottom + 'rpx' : 0, |
10 | 12 | }">{{label}}</text>
|
11 | 13 | </view>
|
12 | 14 | </template>
|
|
26 | 28 | * @property {Object} custom-style icon的样式,对象形式
|
27 | 29 | * @property {String | Number} margin-left label在右侧时与图标的距离,单位rpx(默认6)
|
28 | 30 | * @property {String | Number} margin-top label在下方时与图标的距离,单位rpx(默认6)
|
| 31 | + * @property {String | Number} margin-bottom label在上方时与图标的距离,单位rpx(默认6) |
| 32 | + * @property {String | Number} margin-right label在左侧时与图标的距离,单位rpx(默认6) |
29 | 33 | * @property {String} label-pos label相对于图标的位置,只能right或bottom(默认right)
|
30 | 34 | * @property {String} index 一个用于区分多个图标的值,点击图标时通过click事件传出
|
31 | 35 | * @property {String} hover-class 图标按下去的样式类,用法同uni的view组件的hover-class参数,详情见官网
|
@@ -100,6 +104,16 @@ export default {
|
100 | 104 | type: [String, Number],
|
101 | 105 | default: '6'
|
102 | 106 | },
|
| 107 | + // label与图标的距离(竖向排列) |
| 108 | + marginRight: { |
| 109 | + type: [String, Number], |
| 110 | + default: '6' |
| 111 | + }, |
| 112 | + // label与图标的距离(竖向排列) |
| 113 | + marginBottom: { |
| 114 | + type: [String, Number], |
| 115 | + default: '6' |
| 116 | + }, |
103 | 117 | // 图片的mode
|
104 | 118 | imgMode: {
|
105 | 119 | type: String,
|
@@ -167,32 +181,56 @@ export default {
|
167 | 181 | .u-icon {
|
168 | 182 | display: inline-flex;
|
169 | 183 | align-items: center;
|
170 |
| - |
| 184 | +
|
| 185 | + &--left { |
| 186 | + flex-direction: row; |
| 187 | + align-items: center; |
| 188 | + } |
| 189 | +
|
| 190 | + &--right { |
| 191 | + flex-direction: row-reverse; |
| 192 | + align-items: center; |
| 193 | + } |
| 194 | +
|
| 195 | + &--top { |
| 196 | + flex-direction: column-reverse; |
| 197 | + justify-content: center; |
| 198 | + } |
| 199 | +
|
| 200 | + &--bottom { |
| 201 | + flex-direction: column; |
| 202 | + justify-content: center; |
| 203 | + } |
| 204 | +
|
171 | 205 | &__icon {
|
172 | 206 | &--primary {
|
173 | 207 | color: $u-type-primary;
|
174 | 208 | }
|
175 |
| - |
| 209 | +
|
176 | 210 | &--success {
|
177 | 211 | color: $u-type-success;
|
178 | 212 | }
|
179 |
| - |
| 213 | +
|
180 | 214 | &--error {
|
181 | 215 | color: $u-type-error;
|
182 | 216 | }
|
183 |
| - |
| 217 | +
|
184 | 218 | &--warning {
|
185 | 219 | color: $u-type-warning;
|
186 | 220 | }
|
187 |
| - |
| 221 | +
|
188 | 222 | &--info {
|
189 | 223 | color: $u-type-info;
|
190 | 224 | }
|
191 | 225 | }
|
192 |
| - |
| 226 | +
|
193 | 227 | &__img {
|
194 | 228 | height: auto;
|
195 | 229 | will-change: transform;
|
196 | 230 | }
|
| 231 | +
|
| 232 | + &__label { |
| 233 | + line-height: 1; |
| 234 | + } |
197 | 235 | }
|
198 | 236 | </style>
|
0 commit comments