123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <template>
- <view v-if="show" :class="[
- disabled ? 'u-disabled' : '',
- 'u-size-' + size,
- 'u-shape-' + shape,
- 'u-mode-' + mode + '-' + type
- ]"
- class="u-tag" :style="[customStyle]" @tap="clickTag">
- {{text}}
- <view class="u-icon-wrap" @tap.stop>
- <u-icon @click="close" size="22" v-if="closeable" :color="closeIconColor"
- name="close" class="u-close-icon" :style="[iconStyle]"></u-icon>
- </view>
- </view>
- </template>
- <script>
-
- export default {
- name: 'u-tag',
-
- props: {
-
- type: {
- type: String,
- default: 'primary'
- },
- disabled: {
- type: [Boolean, String],
- default: false
- },
-
- size: {
- type: String,
- default: 'default'
- },
-
- shape: {
- type: String,
- default: 'square'
- },
-
- text: {
- type: [String, Number],
- default: ''
- },
-
- bgColor: {
- type: String,
- default: ''
- },
-
- color: {
- type: String,
- default: ''
- },
-
- borderColor: {
- type: String,
- default: ''
- },
-
- closeColor: {
- type: String,
- default: ''
- },
-
- index: {
- type: [Number, String],
- default: ''
- },
-
- mode: {
- type: String,
- default: 'light'
- },
-
- closeable: {
- type: Boolean,
- default: false
- },
-
- show: {
- type: Boolean,
- default: true
- }
- },
- data() {
- return {
-
- }
- },
- computed: {
- customStyle() {
- let style = {};
-
- if(this.color) style.color = this.color;
-
- if(this.bgColor) style.backgroundColor = this.bgColor;
-
- if(this.mode == 'plain' && this.color && !this.borderColor) style.borderColor = this.color;
- else style.borderColor = this.borderColor;
- return style;
- },
- iconStyle() {
- if(!this.closeable) return ;
- let style = {};
- if(this.size == 'mini') style.fontSize = '20rpx';
- else style.fontSize = '22rpx';
- if(this.mode == 'plain' || this.mode == 'light') style.color = this.type;
- else if(this.mode == 'dark') style.color = "#ffffff";
- if(this.closeColor) style.color = this.closeColor;
- return style;
- },
-
- closeIconColor() {
-
-
-
- let color = '';
- if(this.closeColor) return this.closeColor;
- else if(this.color) return this.color;
- else if(this.mode == 'dark') return '#ffffff';
- else return this.type;
- }
- },
- methods: {
-
- clickTag() {
-
- if(this.disabled) return ;
- this.$emit('click', this.index);
- },
-
- close() {
- this.$emit('close', this.index);
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "../../libs/css/style.components.scss";
-
- .u-tag {
- box-sizing: border-box;
- align-items: center;
- border-radius: 6rpx;
-
- display: inline-block;
-
- line-height: 1;
- }
-
- .u-size-default {
- font-size: 22rpx;
- padding: 12rpx 22rpx;
- }
-
- .u-size-mini {
- font-size: 20rpx;
- padding: 6rpx 12rpx;
- }
- .u-mode-light-primary {
- background-color: $u-type-primary-light;
- color: $u-type-primary;
- border: 1px solid $u-type-primary-disabled;
- }
-
- .u-mode-light-success {
- background-color: $u-type-success-light;
- color: $u-type-success;
- border: 1px solid $u-type-success-disabled;
- }
-
- .u-mode-light-error {
- background-color: $u-type-error-light;
- color: $u-type-error;
- border: 1px solid $u-type-error-disabled;
- }
-
- .u-mode-light-warning {
- background-color: $u-type-warning-light;
- color: $u-type-warning;
- border: 1px solid $u-type-warning-disabled;
- }
-
- .u-mode-light-info {
- background-color: $u-type-info-light;
- color: $u-type-info;
- border: 1px solid $u-type-info-disabled;
- }
-
- .u-mode-dark-primary {
- background-color: $u-type-primary;
- color: #FFFFFF;
- }
-
- .u-mode-dark-success {
- background-color: $u-type-success;
- color: #FFFFFF;
- }
-
- .u-mode-dark-error {
- background-color: $u-type-error;
- color: #FFFFFF;
- }
-
- .u-mode-dark-warning {
- background-color: $u-type-warning;
- color: #FFFFFF;
- }
-
- .u-mode-dark-info {
- background-color: $u-type-info;
- color: #FFFFFF;
- }
-
- .u-mode-plain-primary {
- background-color: #FFFFFF;
- color: $u-type-primary;
- border: 1px solid $u-type-primary;
- }
-
- .u-mode-plain-success {
- background-color: #FFFFFF;
- color: $u-type-success;
- border: 1px solid $u-type-success;
- }
-
- .u-mode-plain-error {
- background-color: #FFFFFF;
- color: $u-type-error;
- border: 1px solid $u-type-error;
- }
-
- .u-mode-plain-warning {
- background-color: #FFFFFF;
- color: $u-type-warning;
- border: 1px solid $u-type-warning;
- }
-
- .u-mode-plain-info {
- background-color: #FFFFFF;
- color: $u-type-info;
- border: 1px solid $u-type-info;
- }
-
- .u-disabled {
- opacity: 0.55;
- }
- .u-shape-circle {
- border-radius: 100rpx;
- }
-
- .u-shape-circleRight {
- border-radius: 0 100rpx 100rpx 0;
- }
- .u-shape-circleLeft {
- border-radius: 100rpx 0 0 100rpx;
- }
-
- .u-close-icon {
- margin-left: 14rpx;
- font-size: 22rpx;
- color: $u-type-success;
- }
-
- .u-icon-wrap {
- display: inline-flex;
- transform: scale(0.86);
- }
- </style>
|