ct-component-plus 2.1.7 → 2.1.10
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.10",
|
|
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": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
:suffix-icon="suffixIcon"
|
|
13
13
|
:fit-input-width="fitInputWidth"
|
|
14
14
|
:select-text="selectText"
|
|
15
|
-
:popper-class="
|
|
15
|
+
:popper-class="popperClass"
|
|
16
16
|
@focus="showSearchPrefix"
|
|
17
17
|
@blur="hideSearchPrefix"
|
|
18
18
|
@click="focusSearchInput"
|
|
@@ -89,7 +89,15 @@
|
|
|
89
89
|
</template>
|
|
90
90
|
|
|
91
91
|
<script setup>
|
|
92
|
-
import {
|
|
92
|
+
import {
|
|
93
|
+
onMounted,
|
|
94
|
+
computed,
|
|
95
|
+
ref,
|
|
96
|
+
watch,
|
|
97
|
+
inject,
|
|
98
|
+
nextTick,
|
|
99
|
+
useAttrs,
|
|
100
|
+
} from "vue";
|
|
93
101
|
import { selectEmits, selectProps } from "./index";
|
|
94
102
|
import { useNamespace, useBuriedParams } from "../../../hooks";
|
|
95
103
|
import { isFunction, isArray } from "../../../utils";
|
|
@@ -100,6 +108,7 @@ const selectTooltip = inject("$selectTooltip");
|
|
|
100
108
|
|
|
101
109
|
const props = defineProps(selectProps);
|
|
102
110
|
const emit = defineEmits(selectEmits);
|
|
111
|
+
const attrs = useAttrs();
|
|
103
112
|
|
|
104
113
|
const ns = useNamespace("select");
|
|
105
114
|
const optionsByApi = ref([]);
|
|
@@ -170,6 +179,18 @@ const emptyText = computed(() => {
|
|
|
170
179
|
? props.noMatchText || "暂无匹配数据"
|
|
171
180
|
: props.noDataText || "暂无数据";
|
|
172
181
|
});
|
|
182
|
+
|
|
183
|
+
const popperClass = computed(() => {
|
|
184
|
+
const defaultClass = ns.e("popper");
|
|
185
|
+
const userClass =
|
|
186
|
+
attrs["popper-class"] ||
|
|
187
|
+
attrs["popperClass"] ||
|
|
188
|
+
(props.rawAttr &&
|
|
189
|
+
(props.rawAttr["popper-class"] || props.rawAttr["popperClass"])) ||
|
|
190
|
+
"";
|
|
191
|
+
return `${defaultClass} ${userClass}`.trim();
|
|
192
|
+
});
|
|
193
|
+
|
|
173
194
|
const getUseLabel = (label) => {
|
|
174
195
|
return typeof label === "string" ? label : String(label);
|
|
175
196
|
};
|
|
@@ -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>
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
:suffix-icon="suffixIcon"
|
|
13
13
|
:fit-input-width="fitInputWidth"
|
|
14
14
|
:select-text="selectText"
|
|
15
|
-
:popper-class="
|
|
15
|
+
:popper-class="popperClass"
|
|
16
16
|
@focus="showSearchPrefix"
|
|
17
17
|
@blur="hideSearchPrefix"
|
|
18
18
|
@click="focusSearchInput"
|
|
@@ -117,6 +117,10 @@ const attrs = useAttrs();
|
|
|
117
117
|
|
|
118
118
|
const bindAttrs = computed(() => {
|
|
119
119
|
const merged = { ...attrs, ...props.rawAttr };
|
|
120
|
+
// 剔除已在组件内部显式处理的属性,避免 v-bind 覆盖或冲突
|
|
121
|
+
delete merged["popper-class"];
|
|
122
|
+
delete merged["popperClass"];
|
|
123
|
+
|
|
120
124
|
if (merged.onChange) {
|
|
121
125
|
const original = merged.onChange;
|
|
122
126
|
merged.onChange = (val) => {
|
|
@@ -223,6 +227,14 @@ const emptyText = computed(() => {
|
|
|
223
227
|
? props.noMatchText || "暂无匹配数据"
|
|
224
228
|
: props.noDataText || "暂无数据";
|
|
225
229
|
});
|
|
230
|
+
|
|
231
|
+
const popperClass = computed(() => {
|
|
232
|
+
const defaultClass = ns.e("popper");
|
|
233
|
+
const merged = { ...attrs, ...props.rawAttr };
|
|
234
|
+
const userClass = merged["popper-class"] || merged["popperClass"] || "";
|
|
235
|
+
return `${defaultClass} ${userClass}`.trim();
|
|
236
|
+
});
|
|
237
|
+
|
|
226
238
|
const getUseLabel = (label) => {
|
|
227
239
|
return typeof label === "string" ? label : String(label);
|
|
228
240
|
};
|