tui-td.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view
  3. class="tui-table__column"
  4. :class="[
  5. ellipsis ? 'tui-column__ellipsis' : 'tui-table__middle',
  6. 'tui-table__' + alignItems,
  7. 'tui-text__' + textAlign,
  8. flexGrow ? 'tui-flex-grow' : '',
  9. shrink ? '' : 'tui-td__shrink',
  10. top ? 'tui-td__upper' : '',
  11. hidden?'tui-td__hidden':''
  12. ]"
  13. :style="{
  14. width: getWidth(span, width),
  15. height: height,
  16. fontSize: size + 'rpx',
  17. color: color,
  18. fontWeight: bold ? 'bold' : 'normal',
  19. backgroundColor: backgroundColor,
  20. borderRight: borderRight ? `${borderWidth} solid ${borderColor}` : '0',
  21. borderBottom: borderBottom ? `${borderWidth} solid ${borderColor}` : '0',
  22. borderLeft: borderLeft ? `${borderWidth} solid ${borderColor}` : '0',
  23. padding: padding
  24. }"
  25. @tap="handleClick"
  26. >
  27. <slot></slot>
  28. </view>
  29. </template>
  30. <script>
  31. //table td
  32. export default {
  33. name: 'tuiTd',
  34. emits: ['click'],
  35. options: {
  36. // 在微信小程序中将组件节点渲染为虚拟节点,更加接近Vue组件的表现
  37. virtualHost: true
  38. },
  39. props: {
  40. //跨度
  41. span: {
  42. type: Number,
  43. default: 24
  44. },
  45. //具体值或者auto
  46. // #ifdef APP-PLUS || MP-WEIXIN || H5 || MP-ALIPAY
  47. width: {
  48. type: String,
  49. default: ''
  50. },
  51. // #endif
  52. // #ifndef APP-PLUS || MP-WEIXIN || H5 || MP-ALIPAY
  53. width: {
  54. type: String,
  55. default: '230rpx'
  56. },
  57. // #endif
  58. height: {
  59. type: String,
  60. default: 'auto'
  61. },
  62. size: {
  63. type: Number,
  64. default: 30
  65. },
  66. color: {
  67. type: String,
  68. default: '#333'
  69. },
  70. bold: {
  71. type: Boolean,
  72. default: false
  73. },
  74. backgroundColor: {
  75. type: String,
  76. default: 'transparent'
  77. },
  78. //border-right width
  79. borderWidth: {
  80. type: String,
  81. default: '1rpx'
  82. },
  83. //边框颜色
  84. borderColor: {
  85. type: String,
  86. default: '#EAEEF5'
  87. },
  88. //是否需要右边框
  89. borderRight: {
  90. type: Boolean,
  91. default: true
  92. },
  93. //是否需要下边框
  94. borderBottom: {
  95. type: Boolean,
  96. default: false
  97. },
  98. //是否需要左边框
  99. borderLeft: {
  100. type: Boolean,
  101. default: false
  102. },
  103. //文字超出隐藏
  104. ellipsis: {
  105. type: Boolean,
  106. default: false
  107. },
  108. padding: {
  109. type: String,
  110. default: '12rpx'
  111. },
  112. //排列:left,center,right
  113. alignItems: {
  114. type: String,
  115. default: 'left'
  116. },
  117. //文本对齐:left,center,right
  118. textAlign: {
  119. type: String,
  120. default: 'left'
  121. },
  122. //是否收缩
  123. shrink: {
  124. type: Boolean,
  125. default: true
  126. },
  127. //铺满剩余空间
  128. flexGrow: {
  129. type: Boolean,
  130. default: false
  131. },
  132. //顶部,上面;
  133. top: {
  134. type: Boolean,
  135. default: false
  136. },
  137. hidden: {
  138. type: Boolean,
  139. default: false
  140. },
  141. //索引
  142. index: {
  143. type: Number,
  144. default: 0
  145. },
  146. //字段key
  147. keys: {
  148. type: String,
  149. default: ''
  150. }
  151. },
  152. data() {
  153. return {};
  154. },
  155. methods: {
  156. getWidth(span, width) {
  157. let w = width;
  158. if (!width) {
  159. w = [
  160. '4.16666667%',
  161. '8.33333333%',
  162. '12.5%',
  163. '16.66666667%',
  164. '20.83333333%',
  165. '25%',
  166. '29.16666667%',
  167. '33.33333333%',
  168. '37.5%',
  169. '41.66666667%',
  170. '45.83333333%',
  171. '50%',
  172. '54.16666667%',
  173. '58.33333333%',
  174. '62.5%',
  175. '66.66666667%',
  176. '70.83333333%',
  177. '75%',
  178. '79.16666667%',
  179. '83.33333333%',
  180. '87.5%',
  181. '91.66666667%',
  182. '95.83333333%',
  183. '100%'
  184. ][span - 1];
  185. }
  186. return w;
  187. },
  188. handleClick() {
  189. this.$emit('click', {
  190. index: this.index,
  191. key: this.keys
  192. });
  193. }
  194. }
  195. };
  196. </script>
  197. <style>
  198. /*栅格 24*/
  199. .tui-table__column {
  200. display: inline-block;
  201. box-sizing: border-box;
  202. position: relative;
  203. word-break: break-all;
  204. }
  205. .tui-td__shrink {
  206. flex-shrink: 0;
  207. }
  208. .tui-flex-grow {
  209. flex-grow: 1;
  210. }
  211. .tui-table__middle {
  212. display: inline-flex;
  213. align-items: center;
  214. }
  215. .tui-table__center {
  216. justify-content: center;
  217. }
  218. .tui-table__right {
  219. justify-content: flex-end;
  220. }
  221. .tui-text__center {
  222. text-align: center;
  223. }
  224. .tui-text__right {
  225. text-align: right;
  226. }
  227. .tui-column__ellipsis {
  228. overflow: hidden;
  229. white-space: nowrap !important;
  230. text-overflow: ellipsis;
  231. }
  232. .tui-td__upper {
  233. z-index: 10;
  234. }
  235. .tui-td__hidden {
  236. visibility: hidden;
  237. }
  238. </style>