123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <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>
-
- <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>
-
-
-
- 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}')`
- })
-
-
- import icons from './icons'
-
- import props from './props.js';;
-
- 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)
-
-
-
-
-
-
-
- if (this.color && uni.$u.config.type.includes(this.color)) classes.push('u-icon__icon--' + this.color)
-
-
-
- classes = classes.join(' ')
-
- 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
- },
-
- isImg() {
- return this.name.indexOf('/') !== -1
- },
- imgStyle() {
- let style = {}
-
- 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() {
-
- 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>
|