u-td.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. if (this.width != "auto") style.flex = `0 0 ${this.width}`;
  60. style.textAlign = this.parent.align;
  61. style.fontSize = addUnit(this.parent.fontSize);
  62. style.padding = this.parent.padding;
  63. style.borderBottom = `solid 1px ${this.parent.borderColor}`;
  64. style.borderRight = `solid 1px ${this.parent.borderColor}`;
  65. style.color = this.parent.color;
  66. if (this.textAlign != '') {
  67. style.textAlign = this.textAlign;
  68. }
  69. if (this.fontSize != '') {
  70. style.fontSize = this.fontSize;
  71. }
  72. if (this.borderColor != '') {
  73. style.borderColor = this.borderColor;
  74. }
  75. if (this.color != '') {
  76. style.color = this.color;
  77. }
  78. this.tdStyle = style;
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. .u-td {
  85. @include flex;
  86. flex-direction: column;
  87. flex: 1;
  88. justify-content: center;
  89. font-size: 14px;
  90. color: $u-content-color;
  91. align-self: stretch;
  92. box-sizing: border-box;
  93. height: 100%;
  94. }
  95. </style>