uni-td.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <!-- #ifdef H5 -->
  3. <td
  4. class="uni-table-td"
  5. :rowspan="rowspan"
  6. :colspan="colspan"
  7. :class="{ 'table--border': border }"
  8. :style="{ width: width + 'px', 'text-align': align }"
  9. >
  10. <slot></slot>
  11. </td>
  12. <!-- #endif -->
  13. <!-- #ifndef H5 -->
  14. <!-- :class="{'table--border':border}" -->
  15. <view
  16. class="uni-table-td"
  17. :class="{ 'table--border': border }"
  18. :style="{ width: width + 'px', 'text-align': align }"
  19. >
  20. <slot></slot>
  21. </view>
  22. <!-- #endif -->
  23. </template>
  24. <script>
  25. /**
  26. * Td 单元格
  27. * @description 表格中的标准单元格组件
  28. * @tutorial https://ext.dcloud.net.cn/plugin?id=3270
  29. * @property {Number} align = [left|center|right] 单元格对齐方式
  30. */
  31. export default {
  32. name: 'uniTd',
  33. options: {
  34. virtualHost: true
  35. },
  36. props: {
  37. width: {
  38. type: [String, Number],
  39. default: ''
  40. },
  41. align: {
  42. type: String,
  43. default: 'left'
  44. },
  45. rowspan: {
  46. type: [Number, String],
  47. default: 1
  48. },
  49. colspan: {
  50. type: [Number, String],
  51. default: 1
  52. }
  53. },
  54. data () {
  55. return {
  56. border: false
  57. }
  58. },
  59. created () {
  60. this.root = this.getTable()
  61. this.border = this.root.border
  62. },
  63. methods: {
  64. /**
  65. * 获取父元素实例
  66. */
  67. getTable () {
  68. let parent = this.$parent
  69. let parentName = parent.$options.name
  70. while (parentName !== 'uniTable') {
  71. parent = parent.$parent
  72. if (!parent) return false
  73. parentName = parent.$options.name
  74. }
  75. return parent
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss">
  81. $border-color: #ebeef5;
  82. .uni-table-td {
  83. display: table-cell;
  84. padding: 8px 10px;
  85. font-size: 32rpx;
  86. border-bottom: 1px $border-color solid;
  87. font-weight: 400;
  88. color: #606266;
  89. line-height: 23px;
  90. box-sizing: border-box;
  91. }
  92. .table--border {
  93. border-right: 1px $border-color solid;
  94. }
  95. </style>