t-th.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <view
  3. class="t-th"
  4. :style="{
  5. flex: width ? `0 0 ${width}upx` : '1',
  6. 'border-width': thBorder + 'upx',
  7. 'border-color': borderColor,
  8. 'font-size': fontSize + 'upx',
  9. 'justify-content': thAlignCpd
  10. }"
  11. >
  12. <slot></slot>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. props: {
  18. align: String,
  19. width: {
  20. type: Number | null,
  21. default: null
  22. }
  23. },
  24. data() {
  25. return {
  26. thBorder: "1",
  27. borderColor: "#d0dee5",
  28. fontSize: "24",
  29. thAlign: "center"
  30. };
  31. },
  32. inject: ["table", "tr"],
  33. created() {
  34. this.thBorder = this.table.border;
  35. this.borderColor = this.table.borderColor;
  36. this.fontSize = this.tr.fontSize;
  37. this.color = this.tr.color;
  38. if (this.align) {
  39. this.thAlign = this.align;
  40. } else {
  41. this.thAlign = this.tr.align;
  42. }
  43. },
  44. computed: {
  45. thAlignCpd() {
  46. let nameAlign = "";
  47. switch (this.thAlign) {
  48. case "left":
  49. nameAlign = "flex-start";
  50. break;
  51. case "center":
  52. nameAlign = "center";
  53. break;
  54. case "right":
  55. nameAlign = "flex-end";
  56. break;
  57. default:
  58. nameAlign = "center";
  59. break;
  60. }
  61. return nameAlign;
  62. }
  63. }
  64. };
  65. </script>
  66. <style>
  67. .t-th {
  68. flex: 1;
  69. display: flex;
  70. flex-shrink: 0;
  71. margin: 0 10upx;
  72. align-items: center;
  73. font-size: 24upx;
  74. font-weight: bold;
  75. text-align: center;
  76. color: #999;
  77. white-space: nowrap;
  78. /* border-left: 1upx #d0dee5 solid;
  79. border-top: 1upx #d0dee5 solid; */
  80. }
  81. </style>