1
0

u-table.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="u-table" :style="[tableStyle]">
  3. <slot />
  4. </view>
  5. </template>
  6. <script>
  7. /**
  8. * table 表格
  9. * @description 表格组件一般用于展示大量结构化数据的场景
  10. * @tutorial https://www.uviewui.com/components/table.html
  11. * @property {String} border-color 表格边框的颜色(默认#e4e7ed)
  12. * @property {String} bg-color 表格的背景颜色(默认#ffffff)
  13. * @property {String} align 单元格的内容对齐方式,作用类似css的text-align(默认center)
  14. * @property {String} padding 单元格的内边距,同css的padding写法(默认10rpx 0)
  15. * @property {String Number} font-size 单元格字体大小,单位rpx(默认28)
  16. * @property {String} color 单元格字体颜色(默认#606266)
  17. * @property {Object} th-style th单元格的样式,对象形式(将th所需参数放在table组件,是为了避免每一个th组件要写一遍)
  18. * @event {Function} click 点击组件时触发
  19. * @event {Function} close 点击关闭按钮时触发
  20. * @example <u-table></u-table>
  21. */
  22. export default {
  23. name: "u-table",
  24. emits: ["click", "close"],
  25. props: {
  26. borderColor: {
  27. type: String,
  28. default: '#e4e7ed'
  29. },
  30. align: {
  31. type: String,
  32. default: 'center'
  33. },
  34. // td的内边距
  35. padding: {
  36. type: String,
  37. default: '10rpx 6rpx'
  38. },
  39. // 字体大小
  40. fontSize: {
  41. type: [String, Number],
  42. default: 28
  43. },
  44. // 字体颜色
  45. color: {
  46. type: String,
  47. default: '#606266'
  48. },
  49. // th的自定义样式
  50. thStyle: {
  51. type: Object,
  52. default () {
  53. return {}
  54. }
  55. },
  56. // td的自定义样式
  57. tdStyle: {
  58. type: Object,
  59. default () {
  60. return {}
  61. }
  62. },
  63. // table的背景颜色
  64. bgColor: {
  65. type: String,
  66. default: '#ffffff'
  67. }
  68. },
  69. data() {
  70. return {}
  71. },
  72. computed: {
  73. tableStyle() {
  74. let style = {};
  75. style.borderLeft = `solid 1px ${this.borderColor}`;
  76. style.borderTop = `solid 1px ${this.borderColor}`;
  77. style.backgroundColor = this.bgColor;;
  78. return style;
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. @import "../../libs/css/style.components.scss";
  85. .u-table {
  86. width: 100%;
  87. box-sizing: border-box;
  88. }
  89. </style>