uni-td.vue 2.1 KB

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