123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- <template>
- <view :style="[customStyle]" class="u-icon" @tap="click" :class="['u-icon--' + labelPos]">
- <image class="u-icon__img" v-if="isImg" :src="name" :mode="imgMode" :style="[imgStyle]"></image>
- <text v-else class="u-icon__icon" :class="customClass" :style="[iconStyle]" :hover-class="hoverClass"
- @touchstart="touchstart">
- <text v-if="showDecimalIcon" :style="[decimalIconStyle]" :class="decimalIconClass" :hover-class="hoverClass"
- class="u-icon__decimal">
- </text>
- </text>
-
- <text v-if="label !== ''" class="u-icon__label" :style="{
- color: labelColor,
- fontSize: $u.addUnit(labelSize),
- marginLeft: labelPos == 'right' ? $u.addUnit(marginLeft) : 0,
- marginTop: labelPos == 'bottom' ? $u.addUnit(marginTop) : 0,
- marginRight: labelPos == 'left' ? $u.addUnit(marginRight) : 0,
- marginBottom: labelPos == 'top' ? $u.addUnit(marginBottom) : 0,
- }">{{ label }}
- </text>
- </view>
- </template>
- <script>
- export default {
- name: 'u-icon',
- props: {
-
- name: {
- type: String,
- default: ''
- },
-
- color: {
- type: String,
- default: ''
- },
-
- size: {
- type: [Number, String],
- default: 'inherit'
- },
-
- bold: {
- type: Boolean,
- default: false
- },
-
- index: {
- type: [Number, String],
- default: ''
- },
-
- hoverClass: {
- type: String,
- default: ''
- },
-
- customPrefix: {
- type: String,
- default: 'uicon'
- },
-
- label: {
- type: [String, Number],
- default: ''
- },
-
- labelPos: {
- type: String,
- default: 'right'
- },
-
- labelSize: {
- type: [String, Number],
- default: '28'
- },
-
- labelColor: {
- type: String,
- default: '#606266'
- },
-
- marginLeft: {
- type: [String, Number],
- default: '6'
- },
-
- marginTop: {
- type: [String, Number],
- default: '6'
- },
-
- marginRight: {
- type: [String, Number],
- default: '6'
- },
-
- marginBottom: {
- type: [String, Number],
- default: '6'
- },
-
- imgMode: {
- type: String,
- default: 'widthFix'
- },
-
- customStyle: {
- type: Object,
- default() {
- return {}
- }
- },
-
- width: {
- type: [String, Number],
- default: ''
- },
-
- height: {
- type: [String, Number],
- default: ''
- },
-
- top: {
- type: [String, Number],
- default: 0
- },
-
- showDecimalIcon: {
- type: Boolean,
- default: false
- },
-
- inactiveColor: {
- type: String,
- default: '#ececec'
- },
-
- percent: {
- type: [Number, String],
- default: '50'
- }
- },
- computed: {
- customClass() {
- let classes = []
- classes.push(this.customPrefix + '-' + this.name)
-
- if (this.customPrefix == 'uicon') {
- classes.push('u-iconfont')
- } else {
- classes.push(this.customPrefix)
- }
-
- if (this.showDecimalIcon && this.inactiveColor && this.$u.config.type.includes(this.inactiveColor)) {
- classes.push('u-icon__icon--' + this.inactiveColor)
- } else if (this.color && this.$u.config.type.includes(this.color)) classes.push('u-icon__icon--' + this.color)
-
-
-
- classes = classes.join(' ')
-
- return classes
- },
- iconStyle() {
- let style = {}
- style = {
- fontSize: this.size == 'inherit' ? 'inherit' : this.$u.addUnit(this.size),
- fontWeight: this.bold ? 'bold' : 'normal',
-
- top: this.$u.addUnit(this.top)
- }
-
- if (this.showDecimalIcon && this.inactiveColor && !this.$u.config.type.includes(this.inactiveColor)) {
- style.color = this.inactiveColor
- } else if (this.color && !this.$u.config.type.includes(this.color)) style.color = this.color
- return style
- },
-
- isImg() {
- return this.name.indexOf('/') !== -1
- },
- imgStyle() {
- let style = {}
-
- style.width = this.width ? this.$u.addUnit(this.width) : this.$u.addUnit(this.size)
- style.height = this.height ? this.$u.addUnit(this.height) : this.$u.addUnit(this.size)
- return style
- },
- decimalIconStyle() {
- let style = {}
- style = {
- fontSize: this.size == 'inherit' ? 'inherit' : this.$u.addUnit(this.size),
- fontWeight: this.bold ? 'bold' : 'normal',
-
- top: this.$u.addUnit(this.top),
- width: this.percent + '%'
- }
-
- if (this.color && !this.$u.config.type.includes(this.color)) style.color = this.color
- return style
- },
- decimalIconClass() {
- let classes = []
- classes.push(this.customPrefix + '-' + this.name)
-
- if (this.customPrefix == 'uicon') {
- classes.push('u-iconfont')
- } else {
- classes.push(this.customPrefix)
- }
-
- if (this.color && this.$u.config.type.includes(this.color)) classes.push('u-icon__icon--' + this.color)
- else classes.push('u-icon__icon--primary')
-
-
-
- classes = classes.join(' ')
-
- return classes
- }
- },
- methods: {
- click() {
- this.$emit('click', this.index)
- },
- touchstart() {
- this.$emit('touchstart', this.index)
- }
- }
- }
- </script>
- <style scoped lang="scss">
- @import "../../libs/css/style.components.scss";
- @import '../../iconfont.css';
- .u-icon {
- display: inline-flex;
- align-items: center;
- &--left {
- flex-direction: row-reverse;
- align-items: center;
- }
- &--right {
- flex-direction: row;
- align-items: center;
- }
- &--top {
- flex-direction: column-reverse;
- justify-content: center;
- }
- &--bottom {
- flex-direction: column;
- justify-content: center;
- }
- &__icon {
- position: relative;
- &--primary {
- color: $u-type-primary;
- }
- &--success {
- color: $u-type-success;
- }
- &--error {
- color: $u-type-error;
- }
- &--warning {
- color: $u-type-warning;
- }
- &--info {
- color: $u-type-info;
- }
- }
- &__decimal {
- position: absolute;
- top: 0;
- left: 0;
- display: inline-block;
- overflow: hidden;
- }
- &__img {
- height: auto;
- will-change: transform;
- }
- &__label {
- line-height: 1;
- }
- }
- </style>
|