25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

101 lines
2.2 KiB

  1. <template>
  2. <view class="u-td" :style="[tdStyle]">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. import { props } from './props';
  8. import { mpMixin } from '../../libs/mixin/mpMixin';
  9. import { mixin } from '../../libs/mixin/mixin';
  10. import { addUnit, $parent } from '../../libs/function/index';
  11. /**
  12. * Td 表格中的单元格
  13. * @description
  14. * @tutorial url
  15. * @property {String | Number}
  16. * @event {Function}
  17. * @example
  18. */
  19. export default {
  20. name: 'u-td',
  21. mixins: [mpMixin, mixin, props],
  22. props: {
  23. // 宽度,百分比或者具体带单位的值,如30%, 200rpx等,一般使用百分比
  24. width: {
  25. type: [String],
  26. default: 'auto'
  27. },
  28. textAlign: {
  29. type: String,
  30. default: ''
  31. },
  32. fontSize: {
  33. type: String,
  34. default: ''
  35. },
  36. borderColor: {
  37. type: String,
  38. default: ''
  39. },
  40. color: {
  41. type: String,
  42. default: ''
  43. }
  44. },
  45. data() {
  46. return {
  47. tdStyle: {
  48. }
  49. }
  50. },
  51. created() {
  52. this.parent = false;
  53. },
  54. mounted() {
  55. this.parent = $parent.call(this, 'u-table');
  56. if (this.parent) {
  57. // 将父组件的相关参数,合并到本组件
  58. let style = {};
  59. const borderColor = this.parent.resolvedBorderColor || this.parent.borderColor;
  60. const textColor = this.parent.resolvedColor || this.parent.color;
  61. if (this.width != "auto") style.flex = `0 0 ${this.width}`;
  62. style.textAlign = this.parent.align;
  63. style.fontSize = addUnit(this.parent.fontSize);
  64. style.padding = this.parent.padding;
  65. style.borderBottom = `solid 1px ${borderColor}`;
  66. style.borderRight = `solid 1px ${borderColor}`;
  67. style.color = textColor;
  68. if (this.textAlign != '') {
  69. style.textAlign = this.textAlign;
  70. }
  71. if (this.fontSize != '') {
  72. style.fontSize = this.fontSize;
  73. }
  74. if (this.borderColor != '') {
  75. style.borderColor = this.borderColor;
  76. }
  77. if (this.color != '') {
  78. style.color = this.color;
  79. }
  80. this.tdStyle = style;
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang="scss" scoped>
  86. .u-td {
  87. @include flex;
  88. flex-direction: column;
  89. flex: 1;
  90. justify-content: center;
  91. font-size: 14px;
  92. color: $u-content-color;
  93. align-self: stretch;
  94. box-sizing: border-box;
  95. height: 100%;
  96. }
  97. </style>