爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB

1 week ago
  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. // #ifdef MP-WEIXIN
  17. // 将自定义节点设置成虚拟的,更加接近Vue组件的表现,能更好的使用flex属性
  18. options: {
  19. virtualHost: true
  20. },
  21. // #endif
  22. props: {
  23. // 宽度,百分比或者具体带单位的值,如30%, 200rpx等,一般使用百分比
  24. width: {
  25. type: [Number, String],
  26. default: 'auto'
  27. }
  28. },
  29. data() {
  30. return {
  31. tdStyle: {
  32. }
  33. }
  34. },
  35. created() {
  36. this.parent = false;
  37. },
  38. mounted() {
  39. this.parent = this.$u.$parent.call(this, 'u-table');
  40. if (this.parent) {
  41. // 将父组件的相关参数,合并到本组件
  42. let style = {};
  43. if (this.width != "auto") style.flex = `0 0 ${this.width}`;
  44. style.textAlign = this.parent.align;
  45. style.fontSize = this.parent.fontSize + 'rpx';
  46. style.padding = this.parent.padding;
  47. style.borderBottom = `solid 1px ${this.parent.borderColor}`;
  48. style.borderRight = `solid 1px ${this.parent.borderColor}`;
  49. style.color = this.parent.color;
  50. Object.assign(style, this.parent.tdStyle);
  51. this.tdStyle = style;
  52. }
  53. }
  54. };
  55. </script>
  56. <style lang="scss" scoped>
  57. @import "../../libs/css/style.components.scss";
  58. .u-td {
  59. @include vue-flex;
  60. flex-direction: column;
  61. flex: 1;
  62. justify-content: center;
  63. font-size: 28rpx;
  64. color: $u-content-color;
  65. align-self: stretch;
  66. box-sizing: border-box;
  67. height: 100%;
  68. }
  69. </style>