Skip to content

Commit 9d07eb4

Browse files
committed
新增read-more组件控制字符缩进的text-indent参数
1 parent c6f6818 commit 9d07eb4

File tree

1 file changed

+43
-34
lines changed

1 file changed

+43
-34
lines changed

uview-ui/components/u-read-more/u-read-more.vue

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
<template>
22
<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+
}">
47
<slot></slot>
58
</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="{
1113
fontSize: fontSize + 'rpx',
1214
color: color
1315
}">
1416
{{ showMore ? openText : closeText }}
1517
</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>
1721
</view>
1822
</view>
1923
</template>
@@ -27,6 +31,7 @@
2731
* @property {Boolean} toggle 展开后是否显示收起按钮(默认false)
2832
* @property {String} close-text 关闭时的提示文字(默认“展开阅读全文”)
2933
* @property {String Number} font-size 提示文字的大小,单位rpx(默认28)
34+
* @property {String} text-indent 段落首行缩进的字符个数(默认2em)
3035
* @property {String} open-text 展开时的提示文字(默认“收起”)
3136
* @property {String} color 提示文字的颜色(默认#2979ff)
3237
* @example <u-read-more><rich-text :nodes="content"></rich-text></u-read-more>
@@ -67,13 +72,18 @@
6772
// 是否显示阴影
6873
shadowStyle: {
6974
type: Object,
70-
default() {
75+
default () {
7176
return {
7277
backgroundImage: "linear-gradient(-180deg, rgba(255, 255, 255, 0) 0%, #fff 80%)",
7378
paddingTop: "300rpx",
7479
marginTop: "-300rpx"
7580
}
7681
}
82+
},
83+
// 段落首行缩进的字符个数
84+
textIndent: {
85+
type: String,
86+
default: '2em'
7787
}
7888
},
7989
watch: {
@@ -87,7 +97,7 @@
8797
},
8898
// 展开后无需阴影,收起时才需要阴影样式
8999
innerShadowStyle() {
90-
if(this.showMore) return {};
100+
if (this.showMore) return {};
91101
else return this.shadowStyle
92102
}
93103
},
@@ -99,7 +109,7 @@
99109
};
100110
},
101111
mounted() {
102-
this.$nextTick(function(){
112+
this.$nextTick(function() {
103113
this.init();
104114
})
105115
},
@@ -125,39 +135,38 @@
125135

126136
<style lang="scss" scoped>
127137
@import "../../libs/css/style.components.scss";
128-
138+
129139
.u-content {
130140
font-size: 30rpx;
131141
color: $u-content-color;
132142
line-height: 1.8;
133143
text-align: left;
134-
text-indent: 2em;
135144
overflow: hidden;
136-
}
137145
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+
}
146151
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;
152159
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;
159165
160-
.u-icon {
161-
margin-left: 14rpx;
166+
&__icon {
167+
margin-left: 14rpx;
168+
}
169+
}
170+
}
162171
}
163172
</style>

0 commit comments

Comments
 (0)