blob: 6f8d7e69ee819ddeebe436dfe2594fb6d80afcfd [file] [log] [blame]
guangchao.xu070005a2020-12-07 09:56:40 +08001<template>
2 <view class="u-divider" :style="{
3 height: height == 'auto' ? 'auto' : height + 'rpx',
4 backgroundColor: bgColor,
5 marginBottom: marginBottom + 'rpx',
6 marginTop: marginTop + 'rpx'
7 }" @tap="click">
8 <view class="u-divider-line" :class="[type ? 'u-divider-line--bordercolor--' + type : '']" :style="[lineStyle]"></view>
9 <view v-if="useSlot" class="u-divider-text" :style="{
10 color: color,
11 fontSize: fontSize + 'rpx'
12 }"><slot /></view>
13 <view class="u-divider-line" :class="[type ? 'u-divider-line--bordercolor--' + type : '']" :style="[lineStyle]"></view>
14 </view>
15</template>
16
17<script>
18/**
19 * divider 分割线
20 * @description 区隔内容的分割线,一般用于页面底部"没有更多"的提示。
21 * @tutorial https://www.uviewui.com/components/divider.html
22 * @property {String Number} half-width 文字左或右边线条宽度,数值或百分比,数值时单位为rpx
23 * @property {String} border-color 线条颜色,优先级高于type(默认#dcdfe6)
24 * @property {String} color 文字颜色(默认#909399)
25 * @property {String Number} fontSize 字体大小,单位rpx(默认26)
26 * @property {String} bg-color 整个divider的背景颜色(默认呢#ffffff)
27 * @property {String Number} height 整个divider的高度,单位rpx(默认40)
28 * @property {String} type 将线条设置主题色(默认primary)
29 * @property {Boolean} useSlot 是否使用slot传入内容,如果不传入,中间不会有空隙(默认true)
30 * @property {String Number} margin-top 与前一个组件的距离,单位rpx(默认0)
31 * @property {String Number} margin-bottom 与后一个组件的距离,单位rpx(0)
32 * @event {Function} click divider组件被点击时触发
33 * @example <u-divider color="#fa3534">长河落日圆</u-divider>
34 */
35export default {
36 name: 'u-divider',
37 props: {
38 // 单一边divider横线的宽度(数值),单位rpx。或者百分比
39 halfWidth: {
40 type: [Number, String],
41 default: 150
42 },
43 // divider横线的颜色,如设置,
44 borderColor: {
45 type: String,
46 default: '#dcdfe6'
47 },
48 // 主题色,可以是primary|info|success|warning|error之一值
49 type: {
50 type: String,
51 default: 'primary'
52 },
53 // 文字颜色
54 color: {
55 type: String,
56 default: '#909399'
57 },
58 // 文字大小,单位rpx
59 fontSize: {
60 type: [Number, String],
61 default: 26
62 },
63 // 整个divider的背景颜色
64 bgColor: {
65 type: String,
66 default: '#ffffff'
67 },
68 // 整个divider的高度单位rpx
69 height: {
70 type: [Number, String],
71 default: 'auto'
72 },
73 // 上边距
74 marginTop: {
75 type: [String, Number],
76 default: 0
77 },
78 // 下边距
79 marginBottom: {
80 type: [String, Number],
81 default: 0
82 },
83 // 是否使用slot传入内容,如果不用slot传入内容,先的中间就不会有空隙
84 useSlot: {
85 type: Boolean,
86 default: true
87 }
88 },
89 computed: {
90 lineStyle() {
91 let style = {};
92 if(String(this.halfWidth).indexOf('%') != -1) style.width = this.halfWidth;
93 else style.width = this.halfWidth + 'rpx';
94 // borderColor优先级高于type值
95 if(this.borderColor) style.borderColor = this.borderColor;
96 return style;
97 }
98 },
99 methods: {
100 click() {
101 this.$emit('click');
102 }
103 }
104};
105</script>
106
107<style lang="scss" scoped>
108@import "../../libs/css/style.components.scss";
109.u-divider {
110 width: 100%;
111 position: relative;
112 text-align: center;
113 @include vue-flex;
114 justify-content: center;
115 align-items: center;
116 overflow: hidden;
117 flex-direction: row;
118}
119
120.u-divider-line {
121 border-bottom: 1px solid $u-border-color;
122 transform: scale(1, 0.5);
123 transform-origin: center;
124
125 &--bordercolor--primary {
126 border-color: $u-type-primary;
127 }
128
129 &--bordercolor--success {
130 border-color: $u-type-success;
131 }
132
133 &--bordercolor--error {
134 border-color: $u-type-primary;
135 }
136
137 &--bordercolor--info {
138 border-color: $u-type-info;
139 }
140
141 &--bordercolor--warning {
142 border-color: $u-type-warning;
143 }
144}
145
146.u-divider-text {
147 white-space: nowrap;
148 padding: 0 16rpx;
149 /* #ifndef APP-NVUE */
150 display: inline-flex;
151 /* #endif */
152}
153</style>