123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <template>
- <view :style="[customStyle]" class="u-icon" @tap="click" :class="[labelPos == 'bottom' ? 'u-flex-col u-row-center' : 'u-flex u-col-center']">
- <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: labelSize + 'rpx',
- marginLeft: labelPos == 'right' ? marginLeft + 'rpx' : 0,
- marginTop: labelPos == 'bottom' ? marginTop + 'rpx' : 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,
- 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'
- },
-
- imgMode: {
- type: String,
- default: 'widthFix'
- },
-
- customStyle: {
- type: Object,
- default() {
- return {}
- }
- }
- },
- data() {
- return {};
- },
- computed: {
- customClass() {
- let classes = [];
- classes.push(this.customPrefix + '-' + this.name);
-
- if (this.customPrefix == 'uicon') classes.push('u-iconfont');
- else classes.push(this.customPrefix);
-
-
-
- classes = classes.join(' ');
-
- return classes;
- },
- iconStyle() {
- let style = {};
- style = {
- fontSize: this.size == 'inherit' ? 'inherit' : this.size + 'rpx',
- fontWeight: this.bold ? 'bold' : 'normal'
- };
- if (this.color) style.color = this.color;
- return style;
- },
-
- isImg() {
- return this.name.indexOf('/') !== -1;
- },
- imgStyle() {
- let style = {};
- style.width = this.size + 'rpx';
- return style;
- }
- },
- methods: {
- click() {
- this.$emit('click', this.index);
- },
- touchstart() {
- this.$emit('touchstart', this.index);
- }
- }
- };
- </script>
- <style scoped lang="scss">
- @import '../../iconfont.css';
- .u-icon {
- display: inline-flex;
- align-items: center;
- }
- .u-icon__img {
- height: auto;
- will-change: transform;
- }
- </style>
|