ol-base-components 3.1.4 → 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.
@@ -27,3 +27,5 @@ const translateWord = async word => {
27
27
  return word.charAt(0).toUpperCase() + word.slice(1);
28
28
  }
29
29
  };
30
+
31
+ // 由于配置更新children
@@ -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
- <!-- <div class="btnbox">
171
- <el-form class="demo-form-inline">
172
- <el-form-item>
173
- <el-button
174
- v-for="(btn, index) in btnlist"
175
- :key="index"
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
- const swaggerData = await getData();
322
- let swaggersearchColumns = swaggerData.paths[this.url].get.parameters || [];
323
- if (typeof this.onSwagger === "function") {
324
- try {
325
- const res = await this.onSwagger({ columns: swaggersearchColumns });
326
- if (res) swaggersearchColumns = res;
327
- } catch (err) {}
328
- }
329
- swaggersearchColumns.forEach(item => {
330
- let tempItem = this.formSearchData.tableSearch.find(
331
- e => e.value.toLowerCase() === item.name.toLowerCase()
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
- // 自动识别范围时间字段,以Begin和End结尾的字段,和"BeginTime", "EndTime",这样的时间范围字段
369
- const rangeTimeCloumns = await this.autoDetectRangeTimeFields(swaggersearchColumns);
370
- this.formSearchData.tableSearch = [...this.formSearchData.tableSearch, ...rangeTimeCloumns];
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 (this.formSearch.createdTime) {
487
- this.formSearch.BeginTime = this.formSearch.createdTime[0];
488
- this.formSearch.EndTime = this.formSearch.createdTime[1];
489
- } else {
490
- this.formSearch.BeginTime = null;
491
- this.formSearch.EndTime = null;
492
- }
493
- // 有originalFields字段的就是范围时间,查询时候转回接口需要的字段
494
- Object.keys(this.formSearch).forEach(key => {
495
- const fieldConfig = this.formSearchData.tableSearch.find(item => item.value === key);
496
- if (fieldConfig && fieldConfig.originalFields) {
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
- const tempFormSearch = Object.assign({}, this.formSearch);
509
- if (this.formSearchData.rules) {
510
- return this.$refs[formName].validate(valid => {
511
- if (!valid) return false;
512
- this.$emit("handleSearch", tempFormSearch, item);
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"
@@ -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 };