Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

120 рядки
3.1 KiB

  1. <template>
  2. <view class="u-table" :style="[tableStyle]">
  3. <template v-if="show">
  4. <slot />
  5. </template>
  6. </view>
  7. </template>
  8. <script>
  9. import { props } from './props';
  10. import { mpMixin } from '../../libs/mixin/mpMixin';
  11. import { mixin } from '../../libs/mixin/mixin';
  12. /**
  13. * Table 表格
  14. * @description 表格组件一般用于展示大量结构化数据的场景 本组件标签类似HTML的table表格,由table、tr、th、td四个组件组成
  15. * @tutorial https://uview-plus.jiangruyi.com/components/table.html
  16. * @property {String} border-color 表格边框的颜色(默认#e4e7ed)
  17. * @property {String} bg-color 表格的背景颜色(默认#ffffff)
  18. * @property {String} align 单元格的内容对齐方式,作用类似css的text-align(默认center)
  19. * @property {String} padding 单元格的内边距,同css的padding写法(默认10rpx 0)
  20. * @property {String Number} font-size 单元格字体大小,单位rpx(默认28)
  21. * @property {String} color 单元格字体颜色(默认#606266)
  22. * @property {Object} th-style th单元格的样式,对象形式(将th所需参数放在table组件,是为了避免每一个th组件要写一遍)
  23. * @event {Function} click 点击组件时触发
  24. * @event {Function} close 点击关闭按钮时触发
  25. * @example <u-table><u-tr><u-th>学校</u-th </u-tr> <u-tr><u-td>浙江大学</u-td> </u-tr> <u-tr><u-td>清华大学</u-td> </u-tr></u-table>
  26. */
  27. export default {
  28. name: 'u-table',
  29. mixins: [mpMixin, mixin, props],
  30. props: {
  31. borderColor: {
  32. type: String,
  33. default: '#e4e7ed'
  34. },
  35. align: {
  36. type: String,
  37. default: 'center'
  38. },
  39. // td的内边距
  40. padding: {
  41. type: String,
  42. default: '5px 3px'
  43. },
  44. // 字体大小
  45. fontSize: {
  46. type: [String],
  47. default: '14px'
  48. },
  49. // 字体颜色
  50. color: {
  51. type: String,
  52. default: '#606266'
  53. },
  54. // th的自定义样式
  55. thStyle: {
  56. type: Object,
  57. default () {
  58. return {}
  59. }
  60. },
  61. // table的背景颜色
  62. bgColor: {
  63. type: String,
  64. default: '#ffffff'
  65. }
  66. },
  67. data() {
  68. return {
  69. show: true
  70. }
  71. },
  72. watch: {
  73. align() {
  74. this.change();
  75. },
  76. borderColor() {
  77. this.change();
  78. }
  79. },
  80. computed: {
  81. resolvedBorderColor() {
  82. return this.borderColor === '#e4e7ed'
  83. ? this.upThemeVar('--up-border-color', '#e4e7ed')
  84. : this.borderColor
  85. },
  86. resolvedColor() {
  87. return this.color === '#606266'
  88. ? this.upThemeVar('--up-content-color', '#606266')
  89. : this.color
  90. },
  91. resolvedBgColor() {
  92. return this.bgColor === '#ffffff'
  93. ? this.upThemeVar('--up-card-bg-color', '#ffffff')
  94. : this.bgColor
  95. },
  96. tableStyle() {
  97. let style = {};
  98. style.borderLeft = `solid 1px ${this.resolvedBorderColor}`;
  99. style.borderTop = `solid 1px ${this.resolvedBorderColor}`;
  100. style.backgroundColor = this.resolvedBgColor;
  101. return style;
  102. }
  103. },
  104. methods: {
  105. change() {
  106. this.show = false;
  107. this.$nextTick(() => {
  108. this.show = true;
  109. });
  110. // this.$forceUpdate();
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. </style>