tn-table.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="tn-table-class tn-table" :class="[tableClass]" :style="[tableStyle]">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'tn-table',
  9. props: {
  10. // 边框宽度
  11. borderWidth: {
  12. type: [String, Number],
  13. default: ''
  14. },
  15. // 边框颜色
  16. borderColor: {
  17. type: String,
  18. default: ''
  19. },
  20. // 显示上边框
  21. borderTop: {
  22. type: Boolean,
  23. default: true
  24. },
  25. // 显示右边框
  26. borderRight: {
  27. type: Boolean,
  28. default: false
  29. },
  30. // 显示下边框
  31. borderBottom: {
  32. type: Boolean,
  33. default: false
  34. },
  35. // 显示左边框
  36. borderLeft: {
  37. type: Boolean,
  38. default: true
  39. }
  40. },
  41. computed: {
  42. parentData() {
  43. return [this.borderWidth, this.borderColor]
  44. },
  45. tableClass() {
  46. let clazz = ''
  47. return clazz
  48. },
  49. tableStyle() {
  50. let style = {}
  51. if (this.borderWidth !== '') {
  52. style.borderWidth = this.$t.string.getLengthUnitValue(this.borderWidth)
  53. }
  54. if (this.borderColor) {
  55. style.borderColor = this.borderColor
  56. }
  57. if (this.borderLeft) {
  58. style.borderLeftStyle = 'solid'
  59. }
  60. if (this.borderRight) {
  61. style.borderRightStyle = 'solid'
  62. }
  63. if (this.borderTop) {
  64. style.borderTopStyle = 'solid'
  65. }
  66. if (this.borderBottom) {
  67. style.borderBottomStyle = 'solid'
  68. }
  69. return style
  70. }
  71. },
  72. data() {
  73. return {}
  74. },
  75. created() {
  76. this.children = []
  77. },
  78. watch: {
  79. parentData() {
  80. // 更新子组件的数据
  81. if (this.children.length) {
  82. this.children.map((child) => {
  83. typeof(child.updateParentData) === 'function' && child.updateParentData()
  84. })
  85. }
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .tn-table {
  92. box-sizing: border-box;
  93. border-width: 1rpx;
  94. border-style: none;
  95. border-color: #AAAAAA;
  96. }
  97. </style>