ol-base-components 0.1.2

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,569 @@
1
+ <template>
2
+ <div class="table_list_fix">
3
+ <!-- 扩展性内容 -->
4
+ <slot name="content_context" />
5
+ <template
6
+ v-if="
7
+ btnlist.length ||
8
+ tableData.options.headTool ||
9
+ tableData.options.refreshBtn ||
10
+ tableData.options.downloadBtn
11
+ "
12
+ >
13
+ <div v-if="showBtnBox" class="btnbox">
14
+ <!-- 左侧按钮 -->
15
+ <div>
16
+ <el-button
17
+ v-for="(btn, index) in btnlist"
18
+ :key="index"
19
+ size="small"
20
+ :type="btn.types ? btn.types : 'primary'"
21
+ @click="btn.method"
22
+ >
23
+ <i v-if="btn.icon" :class="btn.icon" />
24
+ {{ btn.title }}
25
+ </el-button>
26
+ </div>
27
+ <!-- 右侧工具按钮 -->
28
+ <div class="toolbox">
29
+ <el-dropdown
30
+ v-if="tableData.options.headTool"
31
+ class="avatar-container right-menu-item hover-effect"
32
+ trigger="click"
33
+ >
34
+ <div class="avatar-wrapper">
35
+ <div class="layui-table-tool-self">
36
+ <i class="el-icon-s-operation" />
37
+ </div>
38
+ </div>
39
+ <el-dropdown-menu slot="dropdown" style="padding: 5px">
40
+ <el-checkbox-group v-model="checkedTableColumns">
41
+ <el-checkbox
42
+ v-for="column in checkedTableList"
43
+ :key="column.prop"
44
+ class="checkbox"
45
+ :label="column.prop"
46
+ >{{ column.label }}
47
+ </el-checkbox>
48
+ </el-checkbox-group>
49
+ </el-dropdown-menu>
50
+ </el-dropdown>
51
+ <div
52
+ v-if="tableData.options.refreshBtn"
53
+ class="avatar-container right-menu-item hover-effect el-dropdown"
54
+ @click="refreshTable"
55
+ >
56
+ <div class="avatar-wrapper">
57
+ <div class="layui-table-tool-self">
58
+ <i class="el-icon-refresh" />
59
+ </div>
60
+ </div>
61
+ </div>
62
+ <div
63
+ v-if="tableData.options.downloadBtn"
64
+ class="avatar-container right-menu-item hover-effect el-dropdown"
65
+ @click="printTable"
66
+ >
67
+ <div class="avatar-wrapper">
68
+ <div class="layui-table-tool-self">
69
+ <i class="el-icon-printer" />
70
+ </div>
71
+ </div>
72
+ </div>
73
+ </div>
74
+ </div>
75
+ </template>
76
+
77
+ <!-- 表格 -->
78
+ <div class="tablebox">
79
+ <el-table
80
+ :ref="tableRef"
81
+ v-loading="tableData.loading"
82
+ border
83
+ v-bind="tableData.options"
84
+ :data="tableData.rows"
85
+ style="width: 100%"
86
+ height="100%"
87
+ :default-sort="tableData.sort"
88
+ v-on="tableEvents"
89
+ @selection-change="SelectionChange"
90
+ @select="select"
91
+ @select-all="selectAll"
92
+ @row-click="rowClick"
93
+ >
94
+ <el-table-column
95
+ v-if="tableData.options && tableData.options.index"
96
+ width="60"
97
+ align="center"
98
+ type="index"
99
+ :index="computeTableIndex"
100
+ label="序号"
101
+ />
102
+ <template v-for="(item, index) in bindTableColumns">
103
+ <el-table-column
104
+ :key="index"
105
+ :label="item.label"
106
+ :prop="item.prop"
107
+ :min-width="item.minWidth || '150px'"
108
+ :show-overflow-tooltip="item.overHidden || true"
109
+ :type="item.type || 'normal'"
110
+ v-bind="{
111
+ align: 'center',
112
+ width: item.width,
113
+ fixed: item.fixed || false,
114
+ sortable: item.sortable || false,
115
+ ...item.attrs,
116
+ }"
117
+ >
118
+ <template v-slot:header>
119
+ <el-tooltip
120
+ :content="`${item.label} ${item.prop}`"
121
+ placement="top"
122
+ >
123
+ <span>{{ item.label }}</span>
124
+ </el-tooltip>
125
+ </template>
126
+ <template v-if="item.render" v-slot="scope">
127
+ <!-- 使用函数式组件进行dom渲染 -->
128
+ <render-dom :render="() => item.render(scope.row)" />
129
+ </template>
130
+ <template v-else-if="item.renderSlot" v-slot="scope">
131
+ <slot :row="scope.row" :name="item.prop" />
132
+ </template>
133
+ </el-table-column>
134
+ </template>
135
+ <el-table-column
136
+ v-if="tableData.operates && tableData.operates.length > 0"
137
+ label="操作"
138
+ align="center"
139
+ v-bind="tableData.operatesAttrs"
140
+ >
141
+ <template slot-scope="scope">
142
+ <div class="operate-group">
143
+ <template v-for="(btn, key) in tableData.operates">
144
+ <span
145
+ v-if="
146
+ !btn.isShow ||
147
+ (btn.isShow && btn.isShow(scope.row, scope.$index))
148
+ "
149
+ :key="key"
150
+ >
151
+ <el-button
152
+ :style="btn.style || ''"
153
+ :size="btn.size || 'small'"
154
+ :type="btn.type || `text`"
155
+ :icon="btn.icon"
156
+ :plain="btn.plain"
157
+ :disabled="
158
+ btn.disabled && btn.disabled(scope.row, scope.$index)
159
+ "
160
+ @click.stop="btn.method(scope.row, scope.$index)"
161
+ >{{ btn.label
162
+ }}{{
163
+ tableData.operates.length >= 2 ? "&nbsp;&nbsp;" : ""
164
+ }}</el-button
165
+ >
166
+ </span>
167
+ </template>
168
+ </div> </template
169
+
170
+ </el-table-column>
171
+ <div slot="empty" class="empty">
172
+ <img v-if="tableData.rows.length == 0" src="@/assets/nodata.jpg" />
173
+ </div>
174
+ </el-table>
175
+ </div>
176
+ <!-- 分页 -->
177
+ <div class="pagebox">
178
+ <el-row>
179
+ <el-col :span="24">
180
+ <el-pagination
181
+ v-if="paginations.pagetionShow && paginations.total > 0"
182
+ :current-page.sync="paginations.page"
183
+ :page-sizes="paginations.page_sizes || pageSizes"
184
+ :page-size="paginations.limit"
185
+ layout="total, sizes, prev, pager, next, jumper,slot"
186
+ :total="paginations.total"
187
+ @size-change="handleSizeChange"
188
+ @current-change="handleindexChange"
189
+ >
190
+ <div
191
+ v-if="paginations.refresh"
192
+ :key="1"
193
+ class="avatar-container right-menu-item hover-effect el-dropdown"
194
+ style="margin-left: 10px"
195
+ @click="refreshTableBTN"
196
+ >
197
+ <div class="avatar-wrapper">
198
+ <div class="layui-table-tool-self">
199
+ <i class="el-icon-refresh" />
200
+ </div>
201
+ </div>
202
+ </div>
203
+ </el-pagination>
204
+ </el-col>
205
+ </el-row>
206
+ </div>
207
+ <printTemplate
208
+ v-show="false"
209
+ class="printTemplate"
210
+ :print-list-obj="printListObj"
211
+ />
212
+ </div>
213
+ </template>
214
+ <script>
215
+ import printTemplate from "./printTable.vue";
216
+
217
+ export default {
218
+ components: {
219
+ printTemplate,
220
+ // 函数式组件注册
221
+ renderDom: {
222
+ functional: true,
223
+ props: {
224
+ render: Function,
225
+ },
226
+ render(createElement, renDom) {
227
+ return <div>{renDom.props.render()}</div>;
228
+ },
229
+ },
230
+ },
231
+ model: {
232
+ prop: "multipleSelection",
233
+ event: "SelectionChange",
234
+ },
235
+ props: {
236
+ printListObj: {
237
+ type: Object,
238
+ default: () => {
239
+ return {
240
+ title: "",
241
+ tableHeader: "",
242
+ tableData: "",
243
+ };
244
+ },
245
+ }, // 打印参数
246
+ btnlist: Array,
247
+ outTable: {
248
+ type: Object,
249
+ default: () => {
250
+ return {
251
+ tableProp: {},
252
+ };
253
+ },
254
+ },
255
+ // exportBut: {
256
+ // type: Array,
257
+ // default: [],
258
+ // },
259
+ // 表格传的形式
260
+ tableData: {
261
+ type: Object,
262
+ default: () => {
263
+ return {
264
+ loading: false,
265
+ options: {
266
+ selection: null, // 多选框
267
+ index: null, // 序号
268
+ headTool: true, // 开启头部工具栏
269
+ refreshBtn: true, // 开启表格头部刷新按钮
270
+ downloadBtn: true, // 开启表格头部下载按钮
271
+ }, // 序号和复选框
272
+ rows: [], // 表数据
273
+ columns: [], // 表头
274
+ operates: [], // 表格里面的操作按钮
275
+ // tableHeightDiff: 300,
276
+ operatesAttrs: {},
277
+ };
278
+ },
279
+ },
280
+ tableDataShow: {
281
+ type: Boolean,
282
+ default: true,
283
+ },
284
+ displayDetail: {
285
+ type: Boolean,
286
+ default: true,
287
+ },
288
+ pageSizes: {
289
+ type: Array,
290
+ default: () => {
291
+ return [20, 30, 40, 60, 100, 200];
292
+ },
293
+ },
294
+ paginations: {
295
+ // 显示复选框,
296
+ type: Object,
297
+ default: () => {
298
+ return {
299
+ page: 1, // 当前位于那页面
300
+ total: 0, // 总数
301
+ limit: 30, // 一页显示多少条
302
+ pagetionShow: true,
303
+ };
304
+ },
305
+ },
306
+ emptyImg: {
307
+ // 显示复选框,
308
+ type: Boolean,
309
+ default: false,
310
+ },
311
+ tableEvents: Object,
312
+ showBtnBox: {
313
+ type: Boolean,
314
+ default: true,
315
+ },
316
+ },
317
+ data() {
318
+ return {
319
+ tableRef: this.tableData.tableRef || "tableRef", // ref
320
+ toggleRowFlage: this.tableData.toggleRowFlage || false, // 点击行高亮select标识
321
+ // screenWidth: 0,
322
+ // tableHeight:
323
+ // document.documentElement.clientHeight - this.tableData.tableHeightDiff,
324
+ pagetionShow: this.paginations.pagetionShow || true,
325
+ twinPage: 1,
326
+ };
327
+ },
328
+ computed: {
329
+ bindTableColumns() {
330
+ return this.tableData.columns.filter((column) =>
331
+ Object.keys(column).includes("show") ? column.show : true
332
+ );
333
+ },
334
+ checkedTableList: {
335
+ get() {
336
+ // 返回选中的列名
337
+ return this.tableData.columns.filter(
338
+ (item) => item.type != "selection"
339
+ );
340
+ },
341
+ },
342
+ /* 这里使用了getter和setter,这样写的好处不用自己手动监听复选框的选中事件 */
343
+ checkedTableColumns: {
344
+ get() {
345
+ // 返回选中的列名
346
+ return this.bindTableColumns.map((column) => column.prop);
347
+ },
348
+ set(checked) {
349
+ // 设置表格列的显示与隐藏
350
+ this.tableData.columns.forEach((column) => {
351
+ // 如果选中,则设置列显示
352
+ if (checked.includes(column.prop)) {
353
+ this.$set(column, "show", true);
354
+ } else {
355
+ // 如果未选中,则设置列隐藏
356
+ this.$set(column, "show", false);
357
+ }
358
+ });
359
+ },
360
+ },
361
+ },
362
+ watch: {
363
+ displayDetail: {
364
+ handler() {
365
+ this.$nextTick(() => {
366
+ this.$refs[this.tableRef].doLayout();
367
+ });
368
+ },
369
+ deep: true,
370
+ },
371
+ },
372
+ methods: {
373
+ radioChange() {
374
+ this.$emit("radioChange", this.twinPage);
375
+ },
376
+ // 刷新表格
377
+ refreshTable() {
378
+ const view = this.$router.history.current;
379
+ this.$store.dispatch("tagsView/delCachedView", view).then(() => {
380
+ const { fullPath } = view;
381
+ this.$nextTick(() => {
382
+ this.$router.replace({
383
+ path: "/redirect" + fullPath,
384
+ });
385
+ });
386
+ });
387
+ this.$emit("refreshTable");
388
+ },
389
+ printTable() {
390
+ console.log("printTable");
391
+ if (this.tableData.rows.length <= 0) return;
392
+ this.printListObj.title = this.$router.history.current.name;
393
+ this.printListObj.tableHeader = this.tableData.columns;
394
+ this.printListObj.tableData = this.tableData.rows;
395
+ console.log(this.printListObj);
396
+ setTimeout(() => {
397
+ $(".printTemplate").show();
398
+ $(".printTemplate").jqprint();
399
+ $(".printTemplate").hide();
400
+ }, 50);
401
+ this.$emit("printTable");
402
+ },
403
+ selectAll(val) {
404
+ this.$emit("selectAll", val);
405
+ },
406
+ select(val, row) {
407
+ this.$emit("selectTab", val, row);
408
+ },
409
+ refreshTableBTN() {
410
+ this.$emit("refreshTableBTN");
411
+ },
412
+ rowClick(row, column) {
413
+ if (column.label === "操作") return; // 操作列不处罚行点击事件
414
+ this.$emit("rowClick", row);
415
+ if (
416
+ this.tableData.columns.every((item) => {
417
+ return item.label !== "是否只出样件";
418
+ })
419
+ ) {
420
+ // 为true时 点击行高亮select
421
+ this.$refs.tableRef.toggleRowSelection(row);
422
+ }
423
+ },
424
+ computeTableIndex(index) {
425
+ return (this.paginations.page - 1) * this.paginations.limit + index + 1;
426
+ },
427
+ // 挑选的数据
428
+ SelectionChange(val) {
429
+ this.multipleSelection = val;
430
+ this.$emit("SelectionChange", val);
431
+ },
432
+ // 分页选择
433
+ handleSizeChange(val) {
434
+ this.paginations.limit = val;
435
+ this.$emit("handleSizeChange", val);
436
+ },
437
+ handleindexChange(val) {
438
+ this.paginations.page = val;
439
+ this.$emit("handleindexChange", val);
440
+ },
441
+ },
442
+ };
443
+ </script>
444
+ <style lang="scss" scoped>
445
+ .table_list_fix {
446
+ overflow: auto;
447
+ flex: 1;
448
+ display: flex;
449
+ flex-direction: column;
450
+ justify-content: space-between;
451
+ padding: 10px;
452
+ gap: 10px;
453
+
454
+ ::v-deep .el-table {
455
+ td {
456
+ padding: 0px;
457
+
458
+ div {
459
+ line-height: 28px;
460
+ font-size: 12px;
461
+ }
462
+ }
463
+
464
+ th {
465
+ padding: 0px;
466
+ background: #f5f7fa;
467
+ div {
468
+ line-height: 28px;
469
+ color: #909399;
470
+ font-size: 12px;
471
+ }
472
+ }
473
+ }
474
+
475
+ .btn-operates {
476
+ margin: 10px 0px 10px 15px;
477
+
478
+ ::v-deep a {
479
+ color: #fff;
480
+ text-decoration: none;
481
+ display: inline-block;
482
+ margin: 0px 5px;
483
+ ::v-deep .el-button {
484
+ width: 100%;
485
+ padding: 7px;
486
+ font-size: 13px;
487
+ }
488
+ }
489
+ }
490
+ }
491
+
492
+ .table-header {
493
+ padding-top: 10px;
494
+
495
+ .table-header_button {
496
+ text-align: right;
497
+ float: right;
498
+ margin-bottom: 12px;
499
+ line-height: 40px;
500
+ }
501
+ }
502
+
503
+ .newjump {
504
+ text-decoration: none;
505
+ color: dodgerblue;
506
+ }
507
+
508
+ .pagination {
509
+ text-align: center;
510
+ }
511
+
512
+ .tablebox {
513
+ box-sizing: border-box;
514
+ min-height: 240px;
515
+ flex: 1;
516
+ overflow: auto;
517
+ }
518
+
519
+ ::v-deep .el-table__body tr.current-row > td {
520
+ background-color: rgb(24, 144, 255) !important;
521
+ color: #fff;
522
+ }
523
+
524
+ ::v-deep .redrow {
525
+ background: #fde6e6 !important;
526
+ }
527
+
528
+ .btnbox {
529
+ width: 100%;
530
+ display: flex;
531
+ align-items: center;
532
+ justify-content: space-between;
533
+
534
+ .upload-demo {
535
+ display: -webkit-inline-box;
536
+ margin-left: 10px;
537
+ }
538
+
539
+ .el-form-item {
540
+ margin-bottom: 0px;
541
+ }
542
+ }
543
+
544
+ .layui-table-tool-self {
545
+ display: block;
546
+ width: 26px;
547
+ height: 26px;
548
+ padding: 5px;
549
+ line-height: 16px;
550
+ text-align: center;
551
+ color: #333;
552
+ border: 1px solid #ccc;
553
+ cursor: pointer;
554
+ }
555
+
556
+ .checkbox {
557
+ display: block;
558
+ }
559
+ // 操作列按钮布局
560
+ .operate-group {
561
+ display: flex;
562
+ align-items: center;
563
+ justify-content: space-around;
564
+ }
565
+ .toolbox {
566
+ display: flex;
567
+ gap: 10px;
568
+ }
569
+ </style>