123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <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>
-
- <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
- }
- },
- 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.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.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;
- }
- },
- methods: {
- click() {
- this.$emit('click', this.index);
- },
- touchstart() {
- this.$emit('touchstart', this.index);
- }
- }
- };
- </script>
- <style scoped lang="scss">
- @import "../../libs/css/style.components.scss";
- /* #ifndef APP-NVUE */
- // 目前由于nvue对定义字体时的content属性报错,所以nvue先不引入
- @import '../../iconfont.css';
- /* #endif */
- .u-icon {
- /* #ifndef APP-NVUE */
- display: inline-flex;
- /* #endif */
- flex-direction: row;
- 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;
- }
- }
- &__img {
- /* #ifndef APP-PLUS */
- height: auto;
- will-change: transform;
- /* #endif */
- }
- &__label {
- line-height: 1;
- }
- }
- </style>
|