t-tr.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view
  3. :class="['t-tr', { header: header }]"
  4. :style="{
  5. backgroundColor: backgroundColor
  6. }"
  7. >
  8. <view
  9. v-if="isCheck"
  10. class="t-check-box"
  11. :style="{ 'border-width': thBorder + 'px', 'border-color': borderColor }"
  12. >
  13. <checkbox-group @change="checkboxChange">
  14. <checkbox
  15. :value="checkboxData.value + ''"
  16. :checked="checkboxData.checked"
  17. />
  18. </checkbox-group>
  19. </view>
  20. <slot></slot>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. props: {
  26. header: Boolean,
  27. fontSize: String,
  28. color: String,
  29. align: String
  30. },
  31. inject: ["table"],
  32. provide() {
  33. return {
  34. tr: this
  35. };
  36. },
  37. data() {
  38. return {
  39. isCheck: false,
  40. checkboxData: {
  41. value: 0,
  42. checked: false
  43. },
  44. checked: false,
  45. thBorder: "1",
  46. borderColor: "#eeeeee",
  47. backgroundColor: "#ffffff"
  48. };
  49. },
  50. created() {
  51. this.thBorder = this.table.border;
  52. this.borderColor = this.table.borderColor;
  53. this.table.childrens.push(this);
  54. this.checkboxData.value = this.table.index++;
  55. this.isCheck = this.table.isCheck;
  56. if (this.header && this.table.headerBackgroundColor) {
  57. this.backgroundColor = this.table.headerBackgroundColor;
  58. }
  59. },
  60. methods: {
  61. checkboxChange(e) {
  62. this.checkboxData.checked = !this.checkboxData.checked;
  63. this.table.childrens[this.checkboxData.value] = this;
  64. this.table.fire(
  65. e.detail.value[0] ? true : false,
  66. this.checkboxData.value,
  67. this.table.index
  68. );
  69. }
  70. }
  71. };
  72. </script>
  73. <style lang="scss">
  74. .t-tr {
  75. width: 100%;
  76. display: flex;
  77. align-items: center;
  78. padding: 20upx 30upx;
  79. border-bottom: 1upx solid #eeeeee;
  80. &.header {
  81. box-shadow: 0upx 1upx 0upx 0upx #eeeeee;
  82. }
  83. }
  84. .t-tr t-th,
  85. .t-tr t-td {
  86. display: flex;
  87. flex: 1;
  88. }
  89. .t-tr .t-check-box {
  90. flex-shrink: 0;
  91. display: flex;
  92. justify-content: center;
  93. align-items: center;
  94. width: 80upx;
  95. color: #3b4246;
  96. border-left: 1upx #d0dee5 solid;
  97. border-top: 1upx #d0dee5 solid;
  98. }
  99. .t-tr .t-check-box checkbox {
  100. transform: scale(0.8);
  101. }
  102. </style>