u-td.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view class="u-td" :style="[tdStyle]">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. /**
  8. * td td单元格
  9. * @description 表格组件一般用于展示大量结构化数据的场景(搭配u-table使用)
  10. * @tutorial https://www.uviewui.com/components/table.html#td-props
  11. * @property {String Number} width 单元格宽度百分比或者具体带单位的值,如30%, 200rpx等,一般使用百分比,单元格宽度默认为均分tr的长度(默认auto)
  12. * @example <u-td>二年级</u-td>
  13. */
  14. export default {
  15. name: "u-td",
  16. props: {
  17. // 宽度,百分比或者具体带单位的值,如30%, 200rpx等,一般使用百分比
  18. width: {
  19. type: [Number, String],
  20. default: 'auto'
  21. }
  22. },
  23. data() {
  24. return {
  25. tr: []
  26. };
  27. },
  28. inject: ['uTable', 'uTr'],
  29. provide() {
  30. return {
  31. uTd: this
  32. }
  33. },
  34. created() {
  35. },
  36. computed: {
  37. tdStyle() {
  38. let style = {};
  39. if (this.width != "auto") style.flex = `0 0 ${this.width}`;
  40. style.textAlign = this.uTable.align;
  41. style.padding = this.tr.length == 0 ? this.uTable.padding : 0;
  42. style.borderBottom = this.tr.length == 0 ? `solid 1px ${this.uTable.borderColor}` : 0;
  43. style.borderRight = this.tr.length == 0 ? `solid 1px ${this.uTable.borderColor}` : 0;
  44. style.fontSize = this.uTable.fontSize + 'rpx';
  45. style.color = this.uTable.color;
  46. return style;
  47. }
  48. }
  49. };
  50. </script>
  51. <style lang="scss" scoped>
  52. .u-td {
  53. display: flex;
  54. flex-direction: column;
  55. flex: 1;
  56. justify-content: center;
  57. font-size: 28rpx;
  58. color: $u-content-color;
  59. align-self: stretch;
  60. box-sizing: border-box;
  61. }
  62. .u-col-1 {
  63. flex: 0 0 calc(100%/12);
  64. }
  65. .u-col-2 {
  66. flex: 0 0 calc(100%/12 * 2);
  67. }
  68. .u-col-3 {
  69. flex: 0 0 calc(100%/12 * 3);
  70. }
  71. .u-col-4 {
  72. flex: 0 0 calc(100%/12 * 4);
  73. }
  74. .u-col-5 {
  75. flex: 0 0 calc(100%/12 * 5);
  76. }
  77. .u-col-6 {
  78. flex: 0 0 calc(100%/12 * 6);
  79. }
  80. .u-col-7 {
  81. flex: 0 0 calc(100%/12 * 7);
  82. }
  83. .u-col-8 {
  84. flex: 0 0 calc(100%/12 * 8);
  85. }
  86. .u-col-9 {
  87. flex: 0 0 calc(100%/12 * 9);
  88. }
  89. .u-col-10 {
  90. flex: 0 0 calc(100%/12 * 10);
  91. }
  92. .u-col-11 {
  93. flex: 0 0 calc(100%/12 * 11);
  94. }
  95. .u-col-12 {
  96. flex: 0 0 calc(100%/12 * 12);
  97. }
  98. </style>