ct-component-plus 2.1.7 → 2.1.9
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ct-component-plus",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "packages/components/index.js",
|
|
7
7
|
"files": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"cingta-icon": "^2.1.6",
|
|
19
|
-
"element-plus": "
|
|
19
|
+
"element-plus": "2.11.0",
|
|
20
20
|
"vue": "^3.2.47"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buriedParamsKey, searchComponentProps } from
|
|
1
|
+
import { buriedParamsKey, searchComponentProps } from "../../../hooks";
|
|
2
2
|
|
|
3
3
|
export const radioEmits = ["update:modelValue", buriedParamsKey];
|
|
4
4
|
export const radioProps = {
|
|
@@ -7,7 +7,16 @@ export const radioProps = {
|
|
|
7
7
|
options: {
|
|
8
8
|
type: Array,
|
|
9
9
|
default() {
|
|
10
|
-
return []
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
10
|
+
return [];
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
api: String,
|
|
14
|
+
serviceMethod: String,
|
|
15
|
+
serviceParams: Object,
|
|
16
|
+
mapObj: {
|
|
17
|
+
type: Object,
|
|
18
|
+
default() {
|
|
19
|
+
return {};
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -12,9 +12,14 @@
|
|
|
12
12
|
</template>
|
|
13
13
|
|
|
14
14
|
<script setup>
|
|
15
|
-
import { computed, onMounted, ref, watchEffect } from "vue";
|
|
15
|
+
import { computed, onMounted, ref, watchEffect, inject, watch } from "vue";
|
|
16
16
|
import { useNamespace, useBuriedParams } from "../../../hooks";
|
|
17
|
+
import { isFunction } from "../../../utils";
|
|
17
18
|
import { radioEmits, radioProps } from "./index";
|
|
19
|
+
|
|
20
|
+
const baseDao = inject("$ctBaseDao");
|
|
21
|
+
const serviceConfig = inject("$ctServiceConfig");
|
|
22
|
+
|
|
18
23
|
const props = defineProps(radioProps);
|
|
19
24
|
const emit = defineEmits(radioEmits);
|
|
20
25
|
|
|
@@ -29,9 +34,85 @@ const showValue = computed({
|
|
|
29
34
|
},
|
|
30
35
|
});
|
|
31
36
|
const optionList = ref([]);
|
|
37
|
+
const optionsByApi = ref([]);
|
|
38
|
+
|
|
39
|
+
const getUseLabel = (label) => {
|
|
40
|
+
return typeof label === "string" ? label : String(label);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const watchServiceHandle = async () => {
|
|
44
|
+
// 通过api获取数据,会监听api以及serviceParams的改变(收集到的依赖改变)都会触发重新查询
|
|
45
|
+
const cbs = props.cbs || {};
|
|
46
|
+
if (props.api && baseDao) {
|
|
47
|
+
try {
|
|
48
|
+
const method = props.serviceMethod || serviceConfig.defaultMethod;
|
|
49
|
+
let params = props.serviceParams || {};
|
|
50
|
+
if (isFunction(cbs.beforeSearch)) {
|
|
51
|
+
const paramsHandle = await cbs.beforeSearch(params);
|
|
52
|
+
if (paramsHandle === false) return;
|
|
53
|
+
params = paramsHandle || params;
|
|
54
|
+
}
|
|
55
|
+
baseDao[method](props.api, params).then((res) => {
|
|
56
|
+
const mapObj = props.mapObj || {};
|
|
57
|
+
const { list, label = "label", value = "value", self } = mapObj;
|
|
58
|
+
let data = [];
|
|
59
|
+
if (list) {
|
|
60
|
+
data = res[list];
|
|
61
|
+
} else {
|
|
62
|
+
data = res;
|
|
63
|
+
}
|
|
64
|
+
data = data.map((item) => {
|
|
65
|
+
if (self) {
|
|
66
|
+
return { label: getUseLabel(item), value: item };
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...item,
|
|
70
|
+
label: getUseLabel(item[label]),
|
|
71
|
+
value: item[value],
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
optionsByApi.value = data;
|
|
75
|
+
if (isFunction(cbs.afterSearch)) {
|
|
76
|
+
cbs.afterSearch(res, optionsByApi, showValue);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error(error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (isFunction(cbs.defineSearch)) {
|
|
84
|
+
try {
|
|
85
|
+
const defineSearchHandle = await cbs.defineSearch(
|
|
86
|
+
optionsByApi,
|
|
87
|
+
showValue
|
|
88
|
+
);
|
|
89
|
+
if (defineSearchHandle === false) return;
|
|
90
|
+
if (defineSearchHandle) {
|
|
91
|
+
optionsByApi.value = defineSearchHandle;
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
watch(
|
|
98
|
+
[
|
|
99
|
+
() => props.api,
|
|
100
|
+
() => props.serviceParams,
|
|
101
|
+
() => props.serviceMethod,
|
|
102
|
+
() => props.mapObj,
|
|
103
|
+
],
|
|
104
|
+
(newVal, oldVal) => {
|
|
105
|
+
watchServiceHandle();
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
immediate: true,
|
|
109
|
+
}
|
|
110
|
+
);
|
|
32
111
|
|
|
33
112
|
watchEffect(async () => {
|
|
34
|
-
optionList.value =
|
|
113
|
+
optionList.value = optionsByApi.value.length
|
|
114
|
+
? optionsByApi.value
|
|
115
|
+
: props.options;
|
|
35
116
|
});
|
|
36
117
|
|
|
37
118
|
useBuriedParams(props, emit, {
|
|
@@ -44,7 +125,10 @@ useBuriedParams(props, emit, {
|
|
|
44
125
|
defineExpose({
|
|
45
126
|
ref: radioRef,
|
|
46
127
|
});
|
|
47
|
-
onMounted(() => {
|
|
128
|
+
onMounted(() => {
|
|
129
|
+
if (props.api && !baseDao) {
|
|
130
|
+
console.error("请先配置baseDao");
|
|
131
|
+
}
|
|
132
|
+
});
|
|
48
133
|
</script>
|
|
49
|
-
<style lang=
|
|
50
|
-
</style>
|
|
134
|
+
<style lang="less"></style>
|