123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <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'" :href="href" underLine :text="value"></u-link>
- <template v-else-if="openType && isMp">
- <button
- class="u-reset-button u-text__value"
- :style="[valueStyle]"
- :class="[
- type && `u-text__value--${type}`,
- ]"
- :data-index="index"
- :openType="openType"
- :lang="lang"
- :session-from="sessionFrom"
- :send-message-title="sendMessageTitle"
- :send-message-path="sendMessagePath"
- :send-message-img="sendMessageImg"
- :show-message-card="showMessageCard"
- :app-parameter="appParameter"
- @getuserinfo="onGetUserInfo"
- @contact="onContact"
- @getphonenumber="onGetPhoneNumber"
- @error="onError"
- @launchapp="onLaunchApp"
- @opensetting="onOpenSetting"
- >
- {{ 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 mixin from './libs/mixin/mixin.js'
- import button from './libs/mixin/button.js'
- import openType from './libs/mixin/openType.js'
- import addUnit from './libs/function/addUnit.js';
- import props from './props.js'
-
- export default {
- name: 'u-text',
- emits: ["click","copy"],
-
-
- options: {
- virtualHost: true
- },
-
-
- mixins: [mixin, value, button, openType, props],
-
-
- mixins: [mixin, value, props],
-
- computed: {
- valueStyle() {
- const style = {
- textDecoration: this.decoration,
- fontWeight: this.bold ? 'bold' : 'normal',
- wordWrap: this.wordWrap,
- fontSize: addUnit(this.size)
- };
- !this.type && (style.color = this.color);
- this.isNvue && this.lines && (style.lines = this.lines);
- this.lineHeight && (style.lineHeight = addUnit(this.lineHeight));
- !this.isNvue && this.block && (style.display = 'block');
- return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle));
- },
- isNvue() {
- let nvue = false;
-
- nvue = true;
-
- return nvue;
- },
- isMp() {
- let mp = false;
-
- mp = true;
-
- return mp;
- }
- },
- data() {
- return {};
- },
- methods: {
- clickHandler() {
-
- if (this.call && this.mode === 'phone') {
- uni.makePhoneCall({
- phoneNumber: this.text
- });
- } else if (this.copyText) {
- uni.setClipboardData({
- data: this.copyText,
- success: () => {
- this.$emit('copy', this.copyText);
- }
- })
- }
- this.$emit('click');
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "./theme.scss";
- /* #ifndef APP-NVUE */
- // 由于uView是基于nvue环境进行开发的,此环境中普通元素默认为flex-direction: column;
- // 所以在非nvue中,需要对元素进行重置为flex-direction: column; 否则可能会表现异常
- view,
- scroll-view,
- swiper-item {
- display: flex;
- flex-direction: column;
- flex-shrink: 0;
- flex-grow: 0;
- flex-basis: auto;
- align-items: stretch;
- align-content: flex-start;
- }
- /* #endif */
- .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;
- }
- }
- }
- /* #ifdef MP */
- .u-text{
- flex: inherit;
- width: inherit;
- }
- /* #endif */
- </style>
|