ol-base-components 0.1.7 → 0.2.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol-base-components",
3
- "version": "0.1.7",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "main": "src/package/index.js",
6
6
  "scripts": {
@@ -0,0 +1,7 @@
1
+ import OlFormSearch from "./src/formSearch.vue";
2
+
3
+ OlFormSearch.install = function (Vue) {
4
+ Vue.component("ol-formSearch ", OlFormSearch );
5
+ };
6
+
7
+ export default OlFormSearch;
@@ -0,0 +1,610 @@
1
+ <template>
2
+ <div class="formSearch formSearchArrowUp">
3
+ <div
4
+ v-if="
5
+ formSearchData.tableSearch && formSearchData.tableSearch.length >= 0
6
+ "
7
+ class="table-header"
8
+ >
9
+ <el-form
10
+ ref="formSearch"
11
+ size="small"
12
+ :rules="formSearchData.rules"
13
+ :model="formSearch"
14
+ :inline="true"
15
+ label-position="right"
16
+ v-bind="{
17
+ ...(formSearchData.options && formSearchData.options.formProps),
18
+ }"
19
+ >
20
+ <!-- 'label-width': '100px', -->
21
+ <div
22
+ class="transitionGroup"
23
+ :class="[
24
+ formSearchData.expendShow
25
+ ? 'formSearchBtnArrowDowns'
26
+ : 'formSearchBtnArrowUps',
27
+ ]"
28
+ >
29
+ <el-form-item
30
+ v-for="item in findTableSearch"
31
+ v-show="!item.show"
32
+ :key="item.value"
33
+ class="table-header-item"
34
+ :label="item.label"
35
+ :prop="item.value"
36
+ v-bind="item.labelProps || {}"
37
+ :class="{
38
+ picker: item.props && item.props.type === 'datetimerange',
39
+ date: item.props && item.props.type === 'date',
40
+ }"
41
+ >
42
+ <!-- <template v-if="item.inputType === 'treeSelect'">
43
+ <slot name="treeSlot"></slot>
44
+ </template> -->
45
+ <Tree-select
46
+ v-if="item.inputType === 'treeSelect'"
47
+ ref="TreeSelectref"
48
+ v-model="formSearch[item.value]"
49
+ v-bind="item.props || {}"
50
+ :options="item.children"
51
+ @getValue="item.change && item.change(formSearch[item.value])"
52
+ />
53
+
54
+ <el-select
55
+ v-else-if="item.inputType === 'select'"
56
+ v-model="formSearch[item.value]"
57
+ v-el-select-all="item.loadmores"
58
+ :clearable="item.clearable === undefined || item.clearable"
59
+ v-bind="item.props || {}"
60
+ :placeholder="`请选择${item.placeholder || item.label}`"
61
+ :popper-append-to-body="false"
62
+ @change="item.change && item.change(formSearch[item.value])"
63
+ @keyup.enter.native="handleSearch('formSearch')"
64
+ >
65
+ <el-option
66
+ v-for="option in item.children"
67
+ :key="option.key"
68
+ :label="option.value"
69
+ :value="option.key"
70
+ />
71
+ </el-select>
72
+ <!-- v-bind="item.props || {}" -->
73
+ <el-select
74
+ v-else-if="item.inputType === 'selectTEMP'"
75
+ v-model="formSearch[item.value]"
76
+ v-el-select-all="item.loadmores"
77
+ v-bind="{ clearable: true, ...(item.props || {}) }"
78
+ :placeholder="`请选择${item.placeholder || item.label}`"
79
+ :popper-append-to-body="false"
80
+ @change="item.change && item.change(formSearch[item.value])"
81
+ @keyup.enter.native="handleSearch('formSearch')"
82
+ >
83
+ <el-option
84
+ v-for="option in item.children"
85
+ :key="option.key"
86
+ :label="option.value"
87
+ :value="option.key"
88
+ />
89
+ </el-select>
90
+ <el-select
91
+ v-else-if="item.inputType === 'selectRemoteMethod'"
92
+ v-model="formSearch[item.value]"
93
+ v-el-select-all="item.loadmores"
94
+ filterable
95
+ remote
96
+ clearable
97
+ reserve-keyword
98
+ :placeholder="`请输入至少3位关键字`"
99
+ :remote-method="item.remoteMethod"
100
+ :loading="item.loading"
101
+ >
102
+ <el-option
103
+ v-for="option in item.children"
104
+ :key="option.key"
105
+ :label="option.value"
106
+ :value="option.key"
107
+ />
108
+ </el-select>
109
+ <el-date-picker
110
+ v-else-if="item.inputType === 'picker'"
111
+ v-model="formSearch[item.value]"
112
+ clearable
113
+ style="width: 100%"
114
+ :placeholder="item.props.placeholder || '选择日期'"
115
+ v-bind="item.props || { type: 'date' }"
116
+ :default-time="
117
+ item.props.type == 'datetimerange'
118
+ ? ['00:00:00', '23:59:59']
119
+ : ''
120
+ "
121
+ />
122
+ <el-input
123
+ v-else
124
+ v-model="formSearch[item.value]"
125
+ clearable
126
+ v-bind="item.props || {}"
127
+ :type="item.inputType || 'text'"
128
+ :placeholder="`请输入${item.placeholder || item.label}`"
129
+ :maxlength="item.maxlength"
130
+ :oninput="handleChangeInput(item)"
131
+ :class="item.inputType == 'number' ? 'numrule' : ''"
132
+ @keyup.enter.native="handleSearch('formSearch')"
133
+ @keydown.native="keyInput(item, $event)"
134
+ @paste.native="onPaste(item, $event)"
135
+ />
136
+ </el-form-item>
137
+ </div>
138
+ <el-form-item
139
+ style="word-break: keep-all; white-space: nowrap; margin-left: 10px"
140
+ class="fromBtn"
141
+ :class="[
142
+ formSearchData.expendShow
143
+ ? 'formSearchBtnArrowDown'
144
+ : 'formSearchBtnArrowUp',
145
+ ]"
146
+ >
147
+ <el-button
148
+ v-if="formSearchData.reset"
149
+ size="small"
150
+ type="primary"
151
+ @click="handleSearch('formSearch')"
152
+ >查询
153
+ </el-button>
154
+ <el-button
155
+ v-if="formSearchData.reset"
156
+ plain
157
+ size="small"
158
+ @click="handleReset('formSearch')"
159
+ >重置</el-button
160
+ >
161
+ <el-button
162
+ v-if="formSearchData.expendShow"
163
+ plain
164
+ size="small"
165
+ :icon="expend ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
166
+ @click="handleExpend('formSearch')"
167
+ >
168
+ {{ expend ? "收起" : "展开" }}</el-button
169
+ >
170
+ </el-form-item>
171
+ </el-form>
172
+ </div>
173
+
174
+ <!-- <div class="btnbox">
175
+ <el-form class="demo-form-inline">
176
+ <el-form-item>
177
+ <el-button
178
+ v-for="(btn, index) in btnlist"
179
+ :key="index"
180
+ size="small"
181
+ :type="btn.types ? btn.types : 'primary'"
182
+ @click="btn.method"
183
+ >{{ btn.title }}</el-button
184
+ >
185
+ </el-form-item>
186
+ </el-form>
187
+ </div> -->
188
+ </div>
189
+ </template>
190
+
191
+ <script>
192
+ export default {
193
+ name: "FormSearch",
194
+ directives: {
195
+ "el-select-loadmore": {
196
+ bind(el, binding) {
197
+ // 获取element-ui定义好的scroll盒子
198
+ const SELECTWRAP_DOM = el.querySelector(
199
+ ".el-select-dropdown .el-select-dropdown__wrap"
200
+ );
201
+ SELECTWRAP_DOM.addEventListener("scroll", function () {
202
+ /**
203
+ * scrollHeight 获取元素内容高度(只读)
204
+ * scrollTop 获取或者设置元素的偏移值,常用于, 计算滚动条的位置, 当一个元素的容器没有产生垂直方向的滚动条, 那它的scrollTop的值默认为0.
205
+ * clientHeight 读取元素的可见高度(只读)
206
+ * 如果元素滚动到底, 下面等式返回true, 没有则返回false:
207
+ * ele.scrollHeight - ele.scrollTop === ele.clientHeight;
208
+ */
209
+ const condition =
210
+ this.scrollHeight - this.scrollTop <= this.clientHeight;
211
+ if (condition > 0 && condition < 2) {
212
+ binding.value();
213
+ }
214
+ });
215
+ },
216
+ },
217
+ "el-select-all": {
218
+ bind(el, binding, vnode) {
219
+ // console.log(binding.value)
220
+ const _that = vnode.context; // 当前vue对象
221
+ const SELECTWRAP_DOM = el.querySelector(
222
+ ".el-select-dropdown .el-select-dropdown__wrap"
223
+ );
224
+ SELECTWRAP_DOM.addEventListener("scroll", function () {
225
+ // console.log(SELECTWRAP_DOM.scrollHeight) // 文档内容的实际高度
226
+ // console.log(SELECTWRAP_DOM.scrollTop) // 滚动条滚动高度
227
+ // console.log(SELECTWRAP_DOM.clientHeight) // 可视窗口高度
228
+ // CONDITION //滚动条到底了
229
+ const CONDITION =
230
+ SELECTWRAP_DOM.scrollHeight - SELECTWRAP_DOM.scrollTop - 2 <=
231
+ SELECTWRAP_DOM.clientHeight;
232
+ if (CONDITION) {
233
+ binding.value.SELECTWRAP_DOM_index += 10;
234
+ binding.value.fn();
235
+ }
236
+ });
237
+ },
238
+ unbind(el, binding, vnode) {
239
+ // 解除事件监听
240
+ const _that = vnode.context; // 当前vue对象
241
+ const SELECTWRAP_DOM = el.querySelector(
242
+ ".el-select-dropdown .el-select-dropdown__wrap"
243
+ );
244
+ if (SELECTWRAP_DOM) {
245
+ SELECTWRAP_DOM.removeEventListener("scroll", function () {
246
+ binding.value.SELECTWRAP_DOM_index = 0;
247
+ });
248
+ }
249
+ },
250
+ },
251
+ },
252
+ props: {
253
+ formSearchData: {
254
+ type: Object,
255
+ default: () => {
256
+ return {
257
+ buttonData: [],
258
+ rules: {},
259
+ value: {},
260
+ tableSearchSlice: 4, // 默认为展开4当出现特色情况可以自行设置
261
+ // 循环的各种组件
262
+ tableSearch: [],
263
+ // 表格框架各种样式
264
+ options: {},
265
+ reset: false, // 是否要重置
266
+ };
267
+ },
268
+ },
269
+ // btnlist: Array,
270
+ tableSearchSlice: {
271
+ type: Number,
272
+ default: 4,
273
+ },
274
+ tableSearch: {
275
+ type: Array,
276
+ },
277
+ rulesLength: {
278
+ type: Boolean,
279
+ },
280
+ },
281
+ data() {
282
+ return {
283
+ findTableSearch:
284
+ this.formSearchData.tableSearch.length > this.tableSearchSlice
285
+ ? this.formSearchData.tableSearch.slice(0, this.tableSearchSlice)
286
+ : this.formSearchData.tableSearch,
287
+ expend: !this.formSearchData.expendShow,
288
+ formSearch: {
289
+ ...this.formSearchData.value,
290
+ },
291
+ // 自定义指令
292
+ loadmores: {
293
+ fn: this.loadmoreGX,
294
+ SELECTWRAP_DOM_index: 0,
295
+ flage: null,
296
+ },
297
+ tempBoxData: [],
298
+ optionBox: [],
299
+ };
300
+ },
301
+ watch: {
302
+ "formSearchData.value": {
303
+ handler: function (newVal, OldVal) {
304
+ if (newVal) {
305
+ console.log(newVal, "newVal");
306
+ return (this.formSearch = {
307
+ ...newVal,
308
+ });
309
+ // return (this.findTableSearch = { ...newVal });
310
+ }
311
+ },
312
+ deep: true,
313
+ },
314
+ },
315
+ methods: {
316
+ // 树形下拉
317
+ getValue(val) {
318
+ this.$emit("getTreeSelectValue", val);
319
+ },
320
+ // 搜索查询按钮
321
+ handleSearch(formName, item) {
322
+ if (this.formSearchData.rules) {
323
+ return this.$refs[formName].validate((valid) => {
324
+ if (!valid) return false;
325
+
326
+ this.$emit("handleSearch", Object.assign({}, this.formSearch), item);
327
+ });
328
+ }
329
+ this.$emit("handleSearch", Object.assign({}, this.formSearch), item);
330
+ },
331
+ loadmore(obj) {
332
+ this.$emit("loadmore", obj);
333
+ },
334
+ // 搜索重置按钮
335
+ handleReset(formName) {
336
+ this.$refs[formName].resetFields();
337
+ if (this.formSearchData.reset) {
338
+ for (const key in this.formSearch) {
339
+ if (
340
+ Object.prototype.toString.call(this.formSearch[key]) ===
341
+ "[object String]"
342
+ ) {
343
+ this.formSearch[key] = null;
344
+ } else if (
345
+ Object.prototype.toString.call(this.formSearch[key]) ===
346
+ "[object Array]"
347
+ ) {
348
+ this.formSearch[key] = [];
349
+ } else if (
350
+ Object.prototype.toString.call(this.formSearch[key]) ===
351
+ "[object Object]"
352
+ ) {
353
+ this.formSearch[key] = {};
354
+ } else if (
355
+ Object.prototype.toString.call(this.formSearch[key]) ===
356
+ "[object Boolean]"
357
+ ) {
358
+ this.formSearch[key] = false;
359
+ } else {
360
+ this.formSearch[key] = null;
361
+ }
362
+ }
363
+ } else {
364
+ this.formSearch = {
365
+ ...this.formSearchData.value,
366
+ };
367
+ }
368
+ this.$emit("handleReset", this.formSearch);
369
+ if (this.formSearchData.reset) return false;
370
+ this.handleSearch();
371
+ },
372
+ // 展开和收起
373
+ handleExpend() {
374
+ this.expend = !this.expend; // 展开和收起
375
+ this.findTableSearch = this.expend
376
+ ? this.formSearchData.tableSearch.slice(
377
+ 0,
378
+ this.formSearchData.tableSearch.length
379
+ )
380
+ : this.formSearchData.tableSearch.slice(0, this.tableSearchSlice);
381
+
382
+ this.$emit("btnHandleExpend", this.expend);
383
+ },
384
+ // input为number校验
385
+ handleChangeInput(item) {
386
+ return item.inputType === "number"
387
+ ? this.handleOnInput(this.formSearch[item.value], item.value, item.max)
388
+ : null;
389
+ },
390
+ keyInput(item, e) {
391
+ if (item.inputType === "number") {
392
+ let key = e.key;
393
+ if (
394
+ key === "e" ||
395
+ key === "E" ||
396
+ key === "-" ||
397
+ key === "+" ||
398
+ key === "."
399
+ ) {
400
+ e.returnValue = false;
401
+ return false;
402
+ }
403
+ return true;
404
+ }
405
+ },
406
+ // 输入框的粘贴事件
407
+ onPaste(item, e) {
408
+ if (item.inputType === "number") {
409
+ const pastedText = e.clipboardData.getData("text");
410
+ const nonNumericPattern = /[^\d]/g;
411
+ if (nonNumericPattern.test(pastedText)) {
412
+ e.preventDefault();
413
+ }
414
+ }
415
+ },
416
+ // input渲染长度校验
417
+ handleOnInput(val, label, max) {
418
+ if (val && Number(val) <= 0) {
419
+ this.formSearch[label] = 0;
420
+ }
421
+ if (val && Number(val) > max) {
422
+ this.formSearch[label] = max;
423
+ }
424
+ },
425
+ },
426
+ };
427
+ </script>
428
+
429
+ <style lang="scss" scoped>
430
+ .formSearch {
431
+ .el-form-item {
432
+ // width: 21%;
433
+ margin-right: 2px;
434
+ margin-bottom: 5px;
435
+
436
+ ::v-deep .el-form-item__label {
437
+ width: 37% !important;
438
+ padding: 0 5px 0 0;
439
+ word-break: keep-all;
440
+ white-space: nowrap;
441
+ font-size: 13px;
442
+ }
443
+
444
+ ::v-deep .el-form-item__content {
445
+ width: 63% !important;
446
+ }
447
+ }
448
+
449
+ ::v-deep .el-select {
450
+ width: 100% !important;
451
+ }
452
+
453
+ ::v-deep .picker {
454
+ }
455
+
456
+ .formSearchBtnArrowUp {
457
+ // width: 12%;
458
+ ::v-deep .el-form-item__content {
459
+ width: 130px !important;
460
+ }
461
+ }
462
+ }
463
+
464
+ .formSearchArrowUp {
465
+ // height: auto;
466
+ // overflow: hidden;
467
+
468
+ .el-form {
469
+ position: relative;
470
+ }
471
+
472
+ .formSearchBtnArrowDown {
473
+ position: absolute;
474
+ top: 0px;
475
+ width: 15%;
476
+ left: 81.5%;
477
+
478
+ ::v-deep .el-form-item__content {
479
+ width: 100% !important;
480
+
481
+ ::v-deep .el-button {
482
+ // width: 30.3%;
483
+ padding: 7px;
484
+ margin-left: 0px;
485
+ font-size: 13px;
486
+ padding: 5px 10px;
487
+ }
488
+ }
489
+ }
490
+ }
491
+
492
+ .table-header {
493
+ padding-top: 10px;
494
+ border-bottom: 1px #ccc solid;
495
+
496
+ ::v-deep .table-header-item {
497
+ }
498
+
499
+ .table-header-item .el-form-item {
500
+ width: 100%;
501
+ display: flex;
502
+ margin-bottom: 12px;
503
+
504
+ .el-form-item__content,
505
+ .el-select {
506
+ width: 100%;
507
+ }
508
+ }
509
+ }
510
+
511
+ .transitionGroup {
512
+ display: flex;
513
+ flex-wrap: wrap;
514
+
515
+ .el-form-item {
516
+ width: calc(100% / 5);
517
+ }
518
+
519
+ .picker {
520
+ width: 25%;
521
+
522
+ ::v-deep .el-form-item__label {
523
+ width: 27% !important;
524
+ padding: 0 5px 0 0;
525
+ word-break: break-all;
526
+ white-space: nowrap;
527
+ }
528
+
529
+ ::v-deep .el-form-item__content {
530
+ width: 73% !important;
531
+ height: 28px;
532
+ }
533
+ }
534
+ }
535
+
536
+ .formSearchBtnArrowDowns {
537
+ .el-form-item {
538
+ width: 20%;
539
+ }
540
+ }
541
+
542
+ .formSearchBtnArrowUps {
543
+ display: inline;
544
+ }
545
+
546
+ .list-enter-active,
547
+ .list-leave-active {
548
+ transition: all 1s;
549
+ }
550
+
551
+ .list-enter {
552
+ opacity: 0;
553
+ transform: translateX(-30px);
554
+ }
555
+
556
+ .list-leave-to {
557
+ opacity: 0;
558
+ transform: translateX(30px);
559
+ }
560
+
561
+ ::v-deep .el-select-dropdown__item.hover {
562
+ background-color: #eff7ff !important;
563
+ }
564
+
565
+ ::v-deep .el-select-dropdown__item:hover {
566
+ background-color: #eff7ff !important;
567
+ }
568
+
569
+ ::v-deep .el-input.is-disabled {
570
+ ::v-deep .el-input__inner {
571
+ background-color: #eceff8;
572
+ border-color: #eceff8;
573
+ }
574
+ }
575
+
576
+ ::v-deep .el-input--small {
577
+ ::v-deep .el-input__inner {
578
+ height: 28px;
579
+ line-height: 28px;
580
+ }
581
+ }
582
+
583
+ .fromBtn {
584
+ ::v-deep .el-button {
585
+ // padding: 7px;
586
+ font-size: 12px;
587
+ }
588
+ }
589
+
590
+ .btnbox {
591
+ .upload-demo {
592
+ display: -webkit-inline-box;
593
+ margin-left: 10px;
594
+ }
595
+
596
+ padding: 10px;
597
+ }
598
+ //解决type=number的上下箭头
599
+ ::v-deep .numrule input::-webkit-outer-spin-button,
600
+ ::v-deep .numrule input::-webkit-inner-spin-button {
601
+ -webkit-appearance: none !important;
602
+ }
603
+ ::v-deep .numrule input[type="number"] {
604
+ -moz-appearance: textfield !important;
605
+ }
606
+ // 解决type=number输入中文后光标上移的问题
607
+ ::v-deep .numrule .el-input__inner {
608
+ line-height: 1px !important;
609
+ }
610
+ </style>
@@ -1,6 +1,7 @@
1
1
  import OlTable from "./table";
2
+ import OlFormSearch from "./src/formSearch.vue";
2
3
 
3
- const components = [OlTable];
4
+ const components = [OlTable, OlFormSearch];
4
5
 
5
6
  const install = function (Vue) {
6
7
  // 遍历所有组件