江西小程序管理端
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.

62 lines
2.2 KiB

1 year ago
  1. <template>
  2. <view
  3. class="u-line"
  4. :style="[lineStyle]"
  5. >
  6. </view>
  7. </template>
  8. <script>
  9. import props from './props.js';
  10. /**
  11. * line 线条
  12. * @description 此组件一般用于显示一根线条用于分隔内容块有横向和竖向两种模式且能设置0.5px线条使用也很简单
  13. * @tutorial https://www.uviewui.com/components/line.html
  14. * @property {String} color 线条的颜色 ( 默认 '#d6d7d9' )
  15. * @property {String | Number} length 长度竖向时表现为高度横向时表现为长度可以为百分比带px单位的值等 ( 默认 '100%' )
  16. * @property {String} direction 线条的方向row-横向col-竖向 (默认 'row' )
  17. * @property {Boolean} hairline 是否显示细线条 (默认 true )
  18. * @property {String | Number} margin 线条与上下左右元素的间距字符串形式"30px" (默认 0 )
  19. * @property {Boolean} dashed 是否虚线true-虚线false-实线 (默认 false )
  20. * @property {Object} customStyle 定义需要用到的外部样式
  21. * @example <u-line color="red"></u-line>
  22. */
  23. export default {
  24. name: 'u-line',
  25. mixins: [uni.$u.mpMixin, uni.$u.mixin,props],
  26. computed: {
  27. lineStyle() {
  28. const style = {}
  29. style.margin = this.margin
  30. // 如果是水平线条,边框高度为1px,再通过transform缩小一半,就是0.5px了
  31. if (this.direction === 'row') {
  32. // 此处采用兼容分开写,兼容nvue的写法
  33. style.borderBottomWidth = '1px'
  34. style.borderBottomStyle = this.dashed ? 'dashed' : 'solid'
  35. style.width = uni.$u.addUnit(this.length)
  36. if (this.hairline) style.transform = 'scaleY(0.5)'
  37. } else {
  38. // 如果是竖向线条,边框宽度为1px,再通过transform缩小一半,就是0.5px了
  39. style.borderLeftWidth = '1px'
  40. style.borderLeftStyle = this.dashed ? 'dashed' : 'solid'
  41. style.height = uni.$u.addUnit(this.length)
  42. if (this.hairline) style.transform = 'scaleX(0.5)'
  43. }
  44. style.borderColor = this.color
  45. return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle))
  46. }
  47. }
  48. }
  49. </script>
  50. <style lang="scss" scoped>
  51. @import "../../libs/css/components.scss";
  52. .u-line {
  53. /* #ifndef APP-NVUE */
  54. vertical-align: middle;
  55. /* #endif */
  56. }
  57. </style>