| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <script lang="ts">
- /**
- * 组件说明: 文本块。
- *
- * 可设置左右文字,左侧文字支持双行。
- *
- * 此组件适用于需要展示多行文本信息并具备一定交互性和布局灵活性的场景,如列表项、信息展示框等。
- */
- export default {}
- </script>
- <script setup lang="ts">
- import Text, { type TextProps } from '../../basic/Text.vue';
- import type { PropType } from 'vue';
- import Touchable from '@/components/feedback/Touchable.vue';
- defineEmits([ 'click' ])
- defineProps({
- /**
- * 主文本内容
- * @type {string}
- * @default ''
- */
- text : {
- type: String,
- default: '',
- },
- /**
- * 主文本的样式类名
- * @type {string}
- * @default 'contentLight'
- */
- textProps : {
- type: Object as PropType<TextProps>,
- default: () => ({
- color: 'text.content',
- }),
- },
- /**
- * 副文本内容
- * @type {string}
- * @default ''
- */
- text2 : {
- type: String,
- default: '',
- },
- text2Empty : {
- type: String,
- default: '暂无',
- },
- /**
- * 副文本的样式类名
- * @type {string}
- * @default 'contentSecond'
- */
- text2Props : {
- type: Object as PropType<TextProps>,
- default: () => ({
- color: 'text.second',
- }),
- },
- /**
- * 副文本的最大行数
- */
- text2Lines : {
- type: Number,
- default: undefined,
- },
- /**
- * 传递给根容器的额外属性对象
- * @type {Object}
- * @default undefined
- */
- viewProps: {
- type: Object,
- default: undefined
- },
- /**
- * 标识文本块是否可点击
- * @type {boolean}
- * @default false
- */
- touchable: {
- type: Boolean,
- default: false,
- },
- /**
- * 标识文本是否换行显示
- * @type {boolean}
- * @default false
- */
- wrap: {
- type: Boolean,
- default: false,
- },
- })
- </script>
- <template>
- <Touchable
- :touchable="touchable"
- :setCursor="false"
- justify="space-between"
- align="flex-start"
- width="fill"
- direction="row"
- v-bind="viewProps"
- @click="$emit('click')"
- >
- <Text
- :class="[
- 'nana-text first',
- wrap ? 'wrap' : '',
- ]"
- v-bind="textProps"
- :text="text"
- />
- <slot>
- <Text
- :class="[
- 'nana-text second',
- wrap ? 'wrap' : '',
- ]"
- v-bind="text2Props"
- :lines="text2Lines"
- :text="text2 || text2Empty"
- />
- </slot>
- </Touchable>
- </template>
- <style lang="scss">
- .nana-text {
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- flex: 1 1 100%;
- max-width: 100%;
- &.wrap {
- white-space: normal;
- }
- &.first {
- flex-shrink: 1;
- flex-grow: 0;
- flex-basis: 30%;
- }
- }
- .nana-text-prefix {
- flex-shrink: 0;
- overflow: hidden;
- text-overflow: ellipsis;
- margin-right: 20rpx;
- }
- .nana-text-suffix {
- flex-shrink: 0;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- </style>
|