¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <view |
| | | class="u-icon" |
| | | @tap="clickHandler" |
| | | :class="['u-icon--' + labelPos]" |
| | | > |
| | | <image |
| | | class="u-icon__img" |
| | | v-if="isImg" |
| | | :src="name" |
| | | :mode="imgMode" |
| | | :style="[imgStyle, $u.addStyle(customStyle)]" |
| | | ></image> |
| | | <text |
| | | v-else |
| | | class="u-icon__icon" |
| | | :class="uClasses" |
| | | :style="[iconStyle, $u.addStyle(customStyle)]" |
| | | :hover-class="hoverClass" |
| | | >{{icon}}</text> |
| | | <!-- è¿éè¿è¡ç©ºåç¬¦ä¸²å¤æï¼å¦æä»
ä»
æ¯v-if="label"ï¼å¯è½ä¼åºç°ä¼ é0çæ¶åï¼ç»æä¹æ æ³æ¾ç¤º --> |
| | | <text |
| | | v-if="label !== ''" |
| | | class="u-icon__label" |
| | | :style="{ |
| | | color: labelColor, |
| | | fontSize: $u.addUnit(labelSize), |
| | | marginLeft: labelPos == 'right' ? $u.addUnit(space) : 0, |
| | | marginTop: labelPos == 'bottom' ? $u.addUnit(space) : 0, |
| | | marginRight: labelPos == 'left' ? $u.addUnit(space) : 0, |
| | | marginBottom: labelPos == 'top' ? $u.addUnit(space) : 0, |
| | | }" |
| | | >{{ label }}</text> |
| | | </view> |
| | | </template> |
| | | |
| | | <script> |
| | | // #ifdef APP-NVUE |
| | | // nvueéè¿weexçdom模åå¼å
¥åä½ï¼ç¸å
³ææ¡£å°åå¦ä¸ï¼ |
| | | // https://weex.apache.org/zh/docs/modules/dom.html#addrule |
| | | const fontUrl = 'https://at.alicdn.com/t/font_2225171_8kdcwk4po24.ttf' |
| | | const domModule = weex.requireModule('dom') |
| | | domModule.addRule('fontFace', { |
| | | 'fontFamily': "uicon-iconfont", |
| | | 'src': `url('${fontUrl}')` |
| | | }) |
| | | // #endif |
| | | |
| | | // å¼å
¥å¾æ åç§°ï¼å·²ç»å¯¹åºçunicode |
| | | import icons from './icons' |
| | | |
| | | import props from './props.js';; |
| | | |
| | | /** |
| | | * icon 徿 |
| | | * @description åºäºåä½ç徿 éï¼å
å«äºå¤§å¤æ°å¸¸è§åºæ¯ç徿 ã |
| | | * @tutorial https://www.uviewui.com/components/icon.html |
| | | * @property {String} name 徿 åç§°ï¼è§ç¤ºä¾å¾æ é |
| | | * @property {String} color 徿 é¢è²,坿¥å主é¢è² ï¼é»è®¤ color['u-content-color'] ï¼ |
| | | * @property {String | Number} size 徿 åä½å¤§å°ï¼åä½px ï¼é»è®¤ '16px' ï¼ |
| | | * @property {Boolean} bold æ¯å¦æ¾ç¤ºç²ä½ ï¼é»è®¤ false ï¼ |
| | | * @property {String | Number} index ç¹å»å¾æ çæ¶åä¼ éäºä»¶åºå»çindexï¼ç¨äºåºåç¹å»äºåªä¸ä¸ªï¼ |
| | | * @property {String} hoverClass 徿 æä¸å»çæ ·å¼ç±»ï¼ç¨æ³åuniçviewç»ä»¶çhoverClassåæ°ï¼è¯¦æ
è§å®ç½ |
| | | * @property {String} customPrefix èªå®ä¹æ©å±åç¼ï¼æ¹ä¾¿ç¨æ·æ©å±èªå·±ç徿 åº ï¼é»è®¤ 'uicon' ï¼ |
| | | * @property {String | Number} label 徿 å³ä¾§çlabelæå |
| | | * @property {String} labelPos labelç¸å¯¹äºå¾æ çä½ç½®ï¼åªè½rightæbottom ï¼é»è®¤ 'right' ï¼ |
| | | * @property {String | Number} labelSize labelåä½å¤§å°ï¼åä½px ï¼é»è®¤ '15px' ï¼ |
| | | * @property {String} labelColor 徿 å³ä¾§çlabelæåé¢è² ï¼ é»è®¤ color['u-content-color'] ï¼ |
| | | * @property {String | Number} space labelä¸å¾æ çè·ç¦»ï¼åä½px ï¼é»è®¤ '3px' ï¼ |
| | | * @property {String} imgMode å¾ççmode |
| | | * @property {String | Number} width æ¾ç¤ºå¾çå°å¾æ æ¶ç宽度 |
| | | * @property {String | Number} height æ¾ç¤ºå¾çå°å¾æ æ¶çé«åº¦ |
| | | * @property {String | Number} top 徿 å¨åç´æ¹åä¸çå®ä½ ç¨äºè§£å³æäºæ
åµä¸ï¼è®©å¾æ åç´å±
ä¸çç¨é ï¼é»è®¤ 0 ï¼ |
| | | * @property {Boolean} stop æ¯å¦é»æ¢äºä»¶ä¼ æ ï¼é»è®¤ false ï¼ |
| | | * @property {Object} customStyle iconçæ ·å¼ï¼å¯¹è±¡å½¢å¼ |
| | | * @event {Function} click ç¹å»å¾æ æ¶è§¦å |
| | | * @event {Function} touchstart äºä»¶è§¦æ¸æ¶è§¦å |
| | | * @example <u-icon name="photo" color="#2979ff" size="28"></u-icon> |
| | | */ |
| | | export default { |
| | | name: 'u-icon', |
| | | data() { |
| | | return { |
| | | |
| | | } |
| | | }, |
| | | mixins: [uni.$u.mpMixin, uni.$u.mixin,props], |
| | | computed: { |
| | | uClasses() { |
| | | let classes = [] |
| | | classes.push(this.customPrefix + '-' + this.name) |
| | | // // uViewçèªå®ä¹å¾æ ç±»å为u-iconfont |
| | | // if (this.customPrefix == 'uicon') { |
| | | // classes.push('u-iconfont') |
| | | // } else { |
| | | // classes.push(this.customPrefix) |
| | | // } |
| | | // 主é¢è²ï¼éè¿ç±»é
ç½® |
| | | if (this.color && uni.$u.config.type.includes(this.color)) classes.push('u-icon__icon--' + this.color) |
| | | // é¿éï¼å¤´æ¡ï¼ç¾åº¦å°ç¨åºéè¿æ°ç»ç»å®ç±»åæ¶ï¼æ æ³ç´æ¥ä½¿ç¨[a, b, c]çå½¢å¼ï¼å¦åæ æ³è¯å« |
| | | // æ
éå°å
¶ææä¸ä¸ªå符串çå½¢å¼ï¼éè¿ç©ºæ ¼éå¼å个类å |
| | | //#ifdef MP-ALIPAY || MP-TOUTIAO || MP-BAIDU |
| | | classes = classes.join(' ') |
| | | //#endif |
| | | return classes |
| | | }, |
| | | iconStyle() { |
| | | let style = {} |
| | | style = { |
| | | fontSize: uni.$u.addUnit(this.size), |
| | | lineHeight: uni.$u.addUnit(this.size), |
| | | fontWeight: this.bold ? 'bold' : 'normal', |
| | | // æäºç¹æ®æ
åµéè¦è®¾ç½®ä¸ä¸ªå°é¡¶é¨çè·ç¦»ï¼æè½æ´å¥½çåç´å±
ä¸ |
| | | top: uni.$u.addUnit(this.top) |
| | | } |
| | | // é主é¢è²å¼æ¶ï¼æå½ä½é¢è²å¼ |
| | | if (this.color && !uni.$u.config.type.includes(this.color)) style.color = this.color |
| | | |
| | | return style |
| | | }, |
| | | // å¤æä¼ å
¥çname屿§ï¼æ¯å¦å¾çè·¯å¾ï¼åªè¦å¸¦æ"/"å认为æ¯å¾çå½¢å¼ |
| | | isImg() { |
| | | return this.name.indexOf('/') !== -1 |
| | | }, |
| | | imgStyle() { |
| | | let style = {} |
| | | // å¦æè®¾ç½®widthåheight屿§ï¼åä¼å
使ç¨ï¼å¦å使ç¨size屿§ |
| | | style.width = this.width ? uni.$u.addUnit(this.width) : uni.$u.addUnit(this.size) |
| | | style.height = this.height ? uni.$u.addUnit(this.height) : uni.$u.addUnit(this.size) |
| | | return style |
| | | }, |
| | | // éè¿å¾æ åï¼æ¥æ¾å¯¹åºç徿 |
| | | icon() { |
| | | // 妿å
ç½®ç徿 䏿¾ä¸å°å¯¹åºç徿 ï¼å°±ç´æ¥è¿ånameå¼ï¼å ä¸ºç¨æ·å¯è½ä¼ å
¥çæ¯unicode代ç |
| | | return icons['uicon-' + this.name] || this.name |
| | | } |
| | | }, |
| | | methods: { |
| | | clickHandler(e) { |
| | | this.$emit('click', this.index) |
| | | // æ¯å¦é»æ¢äºä»¶å泡 |
| | | this.stop && this.preventEvent(e) |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | @import "../../libs/css/components.scss"; |
| | | |
| | | // åéå®ä¹ |
| | | $u-icon-primary: $u-primary !default; |
| | | $u-icon-success: $u-success !default; |
| | | $u-icon-info: $u-info !default; |
| | | $u-icon-warning: $u-warning !default; |
| | | $u-icon-error: $u-error !default; |
| | | $u-icon-label-line-height:1 !default; |
| | | |
| | | /* #ifndef APP-NVUE */ |
| | | // énvueä¸å è½½åä½ |
| | | @font-face { |
| | | font-family: 'uicon-iconfont'; |
| | | src: url('https://at.alicdn.com/t/font_2225171_8kdcwk4po24.ttf') format('truetype'); |
| | | } |
| | | |
| | | /* #endif */ |
| | | |
| | | .u-icon { |
| | | /* #ifndef APP-NVUE */ |
| | | display: flex; |
| | | /* #endif */ |
| | | 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 { |
| | | font-family: uicon-iconfont; |
| | | position: relative; |
| | | @include flex; |
| | | align-items: center; |
| | | |
| | | &--primary { |
| | | color: $u-icon-primary; |
| | | } |
| | | |
| | | &--success { |
| | | color: $u-icon-success; |
| | | } |
| | | |
| | | &--error { |
| | | color: $u-icon-error; |
| | | } |
| | | |
| | | &--warning { |
| | | color: $u-icon-warning; |
| | | } |
| | | |
| | | &--info { |
| | | color: $u-icon-info; |
| | | } |
| | | } |
| | | |
| | | &__img { |
| | | /* #ifndef APP-NVUE */ |
| | | height: auto; |
| | | will-change: transform; |
| | | /* #endif */ |
| | | } |
| | | |
| | | &__label { |
| | | /* #ifndef APP-NVUE */ |
| | | line-height: $u-icon-label-line-height; |
| | | /* #endif */ |
| | | } |
| | | } |
| | | </style> |