|
1 | 1 | <template>
|
2 | 2 | <view class="">
|
3 |
| - <view class="u-content" :class="[elId]" :style="{ height: isLongContent && !showMore ? showHeight + 'rpx' : 'auto' }"> |
| 3 | + <view class="u-content" :class="[elId]" :style="{ |
| 4 | + height: isLongContent && !showMore ? showHeight + 'rpx' : 'auto', |
| 5 | + textIndent: this.textIndent |
| 6 | + }"> |
4 | 7 | <slot></slot>
|
5 | 8 | </view>
|
6 |
| - <view @tap="toggleReadMore" v-if="isLongContent" class="u-showmore-wrap" |
7 |
| - :class="{ 'u-show-more': showMore }" |
8 |
| - :style="[innerShadowStyle]" |
9 |
| - > |
10 |
| - <text class="u-readmore-btn" :style="{ |
| 9 | + <view @tap="toggleReadMore" v-if="isLongContent" class="u-content__showmore-wrap" |
| 10 | + :class="{ 'u-content__show-more': showMore }" |
| 11 | + :style="[innerShadowStyle]"> |
| 12 | + <text class="u-content__showmore-wrap__readmore-btn" :style="{ |
11 | 13 | fontSize: fontSize + 'rpx',
|
12 | 14 | color: color
|
13 | 15 | }">
|
14 | 16 | {{ showMore ? openText : closeText }}
|
15 | 17 | </text>
|
16 |
| - <u-icon :color="color" :size="fontSize" class="u-icon" :name="showMore ? 'arrow-up' : 'arrow-down'"></u-icon> |
| 18 | + <view class="u-content__showmore-wrap__readmore-btn__icon u-flex"> |
| 19 | + <u-icon :color="color" :size="fontSize" :name="showMore ? 'arrow-up' : 'arrow-down'"></u-icon> |
| 20 | + </view> |
17 | 21 | </view>
|
18 | 22 | </view>
|
19 | 23 | </template>
|
|
27 | 31 | * @property {Boolean} toggle 展开后是否显示收起按钮(默认false)
|
28 | 32 | * @property {String} close-text 关闭时的提示文字(默认“展开阅读全文”)
|
29 | 33 | * @property {String Number} font-size 提示文字的大小,单位rpx(默认28)
|
| 34 | + * @property {String} text-indent 段落首行缩进的字符个数(默认2em) |
30 | 35 | * @property {String} open-text 展开时的提示文字(默认“收起”)
|
31 | 36 | * @property {String} color 提示文字的颜色(默认#2979ff)
|
32 | 37 | * @example <u-read-more><rich-text :nodes="content"></rich-text></u-read-more>
|
|
67 | 72 | // 是否显示阴影
|
68 | 73 | shadowStyle: {
|
69 | 74 | type: Object,
|
70 |
| - default() { |
| 75 | + default () { |
71 | 76 | return {
|
72 | 77 | backgroundImage: "linear-gradient(-180deg, rgba(255, 255, 255, 0) 0%, #fff 80%)",
|
73 | 78 | paddingTop: "300rpx",
|
74 | 79 | marginTop: "-300rpx"
|
75 | 80 | }
|
76 | 81 | }
|
| 82 | + }, |
| 83 | + // 段落首行缩进的字符个数 |
| 84 | + textIndent: { |
| 85 | + type: String, |
| 86 | + default: '2em' |
77 | 87 | }
|
78 | 88 | },
|
79 | 89 | watch: {
|
|
87 | 97 | },
|
88 | 98 | // 展开后无需阴影,收起时才需要阴影样式
|
89 | 99 | innerShadowStyle() {
|
90 |
| - if(this.showMore) return {}; |
| 100 | + if (this.showMore) return {}; |
91 | 101 | else return this.shadowStyle
|
92 | 102 | }
|
93 | 103 | },
|
|
99 | 109 | };
|
100 | 110 | },
|
101 | 111 | mounted() {
|
102 |
| - this.$nextTick(function(){ |
| 112 | + this.$nextTick(function() { |
103 | 113 | this.init();
|
104 | 114 | })
|
105 | 115 | },
|
|
125 | 135 |
|
126 | 136 | <style lang="scss" scoped>
|
127 | 137 | @import "../../libs/css/style.components.scss";
|
128 |
| - |
| 138 | +
|
129 | 139 | .u-content {
|
130 | 140 | font-size: 30rpx;
|
131 | 141 | color: $u-content-color;
|
132 | 142 | line-height: 1.8;
|
133 | 143 | text-align: left;
|
134 |
| - text-indent: 2em; |
135 | 144 | overflow: hidden;
|
136 |
| - } |
137 | 145 |
|
138 |
| - .u-showmore-wrap { |
139 |
| - position: relative; |
140 |
| - width: 100%; |
141 |
| - padding-bottom: 26rpx; |
142 |
| - display: flex; |
143 |
| - align-items: center; |
144 |
| - justify-content: center; |
145 |
| - } |
| 146 | + &__show-more { |
| 147 | + padding-top: 0; |
| 148 | + background: none; |
| 149 | + margin-top: 20rpx; |
| 150 | + } |
146 | 151 |
|
147 |
| - .u-show-more { |
148 |
| - padding-top: 0; |
149 |
| - background: none; |
150 |
| - margin-top: 20rpx; |
151 |
| - } |
| 152 | + &__showmore-wrap { |
| 153 | + position: relative; |
| 154 | + width: 100%; |
| 155 | + padding-bottom: 26rpx; |
| 156 | + display: flex; |
| 157 | + align-items: center; |
| 158 | + justify-content: center; |
152 | 159 |
|
153 |
| - .u-readmore-btn { |
154 |
| - display: flex; |
155 |
| - align-items: center; |
156 |
| - justify-content: center; |
157 |
| - line-height: 1; |
158 |
| - } |
| 160 | + &__readmore-btn { |
| 161 | + display: flex; |
| 162 | + align-items: center; |
| 163 | + justify-content: center; |
| 164 | + line-height: 1; |
159 | 165 |
|
160 |
| - .u-icon { |
161 |
| - margin-left: 14rpx; |
| 166 | + &__icon { |
| 167 | + margin-left: 14rpx; |
| 168 | + } |
| 169 | + } |
| 170 | + } |
162 | 171 | }
|
163 | 172 | </style>
|
0 commit comments