ol-base-components 3.1.3 → 3.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 +2 -1
- package/src/App.vue +350 -76
- package/src/main.js +4 -5
- package/src/package/customSearch/index.js +7 -0
- package/src/package/customSearch/src/index.vue +93 -0
- package/src/package/formSearch/index.js +1 -1
- package/src/package/formSearch/src/components/SearchConfigDialog.vue +867 -0
- package/src/package/formSearch/src/index.js +2 -0
- package/src/package/formSearch/src/index.vue +229 -97
- package/src/package/index.js +5 -2
- package/src/package/table/src/index.vue +7 -7
|
@@ -163,24 +163,25 @@
|
|
|
163
163
|
>
|
|
164
164
|
{{ expend ? "收起" : "展开" }}</el-button
|
|
165
165
|
>
|
|
166
|
+
<el-button
|
|
167
|
+
v-if="formSearchData.enableConfig"
|
|
168
|
+
plain
|
|
169
|
+
size="small"
|
|
170
|
+
icon="el-icon-setting"
|
|
171
|
+
@click="handleOpenConfig"
|
|
172
|
+
>
|
|
173
|
+
配置
|
|
174
|
+
</el-button>
|
|
166
175
|
</el-form-item>
|
|
167
176
|
</el-form>
|
|
168
177
|
</div>
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
size="small"
|
|
177
|
-
:type="btn.types ? btn.types : 'primary'"
|
|
178
|
-
@click="btn.method"
|
|
179
|
-
>{{ btn.title }}</el-button
|
|
180
|
-
>
|
|
181
|
-
</el-form-item>
|
|
182
|
-
</el-form>
|
|
183
|
-
</div> -->
|
|
178
|
+
<search-config-dialog
|
|
179
|
+
v-if="configDialogVisible"
|
|
180
|
+
:visible.sync="configDialogVisible"
|
|
181
|
+
:table-search="formSearchData.tableSearch"
|
|
182
|
+
:customs="formSearchData.customs"
|
|
183
|
+
@save="handleSaveConfig"
|
|
184
|
+
/>
|
|
184
185
|
</div>
|
|
185
186
|
</template>
|
|
186
187
|
|
|
@@ -188,11 +189,13 @@
|
|
|
188
189
|
import { getData } from "../../index.js";
|
|
189
190
|
import { getEnum } from "../../../utils/getEnum.js";
|
|
190
191
|
import OlNumberRange from "../../numberRange/index.js";
|
|
192
|
+
import SearchConfigDialog from "./components/SearchConfigDialog.vue";
|
|
191
193
|
|
|
192
194
|
export default {
|
|
193
195
|
name: "search",
|
|
194
196
|
components: {
|
|
195
197
|
OlNumberRange,
|
|
198
|
+
SearchConfigDialog,
|
|
196
199
|
},
|
|
197
200
|
directives: {
|
|
198
201
|
"el-select-loadmore": {
|
|
@@ -263,6 +266,7 @@ export default {
|
|
|
263
266
|
// 表格框架各种样式
|
|
264
267
|
options: {},
|
|
265
268
|
reset: false, // 是否要重置
|
|
269
|
+
enableConfig: false, // 是否启用配置功能
|
|
266
270
|
};
|
|
267
271
|
},
|
|
268
272
|
},
|
|
@@ -271,12 +275,6 @@ export default {
|
|
|
271
275
|
type: Number,
|
|
272
276
|
default: 4,
|
|
273
277
|
},
|
|
274
|
-
tableSearch: {
|
|
275
|
-
type: Array,
|
|
276
|
-
},
|
|
277
|
-
rulesLength: {
|
|
278
|
-
type: Boolean,
|
|
279
|
-
},
|
|
280
278
|
//获取swagger后的钩子,返回swagger结构数据。用于处理swagger数据
|
|
281
279
|
onSwagger: {
|
|
282
280
|
type: Function,
|
|
@@ -290,6 +288,7 @@ export default {
|
|
|
290
288
|
formSearch: {
|
|
291
289
|
...this.formSearchData.value,
|
|
292
290
|
},
|
|
291
|
+
configDialogVisible: false,
|
|
293
292
|
// 自定义指令
|
|
294
293
|
loadmores: {
|
|
295
294
|
fn: this.loadmoreGX,
|
|
@@ -303,6 +302,11 @@ export default {
|
|
|
303
302
|
async created() {
|
|
304
303
|
this.init();
|
|
305
304
|
},
|
|
305
|
+
mounted() {
|
|
306
|
+
this.$nextTick(() => {
|
|
307
|
+
this.loadOptionSources();
|
|
308
|
+
});
|
|
309
|
+
},
|
|
306
310
|
watch: {
|
|
307
311
|
"formSearchData.value": {
|
|
308
312
|
handler: function (newVal, OldVal) {
|
|
@@ -318,56 +322,62 @@ export default {
|
|
|
318
322
|
},
|
|
319
323
|
methods: {
|
|
320
324
|
async init() {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
if (tempItem) {
|
|
334
|
-
// 匹配到
|
|
335
|
-
tempItem = { ...item, ...tempItem };
|
|
336
|
-
} else if (item.description) {
|
|
337
|
-
// 未匹配到
|
|
338
|
-
const pushItem = {
|
|
339
|
-
value: item.name,
|
|
340
|
-
label: item.description,
|
|
341
|
-
inputType: "text",
|
|
342
|
-
props: {},
|
|
343
|
-
};
|
|
344
|
-
if (item.schema.enum && Array.isArray(item.schema.enum)) {
|
|
345
|
-
//枚举值
|
|
346
|
-
pushItem.inputType = "select";
|
|
347
|
-
const ref = item.schema["$$ref"].split("/");
|
|
348
|
-
const enumName = ref[ref.length - 1];
|
|
349
|
-
const tempEnum = getEnum(enumName);
|
|
350
|
-
pushItem.children = tempEnum.length
|
|
351
|
-
? tempEnum
|
|
352
|
-
: item.schema.enum.map(e => ({
|
|
353
|
-
key: e,
|
|
354
|
-
value: e,
|
|
355
|
-
}));
|
|
356
|
-
} else if (item.schema.format === "date-time") {
|
|
357
|
-
//日期
|
|
358
|
-
pushItem.inputType = "picker";
|
|
359
|
-
pushItem.props.valueFormat = "yyyy-MM-dd";
|
|
360
|
-
pushItem.props.format = "yyyy/MM/dd";
|
|
361
|
-
} else if (item.schema && item.schema.type === "string") {
|
|
362
|
-
pushItem.inputType = "text";
|
|
363
|
-
}
|
|
364
|
-
this.formSearchData.tableSearch.push(pushItem);
|
|
325
|
+
if (
|
|
326
|
+
!this.formSearchData ||
|
|
327
|
+
!this.formSearchData.customs ||
|
|
328
|
+
!this.formSearchData.customs.length
|
|
329
|
+
) {
|
|
330
|
+
const swaggerData = await getData();
|
|
331
|
+
let swaggersearchColumns = swaggerData.paths[this.url].get.parameters || [];
|
|
332
|
+
if (typeof this.onSwagger === "function") {
|
|
333
|
+
try {
|
|
334
|
+
const res = await this.onSwagger({ columns: swaggersearchColumns });
|
|
335
|
+
if (res) swaggersearchColumns = res;
|
|
336
|
+
} catch (err) {}
|
|
365
337
|
}
|
|
366
|
-
|
|
338
|
+
swaggersearchColumns.forEach(item => {
|
|
339
|
+
let tempItem = this.formSearchData.tableSearch.find(
|
|
340
|
+
e => e.value.toLowerCase() === item.name.toLowerCase()
|
|
341
|
+
);
|
|
342
|
+
if (tempItem) {
|
|
343
|
+
// 匹配到
|
|
344
|
+
tempItem = { ...item, ...tempItem };
|
|
345
|
+
} else if (item.description) {
|
|
346
|
+
// 未匹配到
|
|
347
|
+
const pushItem = {
|
|
348
|
+
value: item.name,
|
|
349
|
+
label: item.description,
|
|
350
|
+
inputType: "text",
|
|
351
|
+
props: {},
|
|
352
|
+
};
|
|
353
|
+
if (item.schema.enum && Array.isArray(item.schema.enum)) {
|
|
354
|
+
//枚举值
|
|
355
|
+
pushItem.inputType = "select";
|
|
356
|
+
const ref = item.schema["$$ref"].split("/");
|
|
357
|
+
const enumName = ref[ref.length - 1];
|
|
358
|
+
const tempEnum = getEnum(enumName);
|
|
359
|
+
pushItem.children = tempEnum.length
|
|
360
|
+
? tempEnum
|
|
361
|
+
: item.schema.enum.map(e => ({
|
|
362
|
+
key: e,
|
|
363
|
+
value: e,
|
|
364
|
+
}));
|
|
365
|
+
} else if (item.schema.format === "date-time") {
|
|
366
|
+
//日期
|
|
367
|
+
pushItem.inputType = "picker";
|
|
368
|
+
pushItem.props.valueFormat = "yyyy-MM-dd";
|
|
369
|
+
pushItem.props.format = "yyyy/MM/dd";
|
|
370
|
+
} else if (item.schema && item.schema.type === "string") {
|
|
371
|
+
pushItem.inputType = "text";
|
|
372
|
+
}
|
|
373
|
+
this.formSearchData.tableSearch.push(pushItem);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
367
376
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
377
|
+
// 自动识别范围时间字段,以Begin和End结尾的字段,和"BeginTime", "EndTime",这样的时间范围字段
|
|
378
|
+
const rangeTimeCloumns = await this.autoDetectRangeTimeFields(swaggersearchColumns);
|
|
379
|
+
this.formSearchData.tableSearch = [...this.formSearchData.tableSearch, ...rangeTimeCloumns];
|
|
380
|
+
}
|
|
371
381
|
|
|
372
382
|
this.findTableSearch =
|
|
373
383
|
this.formSearchData.tableSearch.length > this.tableSearchSlice
|
|
@@ -481,39 +491,65 @@ export default {
|
|
|
481
491
|
getValue(val) {
|
|
482
492
|
this.$emit("getTreeSelectValue", val);
|
|
483
493
|
},
|
|
494
|
+
setFilterConditionsByFormSearch(formSearch) {
|
|
495
|
+
const filterConditions = [];
|
|
496
|
+
Object.keys(formSearch).forEach(key => {
|
|
497
|
+
const tempItem = this.formSearchData.tableSearch.find(item => item.value === key);
|
|
498
|
+
if (formSearch[key] !== undefined && formSearch[key] !== null) {
|
|
499
|
+
filterConditions.push({
|
|
500
|
+
key: key,
|
|
501
|
+
value: formSearch[key],
|
|
502
|
+
compare: tempItem && tempItem.compare ? tempItem.compare : "",
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
return filterConditions;
|
|
507
|
+
},
|
|
484
508
|
// 搜索查询按钮
|
|
485
509
|
handleSearch(formName, item) {
|
|
486
|
-
if (
|
|
487
|
-
this.
|
|
488
|
-
this.
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
this.formSearch.
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
const { begin, end } = fieldConfig.originalFields;
|
|
498
|
-
if (this.formSearch[key] && Array.isArray(this.formSearch[key])) {
|
|
499
|
-
this.formSearch[begin] = this.formSearch[key][0];
|
|
500
|
-
this.formSearch[end] = this.formSearch[key][1];
|
|
501
|
-
} else {
|
|
502
|
-
this.formSearch[begin] = null;
|
|
503
|
-
this.formSearch[end] = null;
|
|
504
|
-
}
|
|
510
|
+
if (
|
|
511
|
+
!this.formSearchData ||
|
|
512
|
+
!this.formSearchData.customs ||
|
|
513
|
+
!this.formSearchData.customs.length
|
|
514
|
+
) {
|
|
515
|
+
if (this.formSearch.createdTime) {
|
|
516
|
+
this.formSearch.BeginTime = this.formSearch.createdTime[0];
|
|
517
|
+
this.formSearch.EndTime = this.formSearch.createdTime[1];
|
|
518
|
+
} else {
|
|
519
|
+
this.formSearch.BeginTime = null;
|
|
520
|
+
this.formSearch.EndTime = null;
|
|
505
521
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
522
|
+
// 有originalFields字段的就是范围时间,查询时候转回接口需要的字段
|
|
523
|
+
Object.keys(this.formSearch).forEach(key => {
|
|
524
|
+
const fieldConfig = this.formSearchData.tableSearch.find(item => item.value === key);
|
|
525
|
+
if (fieldConfig && fieldConfig.originalFields) {
|
|
526
|
+
const { begin, end } = fieldConfig.originalFields;
|
|
527
|
+
if (this.formSearch[key] && Array.isArray(this.formSearch[key])) {
|
|
528
|
+
this.formSearch[begin] = this.formSearch[key][0];
|
|
529
|
+
this.formSearch[end] = this.formSearch[key][1];
|
|
530
|
+
} else {
|
|
531
|
+
this.formSearch[begin] = null;
|
|
532
|
+
this.formSearch[end] = null;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
513
535
|
});
|
|
536
|
+
|
|
537
|
+
const tempFormSearch = Object.assign({}, this.formSearch);
|
|
538
|
+
if (this.formSearchData.rules) {
|
|
539
|
+
return this.$refs[formName].validate(valid => {
|
|
540
|
+
if (!valid) return false;
|
|
541
|
+
this.$emit("handleSearch", tempFormSearch, item);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
this.$emit("handleSearch", tempFormSearch, item);
|
|
545
|
+
console.log(`\x1b[36m\x1b[4mol插件-搜索框查询`, tempFormSearch);
|
|
546
|
+
} else {
|
|
547
|
+
// 转成接口需要的结构filterConditions
|
|
548
|
+
const filterConditions = this.setFilterConditionsByFormSearch(this.formSearch) || [];
|
|
549
|
+
// 动态模式
|
|
550
|
+
this.$emit("handleSearch", this.formSearch, { filterConditions });
|
|
551
|
+
console.log(`\x1b[36m\x1b[4mol插件-动态搜索框查询`, this.formSearch, { filterConditions });
|
|
514
552
|
}
|
|
515
|
-
this.$emit("handleSearch", tempFormSearch, item);
|
|
516
|
-
console.log(`\x1b[36m\x1b[4mol插件-搜索框查询`, tempFormSearch);
|
|
517
553
|
},
|
|
518
554
|
loadmore(obj) {
|
|
519
555
|
this.$emit("loadmore", obj);
|
|
@@ -553,6 +589,102 @@ export default {
|
|
|
553
589
|
|
|
554
590
|
this.$emit("btnHandleExpend", this.expend);
|
|
555
591
|
},
|
|
592
|
+
handleOpenConfig() {
|
|
593
|
+
this.configDialogVisible = true;
|
|
594
|
+
},
|
|
595
|
+
handleSaveConfig(configList) {
|
|
596
|
+
this.formSearchData.tableSearch = configList;
|
|
597
|
+
this.findTableSearch =
|
|
598
|
+
this.formSearchData.tableSearch.length > this.tableSearchSlice
|
|
599
|
+
? this.formSearchData.tableSearch.slice(0, this.tableSearchSlice)
|
|
600
|
+
: this.formSearchData.tableSearch;
|
|
601
|
+
this.$emit("onSave", configList);
|
|
602
|
+
},
|
|
603
|
+
async loadOptionSources() {
|
|
604
|
+
for (const item of this.formSearchData.tableSearch) {
|
|
605
|
+
if (item.inputType === "select" && item.optionSource) {
|
|
606
|
+
await this.loadItemOptions(item);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
async loadItemOptions(item) {
|
|
611
|
+
if (!item.optionSource) return;
|
|
612
|
+
|
|
613
|
+
const { sourceType } = item.optionSource;
|
|
614
|
+
|
|
615
|
+
if (sourceType === "dict") {
|
|
616
|
+
await this.loadDictOptions(item);
|
|
617
|
+
} else if (sourceType === "api") {
|
|
618
|
+
await this.loadApiOptions(item);
|
|
619
|
+
}
|
|
620
|
+
},
|
|
621
|
+
async loadDictOptions(item) {
|
|
622
|
+
try {
|
|
623
|
+
const dictKey = item.optionSource.dictKey;
|
|
624
|
+
if (!dictKey) return;
|
|
625
|
+
|
|
626
|
+
const dictData = await this.getDictData(dictKey);
|
|
627
|
+
if (dictData && Array.isArray(dictData)) {
|
|
628
|
+
const children = dictData.map(d => ({
|
|
629
|
+
key: d.key,
|
|
630
|
+
value: d.value,
|
|
631
|
+
}));
|
|
632
|
+
this.$set(item, "children", children);
|
|
633
|
+
}
|
|
634
|
+
} catch (error) {
|
|
635
|
+
console.error("加载字典数据失败:", error);
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
async loadApiOptions(item) {
|
|
639
|
+
try {
|
|
640
|
+
const apiUrl = item.optionSource.apiUrl;
|
|
641
|
+
const method = item.optionSource.method || "get";
|
|
642
|
+
if (!apiUrl) return;
|
|
643
|
+
|
|
644
|
+
let response;
|
|
645
|
+
if (method === "post") {
|
|
646
|
+
response = await this.$http.post(apiUrl);
|
|
647
|
+
} else {
|
|
648
|
+
response = await this.$http.get(apiUrl);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (response.result && Array.isArray(response.result)) {
|
|
652
|
+
const { valueField, labelField } = item.optionSource;
|
|
653
|
+
const children = response.result.map(d => ({
|
|
654
|
+
key: d[valueField],
|
|
655
|
+
value: d[labelField],
|
|
656
|
+
}));
|
|
657
|
+
this.$set(item, "children", children);
|
|
658
|
+
}
|
|
659
|
+
} catch (error) {
|
|
660
|
+
console.error("加载接口数据失败:", error);
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
getDictData(dictKey) {
|
|
664
|
+
return new Promise(resolve => {
|
|
665
|
+
try {
|
|
666
|
+
const wmsStr = localStorage.getItem("wms") || "{}";
|
|
667
|
+
const wmsData = JSON.parse(wmsStr);
|
|
668
|
+
const dictData = wmsData.SET_enumsSelect || {};
|
|
669
|
+
const dictItem = dictData[dictKey];
|
|
670
|
+
const result = [];
|
|
671
|
+
|
|
672
|
+
if (dictItem && dictItem.enums && Array.isArray(dictItem.enums)) {
|
|
673
|
+
dictItem.enums.forEach(item => {
|
|
674
|
+
result.push({
|
|
675
|
+
key: item.key,
|
|
676
|
+
value: item.value,
|
|
677
|
+
});
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
resolve(result);
|
|
682
|
+
} catch (error) {
|
|
683
|
+
console.error("获取字典数据失败:", error);
|
|
684
|
+
resolve([]);
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
},
|
|
556
688
|
// input为number校验
|
|
557
689
|
handleChangeInput(item) {
|
|
558
690
|
return item.inputType === "number"
|
package/src/package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import OlTable from "./table";
|
|
2
2
|
import OlSearch from "./formSearch";
|
|
3
|
+
import OlCustomSearch from "./customSearch";
|
|
3
4
|
import Dialog from "./dialog";
|
|
4
5
|
import OlForm from "./form";
|
|
5
6
|
import OlNumberRange from "./numberRange";
|
|
@@ -205,15 +206,17 @@ function hideLoading() {
|
|
|
205
206
|
}
|
|
206
207
|
}
|
|
207
208
|
|
|
208
|
-
const components = [OlTable, OlSearch, Dialog, OlForm, OlNumberRange, OlPrint];
|
|
209
|
+
const components = [OlTable, OlSearch, OlCustomSearch, Dialog, OlForm, OlNumberRange, OlPrint];
|
|
209
210
|
const install = async function (Vue) {
|
|
210
211
|
// 设置全局数据
|
|
211
212
|
components.map(item => {
|
|
213
|
+
console.log(777, item);
|
|
214
|
+
|
|
212
215
|
Vue.component(`ol-${item.name}`, item);
|
|
213
216
|
});
|
|
214
217
|
consoleTooltip();
|
|
215
218
|
};
|
|
216
219
|
|
|
217
220
|
export default install;
|
|
218
|
-
export { OlTable, OlSearch, Dialog, OlForm, OlNumberRange, OlPrint };
|
|
221
|
+
export { OlTable, OlSearch, OlCustomSearch, Dialog, OlForm, OlNumberRange, OlPrint };
|
|
219
222
|
export { swaggerInstall, swaggerUnload, Hiprint };
|
|
@@ -92,19 +92,19 @@
|
|
|
92
92
|
@row-click="rowClick"
|
|
93
93
|
>
|
|
94
94
|
<el-table-column
|
|
95
|
-
v-if="tableData.options && tableData.options.
|
|
95
|
+
v-if="tableData.options && tableData.options.selection"
|
|
96
96
|
width="60"
|
|
97
97
|
align="center"
|
|
98
|
-
type="
|
|
99
|
-
|
|
100
|
-
label="序号"
|
|
98
|
+
type="selection"
|
|
99
|
+
label=""
|
|
101
100
|
/>
|
|
102
101
|
<el-table-column
|
|
103
|
-
v-if="tableData.options && tableData.options.
|
|
102
|
+
v-if="tableData.options && tableData.options.index"
|
|
104
103
|
width="60"
|
|
105
104
|
align="center"
|
|
106
|
-
type="
|
|
107
|
-
|
|
105
|
+
type="index"
|
|
106
|
+
:index="computeTableIndex"
|
|
107
|
+
label="序号"
|
|
108
108
|
/>
|
|
109
109
|
<!-- 新增插槽,允许父组件自定义表头 -->
|
|
110
110
|
<!-- <template v-if="tableData.options && tableData.options.useSlotHeader">
|