u-table.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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://ijry.github.io/uview-plus/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. tableStyle() {
  82. let style = {};
  83. style.borderLeft = `solid 1px ${this.borderColor}`;
  84. style.borderTop = `solid 1px ${this.borderColor}`;
  85. style.backgroundColor = this.bgColor;;
  86. return style;
  87. }
  88. },
  89. methods: {
  90. change() {
  91. this.show = false;
  92. this.$nextTick(() => {
  93. this.show = true;
  94. });
  95. // this.$forceUpdate();
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. </style>