@zscreate/zhxy-app-component 1.0.164 → 1.0.166
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="wrap" :style="{ height: widget.options.height * 1.5 + 'rpx' }" v-if="dataModel && dataModel.length > 0">
|
|
3
|
+
<!-- @scrolltolower:滚动到底部触发 lower-threshold:距离底部多少距离触发@scrolltolower -->
|
|
4
|
+
<scroll-view class="scroll-view_H" scroll-x="true" scroll-y="true" @scrolltolower='scrollBottom' :lower-threshold='0'>
|
|
5
|
+
<view class="top" id="top" :style="{ width: tableWidths + 'rpx', 'padding-left': '0rpx' }">
|
|
6
|
+
<view class="table-header">
|
|
7
|
+
<view v-for="(h, n) in header" :key='n' :class="{ 'header_dyg': true, 'flexs': h.flxe, }"
|
|
8
|
+
:style="{ width: h.hWidth + 'rpx' }">
|
|
9
|
+
<view v-if="h.columnName !== 'slot'">{{ h.columnName }}</view>
|
|
10
|
+
<view v-else>
|
|
11
|
+
<u-checkbox-group>
|
|
12
|
+
<u-checkbox @change="checkboxChangeAll" v-model="checkedAll" name="all"></u-checkbox>
|
|
13
|
+
</u-checkbox-group>
|
|
14
|
+
</view>
|
|
15
|
+
</view>
|
|
16
|
+
</view>
|
|
17
|
+
</view>
|
|
18
|
+
<view class="bottom" :style="{ maxHeight: (widget.options.height - 70) * 1.5 + 'rpx', width: tableWidths + 'rpx', 'padding-left': '0rpx' }"
|
|
19
|
+
v-if="tableData.length > 0">
|
|
20
|
+
<view class="tablebox" v-for="(t, s) in tableData" :key='s' @click="jumpDetailed(t)">
|
|
21
|
+
<view v-for="(h, n) in header" :key="n"
|
|
22
|
+
:class="{ 'table_dyg': true, 'tdColClass': h.bgcolor, 'tdRowClass': t.bgcolor, 'flexs': h.flxe, }"
|
|
23
|
+
:style="{ width: h.hWidth + 'rpx' }">
|
|
24
|
+
<!-- 不等于操作列就显示文字 -->
|
|
25
|
+
<text v-if="h.columnCode !== 'action' && h.columnName !== 'slot'" :style="{ color: getColor(t, h), }">{{
|
|
26
|
+
t[h.columnCode] }}</text>
|
|
27
|
+
<view v-else-if="h.columnName === 'slot'">
|
|
28
|
+
<u-checkbox-group>
|
|
29
|
+
<u-checkbox @change="checkboxChange" v-model="t.checked" :name="t[rowKey]"></u-checkbox>
|
|
30
|
+
</u-checkbox-group>
|
|
31
|
+
</view>
|
|
32
|
+
<!-- 操作列显示按钮,后期用插槽 -->
|
|
33
|
+
<view class="uni-group" v-else style="background-color: #fff;">
|
|
34
|
+
<button class="uni-button" size="mini" type="primary" style="margin-right: 5px;"
|
|
35
|
+
@click="editTable(t)">编辑</button>
|
|
36
|
+
<button class="uni-button" size="mini" type="warn" @click="deleteTable(t)">删除</button>
|
|
37
|
+
</view>
|
|
38
|
+
</view>
|
|
39
|
+
</view>
|
|
40
|
+
</view>
|
|
41
|
+
</scroll-view>
|
|
42
|
+
<view class="empty" v-if="tableData.length == 0">
|
|
43
|
+
<!-- <image src="../../static/images/empty.png" style="width: 90vw;height: 400rpx;margin: 50rpx 20rpx;" /> -->
|
|
44
|
+
<view class="empty-text" style="text-align: center;width: 100%;">暂无数据</view>
|
|
45
|
+
</view>
|
|
46
|
+
</view>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
// 表头配置:flxe(固定列),bgcolor(列底纹)
|
|
51
|
+
// 表体配置:bgcolor(行底纹)
|
|
52
|
+
export default {
|
|
53
|
+
props: {
|
|
54
|
+
dataModel: {
|
|
55
|
+
type: [Array, String],
|
|
56
|
+
required: true,
|
|
57
|
+
default: function () {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
widget: {
|
|
62
|
+
type: Object,
|
|
63
|
+
required: true,
|
|
64
|
+
default: function () {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
data() {
|
|
70
|
+
return {
|
|
71
|
+
//表体
|
|
72
|
+
tableData: [],
|
|
73
|
+
//表头
|
|
74
|
+
header: [],
|
|
75
|
+
// 表格总长度
|
|
76
|
+
tableWidths: 0,
|
|
77
|
+
// 全选
|
|
78
|
+
checkedAll: false,
|
|
79
|
+
flxed: false,
|
|
80
|
+
isAll: false,
|
|
81
|
+
seletedData: []
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
watch: {
|
|
85
|
+
// 监听列表
|
|
86
|
+
dataModel: {
|
|
87
|
+
async handler(a, b) {
|
|
88
|
+
console.log(a, b);
|
|
89
|
+
if(a && a.length > 0) {
|
|
90
|
+
await this.getColumsList(this.widget.options.defaultSQL.querySql)
|
|
91
|
+
this.tableData = a
|
|
92
|
+
if (!this.header.some(item => item.hWidth)) this.tableWidth()
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
deep: true
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
created() {
|
|
99
|
+
},
|
|
100
|
+
methods: {
|
|
101
|
+
// 获取表头
|
|
102
|
+
getColumsList(id) {
|
|
103
|
+
this.$u.get('/dataset/getDatasetColumns', { id }).then(res => {
|
|
104
|
+
if (!res.success) return
|
|
105
|
+
this.header = res.result ? res.result : []
|
|
106
|
+
if (!this.header.some(item => item.hWidth)) this.tableWidth()
|
|
107
|
+
})
|
|
108
|
+
},
|
|
109
|
+
// 重置复选框
|
|
110
|
+
reseChecked() {
|
|
111
|
+
let obj = this.tableData[0]
|
|
112
|
+
obj.checked = false
|
|
113
|
+
this.$set(this.tableData, 0, obj);
|
|
114
|
+
this.checkedAll = false
|
|
115
|
+
this.$emit('isSelectAll', false);
|
|
116
|
+
},
|
|
117
|
+
// 单选
|
|
118
|
+
checkboxChange(e) {
|
|
119
|
+
let idx = this.tableData.findIndex(item => item[this.rowKey] === e.name)
|
|
120
|
+
let obj = this.tableData[idx]
|
|
121
|
+
obj.checked = e.value
|
|
122
|
+
this.$set(this.tableData, idx, obj)
|
|
123
|
+
if (!e.value && !this.tableData.every(item => item.checked)) this.checkedAll = false
|
|
124
|
+
if (e.value && this.tableData.every(item => item.checked)) this.checkedAll = true
|
|
125
|
+
},
|
|
126
|
+
// 全选
|
|
127
|
+
checkboxChangeAll(e) {
|
|
128
|
+
if (e.value) {
|
|
129
|
+
this.tableData.forEach(item => item.checked = true)
|
|
130
|
+
this.$emit('isSelectAll', true);
|
|
131
|
+
} else {
|
|
132
|
+
this.tableData.forEach(item => item.checked = false)
|
|
133
|
+
this.$emit('isSelectAll', false);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
// 返回行数据
|
|
137
|
+
jumpDetailed(row) {
|
|
138
|
+
this.$emit('rowData', row)
|
|
139
|
+
},
|
|
140
|
+
// 颜色对比
|
|
141
|
+
getColor(row, col) {
|
|
142
|
+
let color = 'black'
|
|
143
|
+
// 传值给父组件,通过父组件的方法内计算判断当前单元格数据是否需要标红,然后通过回调函数,返回一个color值来渲染
|
|
144
|
+
this.$emit('getTextColor', row, col, val => {
|
|
145
|
+
color = val
|
|
146
|
+
})
|
|
147
|
+
return color
|
|
148
|
+
},
|
|
149
|
+
// 修改按钮
|
|
150
|
+
editTable(val) {
|
|
151
|
+
this.$emit('getEdit', val)
|
|
152
|
+
},
|
|
153
|
+
// 删除按钮
|
|
154
|
+
deleteTable(val) {
|
|
155
|
+
this.$emit('getDelete', val)
|
|
156
|
+
},
|
|
157
|
+
// 计算单元格宽度
|
|
158
|
+
tableWidth() {
|
|
159
|
+
let w = 0
|
|
160
|
+
this.header.forEach((item, index) => {
|
|
161
|
+
item['hWidth'] = this.replaceSpecialCharacters(item.columnName) * 40
|
|
162
|
+
if (this.tableData.length > 0) {
|
|
163
|
+
this.tableData.forEach((info, index) => {
|
|
164
|
+
if (info[item.columnCode] && info[item.columnCode].length > item.columnName.length) {
|
|
165
|
+
item['hWidth'] = this.replaceSpecialCharacters(info[item.columnCode]) * 40
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
w += item['hWidth'] //叠加表格总长度
|
|
170
|
+
})
|
|
171
|
+
this.tableWidths = w //给表格赋值总长度
|
|
172
|
+
console.log(this.header);
|
|
173
|
+
},
|
|
174
|
+
// 替换特殊字符
|
|
175
|
+
replaceSpecialCharacters(str) {
|
|
176
|
+
let chineseCount = 0;
|
|
177
|
+
let englishCount = 0;
|
|
178
|
+
let digitCount = 0;
|
|
179
|
+
for (let i = 0; i < str.length; i++) {
|
|
180
|
+
const char = str[i];
|
|
181
|
+
if (this.isChineseCharacter(char)) {
|
|
182
|
+
chineseCount++;
|
|
183
|
+
} else if (this.isEnglishCharacter(char)) {
|
|
184
|
+
englishCount++;
|
|
185
|
+
} else if (this.isDigit(char)) {
|
|
186
|
+
digitCount++;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return chineseCount + ((englishCount + digitCount) * 0.5)
|
|
190
|
+
},
|
|
191
|
+
isChineseCharacter(char) {
|
|
192
|
+
// 使用 Unicode 范围判断是否为中文字符
|
|
193
|
+
return /^[\u4e00-\u9fff]$/.test(char);
|
|
194
|
+
},
|
|
195
|
+
isEnglishCharacter(char) {
|
|
196
|
+
// 使用正则表达式判断是否为英文字符
|
|
197
|
+
return /^[a-zA-Z]$/.test(char);
|
|
198
|
+
},
|
|
199
|
+
isDigit(char) {
|
|
200
|
+
// 使用正则表达式判断是否为数字字符
|
|
201
|
+
return /^[0-9]$/.test(char);
|
|
202
|
+
},
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
</script>
|
|
206
|
+
|
|
207
|
+
<style lang="less" scoped>
|
|
208
|
+
/deep/ .u-checkbox__label {
|
|
209
|
+
display: none !important;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/deep/ .uni-scroll-view-content {
|
|
213
|
+
overflow-x: scroll;
|
|
214
|
+
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.wrap {
|
|
218
|
+
width: 100%;
|
|
219
|
+
|
|
220
|
+
.empty {
|
|
221
|
+
// margin: 200rpx 50rpx;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// 表头
|
|
226
|
+
.top {
|
|
227
|
+
position: sticky; //表头向上滚动时固定住
|
|
228
|
+
top: 0;
|
|
229
|
+
//width: 750px; //左右滚动时不会把固定的表头滚动走
|
|
230
|
+
z-index: 100; //滑动时表头不被覆盖
|
|
231
|
+
|
|
232
|
+
.table-header {
|
|
233
|
+
display: flex;
|
|
234
|
+
overflow: visible;
|
|
235
|
+
|
|
236
|
+
.flxed {
|
|
237
|
+
// position: fixed;
|
|
238
|
+
position: sticky;
|
|
239
|
+
// top: 0;
|
|
240
|
+
left: 0;
|
|
241
|
+
border-left: 1px solid #ccc;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// .header_dyg:nth-child(2) {
|
|
245
|
+
// padding-left: 90rpx;
|
|
246
|
+
// }
|
|
247
|
+
.header_dyg:first-child {
|
|
248
|
+
border-left: 1px solid #ccc;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.header_dyg {
|
|
252
|
+
height: 40px;
|
|
253
|
+
text-align: center;
|
|
254
|
+
line-height: 40px;
|
|
255
|
+
border-top: 1px solid #ccc;
|
|
256
|
+
border-right: 1px solid #ccc;
|
|
257
|
+
border-bottom: 1px solid #ccc;
|
|
258
|
+
padding: 0 5px;
|
|
259
|
+
background-color: #f5f5f6;
|
|
260
|
+
white-space: nowrap;
|
|
261
|
+
overflow: hidden;
|
|
262
|
+
text-overflow: ellipsis;
|
|
263
|
+
font-size: 14px;
|
|
264
|
+
font-weight: bold;
|
|
265
|
+
color: #2b2b2b;
|
|
266
|
+
flex-shrink: 0;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// 列定位固定单元格
|
|
270
|
+
.flexs {
|
|
271
|
+
position: absolute;
|
|
272
|
+
left: 0;
|
|
273
|
+
background-color: #f5f5f6;
|
|
274
|
+
z-index: 10;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
// 表格列表
|
|
283
|
+
.bottom {
|
|
284
|
+
// overflow-y: scroll;
|
|
285
|
+
// padding-left: 77rpx;
|
|
286
|
+
|
|
287
|
+
.tablebox {
|
|
288
|
+
display: flex;
|
|
289
|
+
font-size: 14px;
|
|
290
|
+
overflow: visible;
|
|
291
|
+
|
|
292
|
+
.flxed {
|
|
293
|
+
position: sticky;
|
|
294
|
+
left: 0;
|
|
295
|
+
border-left: 1px solid #ccc;
|
|
296
|
+
background-color: #fff;
|
|
297
|
+
}
|
|
298
|
+
.table_dyg:first-child {
|
|
299
|
+
border-left: 1px solid #ccc;
|
|
300
|
+
}
|
|
301
|
+
.table_dyg {
|
|
302
|
+
height: 30px;
|
|
303
|
+
text-align: center;
|
|
304
|
+
line-height: 30px;
|
|
305
|
+
white-space: nowrap;
|
|
306
|
+
overflow: hidden;
|
|
307
|
+
text-overflow: ellipsis;
|
|
308
|
+
border-right: 1px solid #ccc;
|
|
309
|
+
border-bottom: 1px solid #ccc;
|
|
310
|
+
padding: 0 5px;
|
|
311
|
+
flex-shrink: 0;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// 列定位固定单元格
|
|
315
|
+
.flexs {
|
|
316
|
+
position: absolute;
|
|
317
|
+
left: 0;
|
|
318
|
+
background-color: #fff;
|
|
319
|
+
z-index: 10;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// 列的颜色
|
|
325
|
+
.tdColClass {
|
|
326
|
+
background-color: #d9edf7;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// 行的颜色
|
|
330
|
+
.tdRowClass {
|
|
331
|
+
background-color: #afdfe4;
|
|
332
|
+
}
|
|
333
|
+
</style>
|
|
334
|
+
|
|
335
|
+
|