bug
jiangping
2023-11-07 64b432916af9c9218ab3f3eca614e26c542142ae
minipro_standard/uni_modules/uview-ui/components/u-text/u-text.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,223 @@
<template>
    <view
        class="u-text"
        :class="[]"
        v-if="show"
        :style="{
            margin: margin,
         justifyContent: align === 'left' ? 'flex-start' : align === 'center' ? 'center' : 'flex-end'
        }"
        @tap="clickHandler"
    >
        <text
            :class="['u-text__price', type && `u-text__value--${type}`]"
            v-if="mode === 'price'"
            :style="[valueStyle]"
            >ï¿¥</text
        >
        <view class="u-text__prefix-icon" v-if="prefixIcon">
            <u-icon
                :name="prefixIcon"
                :customStyle="$u.addStyle(iconStyle)"
            ></u-icon>
        </view>
        <u-link
            v-if="mode === 'link'"
            :text="value"
            :href="href"
            underLine
        ></u-link>
        <template v-else-if="openType && isMp">
            <button
                class="u-reset-button u-text__value"
                :style="[valueStyle]"
                :data-index="index"
                :openType="openType"
                @getuserinfo="onGetUserInfo"
                @contact="onContact"
                @getphonenumber="onGetPhoneNumber"
                @error="onError"
                @launchapp="onLaunchApp"
                @opensetting="onOpenSetting"
                :lang="lang"
                :session-from="sessionFrom"
                :send-message-title="sendMessageTitle"
                :send-message-path="sendMessagePath"
                :send-message-img="sendMessageImg"
                :show-message-card="showMessageCard"
                :app-parameter="appParameter"
            >
                {{ value }}
            </button>
        </template>
        <text
            v-else
            class="u-text__value"
            :style="[valueStyle]"
            :class="[
                type && `u-text__value--${type}`,
                lines && `u-line-${lines}`
            ]"
            >{{ value }}</text
        >
        <view class="u-text__suffix-icon" v-if="suffixIcon">
            <u-icon
                :name="suffixIcon"
                :customStyle="$u.addStyle(iconStyle)"
            ></u-icon>
        </view>
    </view>
</template>
<script>
import value from './value.js'
import button from '../../libs/mixin/button.js'
import openType from '../../libs/mixin/openType.js'
import props from './props.js'
/**
 * Text æ–‡æœ¬
 * @description æ­¤ç»„件集成了文本类在项目中的常用功能,包括状态,拨打电话,格式化日期,*替换,超链接...等功能。 æ‚¨å¤§å¯ä¸å¿…在使用特殊文本时自己定义,text组件几乎涵盖您能使用的大部分场景。
 * @tutorial https://www.uviewui.com/components/loading.html
 * @property {String}                type      ä¸»é¢˜é¢œè‰²
 * @property {Boolean}                show      æ˜¯å¦æ˜¾ç¤ºï¼ˆé»˜è®¤ true ï¼‰
 * @property {String | Number}         text      æ˜¾ç¤ºçš„值
 * @property {String}               prefixIcon   å‰ç½®å›¾æ ‡
 * @property {String}                suffixIcon   åŽç½®å›¾æ ‡
 * @property {String}                mode      æ–‡æœ¬å¤„理的匹配模式 text-普通文本,price-价格,phone-手机号,name-姓名,date-日期,link-超链接
 * @property {String}                href      mode=link下,配置的链接
 * @property {String | Function}       format      æ ¼å¼åŒ–规则
 * @property {Boolean}                call      mode=phone时,点击文本是否拨打电话(默认 false ï¼‰
 * @property {String}                openType   å°ç¨‹åºçš„æ‰“开方式
 * @property {Boolean}                bold      æ˜¯å¦ç²—体,默认normal(默认 false ï¼‰
 * @property {Boolean}                block      æ˜¯å¦å—状(默认 false ï¼‰
 * @property {String | Number}          lines      æ–‡æœ¬æ˜¾ç¤ºçš„行数,如果设置,超出此行数,将会显示省略号
 * @property {String}                color      æ–‡æœ¬é¢œè‰²ï¼ˆé»˜è®¤ '#303133' ï¼‰
 * @property {String | Number}          size      å­—体大小(默认 15 ï¼‰
 * @property {Object | String}          iconStyle   å›¾æ ‡çš„æ ·å¼ ï¼ˆé»˜è®¤ {fontSize: '15px'} ï¼‰
 * @property {String}                decoration   æ–‡å­—装饰,下划线,中划线等,可选值 none|underline|line-through(默认 'none' ï¼‰
 * @property {Object | String | Number}   margin      å¤–边距,对象、字符串,数值形式均可(默认 0 ï¼‰
 * @property {String | Number}          lineHeight   æ–‡æœ¬è¡Œé«˜
 * @property {String}                align      æ–‡æœ¬å¯¹é½æ–¹å¼ï¼Œå¯é€‰å€¼left|center|right(默认 'left' ï¼‰
 * @property {String}                wordWrap   æ–‡å­—换行,可选值break-word|normal|anywhere(默认 'normal' ï¼‰
 * @event {Function} click  ç‚¹å‡»è§¦å‘事件
 * @example <u--text text="我用十年青春,赴你最后之约"></u--text>
 */
export default {
    name: 'u--text',
    // #ifdef MP
    mixins: [uni.$u.mpMixin, uni.$u.mixin, value, button, openType, props],
    // #endif
    // #ifndef MP
    mixins: [uni.$u.mpMixin, uni.$u.mixin, value, props],
    // #endif
    computed: {
        valueStyle() {
            const style = {
                textDecoration: this.decoration,
                fontWeight: this.bold ? 'bold' : 'normal',
                wordWrap: this.wordWrap,
                fontSize: uni.$u.addUnit(this.size)
            }
            !this.type && (style.color = this.color)
            this.isNvue && this.lines && (style.lines = this.lines)
            this.lineHeight &&
                (style.lineHeight = uni.$u.addUnit(this.lineHeight))
            !this.isNvue && this.block && (style.display = 'block')
            return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle))
        },
        isNvue() {
            let nvue = false
            // #ifdef APP-NVUE
            nvue = true
            // #endif
            return nvue
        },
        isMp() {
            let mp = false
            // #ifdef MP
            mp = true
            // #endif
            return mp
        }
    },
    data() {
        return {}
    },
    methods: {
        clickHandler() {
            // å¦‚果为手机号模式,拨打电话
            if (this.call && this.mode === 'phone') {
                uni.makePhoneCall({
                    phoneNumber: this.text
                })
            }
            this.$emit('click')
        }
    }
}
</script>
<style lang="scss" scoped>
@import '../../libs/css/components.scss';
.u-text {
    @include flex(row);
    align-items: center;
    flex-wrap: nowrap;
    flex: 1;
   /* #ifndef APP-NVUE */
   width: 100%;
   /* #endif */
    &__price {
        font-size: 14px;
        color: $u-content-color;
    }
    &__value {
        font-size: 14px;
        @include flex;
        color: $u-content-color;
        flex-wrap: wrap;
        // flex: 1;
        text-overflow: ellipsis;
        align-items: center;
        &--primary {
            color: $u-primary;
        }
        &--warning {
            color: $u-warning;
        }
        &--success {
            color: $u-success;
        }
        &--info {
            color: $u-info;
        }
        &--error {
            color: $u-error;
        }
        &--main {
            color: $u-main-color;
        }
        &--content {
            color: $u-content-color;
        }
        &--tips {
            color: $u-tips-color;
        }
        &--light {
            color: $u-light-color;
        }
    }
}
</style>