guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame^] | 1 | <template> |
| 2 | <view class="u-line" :style="[lineStyle]"> |
| 3 | |
| 4 | </view> |
| 5 | </template> |
| 6 | |
| 7 | <script> |
| 8 | /** |
| 9 | * line 线条 |
| 10 | * @description 此组件一般用于显示一根线条,用于分隔内容块,有横向和竖向两种模式,且能设置0.5px线条,使用也很简单 |
| 11 | * @tutorial https://www.uviewui.com/components/line.html |
| 12 | * @property {String} color 线条的颜色(默认#e4e7ed) |
| 13 | * @property {String} length 长度,竖向时表现为高度,横向时表现为长度,可以为百分比,带rpx单位的值等 |
| 14 | * @property {String} direction 线条的方向,row-横向,col-竖向(默认row) |
| 15 | * @property {String} border-style 线条的类型,solid-实线,dashed-方形虚线,dotted-圆点虚线(默认solid) |
| 16 | * @property {Boolean} hair-line 是否显示细线条(默认true) |
| 17 | * @property {String} margin 线条与上下左右元素的间距,字符串形式,如"30rpx" |
| 18 | * @example <u-line color="red"></u-line> |
| 19 | */ |
| 20 | export default { |
| 21 | name: 'u-line', |
| 22 | props: { |
| 23 | color: { |
| 24 | type: String, |
| 25 | default: '#e4e7ed' |
| 26 | }, |
| 27 | // 长度,竖向时表现为高度,横向时表现为长度,可以为百分比,带rpx单位的值等 |
| 28 | length: { |
| 29 | type: String, |
| 30 | default: '100%' |
| 31 | }, |
| 32 | // 线条方向,col-竖向,row-横向 |
| 33 | direction: { |
| 34 | type: String, |
| 35 | default: 'row' |
| 36 | }, |
| 37 | // 是否显示细边框 |
| 38 | hairLine: { |
| 39 | type: Boolean, |
| 40 | default: true |
| 41 | }, |
| 42 | // 线条与上下左右元素的间距,字符串形式,如"30rpx"、"20rpx 30rpx" |
| 43 | margin: { |
| 44 | type: String, |
| 45 | default: '0' |
| 46 | }, |
| 47 | // 线条的类型,solid-实线,dashed-方形虚线,dotted-圆点虚线 |
| 48 | borderStyle: { |
| 49 | type: String, |
| 50 | default: 'solid' |
| 51 | } |
| 52 | }, |
| 53 | computed: { |
| 54 | lineStyle() { |
| 55 | let style = {}; |
| 56 | style.margin = this.margin; |
| 57 | // 如果是水平线条,边框高度为1px,再通过transform缩小一半,就是0.5px了 |
| 58 | if(this.direction == 'row') { |
| 59 | // 此处采用兼容分开写,兼容nvue的写法 |
| 60 | style.borderBottomWidth = '1px'; |
| 61 | style.borderBottomStyle = this.borderStyle; |
| 62 | style.width = this.$u.addUnit(this.length); |
| 63 | if(this.hairLine) style.transform = 'scaleY(0.5)'; |
| 64 | } else { |
| 65 | // 如果是竖向线条,边框宽度为1px,再通过transform缩小一半,就是0.5px了 |
| 66 | style.borderLeftWidth = '1px'; |
| 67 | style.borderLeftStyle = this.borderStyle; |
| 68 | style.height = this.$u.addUnit(this.length); |
| 69 | if(this.hairLine) style.transform = 'scaleX(0.5)'; |
| 70 | } |
| 71 | style.borderColor = this.color; |
| 72 | return style; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | </script> |
| 77 | |
| 78 | <style scoped lang="scss"> |
| 79 | @import "../../libs/css/style.components.scss"; |
| 80 | |
| 81 | .u-line { |
| 82 | vertical-align: middle; |
| 83 | } |
| 84 | </style> |