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
| <template>
| <view class="tn-tr-class tn-tr" :class="[trClass]" :style="[trStyle]">
| <slot></slot>
| </view>
| </template>
|
| <script>
| import componentsColorMixin from '../../libs/mixin/components_color.js'
| export default {
| name: 'tn-tr',
| options: {
| // 在微信小程序中将组件节点渲染为虚拟节点,更加接近Vue组件的表现(不会出现shadow节点下再去创建元素)
| virtualHost: true
| },
| mixins: [componentsColorMixin],
| props: {
| // 宽度
| width: {
| type: [String, Number],
| default: ''
| },
| // 边框颜色
| borderColor: {
| type: String,
| default: ''
| },
| // 边框宽度
| borderWidth: {
| type: [String, Number],
| default: ''
| },
| // 左边框
| borderLeft: {
| type: Boolean,
| default: false
| },
| // 上边框
| borderTop: {
| type: Boolean,
| default: false
| },
| // 换行显示
| wrap: {
| type: Boolean,
| default: false
| },
| // 固定表格
| fixed: {
| type: Boolean,
| default: false
| },
| // left偏移值
| left: {
| type: [String, Number],
| default: 0
| },
| // right偏移值
| right: {
| type: [String, Number],
| default: 0
| },
| // top偏移值(自定义顶部导航栏时用到)
| top: {
| type: [String, Number],
| default: 0
| },
| // 外边距
| margin: {
| type: String,
| default: ''
| },
| // zIndex
| zIndex: {
| type: Number,
| default: 0
| },
| // 行数索引
| index: {
| type: [String, Number],
| default: 0
| },
| // 参数
| params: {
| type: String,
| default: ''
| }
| },
| computed: {
| borderWidthValue() {
| return this.borderWidth || this.parentData.borderWidth || ''
| },
| borderColorValue() {
| return this.borderColor || this.parentData.borderColor || ''
| },
| trClass() {
| let clazz = ''
| if (this.backgroundColorClass) {
| clazz += ` ${this.backgroundColorClass}`
| }
| if (this.fontColorClass) {
| clazz += ` ${this.fontColorClass}`
| }
| if (this.wrap) {
| clazz += ' tn-tr--wrap'
| }
| if (this.fixed) {
| clazz += ' tn-tr--fixed'
| }
| return clazz
| },
| trStyle() {
| let style = {}
| if (this.width) {
| style.width = this.$t.string.getLengthUnitValue(this.width)
| }
| if (this.backgroundColorStyle) {
| style.backgroundColor = this.backgroundColorStyle
| }
| if (this.fontColorStyle) {
| style.color = this.fontColorStyle
| }
| if (this.fontSizeStyle) {
| style.fontSize = this.fontSizeStyle
| }
| if (this.borderWidth !== '' || this.parentData.borderWidth !== '') {
| style.borderWidth = this.borderWidth !== '' ? this.$t.string.getLengthUnitValue(this.borderWidth) : this.$t.string.getLengthUnitValue(this.parentData.borderWidth)
| }
| if (this.borderColor || this.parentData.borderColor) {
| style.borderColor = this.borderColor || this.parentData.borderColor
| }
| if (this.borderLeft) {
| style.borderLeftStyle = 'solid'
| }
| if (this.borderTop) {
| style.borderTopStyle = 'solid'
| }
| if (this.fixed) {
| style.left = this.left ? this.$t.string.getLengthUnitValue(this.left) : 'auto'
| style.right = this.right ? this.$t.string.getLengthUnitValue(this.right) : 'auto'
| style.top = this.top ? this.$t.string.getLengthUnitValue(this.top) : 'auto'
| }
| if (this.margin) {
| style.margin = this.margin
| }
| style.zIndex = this.zIndex ? this.zIndex : this.$t.zIndex.tableTr
| return style
| }
| },
| data() {
| return {
| parentData: {
| borderColor: null,
| borderWidth: null
| }
| }
| },
| watch: {
| parentData: {
| handler() {
| // 更新子组件的数据
| if (this.children.length) {
| this.children.map((child) => {
| typeof(child.updateParentData) === 'function' && child.updateParentData()
| })
| }
| },
| deep: true
| }
| },
| created() {
| this.children = []
| this.parent = false
| this.updateParentData()
| this.parent && this.parent.children.push(this)
| },
| methods: {
| handleClick() {
| this.$emit('click', {
| index: this.index,
| params: this.params
| })
| },
| // 更新父组件信息
| updateParentData() {
| this.getParentData('tn-table')
| }
| }
| }
| </script>
|
| <style lang="scss" scoped>
| .tn-tr {
| width: 100%;
| display: flex;
| box-sizing: border-box;
| background-color: #FFFFFF;
|
| border-width: 1rpx;
| border-style: none none solid none;
| border-color: #AAAAAA;
|
| &--wrap {
| flex-wrap: wrap;
| }
|
| &--fixed {
| position: fixed;
| }
| }
| </style>
|
|