ol-base-components 3.2.2 → 3.2.5
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
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
@onSave="onSave"
|
|
5
5
|
v-bind="$attrs"
|
|
6
6
|
v-on="$listeners"
|
|
7
|
+
:key="key"
|
|
7
8
|
/>
|
|
8
9
|
</template>
|
|
9
10
|
|
|
@@ -33,12 +34,13 @@ export default {
|
|
|
33
34
|
data() {
|
|
34
35
|
return {
|
|
35
36
|
currentPageItem: {},
|
|
37
|
+
key: 0,
|
|
36
38
|
};
|
|
37
39
|
},
|
|
38
|
-
|
|
40
|
+
|
|
41
|
+
mounted() {
|
|
39
42
|
this.init();
|
|
40
43
|
},
|
|
41
|
-
mounted() {},
|
|
42
44
|
methods: {
|
|
43
45
|
init() {
|
|
44
46
|
const handleMenu = (arr, _this) => {
|
|
@@ -68,6 +70,7 @@ export default {
|
|
|
68
70
|
if (res.code !== 200) return;
|
|
69
71
|
const configList = res.result.settingJson ? JSON.parse(res.result.settingJson) : [];
|
|
70
72
|
this.formSearchData.tableSearch = configList;
|
|
73
|
+
this.key++;
|
|
71
74
|
});
|
|
72
75
|
},
|
|
73
76
|
//保存
|
|
@@ -375,6 +375,7 @@ export default {
|
|
|
375
375
|
dictLoading: false,
|
|
376
376
|
dictQuery: "",
|
|
377
377
|
sortable: null,
|
|
378
|
+
currentConfig: {}, // 配置选项
|
|
378
379
|
};
|
|
379
380
|
},
|
|
380
381
|
computed: {
|
|
@@ -595,6 +596,7 @@ export default {
|
|
|
595
596
|
handleConfigOptions(index) {
|
|
596
597
|
this.currentEditIndex = index;
|
|
597
598
|
const currentConfig = this.configList[index];
|
|
599
|
+
this.currentConfig = JSON.parse(JSON.stringify(currentConfig));
|
|
598
600
|
|
|
599
601
|
const optionSource = currentConfig.optionSource || {};
|
|
600
602
|
this.currentOptionConfig = {
|
|
@@ -624,7 +626,55 @@ export default {
|
|
|
624
626
|
handleDeleteOption(index) {
|
|
625
627
|
this.currentOptionConfig.options.splice(index, 1);
|
|
626
628
|
},
|
|
627
|
-
|
|
629
|
+
async loadApiOptions(item) {
|
|
630
|
+
try {
|
|
631
|
+
const apiUrl = item.optionSource.apiUrl;
|
|
632
|
+
const method = item.optionSource.method || "get";
|
|
633
|
+
if (!apiUrl) return;
|
|
634
|
+
|
|
635
|
+
let response;
|
|
636
|
+
if (method === "post") {
|
|
637
|
+
response = await this.post({ url: apiUrl });
|
|
638
|
+
} else {
|
|
639
|
+
response = await this.get({ url: apiUrl });
|
|
640
|
+
}
|
|
641
|
+
if (response.code !== 200) return;
|
|
642
|
+
if (response.result && Array.isArray(response.result)) {
|
|
643
|
+
const { valueField, labelField } = item.optionSource;
|
|
644
|
+
const children = response.result.map(d => ({
|
|
645
|
+
key: d[valueField],
|
|
646
|
+
value: d[labelField],
|
|
647
|
+
}));
|
|
648
|
+
return children;
|
|
649
|
+
}
|
|
650
|
+
} catch (error) {
|
|
651
|
+
console.error("加载接口数据失败:", error);
|
|
652
|
+
return [];
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
needSetChildren(oldConfig, newConfig) {
|
|
656
|
+
const { inputType, optionSource } = oldConfig;
|
|
657
|
+
if (!optionSource) return false;
|
|
658
|
+
const { sourceType, apiUrl, method, valueField, labelField } = optionSource;
|
|
659
|
+
if (inputType !== "select" || sourceType !== "api") return false;
|
|
660
|
+
const {
|
|
661
|
+
sourceType: newSourceType,
|
|
662
|
+
apiUrl: newApiUrl,
|
|
663
|
+
method: newMethod,
|
|
664
|
+
valueField: newValueField,
|
|
665
|
+
labelField: newLabelField,
|
|
666
|
+
} = newConfig;
|
|
667
|
+
if (
|
|
668
|
+
sourceType === newSourceType &&
|
|
669
|
+
apiUrl === newApiUrl &&
|
|
670
|
+
method === newMethod &&
|
|
671
|
+
valueField === newValueField &&
|
|
672
|
+
labelField === newLabelField
|
|
673
|
+
)
|
|
674
|
+
return false;
|
|
675
|
+
return true;
|
|
676
|
+
},
|
|
677
|
+
async handleSaveOptions() {
|
|
628
678
|
const config = this.configList[this.currentEditIndex];
|
|
629
679
|
const configDefault = {
|
|
630
680
|
sourceType: "",
|
|
@@ -654,7 +704,12 @@ export default {
|
|
|
654
704
|
valueField: this.currentOptionConfig.valueField,
|
|
655
705
|
labelField: this.currentOptionConfig.labelField,
|
|
656
706
|
};
|
|
657
|
-
|
|
707
|
+
// 接口请求
|
|
708
|
+
// 判断是否需要走 api接口获取
|
|
709
|
+
let children = [];
|
|
710
|
+
const bool = this.needSetChildren(this.currentConfig, config.optionSource);
|
|
711
|
+
if (bool) children = await this.loadApiOptions(config);
|
|
712
|
+
else config.children = children || [];
|
|
658
713
|
}
|
|
659
714
|
this.optionsDialogVisible = false;
|
|
660
715
|
},
|