blob: 02293ce36cac79832b3b211c240ba1df01ccb128 [file] [log] [blame]
guangchao.xu070005a2020-12-07 09:56:40 +08001<template>
2 <view class="u-section">
3 <view class="u-section__title" :style="{
4 fontWeight: bold ? 'bold' : 'normal',
5 color: color,
6 fontSize: fontSize + 'rpx',
7 paddingLeft: showLine ? (fontSize * 0.7) + 'rpx' : 0
8 }" :class="{
9 'u-section--line': showLine
10 }">
11 <view class="u-section__title__icon-wrap u-flex" :style="[lineStyle]" v-if="showLine">
12 <u-icon top="0" name="column-line" :size="fontSize * 1.25" bold :color="lineColor ? lineColor : color"></u-icon>
13 </view>
14 <text class="u-flex u-section__title__text">{{title}}</text>
15 </view>
16 <view class="u-section__right-info" v-if="right || $slots.right" :style="{
17 color: subColor
18 }" @tap="rightClick">
19 <slot name="right" v-if="$slots.right" />
20 <block v-else>
21 {{subTitle}}
22 <view class="u-section__right-info__icon-arrow u-flex" v-if="arrow">
23 <u-icon name="arrow-right" size="24" :color="subColor"></u-icon>
24 </view>
25 </block>
26 </view>
27 </view>
28</template>
29
30<script>
31 /**
32 * section 查看更多
33 * @description 该组件一般用于分类信息有很多,但是限于篇幅只能列出一部分,让用户通过"查看更多"获得更多信息的场景,实际效果见演示。
34 * @tutorial https://www.uviewui.com/components/section.html
35 * @property {String} title 左边主标题
36 * @property {String} sub-title 右边副标题(默认更多)
37 * @property {Boolean} right 是否显示右边的内容(默认true)
38 * @property {Boolean} showLine 是否显示左边的竖条(默认true)
39 * @property {Boolean} arrow 是否显示右边箭头(默认true)
40 * @property {String Number} font-size 主标题的字体大小(默认28)
41 * @property {Boolean} bold 主标题是否加粗(默认true)
42 * @property {String} color 主标题颜色(默认#303133)
43 * @event {Function} click 组件右侧的内容被点击时触发,用于跳转"更多"
44 * @example <u-section title="今日热门" :right="false"></u-section>
45 */
46 export default {
47 name: "u-section",
48 props: {
49 // 标题信息
50 title: {
51 type: String,
52 default: ''
53 },
54 // 右边副标题内容
55 subTitle: {
56 type: String,
57 default: '更多'
58 },
59 // 是否显示右边的内容
60 right: {
61 type: Boolean,
62 default: true
63 },
64 fontSize: {
65 type: [Number, String],
66 default: 28
67 },
68 // 主标题是否加粗
69 bold: {
70 type: Boolean,
71 default: true
72 },
73 // 主标题的颜色
74 color: {
75 type: String,
76 default: '#303133'
77 },
78 // 右边副标题的颜色
79 subColor: {
80 type: String,
81 default: '#909399'
82 },
83 // 是否显示左边的竖条
84 showLine: {
85 type: Boolean,
86 default: true
87 },
88 // 左边竖线的颜色
89 lineColor: {
90 type: String,
91 default: ''
92 },
93 // 是否显示右边箭头
94 arrow: {
95 type: Boolean,
96 default: true
97 },
98 },
99 computed: {
100 // 左边竖条的样式
101 lineStyle() {
102 // 由于安卓和iOS的,需要稍微调整绝对定位的top值,才能让左边的竖线和右边的文字垂直居中
103 return {
104 // 由于竖线为字体图标,具有比实际线宽更宽的宽度,所以也需要根据字体打下动态调整
105 left: -(Number(this.fontSize) * 0.9) + 'rpx',
106 top: -(Number(this.fontSize) * (this.$u.os() == 'ios' ? 0.14 : 0.15)) + 'rpx',
107 }
108 }
109 },
110 methods: {
111 rightClick() {
112 this.$emit('click');
113 }
114 }
115 }
116</script>
117
118<style lang="scss" scoped>
119 @import "../../libs/css/style.components.scss";
120
121 .u-section {
122 @include vue-flex;
123 justify-content: space-between;
124 align-items: center;
125 width: 100%;
126
127 &__title {
128 position: relative;
129 font-size: 28rpx;
130 padding-left: 20rpx;
131 @include vue-flex;
132 align-items: center;
133
134 &__icon-wrap {
135 position: absolute;
136 }
137
138 &__text {
139 line-height: 1;
140 }
141 }
142
143 &__right-info {
144 color: $u-tips-color;
145 font-size: 26rpx;
146 @include vue-flex;
147 align-items: center;
148
149 &__icon-arrow {
150 margin-left: 6rpx;
151 }
152 }
153 }
154</style>