You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB

4 years ago
<template>
4 years ago
<view
class="u-line"
:style="[lineStyle]"
>
4 years ago
</view>
</template>
<script>
4 years ago
import props from './props.js';
4 years ago
/**
* line 线条
* @description 此组件一般用于显示一根线条用于分隔内容块有横向和竖向两种模式且能设置0.5px线条使用也很简单
* @tutorial https://www.uviewui.com/components/line.html
4 years ago
* @property {String} color 线条的颜色 ( 默认 '#d6d7d9' )
* @property {String | Number} length 长度竖向时表现为高度横向时表现为长度可以为百分比带px单位的值等 ( 默认 '100%' )
* @property {String} direction 线条的方向row-横向col-竖向 (默认 'row' )
* @property {Boolean} hairline 是否显示细线条 (默认 true )
* @property {String | Number} margin 线条与上下左右元素的间距字符串形式"30px" (默认 0 )
* @property {Boolean} dashed 是否虚线true-虚线false-实线 (默认 false )
* @property {Object} customStyle 定义需要用到的外部样式
4 years ago
* @example <u-line color="red"></u-line>
*/
export default {
name: 'u-line',
4 years ago
mixins: [uni.$u.mpMixin, uni.$u.mixin,props],
4 years ago
computed: {
lineStyle() {
4 years ago
const style = {}
style.margin = this.margin
4 years ago
// 如果是水平线条边框高度为1px再通过transform缩小一半就是0.5px了
4 years ago
if (this.direction === 'row') {
4 years ago
// 此处采用兼容分开写兼容nvue的写法
4 years ago
style.borderBottomWidth = '1px'
style.borderBottomStyle = this.dashed ? 'dashed' : 'solid'
style.width = uni.$u.addUnit(this.length)
if (this.hairline) style.transform = 'scaleY(0.5)'
4 years ago
} else {
// 如果是竖向线条边框宽度为1px再通过transform缩小一半就是0.5px了
4 years ago
style.borderLeftWidth = '1px'
style.borderLeftStyle = this.dashed ? 'dashed' : 'solid'
style.height = uni.$u.addUnit(this.length)
if (this.hairline) style.transform = 'scaleX(0.5)'
4 years ago
}
4 years ago
style.borderColor = this.color
return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle))
4 years ago
}
}
}
</script>
4 years ago
<style lang="scss" scoped>
@import "../../libs/css/components.scss";
4 years ago
.u-line {
4 years ago
/* #ifndef APP-NVUE */
4 years ago
vertical-align: middle;
4 years ago
/* #endif */
4 years ago
}
</style>