|
1
|
<!-- JEditableTable -->
|
|
2
|
<!-- @version 1.5.0 -->
|
|
3
4
5
6
|
<!-- @author sjlei -->
<template>
<a-spin :spinning="loading">
|
|
7
8
9
10
11
12
13
14
|
<a-row type="flex">
<a-col>
<slot name="buttonBefore" :target="getVM()"/>
</a-col>
<a-col>
<!-- 操作按钮 -->
<div v-if="actionButton" class="action-button">
<a-button type="primary" icon="plus" @click="handleClickAdd">新增</a-button>
|
|
15
|
<span class="gap"></span>
|
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<template v-if="selectedRowIds.length>0">
<a-popconfirm
:title="`确定要删除这 ${selectedRowIds.length} 项吗?`"
@confirm="handleConfirmDelete">
<a-button type="primary" icon="minus">删除</a-button>
<span class="gap"></span>
</a-popconfirm>
<template v-if="showClearSelectButton">
<a-button icon="delete" @click="handleClickClearSelection">清空选择</a-button>
<span class="gap"></span>
</template>
</template>
</div>
</a-col>
<a-col>
<slot name="buttonAfter" :target="getVM()"/>
</a-col>
</a-row>
|
|
34
35
36
|
<div :id="`${caseId}inputTable`" class="input-table">
<!-- 渲染表头 -->
|
|
37
38
|
<div class="thead" ref="thead">
<div class="tr" :style="{width: this.realTrWidth}">
|
|
39
|
<!-- 左侧固定td -->
|
|
40
41
42
|
<div v-if="dragSort" class="td td-ds" :style="style.tdLeftDs">
<span></span>
</div>
|
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
<div v-if="rowSelection" class="td td-cb" :style="style.tdLeft">
<!--:indeterminate="true"-->
<a-checkbox
:checked="getSelectAll"
:indeterminate="getSelectIndeterminate"
@change="handleChangeCheckedAll"
/>
</div>
<div v-if="rowNumber" class="td td-num" :style="style.tdLeft">
<span>#</span>
</div>
<!-- 右侧动态生成td -->
<template v-for="col in columns">
<div
|
|
57
|
v-show="col.type !== formTypes.hidden"
|
|
58
59
60
61
62
63
64
65
66
67
|
class="td"
:key="col.key"
:style="buildTdStyle(col)">
<span>{{ col.title }}</span>
</div>
</template>
</div>
</div>
|
|
68
|
<div class="scroll-view" ref="scrollView" :style="{'max-height':maxHeight+'px'}">
|
|
69
70
|
|
|
71
72
73
74
75
76
77
78
|
<!-- 渲染主体 body -->
<div :id="`${caseId}tbody`" class="tbody" :style="tbodyStyle">
<!-- 扩展高度 -->
<div class="tr-expand" :style="`height:${getExpandHeight}px; z-index:${loading?'11':'9'};`"></div>
<!-- 无数据时显示 -->
<div v-if="rows.length===0" class="tr-nodata">
<span>暂无数据</span>
</div>
|
|
79
80
|
<!-- v-model="rows"-->
<draggable :value="rows" handle=".td-ds-icons" @end="handleDragMoveEnd">
|
|
81
82
83
84
85
86
|
<!-- 动态生成tr -->
<template v-for="(row,rowIndex) in rows">
<!-- tr 只加载可见的和预加载的总共十条数据 -->
<div
v-if="
|
|
87
88
89
|
rowIndex >= parseInt(`${(scrollTop-rowHeight) / rowHeight}`) &&
(parseInt(`${scrollTop / rowHeight}`) + 9) > rowIndex
"
|
|
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
:id="`${caseId}tbody-tr-${rowIndex}`"
:data-idx="rowIndex"
class="tr"
:class="selectedRowIds.indexOf(row.id) !== -1 ? 'tr-checked' : ''"
:style="buildTrStyle(rowIndex)"
:key="row.id">
<!-- 左侧固定td -->
<div v-if="dragSort" class="td td-ds" :style="style.tdLeftDs">
<div class="td-ds-icons">
<a-icon type="align-left"/>
<a-icon type="align-right"/>
</div>
</div>
|
|
104
|
|
|
105
106
107
|
<div v-if="rowSelection" class="td td-cb" :style="style.tdLeft">
<!-- 此 v-for 只是为了拼接 id 字符串 -->
<template v-for="(id,i) in [`${row.id}`]">
|
|
108
109
110
|
<a-checkbox
:id="id"
:key="i"
|
|
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
|
:checked="selectedRowIds.indexOf(id) !== -1"
@change="handleChangeLeftCheckbox"/>
</template>
</div>
<div v-if="rowNumber" class="td td-num" :style="style.tdLeft">
<span>{{ rowIndex+1 }}</span>
</div>
<!-- 右侧动态生成td -->
<div
class="td"
v-for="col in columns"
v-show="col.type !== formTypes.hidden"
:key="col.key"
:style="buildTdStyle(col)">
<!-- 此 v-for 只是为了拼接 id 字符串 -->
<template v-for="(id,i) in [`${col.key}${row.id}`]">
<!-- native input -->
<label :key="i" v-if="col.type === formTypes.input || col.type === formTypes.inputNumber">
<a-tooltip
:id="id"
placement="top"
:title="(tooltips[id] || {}).title"
:visible="(tooltips[id] || {}).visible || false"
:autoAdjustOverflow="true">
<input
:id="id"
v-bind="buildProps(row,col)"
:data-input-number="col.type === formTypes.inputNumber"
:placeholder="replaceProps(col, col.placeholder)"
|
|
143
|
@blur="(e)=>{handleBlurCommono(e.target,rowIndex,row,col)}"
|
|
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
|
@input="(e)=>{handleInputCommono(e.target,rowIndex,row,col)}"
@mouseover="()=>{handleMouseoverCommono(row,col)}"
@mouseout="()=>{handleMouseoutCommono(row,col)}"/>
</a-tooltip>
</label>
<!-- checkbox -->
<template v-else-if="col.type === formTypes.checkbox">
<a-checkbox
:key="i"
:id="id"
v-bind="buildProps(row,col)"
:checked="checkboxValues[id]"
@change="(e)=>handleChangeCheckboxCommon(e,row,col)"
/>
</template>
<!-- select -->
<template v-else-if="col.type === formTypes.select">
<a-tooltip
:key="i"
:id="id"
placement="top"
:title="(tooltips[id] || {}).title"
:visible="(tooltips[id] || {}).visible || false"
:autoAdjustOverflow="true">
|
|
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
<span
@mouseover="()=>{handleMouseoverCommono(row,col)}"
@mouseout="()=>{handleMouseoutCommono(row,col)}">
<a-select
:id="id"
:key="i"
v-bind="buildProps(row,col)"
style="width: 100%;"
:value="selectValues[id]"
:options="col.options"
:getPopupContainer="getParentContainer"
:placeholder="replaceProps(col, col.placeholder)"
|
|
184
|
:filterOption="(i,o)=>handleSelectFilterOption(i,o,col)"
|
|
185
186
187
188
|
@change="(v)=>handleChangeSelectCommon(v,id,row,col)"
@search="(v)=>handleSearchSelect(v,id,row,col)"
@blur="(v)=>handleBlurSearch(v,id,row,col)"
>
|
|
189
190
191
192
193
194
|
<!--<template v-for="(opt,optKey) in col.options">-->
<!--<a-select-option :value="opt.value" :key="optKey">{{ opt.title }}</a-select-option>-->
<!--</template>-->
</a-select>
</span>
|
|
195
196
197
198
199
200
201
202
203
204
205
|
</a-tooltip>
</template>
<!-- date -->
<template v-else-if="col.type === formTypes.date || col.type === formTypes.datetime">
<a-tooltip
:key="i"
:id="id"
placement="top"
:title="(tooltips[id] || {}).title"
:visible="(tooltips[id] || {}).visible || false"
:autoAdjustOverflow="true">
|
|
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
<span
@mouseover="()=>{handleMouseoverCommono(row,col)}"
@mouseout="()=>{handleMouseoutCommono(row,col)}">
<j-date
:id="id"
:key="i"
v-bind="buildProps(row,col)"
style="width: 100%;"
:value="jdateValues[id]"
:getCalendarContainer="getParentContainer"
:placeholder="replaceProps(col, col.placeholder)"
:trigger-change="true"
:showTime="col.type === formTypes.datetime"
:dateFormat="col.type === formTypes.date? 'YYYY-MM-DD':'YYYY-MM-DD HH:mm:ss'"
@change="(v)=>handleChangeJDateCommon(v,id,row,col,col.type === formTypes.datetime)"/>
</span>
|
|
225
|
</a-tooltip>
|
|
226
|
</template>
|
|
227
|
|
|
228
229
230
231
232
233
234
|
<div v-else-if="col.type === formTypes.upload" :key="i">
<template v-if="uploadValues[id] != null" v-for="(file,fileKey) of [(uploadValues[id]||{})]">
<a-input
:key="fileKey"
:readOnly="true"
:value="file.name"
>
|
|
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
|
<template slot="addonBefore" style="width: 30px">
<a-tooltip v-if="file.status==='uploading'" :title="`上传中(${Math.floor(file.percent)}%)`">
<a-icon type="loading"/>
</a-tooltip>
<a-tooltip v-else-if="file.status==='done'" title="上传完成">
<a-icon type="check-circle" style="color:#00DB00;"/>
</a-tooltip>
<a-tooltip v-else title="上传失败">
<a-icon type="exclamation-circle" style="color:red;"/>
</a-tooltip>
</template>
<template slot="addonAfter" style="width: 30px">
<a-tooltip title="删除并重新上传">
<a-icon
v-if="file.status!=='uploading'"
type="close-circle"
style="cursor: pointer;"
@click="()=>handleClickDelFile(id)"/>
</a-tooltip>
</template>
</a-input>
</template>
<div :hidden="uploadValues[id] != null">
<a-upload
name="file"
:data="{'isup':1}"
:multiple="false"
:action="col.action"
:headers="uploadGetHeaders(row,col)"
:showUploadList="false"
v-bind="buildProps(row,col)"
@change="(v)=>handleChangeUpload(v,id,row,col)"
>
<a-button icon="upload">{{ col.placeholder }}</a-button>
</a-upload>
</div>
|
|
276
|
|
|
277
|
</div>
|
|
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
<!-- update-begin-author:taoyan date:0827 for:popup -->
<template v-else-if="col.type === formTypes.popup">
<a-tooltip
:key="i"
:id="id"
placement="top"
:title="(tooltips[id] || {}).title"
:visible="(tooltips[id] || {}).visible || false"
:autoAdjustOverflow="true">
<span
@mouseover="()=>{handleMouseoverCommono(row,col)}"
@mouseout="()=>{handleMouseoutCommono(row,col)}">
<j-popup
:id="id"
:key="i"
v-bind="buildProps(row,col)"
:placeholder="replaceProps(col, col.placeholder)"
style="width: 100%;"
:value="getPopupValue(id)"
:field="col.key"
:org-fields="col.orgFieldse"
:dest-fields="col.destFields"
:code="col.popupCode"
@input="(value,others)=>popupCallback(value,others,id,row,col,rowIndex)"/>
</span>
</a-tooltip>
</template>
<!-- update-end-author:taoyan date:0827 for:popup -->
<!-- update-beign-author:taoyan date:0827 for:文件/图片逻辑新增 -->
<div v-else-if="col.type === formTypes.file" :key="i">
<template v-if="uploadValues[id] != null" v-for="(file,fileKey) of [(uploadValues[id]||{})]">
<a-input
:key="fileKey"
:readOnly="true"
:value="file.name"
>
<template slot="addonBefore" style="width: 30px">
<a-tooltip v-if="file.status==='uploading'" :title="`上传中(${Math.floor(file.percent)}%)`">
<a-icon type="loading"/>
</a-tooltip>
<a-tooltip v-else-if="file.status==='done'" title="上传完成">
<a-icon type="check-circle" style="color:#00DB00;"/>
</a-tooltip>
<a-tooltip v-else title="上传失败">
<a-icon type="exclamation-circle" style="color:red;"/>
</a-tooltip>
</template>
<template slot="addonAfter" style="width: 30px">
<a-tooltip title="删除并重新上传">
<a-icon
v-if="file.status!=='uploading'"
type="close-circle"
style="cursor: pointer;"
@click="()=>handleClickDelFile(id)"/>
</a-tooltip>
</template>
</a-input>
</template>
<div :hidden="uploadValues[id] != null">
<a-upload
name="file"
:data="{'isup':1}"
:multiple="false"
:action="getUploadAction(col.action)"
:headers="uploadGetHeaders(row,col)"
:showUploadList="false"
v-bind="buildProps(row,col)"
@change="(v)=>handleChangeUpload(v,id,row,col)"
>
<a-button icon="upload">{{ col.placeholder }}</a-button>
</a-upload>
</div>
</div>
<div v-else-if="col.type === formTypes.image" :key="i">
<template v-if="uploadValues[id] != null" v-for="(file,fileKey) of [(uploadValues[id]||{})]">
<div :key="fileKey" style="position: relative;">
<img :src="getCellImageView(id)" style="height:32px;max-width:100px !important;" alt="无图片"/>
<template slot="addonBefore" style="width: 30px">
<a-tooltip v-if="file.status==='uploading'" :title="`上传中(${Math.floor(file.percent)}%)`">
<a-icon type="loading"/>
</a-tooltip>
<a-tooltip v-else-if="file.status==='done'" title="上传完成">
<a-icon type="check-circle" style="color:#00DB00;"/>
</a-tooltip>
<a-tooltip v-else title="上传失败">
<a-icon type="exclamation-circle" style="color:red;"/>
</a-tooltip>
</template>
<template style="width: 30px">
<a-tooltip title="删除并重新上传" style="margin-left:5px">
<a-icon
v-if="file.status!=='uploading'"
type="close-circle"
style="cursor: pointer;"
@click="()=>handleClickDelFile(id)"/>
</a-tooltip>
</template>
</div>
</template>
<div :hidden="uploadValues[id] != null">
<a-upload
name="file"
:data="{'isup':1}"
:multiple="false"
:action="getUploadAction(col.action)"
:headers="uploadGetHeaders(row,col)"
:showUploadList="false"
v-bind="buildProps(row,col)"
@change="(v)=>handleChangeUpload(v,id,row,col)"
>
<a-button icon="upload">请上传图片</a-button>
</a-upload>
</div>
</div>
<!-- update-end-author:taoyan date:0827 for:图片逻辑新增 -->
<!-- radio-begin -->
<template v-else-if="col.type === formTypes.radio">
<a-tooltip
:key="i"
:id="id"
placement="top"
:title="(tooltips[id] || {}).title"
:visible="(tooltips[id] || {}).visible || false"
:autoAdjustOverflow="true">
<span
@mouseover="()=>{handleMouseoverCommono(row,col)}"
@mouseout="()=>{handleMouseoutCommono(row,col)}">
<a-radio-group
:id="id"
:key="i"
v-bind="buildProps(row,col)"
:value="radioValues[id]"
@change="(e)=>handleRadioChange(e.target.value,id,row,col)">
<a-radio v-for="(item, key) in col.options" :key="key" :value="item.value">{{ item.text }}</a-radio>
</a-radio-group>
</span>
</a-tooltip>
</template>
<!-- radio-end -->
<!-- select多选 -begin -->
<template v-else-if="col.type === formTypes.list_multi">
<a-tooltip
:key="i"
:id="id"
placement="top"
:title="(tooltips[id] || {}).title"
:visible="(tooltips[id] || {}).visible || false"
:autoAdjustOverflow="true">
<span
@mouseover="()=>{handleMouseoverCommono(row,col)}"
@mouseout="()=>{handleMouseoutCommono(row,col)}">
<a-select
:id="id"
:key="i"
mode="multiple"
:maxTagCount="1"
v-bind="buildProps(row,col)"
style="width: 100%;"
:value="multiSelectValues[id]"
:options="col.options"
:getPopupContainer="getParentContainer"
:placeholder="replaceProps(col, col.placeholder)"
@change="(v)=>handleMultiSelectChange(v,id,row,col)"
allowClear>
</a-select>
</span>
</a-tooltip>
</template>
<!-- select多选 -end -->
<!-- select搜索 -begin -->
<template v-else-if="col.type === formTypes.sel_search">
<a-tooltip
:key="i"
:id="id"
placement="top"
:title="(tooltips[id] || {}).title"
:visible="(tooltips[id] || {}).visible || false"
:autoAdjustOverflow="true">
<span
@mouseover="()=>{handleMouseoverCommono(row,col)}"
@mouseout="()=>{handleMouseoutCommono(row,col)}">
<a-select
:id="id"
:key="i"
showSearch
optionFilterProp="children"
:filterOption="filterOption"
v-bind="buildProps(row,col)"
style="width: 100%;"
:value="searchSelectValues[id]"
:options="col.options"
:getPopupContainer="getParentContainer"
:placeholder="replaceProps(col, col.placeholder)"
@change="(v)=>handleSearchSelectChange(v,id,row,col)"
allowClear>
</a-select>
</span>
</a-tooltip>
</template>
<!-- select搜索 -end -->
|
|
503
504
505
506
507
508
509
510
|
<div v-else-if="col.type === formTypes.slot" :key="i">
<slot
:name="(col.slot || col.slotName) || col.key"
:index="rowIndex"
:text="inputValues[rowIndex][col.key]"
:column="col"
:rowId="removeCaseId(row.id)"
:getValue="()=>_getValueForSlot(row.id)"
|
|
511
512
|
:caseId="caseId"
:allValues="_getAllValuesForSlot()"
|
|
513
514
515
|
:target="getVM()"
/>
</div>
|
|
516
|
|
|
517
|
<!-- else (normal) -->
|
|
518
|
<span v-else :key="i" v-bind="buildProps(row,col)">{{ inputValues[rowIndex][col.key] }}</span>
|
|
519
520
|
</template>
</div>
|
|
521
|
</div>
|
|
522
|
<!-- -- tr end -- -->
|
|
523
|
|
|
524
525
|
</template>
</draggable>
|
|
526
|
|
|
527
|
</div>
|
|
528
529
530
531
532
533
|
</div>
</div>
</a-spin>
</template>
<script>
|
|
534
|
import Vue from 'vue'
|
|
535
|
import Draggable from 'vuedraggable'
|
|
536
|
import { ACCESS_TOKEN } from '@/store/mutation-types'
|
|
537
538
539
|
import { FormTypes, VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
import { cloneObject, randomString } from '@/utils/util'
import JDate from '@/components/jeecg/JDate'
|
|
540
|
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
|
|
541
|
|
|
542
|
|
|
543
544
545
546
547
|
// 行高,需要在实例加载完成前用到
let rowHeight = 61
export default {
name: 'JEditableTable',
|
|
548
|
components: { JDate, Draggable },
|
|
549
550
551
552
553
554
555
556
557
|
props: {
// 列信息
columns: {
type: Array,
required: true
},
// 数据源
dataSource: {
type: Array,
|
|
558
559
|
required: true,
default: () => []
|
|
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
|
},
// 是否显示操作按钮
actionButton: {
type: Boolean,
default: false
},
// 是否显示行号
rowNumber: {
type: Boolean,
default: false
},
// 是否可选择行
rowSelection: {
type: Boolean,
default: false
},
// 页面是否在加载中
loading: {
type: Boolean,
default: false
},
// 页面是否在加载中
maxHeight: {
type: Number,
default: 400
},
// 要禁用的行
disabledRows: {
type: Object,
default() {
return {}
}
|
|
592
593
594
595
596
|
},
// 是否禁用全部组件
disabled: {
type: Boolean,
default: false
|
|
597
598
599
600
601
602
603
604
605
606
|
},
// 是否可拖拽排序
dragSort: {
type: Boolean,
default: false
},
dragSortKey: {
type: String,
default: 'orderNum'
},
|
|
607
608
609
610
611
612
613
614
615
616
617
618
|
},
data() {
return {
// caseId,用于防止有多个实例的时候会冲突
caseId: `_jet-${randomString(6)}-`,
// 存储document element 对象
el: {
inputTable: null,
tbody: null
},
// 存储各个div的style
style: {
|
|
619
620
|
// 'max-height': '400px'
tbody: { left: '0px' },
|
|
621
|
// 左侧固定td的style
|
|
622
623
|
tdLeft: { 'min-width': '4%', 'max-width': '45px' },
tdLeftDs: { 'min-width': '30px', 'max-width': '35px' },
|
|
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
|
},
// 表单的类型
formTypes: FormTypes,
// 行数据
rows: [],
// 行高,height + padding + border
rowHeight,
// 滚动条顶部距离
scrollTop: 0,
// 绑定 select 的值
selectValues: {},
// 绑定 checkbox 的值
checkboxValues: {},
// 绑定 jdate 的值
jdateValues: {},
|
|
639
640
|
// file 信息
uploadValues: {},
|
|
641
642
643
644
645
646
647
|
//popup信息
popupValues:{},
radioValues:{},
metaCheckboxValues:{},
multiSelectValues:{},
searchSelectValues:{},
|
|
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
|
// 绑定左侧选择框已选择的id
selectedRowIds: [],
// 存储被删除行的id
deleteIds: [],
// 存储显示tooltip的信息
tooltips: {},
// 存储没有通过验证的inputId
notPassedIds: []
}
},
created() {
// 当前显示的tr
this.visibleTrEls = []
this.disabledRowIds = (this.disabledRowIds || [])
},
// 计算属性
computed: {
// expandHeight = rows.length * rowHeight
getExpandHeight() {
return this.rows.length * this.rowHeight
},
// 获取是否选择了部分
getSelectIndeterminate() {
return (this.selectedRowIds.length > 0 &&
this.selectedRowIds.length < this.rows.length)
},
// 获取是否选择了全部
getSelectAll() {
return (this.selectedRowIds.length === this.rows.length) && this.rows.length > 0
},
tbodyStyle() {
let style = Object.assign({}, this.style.tbody)
|
|
680
681
|
// style['max-height'] = `${this.maxHeight}px`
style['width'] = this.realTrWidth
|
|
682
683
684
685
686
687
688
689
|
return style
},
showClearSelectButton() {
let count = 0
for (let key in this.disabledRows) {
if (this.disabledRows.hasOwnProperty(key)) count++
}
return count > 0
|
|
690
691
692
693
694
695
696
|
},
accessToken() {
return Vue.ls.get(ACCESS_TOKEN)
},
realTrWidth() {
let calcWidth = 'calc('
this.columns.forEach((column, i) => {
|
|
697
698
699
700
701
702
703
704
705
706
|
let { type, width } = column
// 隐藏字段不参与计算
if (type !== FormTypes.hidden) {
if (typeof width === 'number') {
calcWidth += width + 'px'
} else if (typeof width === 'string') {
calcWidth += width
} else {
calcWidth += '120px'
}
|
|
707
|
|
|
708
709
710
|
if (i < this.columns.length - 1) {
calcWidth += ' + '
}
|
|
711
712
713
|
}
})
calcWidth += ')'
|
|
714
|
// console.log('calcWidth: ', calcWidth)
|
|
715
|
return calcWidth
|
|
716
717
718
719
|
}
},
// 侦听器
watch: {
|
|
720
721
722
723
724
725
726
727
728
729
730
731
732
733
|
rows:{
immediate:true,
handler(val,old) {
// val.forEach(item => {
// for (let inputValue of this.inputValues) {
// if (inputValue.id === item.id) {
// item['dbFieldName'] = inputValue['dbFieldName']
// break
// }
// }
// })
// console.log('watch.rows:', cloneObject({ val, old }))
}
},
|
|
734
735
736
737
738
739
740
741
742
|
dataSource: {
immediate: true,
handler: function (newValue) {
this.initialize()
let rows = []
let checkboxValues = {}
let selectValues = {}
let jdateValues = {}
|
|
743
744
745
746
747
748
|
let uploadValues = {}
let popupValues={}
let radioValues = {}
let multiSelectValues = {}
let searchSelectValues = {}
|
|
749
750
751
752
753
754
755
|
// 禁用行的id
let disabledRowIds = (this.disabledRowIds || [])
newValue.forEach((data, newValueIndex) => {
// 判断源数据是否带有id
if (data.id == null || data.id === '') {
data.id = this.removeCaseId(this.generateId() + newValueIndex)
}
|
|
756
|
|
|
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
|
let value = { id: this.caseId + data.id }
let row = { id: value.id }
let disabled = false
this.columns.forEach(column => {
let inputId = column.key + value.id
let sourceValue = (data[column.key] == null ? '' : data[column.key]).toString()
if (column.type === FormTypes.checkbox) {
// 判断是否设定了customValue(自定义值)
if (column.customValue instanceof Array) {
let customValue = (column.customValue[0] || '').toString()
checkboxValues[inputId] = (sourceValue === customValue)
} else {
checkboxValues[inputId] = sourceValue
}
|
|
772
|
|
|
773
774
775
776
777
778
779
|
} else if (column.type === FormTypes.select) {
if (sourceValue) {
// 判断是否是多选
selectValues[inputId] = (column.props || {})['mode'] === 'multiple' ? sourceValue.split(',') : sourceValue
} else {
selectValues[inputId] = undefined
}
|
|
780
|
|
|
781
782
|
} else if (column.type === FormTypes.date || column.type === FormTypes.datetime) {
jdateValues[inputId] = sourceValue
|
|
783
|
|
|
784
785
786
787
788
789
|
} else if (column.type === FormTypes.slot) {
if (sourceValue !== 0 && !sourceValue) {
value[column.key] = column.defaultValue
} else {
value[column.key] = sourceValue
}
|
|
790
|
|
|
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
|
} else if (column.type === FormTypes.popup) {
popupValues[inputId] = sourceValue
} else if (column.type === FormTypes.radio) {
radioValues[inputId] = sourceValue
} else if (column.type === FormTypes.sel_search) {
searchSelectValues[inputId] = sourceValue
} else if (column.type === FormTypes.list_multi) {
if(sourceValue.length>0){
multiSelectValues[inputId] = sourceValue.split(",")
}else{
multiSelectValues[inputId] = []
}
} else if (column.type === FormTypes.file || column.type === FormTypes.image) {
if(sourceValue){
let fileName = sourceValue.substring(sourceValue.lastIndexOf("/")+1)
uploadValues[inputId] = {
name: fileName,
status: 'done',
path:sourceValue
}
}
|
|
812
813
814
815
|
} else {
value[column.key] = sourceValue
}
|
|
816
817
818
819
820
|
// 解析disabledRows
for (let columnKey in this.disabledRows) {
// 判断是否有该属性
if (this.disabledRows.hasOwnProperty(columnKey) && data.hasOwnProperty(columnKey)) {
if (disabled !== true) {
|
|
821
822
823
824
825
826
827
|
let temp = this.disabledRows[columnKey]
// 禁用规则可以是一个数组
if (temp instanceof Array) {
disabled = temp.includes(data[columnKey])
} else {
disabled = (temp === data[columnKey])
}
|
|
828
829
830
|
if (disabled) {
disabledRowIds.push(row.id)
}
|
|
831
|
}
|
|
832
|
}
|
|
833
|
}
|
|
834
835
836
|
})
this.inputValues.push(value)
rows.push(row)
|
|
837
|
})
|
|
838
839
840
841
842
|
this.disabledRowIds = disabledRowIds
this.checkboxValues = checkboxValues
this.selectValues = selectValues
this.jdateValues = jdateValues
this.rows = rows
|
|
843
844
845
846
847
|
this.uploadValues = uploadValues
this.popupValues = popupValues
this.radioValues = radioValues
this.multiSelectValues = multiSelectValues
this.searchSelectValues = searchSelectValues
|
|
848
|
|
|
849
850
851
852
|
// 更新form表单的值
this.$nextTick(() => {
this.updateFormValues()
})
|
|
853
|
|
|
854
|
}
|
|
855
|
},
|
|
856
857
858
859
|
columns: {
immediate: true,
handler(columns) {
columns.forEach(column => {
|
|
860
|
if (column.type === FormTypes.select || column.type === FormTypes.list_multi || column.type === FormTypes.sel_search) {
|
|
861
862
863
864
865
|
// 兼容 旧版本 options
if (column.options instanceof Array) {
column.options = column.options.map(item => {
if (item) {
return {
|
|
866
|
...item,
|
|
867
|
text: item.text || item.title,
|
|
868
|
title: item.text || item.title
|
|
869
870
871
872
873
|
}
}
return {}
})
}
|
|
874
875
876
|
if (column.dictCode) {
this._loadDictConcatToOptions(column)
}
|
|
877
878
879
880
|
}
})
}
},
|
|
881
882
|
// 当selectRowIds改变时触发事件
selectedRowIds(newValue) {
|
|
883
|
this.$emit('selectRowChange', cloneObject(newValue).map(i => this.removeCaseId(i)))
|
|
884
885
886
887
888
889
890
891
892
893
894
895
|
}
},
mounted() {
// 获取document element对象
let elements = {};
['inputTable', 'tbody'].forEach(id => {
elements[id] = document.getElementById(this.caseId + id)
})
this.el = elements
let vm = this
/** 监听滚动条事件 */
|
|
896
|
this.el.inputTable.onscroll = function (event) {
|
|
897
898
|
vm.syncScrollBar(event.target.scrollLeft)
}
|
|
899
|
this.el.tbody.onscroll = function (event) {
|
|
900
901
902
903
|
// vm.recalcTrHiddenItem(event.target.scrollTop)
}
let { thead, scrollView } = this.$refs
|
|
904
|
scrollView.onscroll = function (event) {
|
|
905
906
907
908
909
910
911
|
// console.log(event.target.scrollTop, ' - ', event.target.scrollLeft)
thead.scrollLeft = event.target.scrollLeft
// vm.recalcTrHiddenItem(event.target.scrollTop)
|
|
912
|
vm.recalcTrHiddenItem(event.target.scrollTop)
|
|
913
|
|
|
914
|
}
|
|
915
|
|
|
916
917
918
919
920
|
},
methods: {
/** 初始化列表 */
initialize() {
|
|
921
922
923
924
925
926
927
928
929
930
931
|
// inputValues:用来存储input表单的值
// 数组里的每项都是一个对象,对象里每个key都是input的rowKey,值就是input的值,其中有个id的字段来区分
// 示例:
// [{
// id: "_jet-4sp0iu-15541771111770"
// dbDefaultVal: "aaa",
// dbFieldName: "bbb",
// dbFieldTxt: "ccc",
// dbLength: 32
// }]
this.inputValues = []
|
|
932
933
934
935
936
937
938
939
940
|
this.visibleTrEls = []
this.rows = []
this.deleteIds = []
this.selectValues = {}
this.checkboxValues = {}
this.jdateValues = {}
this.selectedRowIds = []
this.tooltips = {}
this.notPassedIds = []
|
|
941
942
943
944
945
|
this.uploadValues=[]
this.popupValues=[]
this.radioValues=[]
this.multiSelectValues = []
this.searchSelectValues = []
|
|
946
947
948
949
950
951
952
953
|
this.scrollTop = 0
this.$nextTick(() => {
this.el.tbody.scrollTop = 0
})
},
/** 同步滚动条状态 */
syncScrollBar(scrollLeft) {
|
|
954
955
|
// this.style.tbody.left = `${scrollLeft}px`
// this.el.tbody.scrollLeft = scrollLeft
|
|
956
957
958
|
},
/** 重置滚动条位置,参数留空则滚动到上次记录的位置 */
resetScrollTop(top) {
|
|
959
|
let { scrollView } = this.$refs
|
|
960
|
if (top != null && typeof top === 'number') {
|
|
961
|
scrollView.scrollTop = top
|
|
962
|
} else {
|
|
963
|
scrollView.scrollTop = this.scrollTop
|
|
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
|
}
},
/** 重新计算需要隐藏或显示的tr */
recalcTrHiddenItem(top) {
let diff = top - this.scrollTop
if (diff < 0) {
diff = this.scrollTop - top
}
// 只有在滚动了百分之三十的行高的距离时才进行更新
if (diff >= this.rowHeight * 0.3) {
this.scrollTop = top
// 更新form表单的值
this.$nextTick(() => {
this.updateFormValues()
})
}
},
|
|
981
982
983
984
985
986
987
988
|
/** 生成id */
generateId(rows) {
if (!(rows instanceof Array)) {
rows = this.rows || []
}
let timestamp = new Date().getTime()
return `${this.caseId}${timestamp}${rows.length}`
},
|
|
989
990
991
992
993
994
995
|
/** push 一条数据 */
push(record, update = true, rows) {
if (!(rows instanceof Array)) {
rows = cloneObject(this.rows) || []
}
if (record.id == null) {
|
|
996
997
998
|
record.id = this.generateId(rows)
// let timestamp = new Date().getTime()
// record.id = `${this.caseId}${timestamp}${rows.length}`
|
|
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
|
}
if (record.id.indexOf(this.caseId) === -1) {
record.id = this.caseId + record.id
}
let row = { id: record.id }
let value = { id: row.id }
let checkboxValues = Object.assign({}, this.checkboxValues)
let selectValues = Object.assign({}, this.selectValues)
let jdateValues = Object.assign({}, this.jdateValues)
this.columns.forEach(column => {
let key = column.key
let inputId = key + row.id
// record中是否有该列的值
let recordHasValue = record[key] != null
if (column.type === FormTypes.input) {
|
|
1014
|
value[key] = recordHasValue ? record[key] : (column.defaultValue || (column.defaultValue === 0 ? 0 : ''))
|
|
1015
1016
1017
1018
1019
1020
|
} else if (column.type === FormTypes.inputNumber) {
// 判断是否是排序字段,如果是就赋最大值
if (column.isOrder === true) {
value[key] = this.getInputNumberMaxValue(column) + 1
} else {
|
|
1021
|
value[key] = recordHasValue ? record[key] : (column.defaultValue || (column.defaultValue === 0 ? 0 : ''))
|
|
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
|
}
} else if (column.type === FormTypes.checkbox) {
checkboxValues[inputId] = recordHasValue ? record[key] : column.defaultChecked
} else if (column.type === FormTypes.select) {
let selected = column.defaultValue
if (selected !== 0 && !selected) {
selected = undefined
}
|
|
1032
1033
1034
1035
|
// 判断多选
if (typeof selected === 'string' && (column.props || {})['mode'] === 'multiple') {
selected = selected.split(',')
}
|
|
1036
1037
1038
1039
1040
|
selectValues[inputId] = recordHasValue ? record[key] : selected
} else if (column.type === FormTypes.date || column.type === FormTypes.datetime) {
jdateValues[inputId] = recordHasValue ? record[key] : column.defaultValue
|
|
1041
1042
1043
|
} else if (column.type === FormTypes.slot) {
value[key] = recordHasValue ? record[key] : (column.defaultValue || '')
|
|
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
|
} else {
value[key] = recordHasValue ? record[key] : ''
}
})
rows.push(row)
this.inputValues.push(value)
this.checkboxValues = checkboxValues
this.selectValues = selectValues
this.jdateValues = jdateValues
|
|
1054
1055
1056
1057
1058
1059
|
if (this.dragSort) {
this.inputValues.forEach((item, index) => {
item[this.dragSortKey] = (index + 1)
})
}
|
|
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
|
if (update) {
this.rows = rows
this.$nextTick(() => {
this.updateFormValues()
})
}
return rows
},
/** 获取某一数字输入框列中的最大的值 */
getInputNumberMaxValue(column) {
let maxNum = 0
this.inputValues.forEach((item, index) => {
let val = item[column.key], num
try {
num = parseInt(val)
} catch {
num = 0
}
// 把首次循环的结果当成最大值
if (index === 0) {
maxNum = num
} else {
maxNum = (num > maxNum) ? num : maxNum
}
})
return maxNum
},
/** 添加一行 */
add(num = 1, forceScrollToBottom = false) {
|
|
1089
|
if (num < 1) return
|
|
1090
|
// let timestamp = new Date().getTime()
|
|
1091
|
let rows = this.rows
|
|
1092
|
let row
|
|
1093
|
for (let i = 0; i < num; i++) {
|
|
1094
1095
|
// row = { id: `${this.caseId}${timestamp}${rows.length}` }
row = { id: this.generateId(rows) }
|
|
1096
1097
1098
1099
|
rows = this.push(row, false, rows)
}
this.rows = rows
|
|
1100
1101
1102
1103
1104
|
let rowValue = this.getValuesSync({
validate: false,
rowIds: [this.removeCaseId(row.id)]
}).values[0]
|
|
1105
1106
1107
|
this.$nextTick(() => {
this.updateFormValues()
})
|
|
1108
1109
|
// 触发add事件
this.$emit('added', {
|
|
1110
|
row: rowValue,
|
|
1111
1112
|
target: this
})
|
|
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
|
// 设置滚动条位置
let tbody = this.el.tbody
let offsetHeight = tbody.offsetHeight
let realScrollTop = tbody.scrollTop + offsetHeight
if (forceScrollToBottom === false) {
// 只有滚动条在底部的时候才自动滚动
if (!((tbody.scrollHeight - realScrollTop) <= 10)) {
return
}
}
this.$nextTick(() => {
tbody.scrollTop = tbody.scrollHeight
})
},
/** 删除被选中的行 */
removeSelectedRows() {
this.removeRows(this.selectedRowIds)
this.selectedRowIds = []
},
/** 删除一行或多行 */
removeRows(id) {
let ids = id
if (!(id instanceof Array)) {
if (typeof id === 'string') {
ids = [id]
} else {
|
|
1139
|
throw `JEditableTable.removeRows() 函数需要的参数可以是string或Array类型,但提供的却是${typeof id}`
|
|
1140
1141
1142
1143
1144
1145
1146
1147
|
}
}
let rows = cloneObject(this.rows)
ids.forEach(removeId => {
// 找到每个id对应的真实index并删除
const findAndDelete = (arr) => {
for (let i = 0; i < arr.length; i++) {
|
|
1148
|
if (arr[i].id === removeId || arr[i].id === this.caseId + removeId) {
|
|
1149
1150
1151
1152
1153
1154
1155
|
arr.splice(i, 1)
return true
}
}
}
// 找到rows对应的index,并删除
if (findAndDelete(rows)) {
|
|
1156
1157
|
// 找到values对应的index,并删除
findAndDelete(this.inputValues)
|
|
1158
|
// 将caseId去除
|
|
1159
1160
|
let id = this.removeCaseId(removeId)
this.deleteIds.push(id)
|
|
1161
1162
1163
1164
|
}
})
this.rows = rows
this.$emit('deleted', this.getDeleteIds())
|
|
1165
1166
1167
1168
|
this.$nextTick(() => {
// 更新formValues
this.updateFormValues()
})
|
|
1169
1170
1171
|
return true
},
|
|
1172
1173
1174
1175
1176
1177
1178
|
/** 获取表格表单里的值(同步版) */
getValuesSync(options = {}) {
let { validate, rowIds } = options
if (typeof validate !== 'boolean') validate = true
if (!(rowIds instanceof Array)) rowIds = null
// console.log('options:', { validate, rowIds })
|
|
1179
|
let error = 0
|
|
1180
|
let inputValues = cloneObject(this.inputValues)
|
|
1181
1182
|
let tooltips = Object.assign({}, this.tooltips)
let notPassedIds = cloneObject(this.notPassedIds)
|
|
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
|
// 用于存储合并后的值
let values = []
// 遍历inputValues来获取每行的值
for (let value of inputValues) {
let rowIdsFlag = false
// 如果带有rowIds,那么就只存这几行的数据
if (rowIds == null) {
rowIdsFlag = true
} else {
for (let rowId of rowIds) {
if (rowId === value.id || `${this.caseId}${rowId}` === value.id) {
rowIdsFlag = true
break
}
}
}
if (!rowIdsFlag) continue
|
|
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
|
this.columns.forEach(column => {
let inputId = column.key + value.id
if (column.type === FormTypes.checkbox) {
let checked = this.checkboxValues[inputId]
if (column.customValue instanceof Array) {
value[column.key] = checked ? column.customValue[0] : column.customValue[1]
} else {
value[column.key] = checked
}
} else if (column.type === FormTypes.select) {
|
|
1213
1214
1215
1216
1217
1218
|
let selected = this.selectValues[inputId]
if (selected instanceof Array) {
value[column.key] = cloneObject(selected)
} else {
value[column.key] = selected
}
|
|
1219
1220
1221
1222
|
} else if (column.type === FormTypes.date || column.type === FormTypes.datetime) {
value[column.key] = this.jdateValues[inputId]
|
|
1223
1224
1225
|
} else if (column.type === FormTypes.upload) {
value[column.key] = cloneObject(this.uploadValues[inputId] || null)
|
|
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
|
} else if (column.type === FormTypes.image || column.type === FormTypes.file) {
let currUploadObj = cloneObject(this.uploadValues[inputId] || null)
if(currUploadObj){
value[column.key] = currUploadObj['path'] || null
}
} else if (column.type === FormTypes.popup) {
if(!value[column.key]){
value[column.key] = this.popupValues[inputId] || null
}
} else if (column.type === FormTypes.radio) {
value[column.key] = this.radioValues[inputId]
}else if (column.type === FormTypes.sel_search) {
value[column.key] = this.searchSelectValues[inputId]
}else if (column.type === FormTypes.list_multi) {
if(!this.multiSelectValues[inputId] || this.multiSelectValues[inputId].length==0){
value[column.key] = ''
}else{
value[column.key] = this.multiSelectValues[inputId].join(",")
}
|
|
1246
|
}
|
|
1247
1248
|
|
|
1249
|
// 检查表单验证
|
|
1250
|
if (validate === true) {
|
|
1251
|
let results = this.validateOneInput(value[column.key], value, column, notPassedIds, false, 'getValues')
|
|
1252
|
tooltips[inputId] = results[0]
|
|
1253
|
if (tooltips[inputId].passed === false) {
|
|
1254
1255
1256
1257
1258
1259
1260
1261
|
error++
// if (error++ === 0) {
// let element = document.getElementById(inputId)
// while (element.className !== 'tr') {
// element = element.parentElement
// }
// this.jumpToId(inputId, element)
// }
|
|
1262
1263
1264
1265
1266
1267
|
}
tooltips[inputId].visible = false
notPassedIds = results[1]
}
})
// 将caseId去除
|
|
1268
1269
1270
1271
1272
|
value.id = this.removeCaseId(value.id)
values.push(value)
}
|
|
1273
1274
1275
1276
|
if (validate === true) {
this.tooltips = tooltips
this.notPassedIds = notPassedIds
}
|
|
1277
1278
1279
1280
1281
1282
1283
1284
1285
|
return { error, values }
},
/** 获取表格表单里的值 */
getValues(callback, validate = true, rowIds) {
let result = this.getValuesSync({ validate, rowIds })
if (typeof callback === 'function') {
callback(result.error, result.values)
}
|
|
1286
1287
|
},
/** getValues的Promise版 */
|
|
1288
|
getValuesPromise(validate = true, rowIds) {
|
|
1289
|
return new Promise((resolve, reject) => {
|
|
1290
1291
1292
1293
1294
1295
|
let { error, values } = this.getValuesSync({ validate, rowIds })
if (error === 0) {
resolve(values)
} else {
reject(VALIDATE_NO_PASSED)
}
|
|
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
|
})
},
/** 获取被删除项的id */
getDeleteIds() {
return cloneObject(this.deleteIds)
},
/** 获取所有的数据,包括values、deleteIds */
getAll(validate) {
return new Promise((resolve, reject) => {
let deleteIds = this.getDeleteIds()
this.getValuesPromise(validate).then((values) => {
resolve({ values, deleteIds })
}).catch(error => {
reject(error)
})
})
},
|
|
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
|
/** Sync 获取所有的数据,包括values、deleteIds */
getAllSync(validate, rowIds) {
let result = this.getValuesSync({ validate, rowIds })
result.deleteIds = this.getDeleteIds()
return result
},
// slot 获取值
_getValueForSlot(rowId) {
return this.getValuesSync({ rowIds: [rowId] }).values[0]
},
|
|
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
|
_getAllValuesForSlot() {
return cloneObject({
inputValues: this.inputValues,
selectValues: this.selectValues,
checkboxValues: this.checkboxValues,
jdateValues: this.jdateValues,
uploadValues: this.uploadValues,
popupValues: this.popupValues,
radioValues: this.radioValues,
multiSelectValues: this.multiSelectValues,
searchSelectValues: this.searchSelectValues,
})
},
|
|
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
|
/** 设置某行某列的值 */
setValues(values) {
values.forEach(item => {
let { rowKey, values: newValues } = item
for (let newValueKey in newValues) {
if (newValues.hasOwnProperty(newValueKey)) {
let newValue = newValues[newValueKey]
let edited = false // 已被修改
this.inputValues.forEach(value => {
// 在inputValues中找到了该字段
if (`${this.caseId}${rowKey}` === value.id) {
|
|
1348
1349
1350
1351
|
if (value.hasOwnProperty(newValueKey)) {
edited = true
value[newValueKey] = newValue
}
|
|
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
|
}
})
let modelKey = `${newValueKey}${this.caseId}${rowKey}`
// 在 selectValues 中寻找值
if (!edited && this.selectValues.hasOwnProperty(modelKey)) {
if (newValue !== 0 && !newValue) {
this.selectValues[modelKey] = undefined
} else {
this.selectValues[modelKey] = newValue
}
edited = true
}
// 在 checkboxValues 中寻找值
if (!edited && this.checkboxValues.hasOwnProperty(modelKey)) {
this.checkboxValues[modelKey] = newValue
edited = true
}
// 在 jdateValues 中寻找值
if (!edited && this.jdateValues.hasOwnProperty(modelKey)) {
this.jdateValues[modelKey] = newValue
edited = true
}
}
}
})
// 强制更新formValues
this.forceUpdateFormValues()
},
/** 跳转到指定位置 */
// jumpToId(id, element) {
// if (element == null) {
// element = document.getElementById(id)
// }
// if (element != null) {
// console.log(this.el.tbody.scrollTop, element.offsetTop)
// this.el.tbody.scrollTop = element.offsetTop
// console.log(this.el.tbody.scrollTop, element.offsetTop)
// }
// },
|
|
1392
|
|
|
1393
|
/** 验证单个表单 */
|
|
1394
|
validateOneInput(value, row, column, notPassedIds, update = false, validType = 'input') {
|
|
1395
1396
1397
1398
1399
|
let tooltips = Object.assign({}, this.tooltips)
// let notPassedIds = cloneObject(this.notPassedIds)
let inputId = column.key + row.id
tooltips[inputId] = tooltips[inputId] ? tooltips[inputId] : {}
|
|
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
|
let [passed, message] = this.validateValue(column.validateRules, value)
const nextThen = res => {
let [passed, message] = res
if (passed == null) {
// debugger
}
if (passed == null && tooltips[inputId].visible != null) {
return
}
passed = passed == null ? true : passed
tooltips[inputId].visible = !passed
tooltips[inputId].passed = passed
let index = notPassedIds.indexOf(inputId)
let borderColor = null, boxShadow = null
if (!passed) {
tooltips[inputId].title = this.replaceProps(column, message)
borderColor = 'red'
boxShadow = `0 0 0 2px rgba(255, 0, 0, 0.2)`
if (index === -1) notPassedIds.push(inputId)
} else {
if (index !== -1) notPassedIds.splice(index, 1)
}
let element = document.getElementById(inputId)
if (element != null) {
// select 在 .ant-select-selection 上设置 border-color
if (column.type === FormTypes.select) {
element = element.getElementsByClassName('ant-select-selection')[0]
}
// jdate 在 input 上设置 border-color
if (column.type === FormTypes.date || column.type === FormTypes.datetime) {
element = element.getElementsByTagName('input')[0]
}
element.style.borderColor = borderColor
element.style.boxShadow = boxShadow
|
|
1436
|
}
|
|
1437
1438
1439
1440
|
// 是否更新到data
if (update) {
this.tooltips = tooltips
this.notPassedIds = notPassedIds
|
|
1441
|
}
|
|
1442
|
|
|
1443
|
}
|
|
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
|
if (typeof passed === 'function') {
let executed = false
passed(validType, value, row, column, (flag, msg) => {
if (executed) return
executed = true
if (typeof msg === 'string') {
message = msg
}
if (flag == null) {
nextThen([null, message])
}else if (typeof flag === 'boolean' && flag) {
nextThen([true, message])
} else {
nextThen([false, message])
}
}, this)
} else {
nextThen([passed, message])
|
|
1464
|
}
|
|
1465
|
|
|
1466
1467
1468
1469
|
return [tooltips[inputId], notPassedIds]
},
/** 通过规则验证值是否正确 */
validateValue(rules, value) {
|
|
1470
1471
1472
1473
1474
1475
1476
1477
|
let passed = true, message = ''
// 判断有没有验证规则或验证规则格式正不正确,若条件不符合则默认通过
if (rules instanceof Array) {
for (let rule of rules) {
// 当前值是否为空
let isNull = (value == null || value === '')
// 验证规则:非空
if (rule.required === true && isNull) {
|
|
1478
|
passed = false
|
|
1479
1480
1481
|
} else // 使用 else-if 是为了防止一个 rule 中出现两个规则
// 验证规则:正则表达式
if (!!rule.pattern && !isNull) {
|
|
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
|
// 兼容 online 的规则
let foo = [
{ title: '唯一校验', value: 'only', pattern: null },
{ title: '6到16位数字', value: 'n6-16', pattern: /\d{6,18}/ },
{ title: '6到16位任意字符', value: '*6-16', pattern: /^.{6,16}$/ },
{ title: '网址', value: 'url', pattern: /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/ },
{ title: '电子邮件', value: 'e', pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/ },
{ title: '手机号码', value: 'm', pattern: /^1[3456789]\d{9}$/ },
{ title: '邮政编码', value: 'p', pattern: /^[1-9]\d{5}$/ },
{ title: '字母', value: 's', pattern: /^[A-Z|a-z]+$/ },
{ title: '数字', value: 'n', pattern: /^-?\d+\.?\d*$/ },
{ title: '整数', value: 'z', pattern: /^[1-9]\d*$/ },
{ title: '非空', value: '*', pattern: /^.+$/ },
{ title: '6到18位字符串', value: 's6-18', pattern: /^.{6,18}$/ },
{ title: '金额', value: 'money', pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/ },
]
let flag = false
for (let item of foo) {
if (rule.pattern === item.value && item.pattern) {
passed = new RegExp(item.pattern).test(value)
flag = true
break
}
}
if (!flag) passed = new RegExp(rule.pattern).test(value)
|
|
1508
1509
|
} else if (typeof rule.handler === 'function') {
return [rule.handler, rule.message]
|
|
1510
1511
1512
|
}
// 如果没有通过验证,则跳出循环。如果通过了验证,则继续验证下一条规则
if (!passed) {
|
|
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
|
message = rule.message
break
}
}
}
return [passed, message]
},
/** 动态更新表单的值 */
updateFormValues() {
let trs = this.el.tbody.getElementsByClassName('tr')
let trEls = []
for (let tr of trs) {
trEls.push(tr)
}
// 获取新增的 tr
let newTrEls = trEls
if (this.visibleTrEls.length > 0) {
newTrEls = []
for (let tr of trEls) {
let isNewest = true
for (let vtr of this.visibleTrEls) {
if (vtr.id === tr.id) {
isNewest = false
break
}
}
if (isNewest) {
newTrEls.push(tr)
}
}
}
this.visibleTrEls = trEls
// 向新增的tr中赋值
newTrEls.forEach(tr => {
let { idx } = tr.dataset
let value = this.inputValues[idx]
for (let key in value) {
if (value.hasOwnProperty(key)) {
let elid = `${key}${value.id}`
let el = document.getElementById(elid)
if (el) {
el.value = value[key]
}
}
}
})
},
/** 强制更新FormValues */
forceUpdateFormValues() {
this.visibleTrEls = []
this.updateFormValues()
},
/** 全选或取消全选 */
handleChangeCheckedAll() {
let selectedRowIds = []
if (!this.getSelectAll) {
this.rows.forEach(row => {
if ((this.disabledRowIds || []).indexOf(row.id) === -1) {
selectedRowIds.push(row.id)
}
})
}
this.selectedRowIds = selectedRowIds
},
/** 左侧行选择框change事件 */
handleChangeLeftCheckbox(event) {
let { id } = event.target
if ((this.disabledRowIds || []).indexOf(id) !== -1) {
return
}
let index = this.selectedRowIds.indexOf(id)
if (index !== -1) {
this.selectedRowIds.splice(index, 1)
} else {
this.selectedRowIds.push(id)
}
},
handleClickAdd() {
this.add()
},
handleConfirmDelete() {
this.removeSelectedRows()
},
|
|
1601
1602
1603
1604
|
handleClickClearSelection() {
this.clearSelection()
},
clearSelection() {
|
|
1605
1606
|
this.selectedRowIds = []
},
|
|
1607
1608
1609
1610
1611
1612
1613
|
/** 用于搜索下拉框中的内容 */
handleSelectFilterOption(input, option, column) {
if (column.allowSearch === true) {
return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
return true
},
|
|
1614
1615
|
/** select 搜索时的事件,用于动态添加options */
handleSearchSelect(value, id, row, col) {
|
|
1616
|
if (col.allowSearch !== true && col.allowInput === true) {
|
|
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
|
// 是否找到了对应的项,找不到则添加这一项
let flag = false
for (let option of col.options) {
if (option.value.toLocaleString() === value.toLocaleString()) {
flag = true
break
}
}
// !!value :不添加空值
if (!flag && !!value) {
// searchAdd 是否是通过搜索添加的
col.options.push({ title: value, value: value, searchAdd: true })
}
}
},
// blur 失去焦点
handleBlurSearch(value, id, row, col) {
if (col.allowInput === true) {
// 删除无用的因搜索(用户输入)而创建的项
if (typeof value === 'string') {
let indexs = []
col.options.forEach((option, index) => {
if (option.value.toLocaleString() === value.toLocaleString()) {
delete option.searchAdd
} else if (option.searchAdd === true) {
indexs.push(index)
}
})
// 翻转删除数组中的项
for (let index of indexs.reverse()) {
col.options.splice(index, 1)
}
}
|
|
1651
|
|
|
1652
1653
|
}
},
|
|
1654
|
|
|
1655
1656
|
/** 拖动结束,交换inputValue中的值 */
handleDragMoveEnd(event) {
|
|
1657
|
let { oldIndex, newIndex, item: { dataset: { idx: dataIdx } } } = event
|
|
1658
|
|
|
1659
1660
1661
1662
|
// 由于动态显示隐藏行导致index有误差,需要算出真实的index
let diff = Number.parseInt(dataIdx) - oldIndex
oldIndex += diff
newIndex += diff
|
|
1663
|
|
|
1664
|
this.rowResort(oldIndex, newIndex)
|
|
1665
1666
1667
1668
1669
1670
1671
1672
1673
|
// 触发已拖动事件
this.$emit('dragged', {
oldIndex,
newIndex,
target: this
})
},
|
|
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
|
/** 行重新排序 */
rowResort(oldIndex, newIndex) {
const sort = (array) => {
// 存储旧数据,并删除旧项目
let temp = array[oldIndex]
array.splice(oldIndex, 1)
// 向新项目里添加旧数据
array.splice(newIndex, 0, temp)
}
sort(this.rows)
sort(this.inputValues)
// 重置排序字段
this.inputValues.forEach((val, idx) => val[this.dragSortKey] = (idx + 1))
this.forceUpdateFormValues()
},
|
|
1693
1694
1695
1696
1697
1698
|
/* --- common function begin --- */
/** 鼠标移入 */
handleMouseoverCommono(row, column) {
let inputId = column.key + row.id
if (this.notPassedIds.indexOf(inputId) !== -1) {
|
|
1699
|
this.showOrHideTooltip(inputId, true, true)
|
|
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
|
}
},
/** 鼠标移出 */
handleMouseoutCommono(row, column) {
let inputId = column.key + row.id
this.showOrHideTooltip(inputId, false)
},
/** input事件 */
handleInputCommono(target, index, row, column) {
let { value, dataset, selectionStart } = target
|
|
1710
1711
|
let type = FormTypes.input
let change = true
|
|
1712
|
if (`${dataset.inputNumber}` === 'true') {
|
|
1713
|
type = FormTypes.inputNumber
|
|
1714
1715
|
let replace = value.replace(/[^0-9]/g, '')
if (value !== replace) {
|
|
1716
|
change = false
|
|
1717
1718
|
value = replace
target.value = replace
|
|
1719
|
if (typeof selectionStart === 'number') {
|
|
1720
1721
1722
1723
1724
1725
1726
1727
|
target.selectionStart = selectionStart - 1
target.selectionEnd = selectionStart - 1
}
}
}
// 存储输入的值
this.inputValues[index][column.key] = value
// 做单个表单验证
|
|
1728
|
this.validateOneInput(value, row, column, this.notPassedIds, true, 'input')
|
|
1729
1730
1731
1732
1733
|
// 触发valueChange 事件
if (change) {
this.elemValueChange(type, row, column, value)
}
|
|
1734
|
},
|
|
1735
1736
1737
1738
1739
|
handleBlurCommono(target, index, row, column) {
let { value } = target
// 做单个表单验证
this.validateOneInput(value, row, column, this.notPassedIds, true, 'blur')
},
|
|
1740
|
handleChangeCheckboxCommon(event, row, column) {
|
|
1741
1742
|
let { id, checked } = event.target
this.checkboxValues = this.bindValuesChange(checked, id, 'checkboxValues')
|
|
1743
1744
1745
|
// 触发valueChange 事件
this.elemValueChange(FormTypes.checkbox, row, column, checked)
|
|
1746
1747
1748
1749
|
},
handleChangeSelectCommon(value, id, row, column) {
this.selectValues = this.bindValuesChange(value, id, 'selectValues')
// 做单个表单验证
|
|
1750
|
this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
|
|
1751
1752
1753
|
// 触发valueChange 事件
this.elemValueChange(FormTypes.select, row, column, value)
|
|
1754
|
},
|
|
1755
|
handleChangeJDateCommon(value, id, row, column, showTime) {
|
|
1756
|
this.jdateValues = this.bindValuesChange(value, id, 'jdateValues')
|
|
1757
|
this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
|
|
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
|
// 触发valueChange 事件
if (showTime) {
this.elemValueChange(FormTypes.datetime, row, column, value)
} else {
this.elemValueChange(FormTypes.date, row, column, value)
}
},
handleChangeUpload(info, id, row, column) {
let { file } = info
let value = {
name: file.name,
type: file.type,
size: file.size,
status: file.status,
percent: file.percent
}
if (column.responseName && file.response) {
value['responseName'] = file.response[column.responseName]
}
|
|
1778
1779
1780
|
if(file.status =='done'){
value['path'] = file.response[column.responseName]
}
|
|
1781
|
this.uploadValues = this.bindValuesChange(value, id, 'uploadValues')
|
|
1782
1783
1784
1785
1786
1787
1788
1789
1790
|
},
/** 记录用到数据绑定的组件的值 */
bindValuesChange(value, id, key) {
let values = Object.assign({}, this[key])
values[id] = value
return values
},
/** 显示或隐藏tooltip */
|
|
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
|
showOrHideTooltip(inputId, show, force = false) {
if (!this.tooltips[inputId] && !force) {
return
}
let tooltip = this.tooltips[inputId] || {}
if (tooltip.visible !== show) {
tooltip.visible = show
this.$set(this.tooltips, inputId, tooltip)
}
|
|
1801
1802
|
},
|
|
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
|
/** value 触发valueChange事件 */
elemValueChange(type, rowSource, columnSource, value) {
let column = Object.assign({}, columnSource)
// 将caseId去除
let row = Object.assign({}, rowSource)
row.id = this.removeCaseId(row.id)
// 获取整行的数据
let { values } = this.getValuesSync({ validate: false, rowIds: [row.id] })
if (values.length > 0) {
Object.assign(row, values[0])
}
this.$emit('valueChange', { type, row, column, value, target: this })
},
/** 将caseId去除 */
removeCaseId(id) {
|
|
1819
1820
|
let remove = id.split(this.caseId)[1]
return remove ? remove : id
|
|
1821
1822
1823
1824
1825
1826
|
},
handleClickDelFile(id) {
this.uploadValues[id] = null
},
|
|
1827
1828
1829
1830
|
/** 加载数据字典并合并到 options */
_loadDictConcatToOptions(column) {
initDictOptions(column.dictCode).then((res) => {
if (res.success) {
|
|
1831
1832
1833
1834
1835
1836
|
let newOptions = (column.options || [])// .concat(res.result)
res.result.forEach(item => {
for (let option of newOptions) if (option.value === item.value) return
newOptions.push(item)
})
column.options = newOptions
|
|
1837
1838
1839
1840
1841
1842
1843
1844
|
} else {
console.group(`JEditableTable 查询字典(${column.dictCode})发生异常`)
console.log(res.message)
console.groupEnd()
}
})
},
|
|
1845
1846
1847
1848
1849
1850
1851
|
/* --- common function end --- */
/* --- 以下是辅助方法,多用于动态构造页面中的数据 --- */
/** 辅助方法:打印日志 */
log: console.log,
|
|
1852
1853
1854
1855
1856
1857
|
getVM() {
return this
},
/** 辅助方法:指定a-select 和 j-data 的父容器 */
getParentContainer(node) {
|
|
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
|
let element = (() => {
// nodeType 8 : Comment : 注释
if (this.$el && this.$el.nodeType !== 8) {
return this.$el
}
let doc = document.getElementById(this.caseId + 'inputTable')
if (doc != null) {
return doc
}
return node.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
})()
// 递归判断是否带有 overflow: hidden;的父元素
const ifParent = (child) => {
let currentOverflow = null
if (child['currentStyle']) {
currentOverflow = child['currentStyle']['overflow']
} else if (window.getComputedStyle) {
currentOverflow = window.getComputedStyle(child)['overflow']
}
if (currentOverflow != null) {
if (currentOverflow === 'hidden') {
// 找到了带有 hidden 的标签,判断它的父级是否还有 hidden,直到遇到完全没有 hidden 或 body 的时候才停止递归
let temp = ifParent(child.parentNode)
return temp != null ? temp : child.parentNode
} else
// 当前标签没有 hidden ,如果有父级并且父级不是 body 的话就继续递归判断父级
if (child.parentNode && child.parentNode.tagName.toLocaleLowerCase() !== 'body') {
return ifParent(child.parentNode)
} else {
// 直到 body 都没有遇到有 hidden 的标签
return null
}
} else {
return child
}
|
|
1894
|
}
|
|
1895
1896
1897
|
let temp = ifParent(element)
return (temp != null) ? temp : element
|
|
1898
1899
|
},
|
|
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
|
/** 辅助方法:替换${...}变量 */
replaceProps(col, value) {
if (value && typeof value === 'string') {
value = value.replace(/\${title}/g, col.title)
value = value.replace(/\${key}/g, col.key)
value = value.replace(/\${defaultValue}/g, col.defaultValue)
}
return value
},
/** view辅助方法:构建 tr style */
buildTrStyle(index) {
return {
'top': `${rowHeight * index}px`
}
},
/** view辅助方法:构建 td style */
buildTdStyle(col) {
|
|
1918
1919
|
const isEmptyWidth = (column) => (column.type === FormTypes.hidden || column.width === '0px' || column.width === '0' || column.width === 0)
|
|
1920
1921
1922
1923
1924
|
let style = {}
// 计算宽度
if (col.width) {
style['width'] = col.width
} else if (this.columns) {
|
|
1925
|
style['width'] = `${(100 - 4 * 2) / (this.columns.filter(column => !isEmptyWidth(column))).length}%`
|
|
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
|
} else {
style['width'] = '120px'
}
// checkbox 居中显示
let isCheckbox = col.type === FormTypes.checkbox
if (isCheckbox) {
style['align-items'] = 'center'
style['text-align'] = 'center'
style['padding-left'] = '0'
style['padding-right'] = '0'
}
|
|
1937
1938
1939
1940
|
if (isEmptyWidth(col)) {
style['padding-left'] = '0'
style['padding-right'] = '0'
}
|
|
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
|
return style
},
/** view辅助方法:构造props */
buildProps(row, col) {
let props = {}
// 解析props
if (typeof col.props === 'object') {
for (let prop in col.props) {
if (col.props.hasOwnProperty(prop)) {
props[prop] = this.replaceProps(col, col.props[prop])
}
}
}
|
|
1954
|
// 判断select是否允许输入
|
|
1955
|
if (col.type === FormTypes.select && (col.allowInput === true || col.allowSearch === true)) {
|
|
1956
1957
1958
|
props['showSearch'] = true
}
|
|
1959
|
// 判断是否是禁用的列
|
|
1960
|
props['disabled'] = (typeof col['disabled'] === 'boolean' ? col['disabled'] : props['disabled'])
|
|
1961
|
|
|
1962
1963
1964
1965
|
// 判断是否为禁用的行
if (props['disabled'] !== true) {
props['disabled'] = ((this.disabledRowIds || []).indexOf(row.id) !== -1)
}
|
|
1966
1967
1968
1969
1970
1971
|
// 判断是否禁用全部组件
if (this.disabled === true) {
props['disabled'] = true
}
|
|
1972
|
return props
|
|
1973
1974
1975
1976
1977
1978
1979
1980
|
},
/** upload 辅助方法:获取 headers */
uploadGetHeaders(row, column) {
let headers = {}
if (column.token === true) {
headers['X-Access-Token'] = this.accessToken
}
return headers
|
|
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
|
},
/** 上传请求地址 */
getUploadAction(value){
if(!value){
return window._CONFIG['domianURL']+"/sys/common/upload"
}else{
return value
}
},
/** 预览图片地址 */
getCellImageView(id){
let currUploadObj = this.uploadValues[id] || null
if(currUploadObj && currUploadObj['path']){
return window._CONFIG['domianURL']+"/sys/common/view/"+currUploadObj['path']
}else{
return ''
}
},
/** popup回调 */
popupCallback(value,others,id,row,column,index){
// 存储输入的值
this.popupValues[id]=value
if(others){
Object.keys(others).map((key)=>{
this.inputValues[index][key] = others[key]
})
}
// 做单个表单验证
this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
// 触发valueChange 事件
this.elemValueChange("input", row, column, value)
// 更新form表单的值
this.$nextTick(() => {
this.forceUpdateFormValues()
})
},
/** popup输入框回显 */
getPopupValue(id){
return this.popupValues[id]
},
handleRadioChange(value, id, row, column) {
this.radioValues = this.bindValuesChange(value, id, 'radioValues')
// 做单个表单验证
this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
// 触发valueChange 事件
this.elemValueChange(FormTypes.radio, row, column, value)
},
handleMultiSelectChange(value, id, row, column) {
this.multiSelectValues = this.bindValuesChange(value, id, 'multiSelectValues')
// 做单个表单验证
this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
// 触发valueChange 事件
this.elemValueChange(FormTypes.list_multi, row, column, value)
},
handleSearchSelectChange(value, id, row, column) {
this.searchSelectValues = this.bindValuesChange(value, id, 'searchSelectValues')
this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
this.elemValueChange(FormTypes.sel_search, row, column, value)
},
filterOption(input, option) {
return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
},
|
|
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
|
}
}
</script>
<style lang="less" scoped>
.action-button {
margin-bottom: 8px;
.gap {
padding-left: 8px;
}
}
/* 设定边框参数 */
@borderColor: #e8e8e8;
@border: 1px solid @borderColor;
/* tr & td 之间的间距 */
@spacing: 8px;
.input-table {
max-width: 100%;
|
|
2068
|
overflow-x: hidden;
|
|
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
|
overflow-y: hidden;
position: relative;
border: @border;
.thead, .tbody {
.tr, .td {
display: flex;
}
.td {
|
|
2080
2081
|
/*border-right: 1px solid red;*/
|
|
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
|
/*color: white;*/
/*background-color: black;*/
/*margin-right: @spacing !important;*/
padding-left: @spacing;
flex-direction: column;
&.td-cb, &.td-num {
min-width: 4%;
max-width: 45px;
margin-right: 0;
padding-left: 0;
padding-right: 0;
justify-content: center;
align-items: center;
}
|
|
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
|
&.td-ds {
margin-right: 0;
padding-left: 0;
padding-right: 0;
justify-content: center;
align-items: center;
.td-ds-icons {
position: relative;
cursor: move;
width: 100%;
/*padding: 25% 0;*/
height: 100%;
.anticon-align-left,
.anticon-align-right {
position: absolute;
top: 30%;
}
.anticon-align-left {
left: 25%;
}
.anticon-align-right {
right: 25%;
}
}
}
|
|
2131
2132
2133
2134
2135
2136
|
}
}
.thead {
overflow-y: scroll;
|
|
2137
|
overflow-x: hidden;
|
|
2138
2139
|
border-bottom: @border;
|
|
2140
|
/** 隐藏thead的滑块 */
|
|
2141
|
|
|
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
|
&::-webkit-scrollbar-thumb {
box-shadow: none !important;
background-color: transparent !important;
}
.tr {
min-width: 100%;
overflow-y: scroll;
}
|
|
2152
|
.td {
|
|
2153
|
/*flex: 1;*/
|
|
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
|
padding: 8px @spacing;
justify-content: center;
}
}
.tbody {
position: relative;
top: 0;
left: 0;
overflow-x: hidden;
|
|
2165
|
overflow-y: hidden;
|
|
2166
|
min-height: 61px;
|
|
2167
2168
|
/*max-height: 400px;*/
min-width: 100%;
|
|
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
|
.tr-nodata {
color: #999;
line-height: 61px;
text-align: center;
}
.tr {
/*line-height: 50px;*/
border-bottom: @border;
transition: background-color 300ms;
width: 100%;
position: absolute;
left: 0;
z-index: 10;
&.tr-checked {
background-color: #fafafa;
}
&:hover {
background-color: #E6F7FF;
}
}
.tr-expand {
position: relative;
z-index: 9;
background-color: white;
}
.td {
|
|
2203
|
/*flex: 1;*/
|
|
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
|
padding: 14px 0 14px @spacing;
justify-content: center;
&:last-child {
padding-right: @spacing;
}
input {
font-variant: tabular-nums;
box-sizing: border-box;
margin: 0;
list-style: none;
position: relative;
display: inline-block;
padding: 4px 11px;
width: 100%;
height: 32px;
font-size: 14px;
line-height: 1.5;
color: rgba(0, 0, 0, 0.65);
background-color: #fff;
border: 1px solid #d9d9d9;
border-radius: 4px;
transition: all 0.3s;
outline: none;
&:hover {
border-color: #4D90FE
}
&:focus {
border-color: #40a9ff;
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
border-right-width: 1px !important;
}
&:disabled {
color: rgba(0, 0, 0, 0.25);
background: #f5f5f5;
cursor: not-allowed;
}
/* 设置placeholder的颜色 */
|
|
2247
|
|
|
2248
2249
2250
|
&::-webkit-input-placeholder { /* WebKit browsers */
color: #ccc;
}
|
|
2251
|
|
|
2252
2253
2254
|
&:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #ccc;
}
|
|
2255
|
|
|
2256
2257
2258
|
&::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #ccc;
}
|
|
2259
|
|
|
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
|
&:-ms-input-placeholder { /* Internet Explorer 10+ */
color: #ccc;
}
}
}
}
|
|
2270
2271
2272
2273
2274
2275
2276
2277
|
.scroll-view {
overflow: auto;
overflow-y: scroll;
}
.thead, .thead .tr, .scroll-view {
@scrollBarSize: 6px;
/* 定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
|
|
2278
|
|
|
2279
2280
2281
2282
2283
|
&::-webkit-scrollbar {
width: @scrollBarSize;
height: @scrollBarSize;
background-color: transparent;
}
|
|
2284
|
|
|
2285
|
/* 定义滚动条轨道 */
|
|
2286
|
|
|
2287
2288
2289
|
&::-webkit-scrollbar-track {
background-color: #f0f0f0;
}
|
|
2290
|
|
|
2291
|
/* 定义滑块 */
|
|
2292
|
|
|
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
|
&::-webkit-scrollbar-thumb {
background-color: #eee;
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
&:hover {
background-color: #bbb;
}
&:active {
background-color: #888;
}
}
}
.thead .tr {
&::-webkit-scrollbar-track {
background-color: transparent;
}
/* IE模式下隐藏 */
-ms-overflow-style: none;
-ms-scroll-chaining: chained;
-ms-content-zooming: zoom;
-ms-scroll-rails: none;
-ms-content-zoom-limit-min: 100%;
-ms-content-zoom-limit-max: 500%;
-ms-scroll-snap-type: proximity;
-ms-scroll-snap-points-x: snapList(100%, 200%, 300%, 400%, 500%);
}
|
|
2325
2326
2327
|
}
</style>
|