ct-component-plus 2.1.5 → 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 +2 -2
- package/packages/components/date-picker/src/date-picker.vue +12 -1
- package/packages/components/date-picker/src/index.js +16 -12
- package/packages/components/radio/src/index.js +14 -5
- package/packages/components/radio/src/radio.vue +89 -5
- package/packages/components/select/src/select.vue +63 -5
- package/packages/components/year-select/src/index.js +8 -8
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": "2.
|
|
19
|
+
"element-plus": "2.11.0",
|
|
20
20
|
"vue": "^3.2.47"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
<el-date-picker
|
|
3
3
|
:class="[ns.b()]"
|
|
4
4
|
v-model="showValue"
|
|
5
|
+
:name="componentName"
|
|
5
6
|
:value-format="valueFormat"
|
|
6
7
|
:range-separator="rangeSeparator"
|
|
7
8
|
:clear-icon="clearIcon"
|
|
8
9
|
:prefix-icon="prefixIcon"
|
|
9
10
|
:unlink-panels="unlinkPanels"
|
|
10
|
-
v-bind="rawAttr"
|
|
11
|
+
v-bind="rawAttr"
|
|
12
|
+
>
|
|
11
13
|
<template #default="cell">
|
|
12
14
|
<slot v-bind="cell"></slot>
|
|
13
15
|
</template>
|
|
@@ -24,6 +26,15 @@ const emit = defineEmits(datePickerEmits);
|
|
|
24
26
|
const attr = useAttrs();
|
|
25
27
|
const ns = useNamespace("date-picker");
|
|
26
28
|
|
|
29
|
+
const componentName = computed(() => {
|
|
30
|
+
const rawType = props.rawAttr?.type || attr.type;
|
|
31
|
+
if (isArray(props.name)) return props.name;
|
|
32
|
+
if (rawType && rawType.includes("range")) {
|
|
33
|
+
return props.name ? [props.name, props.name] : [];
|
|
34
|
+
}
|
|
35
|
+
return props.name;
|
|
36
|
+
});
|
|
37
|
+
|
|
27
38
|
const showValue = computed({
|
|
28
39
|
get() {
|
|
29
40
|
return props.modelValue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { buriedParamsKey, searchComponentProps } from
|
|
2
|
-
import clearIcon from
|
|
3
|
-
import dateIcon from
|
|
1
|
+
import { buriedParamsKey, searchComponentProps } from "../../../hooks";
|
|
2
|
+
import clearIcon from "./clear-icon.vue";
|
|
3
|
+
import dateIcon from "./date-icon.vue";
|
|
4
4
|
|
|
5
5
|
export const datePickerEmits = ["update:modelValue", buriedParamsKey];
|
|
6
6
|
export const datePickerProps = {
|
|
@@ -8,27 +8,31 @@ export const datePickerProps = {
|
|
|
8
8
|
modelValue: [Date, Number, String, Array],
|
|
9
9
|
valueFormat: {
|
|
10
10
|
type: String,
|
|
11
|
-
default:
|
|
11
|
+
default: "x",
|
|
12
12
|
},
|
|
13
13
|
addTimestamp: [Number, String, Array, Function],
|
|
14
14
|
rangeSeparator: {
|
|
15
15
|
type: String,
|
|
16
|
-
default:
|
|
16
|
+
default: "至",
|
|
17
17
|
},
|
|
18
18
|
clearIcon: {
|
|
19
19
|
type: [String, Object],
|
|
20
20
|
default() {
|
|
21
|
-
return clearIcon
|
|
22
|
-
}
|
|
21
|
+
return clearIcon;
|
|
22
|
+
},
|
|
23
23
|
},
|
|
24
24
|
prefixIcon: {
|
|
25
25
|
type: [String, Object],
|
|
26
26
|
default() {
|
|
27
|
-
return dateIcon
|
|
28
|
-
}
|
|
27
|
+
return dateIcon;
|
|
28
|
+
},
|
|
29
29
|
},
|
|
30
30
|
unlinkPanels: {
|
|
31
31
|
type: Boolean,
|
|
32
|
-
default: true
|
|
33
|
-
}
|
|
34
|
-
|
|
32
|
+
default: true,
|
|
33
|
+
},
|
|
34
|
+
name: {
|
|
35
|
+
type: [String, Array],
|
|
36
|
+
default: "",
|
|
37
|
+
},
|
|
38
|
+
};
|
|
@@ -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>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
:class="[ns.b(), ns.is('multiple', multiple)]"
|
|
6
6
|
v-model="valueModel"
|
|
7
7
|
collapse-tags
|
|
8
|
-
v-bind="
|
|
8
|
+
v-bind="bindAttrs"
|
|
9
9
|
:multiple="multiple"
|
|
10
10
|
:filterable="filterable"
|
|
11
11
|
:clear-icon="clearIcon"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
</template>
|
|
36
36
|
</el-input>
|
|
37
37
|
</div>
|
|
38
|
-
<div :class="[ns.e('select')]" v-if="!
|
|
38
|
+
<div :class="[ns.e('select')]" v-if="!bindAttrs.multipleLimit">
|
|
39
39
|
<span :class="[ns.e('select-title')]">
|
|
40
40
|
<span v-if="!keyword">已选{{ selectLength }}项</span>
|
|
41
41
|
<span v-else>检索结果</span>
|
|
@@ -74,6 +74,12 @@
|
|
|
74
74
|
</el-select>
|
|
75
75
|
</template>
|
|
76
76
|
|
|
77
|
+
<script>
|
|
78
|
+
export default {
|
|
79
|
+
inheritAttrs: false,
|
|
80
|
+
};
|
|
81
|
+
</script>
|
|
82
|
+
|
|
77
83
|
<script setup>
|
|
78
84
|
import {
|
|
79
85
|
onMounted,
|
|
@@ -83,6 +89,7 @@ import {
|
|
|
83
89
|
inject,
|
|
84
90
|
watchEffect,
|
|
85
91
|
nextTick,
|
|
92
|
+
useAttrs,
|
|
86
93
|
} from "vue";
|
|
87
94
|
import { selectEmits, selectProps } from "./index";
|
|
88
95
|
import { useNamespace, useBuriedParams, useCheckedAll } from "../../../hooks";
|
|
@@ -104,15 +111,66 @@ const emit = defineEmits(selectEmits);
|
|
|
104
111
|
// };
|
|
105
112
|
const ns = useNamespace("select");
|
|
106
113
|
const optionsByApi = ref([]);
|
|
114
|
+
|
|
115
|
+
const EMPTY_VALUE = "___CT_EMPTY_STRING___";
|
|
116
|
+
const attrs = useAttrs();
|
|
117
|
+
|
|
118
|
+
const bindAttrs = computed(() => {
|
|
119
|
+
const merged = { ...attrs, ...props.rawAttr };
|
|
120
|
+
if (merged.onChange) {
|
|
121
|
+
const original = merged.onChange;
|
|
122
|
+
merged.onChange = (val) => {
|
|
123
|
+
let realVal = val;
|
|
124
|
+
if (Array.isArray(val)) {
|
|
125
|
+
realVal = val.map((v) => (v === EMPTY_VALUE ? "" : v));
|
|
126
|
+
} else {
|
|
127
|
+
if (realVal === EMPTY_VALUE) realVal = "";
|
|
128
|
+
}
|
|
129
|
+
original(realVal);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return merged;
|
|
133
|
+
});
|
|
134
|
+
|
|
107
135
|
const showOptions = computed(() => {
|
|
108
|
-
|
|
136
|
+
const opts = optionsByApi.value.length ? optionsByApi.value : props.options;
|
|
137
|
+
return opts.map((item) => {
|
|
138
|
+
if (item.value === "") {
|
|
139
|
+
return { ...item, value: EMPTY_VALUE };
|
|
140
|
+
}
|
|
141
|
+
return item;
|
|
142
|
+
});
|
|
109
143
|
});
|
|
110
144
|
const valueModel = computed({
|
|
111
145
|
get() {
|
|
112
|
-
|
|
146
|
+
const val = props.modelValue;
|
|
147
|
+
const hasEmptyOption = showOptions.value.some(
|
|
148
|
+
(item) => item.value === EMPTY_VALUE
|
|
149
|
+
);
|
|
150
|
+
if (props.multiple) {
|
|
151
|
+
if (Array.isArray(val)) {
|
|
152
|
+
return val.map((v) => {
|
|
153
|
+
if (v === "") {
|
|
154
|
+
return hasEmptyOption ? EMPTY_VALUE : "";
|
|
155
|
+
}
|
|
156
|
+
return v;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
if (val === "") {
|
|
162
|
+
return hasEmptyOption ? EMPTY_VALUE : "";
|
|
163
|
+
}
|
|
164
|
+
return val ?? "";
|
|
113
165
|
},
|
|
114
166
|
set(newValue) {
|
|
115
|
-
|
|
167
|
+
let emitVal = newValue;
|
|
168
|
+
if (Array.isArray(emitVal)) {
|
|
169
|
+
emitVal = emitVal.map((v) => (v === EMPTY_VALUE ? "" : v));
|
|
170
|
+
} else {
|
|
171
|
+
if (emitVal === EMPTY_VALUE) emitVal = "";
|
|
172
|
+
}
|
|
173
|
+
emit("update:modelValue", emitVal);
|
|
116
174
|
},
|
|
117
175
|
});
|
|
118
176
|
const keyword = ref("");
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { buriedParamsKey, searchComponentProps } from
|
|
1
|
+
import { buriedParamsKey, searchComponentProps } from "../../../hooks";
|
|
2
2
|
|
|
3
3
|
export const yearSelectEmits = [
|
|
4
4
|
"update:modelValue",
|
|
5
5
|
buriedParamsKey,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
"change",
|
|
7
|
+
"changeSelect",
|
|
8
|
+
"visible-change",
|
|
9
|
+
"blur",
|
|
10
|
+
"focus",
|
|
11
11
|
];
|
|
12
12
|
export const yearSelectProps = {
|
|
13
13
|
...searchComponentProps,
|
|
@@ -15,7 +15,7 @@ export const yearSelectProps = {
|
|
|
15
15
|
disabled: Boolean,
|
|
16
16
|
multiple: {
|
|
17
17
|
type: Boolean,
|
|
18
|
-
default: true
|
|
18
|
+
default: true,
|
|
19
19
|
},
|
|
20
20
|
startPlaceholder: String,
|
|
21
21
|
endPlaceholder: String,
|
|
@@ -42,4 +42,4 @@ export const yearSelectProps = {
|
|
|
42
42
|
type: [String, Object],
|
|
43
43
|
default: "至",
|
|
44
44
|
},
|
|
45
|
-
}
|
|
45
|
+
};
|