1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
| <template>
| <view class="tn-td-class tn-td" :class="[tdClass]" :style="[tdStyle]" @tap.stop="handleClick">
| <slot></slot>
| </view>
| </template>
|
| <script>
| import componentsColorMixin from '../../libs/mixin/components_color.js'
| export default {
| name: 'tn-td',
| options: {
| // 在微信小程序中将组件节点渲染为虚拟节点,更加接近Vue组件的表现(不会出现shadow节点下再去创建元素)
| virtualHost: true
| },
| mixins: [componentsColorMixin],
| props: {
| // 占整个表格的宽度跨度
| // [1-24]
| span: {
| type: Number,
| default: 24
| },
| // 宽度
| // 优先级比span高
| width: {
| type: [String, Number],
| default: ''
| },
| // 高度
| height: {
| type: [String, Number],
| default: ''
| },
| // 字体加粗
| bold: {
| type: Boolean,
| default: false
| },
| // 格内边距
| padding: {
| type: String,
| default: ''
| },
| // 边框颜色
| borderColor: {
| type: String,
| default: ''
| },
| // 边框宽度
| borderWidth: {
| type: [String, Number],
| default: ''
| },
| // 左边框
| borderLeft: {
| type: Boolean,
| default: false
| },
| // 下边框
| borderBottom: {
| type: Boolean,
| default: false
| },
| // 右边框
| borderRight: {
| type: Boolean,
| default: true
| },
| // 文字超出隐藏
| ellipsis: {
| type: Boolean,
| default: false
| },
| // 文本对齐方式
| // left center right
| textAlign: {
| type: String,
| default: 'left'
| },
| // 排列方式
| // left center right
| alignItems: {
| type: String,
| default: 'left'
| },
| // 收缩表格
| shrink: {
| type: Boolean,
| default: true
| },
| // 铺满剩余空间
| grow: {
| type: Boolean,
| default: false
| },
| // 隐藏
| hidden: {
| type: Boolean,
| default: false
| },
| // 固定列数据
| fixed: {
| type: Boolean,
| default: false
| },
| // zIndex
| zIndex: {
| type: Number,
| default: 0
| },
| // 列数
| index: {
| type: [String, Number],
| default: 0
| },
| // keys
| keys: {
| type: [String, Number],
| default: ''
| }
| },
| computed: {
| tdClass() {
| let clazz = ''
| clazz += `${this.ellipsis ? 'tn-td--ellipsis' : 'tn-td--normal'}`
| if (this.backgroundColorClass) {
| clazz += ` ${this.backgroundColorClass}`
| }
| if (this.fontColorClass) {
| clazz += ` ${this.fontColorClass}`
| }
| if (this.alignItems) {
| clazz += ` tn-td--${this.alignItems}`
| }
| if (this.textAlign) {
| clazz += ` tn-td__text--${this.textAlign}`
| }
| if (!this.shrink) {
| clazz += ' tn-td--shrink'
| }
| if (this.grow) {
| clazz += ' tn-td--grow'
| }
| if (this.hidden) {
| clazz += ' tn-td--hidden'
| }
| return clazz
| },
| tdStyle() {
| let style = {}
| if (this.backgroundColorStyle) {
| style.backgroundColor = this.backgroundColorStyle
| }
| if (this.fontColorStyle) {
| style.color = this.fontColorStyle
| }
| if (this.fontSizeStyle) {
| style.fontSize = this.fontSizeStyle
| }
| style.width = this.getWidth()
| if (this.height) {
| style.height = this.$t.string.getLengthUnitValue(this.height)
| }
| style.fontWeight = this.bold ? 'bold' : 'normal'
| if (this.padding) {
| style.padding = this.padding
| }
| if (this.borderWidth !== '' || this.parentData.borderWidthValue !== '') {
| style.borderWidth = this.borderWidth !== '' ? this.$t.string.getLengthUnitValue(this.borderWidth) : this.$t.string.getLengthUnitValue(this.parentData.borderWidthValue)
| }
| if (this.borderColor || this.parentData.borderColorValue) {
| style.borderColor = this.borderColor || this.parentData.borderColorValue
| }
| if (this.borderLeft) {
| style.borderLeftStyle = 'solid'
| }
| if (this.borderRight) {
| style.borderRightStyle = 'solid'
| }
| if (this.borderBottom) {
| style.borderBottomStyle = 'solid'
| }
| if (this.fixed) {
| style.zIndex = this.zIndex ? this.zIndex : this.$t.zIndex.tableTd
| }
| return style
| }
| },
| data() {
| return {
| parentData: {
| borderColorValue: null,
| borderWidthValue: null
| }
| }
| },
| created() {
| this.parent = false
| this.updateParentData()
| this.parent && this.parent.children.push(this)
| },
| methods: {
| // 获取表格宽度
| getWidth() {
| if (this.width) {
| return this.$t.string.getLengthUnitValue(this.width)
| }
| return [
| '4.16666667%',
| '8.33333333%',
| '12.5%',
| '16.66666667%',
| '20.83333333%',
| '25%',
| '29.16666667%',
| '33.33333333%',
| '37.5%',
| '41.66666667%',
| '45.83333333%',
| '50%',
| '54.16666667%',
| '58.33333333%',
| '62.5%',
| '66.66666667%',
| '70.83333333%',
| '75%',
| '79.16666667%',
| '83.33333333%',
| '87.5%',
| '91.66666667%',
| '95.83333333%',
| '100%'
| ][this.span - 1]
| },
| // 点击事件
| handleClick() {
| this.$emit('click', {
| index: this.index,
| key: this.keys
| })
| },
| // 更新父组件信息
| updateParentData() {
| this.getParentData('tn-tr')
| }
| }
| }
| </script>
|
| <style lang="scss" scoped>
| .tn-td {
| box-sizing: border-box;
| position: relative;
| word-break: break-all;
| background-color: transparent;
| height: auto;
| padding: 12rpx;
|
| border-width: 1rpx;
| border-style: none;
| border-color: #AAAAAA;
|
| &--normal {
| display: inline-flex;
| align-items: center;
| }
| &--ellipsis {
| display: inline-block;
| overflow: hidden;
| white-space: nowrap !important;
| text-overflow: ellipsis;
| }
|
| &--shrink {
| flex-shrink: 0;
| }
| &--grow {
| flex-grow: 1;
| }
|
| &--left {
| justify-content: flex-start;
| }
| &--center {
| justify-content: center;
| }
| &--right {
| justify-content: flex-end;
| }
|
| &__text {
| &--left {
| text-align: left;
| }
| &--center {
| text-align: center;
| }
| &--right {
| text-align: right;
| }
| }
|
| &--hidden {
| visibility: hidden;
| }
| }
| </style>
|
|