ct-component-plus 2.1.3 → 2.1.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 +1 -1
- package/packages/components/index.js +5 -1
- package/packages/components/number-input-range/index.js +9 -0
- package/packages/components/number-input-range/src/index.js +31 -0
- package/packages/components/number-input-range/src/number-input-range.vue +168 -0
- package/packages/components/paging-select/index.js +8 -0
- package/packages/components/paging-select/src/arrow-down.vue +3 -0
- package/packages/components/paging-select/src/clear-icon.vue +3 -0
- package/packages/components/paging-select/src/empty.vue +14 -0
- package/packages/components/paging-select/src/index.js +50 -0
- package/packages/components/paging-select/src/paging-select.vue +469 -0
- package/packages/components/search-box/index.js +15 -11
- package/packages/components/search-box/src/search-box.vue +15 -4
- package/packages/components/select/src/select.vue +4 -1
package/package.json
CHANGED
|
@@ -3,7 +3,9 @@ import radio from './radio';
|
|
|
3
3
|
import checkbox from './checkbox';
|
|
4
4
|
import input from './input';
|
|
5
5
|
import inputRange from './input-range';
|
|
6
|
+
import numberInputRange from './number-input-range';
|
|
6
7
|
import select from './select';
|
|
8
|
+
import pagingSelect from './paging-select';
|
|
7
9
|
import yearSelect from './year-select';
|
|
8
10
|
import datePicker from './date-picker';
|
|
9
11
|
import cascader from './cascader';
|
|
@@ -34,7 +36,9 @@ const components = [
|
|
|
34
36
|
checkbox,
|
|
35
37
|
input,
|
|
36
38
|
inputRange,
|
|
39
|
+
numberInputRange,
|
|
37
40
|
select,
|
|
41
|
+
pagingSelect,
|
|
38
42
|
yearSelect,
|
|
39
43
|
datePicker,
|
|
40
44
|
cascader,
|
|
@@ -79,4 +83,4 @@ export default {
|
|
|
79
83
|
install
|
|
80
84
|
}
|
|
81
85
|
export { CtMessage }
|
|
82
|
-
export * from 'element-plus'
|
|
86
|
+
export * from 'element-plus'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import CtNumberInputRange from "./src/number-input-range.vue";
|
|
2
|
+
|
|
3
|
+
/* istanbul ignore next */
|
|
4
|
+
CtNumberInputRange.install = function (Vue) {
|
|
5
|
+
// TODO 这里D组件名是这这里写死的,不是使用CtNumberInputRange.name的形式,因为setup里面不可以直接什么组件的name属性,故而这里没有这个属性,后续可以考虑使用defineOptions(需要安装unplugin-vue-macros插件)
|
|
6
|
+
Vue.component("CtNumberInputRange", CtNumberInputRange);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default CtNumberInputRange;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { buriedParamsKey, searchComponentProps } from "../../../hooks";
|
|
2
|
+
|
|
3
|
+
export const numberInputRangeEmits = [
|
|
4
|
+
"update:modelValue",
|
|
5
|
+
buriedParamsKey,
|
|
6
|
+
"change",
|
|
7
|
+
];
|
|
8
|
+
export const numberInputRangeProps = {
|
|
9
|
+
...searchComponentProps,
|
|
10
|
+
modelValue: Array,
|
|
11
|
+
min: Number,
|
|
12
|
+
max: Number,
|
|
13
|
+
step: {
|
|
14
|
+
type: Number,
|
|
15
|
+
default: 1,
|
|
16
|
+
},
|
|
17
|
+
precision: Number,
|
|
18
|
+
disabled: Boolean,
|
|
19
|
+
separator: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: "--",
|
|
22
|
+
},
|
|
23
|
+
controlsPosition: {
|
|
24
|
+
type: String,
|
|
25
|
+
default: "right",
|
|
26
|
+
},
|
|
27
|
+
placeholder: {
|
|
28
|
+
type: String,
|
|
29
|
+
default: "请输入数字",
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="[ns.b(), ns.is('disabled', disabled)]">
|
|
3
|
+
<div :class="[ns.e('wrapper')]">
|
|
4
|
+
<el-input-number
|
|
5
|
+
ref="inputRef1"
|
|
6
|
+
v-model="leftModel"
|
|
7
|
+
:placeholder="placeholder"
|
|
8
|
+
:min="min"
|
|
9
|
+
:max="max"
|
|
10
|
+
:step="step"
|
|
11
|
+
:precision="precision"
|
|
12
|
+
:disabled="disabled"
|
|
13
|
+
v-bind="rawAttr"
|
|
14
|
+
:controls-position="controlsPosition"
|
|
15
|
+
@change="handleChange($event, 0)"
|
|
16
|
+
/>
|
|
17
|
+
<span :class="[ns.e('separator')]">
|
|
18
|
+
<slot name="separator">{{ separator }}</slot>
|
|
19
|
+
</span>
|
|
20
|
+
<el-input-number
|
|
21
|
+
ref="inputRef2"
|
|
22
|
+
v-model="rightModel"
|
|
23
|
+
:placeholder="placeholder"
|
|
24
|
+
:min="min"
|
|
25
|
+
:max="max"
|
|
26
|
+
:step="step"
|
|
27
|
+
:precision="precision"
|
|
28
|
+
:disabled="disabled"
|
|
29
|
+
v-bind="rawAttr"
|
|
30
|
+
:controls-position="controlsPosition"
|
|
31
|
+
@change="handleChange($event, 1)"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script setup>
|
|
38
|
+
import { computed, ref } from "vue";
|
|
39
|
+
import { useNamespace, useBuriedParams } from "../../../hooks";
|
|
40
|
+
import { numberInputRangeEmits, numberInputRangeProps } from "./index";
|
|
41
|
+
const props = defineProps(numberInputRangeProps);
|
|
42
|
+
const emit = defineEmits(numberInputRangeEmits);
|
|
43
|
+
|
|
44
|
+
useBuriedParams(props, emit);
|
|
45
|
+
const ns = useNamespace("number-input-range");
|
|
46
|
+
|
|
47
|
+
const inputRef1 = ref(null);
|
|
48
|
+
const inputRef2 = ref(null);
|
|
49
|
+
|
|
50
|
+
const normalizePair = (left, right) => {
|
|
51
|
+
const l = left;
|
|
52
|
+
const r = right;
|
|
53
|
+
if (l !== undefined && r !== undefined && l > r) {
|
|
54
|
+
return [r, l];
|
|
55
|
+
}
|
|
56
|
+
return [l, r];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const leftModel = computed({
|
|
60
|
+
get() {
|
|
61
|
+
return Array.isArray(props.modelValue) ? props.modelValue[0] : undefined;
|
|
62
|
+
},
|
|
63
|
+
set(newValue) {
|
|
64
|
+
const right = Array.isArray(props.modelValue)
|
|
65
|
+
? props.modelValue[1]
|
|
66
|
+
: undefined;
|
|
67
|
+
emit("update:modelValue", [newValue, right]);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
const rightModel = computed({
|
|
71
|
+
get() {
|
|
72
|
+
return Array.isArray(props.modelValue) ? props.modelValue[1] : undefined;
|
|
73
|
+
},
|
|
74
|
+
set(newValue) {
|
|
75
|
+
const left = Array.isArray(props.modelValue)
|
|
76
|
+
? props.modelValue[0]
|
|
77
|
+
: undefined;
|
|
78
|
+
emit("update:modelValue", [left, newValue]);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const handleChange = (val, index) => {
|
|
83
|
+
const currentLeft = index === 0
|
|
84
|
+
? val
|
|
85
|
+
: (Array.isArray(props.modelValue) ? props.modelValue[0] : undefined);
|
|
86
|
+
const currentRight = index === 1
|
|
87
|
+
? val
|
|
88
|
+
: (Array.isArray(props.modelValue) ? props.modelValue[1] : undefined);
|
|
89
|
+
const bothFilled = typeof currentLeft === "number" && !isNaN(currentLeft)
|
|
90
|
+
&& typeof currentRight === "number" && !isNaN(currentRight);
|
|
91
|
+
if (bothFilled) {
|
|
92
|
+
const normalized = normalizePair(currentLeft, currentRight);
|
|
93
|
+
emit("update:modelValue", normalized);
|
|
94
|
+
emit("change", normalized, index, val);
|
|
95
|
+
} else {
|
|
96
|
+
emit("change", [currentLeft, currentRight], index, val);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
defineExpose({
|
|
101
|
+
ref: [inputRef1, inputRef2],
|
|
102
|
+
});
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<style lang="less">
|
|
106
|
+
.ct-number-input-range {
|
|
107
|
+
position: relative;
|
|
108
|
+
display: inline-flex;
|
|
109
|
+
width: var(--ct-component-width);
|
|
110
|
+
font-size: var(--ct-font-size);
|
|
111
|
+
color: var(--ct-border-color);
|
|
112
|
+
box-sizing: border-box;
|
|
113
|
+
vertical-align: middle;
|
|
114
|
+
@R: .ct-number-input-range;
|
|
115
|
+
&.is-disabled {
|
|
116
|
+
cursor: not-allowed;
|
|
117
|
+
--ct-component-fill-color: var(--ct-component-disabled-bg-color);
|
|
118
|
+
@{R}__wrapper {
|
|
119
|
+
.el-input__wrapper {
|
|
120
|
+
height: var(--ct-component-inner-height);
|
|
121
|
+
padding: 1px var(--ct-component-inner-padding);
|
|
122
|
+
box-shadow: unset;
|
|
123
|
+
border-radius: 0;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
&:not(.is-disabled):hover {
|
|
128
|
+
--ct-component-border-color: var(--ct-component-hover-border-color);
|
|
129
|
+
}
|
|
130
|
+
&__wrapper {
|
|
131
|
+
display: inline-flex;
|
|
132
|
+
flex-grow: 1;
|
|
133
|
+
align-items: center;
|
|
134
|
+
justify-content: center;
|
|
135
|
+
padding: 1px 0;
|
|
136
|
+
background-color: var(--ct-component-fill-color);
|
|
137
|
+
background-image: none;
|
|
138
|
+
border-radius: var(--ct-component-border-radius);
|
|
139
|
+
transition: var(--el-transition-box-shadow);
|
|
140
|
+
transform: translate3d(0, 0, 0);
|
|
141
|
+
box-shadow: 0 0 0 1px var(--ct-component-border-color) inset;
|
|
142
|
+
&:focus-within {
|
|
143
|
+
--ct-component-border-color: var(--ct-color-primary);
|
|
144
|
+
}
|
|
145
|
+
.el-input-number {
|
|
146
|
+
width: calc(50% - 8px);
|
|
147
|
+
&.is-controls-right .el-input__wrapper {
|
|
148
|
+
padding: 1px var(--ct-component-inner-padding);
|
|
149
|
+
}
|
|
150
|
+
.el-input__wrapper {
|
|
151
|
+
padding: 1px var(--ct-component-inner-padding);
|
|
152
|
+
box-shadow: unset;
|
|
153
|
+
border-radius: 0;
|
|
154
|
+
}
|
|
155
|
+
.el-input__inner {
|
|
156
|
+
color: var(--ct-component-color);
|
|
157
|
+
font-size: inherit;
|
|
158
|
+
}
|
|
159
|
+
span[role="button"] {
|
|
160
|
+
display: none;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
&__separator {
|
|
165
|
+
color: var(--ct-color-grey-sub);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
</style>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { buriedParamsKey, searchComponentProps } from "../../../hooks";
|
|
2
|
+
import arrowDown from "./arrow-down.vue";
|
|
3
|
+
import clearIcon from "./clear-icon.vue";
|
|
4
|
+
|
|
5
|
+
export const selectEmits = ["update:modelValue", buriedParamsKey];
|
|
6
|
+
export const selectProps = {
|
|
7
|
+
...searchComponentProps,
|
|
8
|
+
modelValue: [String, Number, Array, Boolean],
|
|
9
|
+
multiple: Boolean,
|
|
10
|
+
filterable: Boolean,
|
|
11
|
+
api: String,
|
|
12
|
+
serviceMethod: String,
|
|
13
|
+
serviceParams: Object,
|
|
14
|
+
mapObj: {
|
|
15
|
+
type: Object,
|
|
16
|
+
default() {
|
|
17
|
+
return {};
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
pageSize: {
|
|
21
|
+
type: Number,
|
|
22
|
+
default: 50,
|
|
23
|
+
},
|
|
24
|
+
selectAllText: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: "全部",
|
|
27
|
+
},
|
|
28
|
+
connectors: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: "、",
|
|
31
|
+
},
|
|
32
|
+
fitInputWidth: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: true,
|
|
35
|
+
},
|
|
36
|
+
clearIcon: {
|
|
37
|
+
type: [String, Object],
|
|
38
|
+
default() {
|
|
39
|
+
return clearIcon;
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
suffixIcon: {
|
|
43
|
+
type: [String, Object],
|
|
44
|
+
default() {
|
|
45
|
+
return arrowDown;
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
noMatchText: String,
|
|
49
|
+
noDataText: String,
|
|
50
|
+
};
|
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- {{ rawAttr }}-- -->
|
|
3
|
+
<el-select
|
|
4
|
+
ref="selectRef"
|
|
5
|
+
:class="[ns.b(), ns.is('multiple', multiple)]"
|
|
6
|
+
v-model="valueModel"
|
|
7
|
+
collapse-tags
|
|
8
|
+
v-bind="rawAttr"
|
|
9
|
+
:multiple="multiple"
|
|
10
|
+
:filterable="filterable"
|
|
11
|
+
:clear-icon="clearIcon"
|
|
12
|
+
:suffix-icon="suffixIcon"
|
|
13
|
+
:fit-input-width="fitInputWidth"
|
|
14
|
+
:select-text="selectText"
|
|
15
|
+
:popper-class="ns.e('popper')"
|
|
16
|
+
@focus="showSearchPrefix"
|
|
17
|
+
@blur="hideSearchPrefix"
|
|
18
|
+
@click="focusSearchInput"
|
|
19
|
+
@visible-change="handleListSort"
|
|
20
|
+
>
|
|
21
|
+
<template #prefix>
|
|
22
|
+
<div
|
|
23
|
+
:class="[ns.e('filterable-icon')]"
|
|
24
|
+
v-if="filterable && showSearch && !multiple"
|
|
25
|
+
>
|
|
26
|
+
<ct-icon name="search_line"></ct-icon>
|
|
27
|
+
</div>
|
|
28
|
+
<slot name="prefix"></slot>
|
|
29
|
+
</template>
|
|
30
|
+
<div :class="[ns.e('top')]" v-if="multiple">
|
|
31
|
+
<div :class="[ns.e('filter')]">
|
|
32
|
+
<el-input v-model="keyword" ref="filterInput" @input="changeKeyword">
|
|
33
|
+
<template #prefix>
|
|
34
|
+
<ct-icon name="search_line"></ct-icon>
|
|
35
|
+
</template>
|
|
36
|
+
</el-input>
|
|
37
|
+
</div>
|
|
38
|
+
<div :class="[ns.e('select')]" v-if="!rawAttr.multipleLimit">
|
|
39
|
+
<span :class="[ns.e('select-title')]">
|
|
40
|
+
<span v-if="!keyword">已选{{ selectLength }}项</span>
|
|
41
|
+
<span v-else>检索结果</span>
|
|
42
|
+
</span>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<div
|
|
46
|
+
:class="[ns.e('options')]"
|
|
47
|
+
v-show="!noFilterOptions"
|
|
48
|
+
ref="optionsRef"
|
|
49
|
+
@scroll="handleScrollLoad"
|
|
50
|
+
>
|
|
51
|
+
<slot>
|
|
52
|
+
<el-option
|
|
53
|
+
v-for="(item, index) in filterOptions"
|
|
54
|
+
:key="item.value"
|
|
55
|
+
:label="item.label"
|
|
56
|
+
:value="item.value"
|
|
57
|
+
:disabled="item.disabled"
|
|
58
|
+
>
|
|
59
|
+
<slot name="option" :item="item" :index="index">
|
|
60
|
+
<span :title="selectTooltip ? item.label : undefined">{{
|
|
61
|
+
item.label
|
|
62
|
+
}}</span>
|
|
63
|
+
</slot>
|
|
64
|
+
</el-option>
|
|
65
|
+
</slot>
|
|
66
|
+
</div>
|
|
67
|
+
<Empty :text="emptyText" v-if="multiple && noFilterOptions" />
|
|
68
|
+
<template #empty>
|
|
69
|
+
<div :class="[ns.e('top')]" v-if="multiple">
|
|
70
|
+
<div :class="[ns.e('filter')]">
|
|
71
|
+
<el-input v-model="keyword" ref="filterInput" @input="changeKeyword">
|
|
72
|
+
<template #prefix>
|
|
73
|
+
<ct-icon name="search_line"></ct-icon>
|
|
74
|
+
</template>
|
|
75
|
+
</el-input>
|
|
76
|
+
</div>
|
|
77
|
+
<div :class="[ns.e('select')]" v-if="!rawAttr.multipleLimit">
|
|
78
|
+
<span :class="[ns.e('select-title')]">
|
|
79
|
+
<span v-if="!keyword">已选{{ selectLength }}项</span>
|
|
80
|
+
<span v-else>检索结果</span>
|
|
81
|
+
</span>
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
<slot name="empty">
|
|
85
|
+
<Empty :text="emptyText" />
|
|
86
|
+
</slot>
|
|
87
|
+
</template>
|
|
88
|
+
</el-select>
|
|
89
|
+
</template>
|
|
90
|
+
|
|
91
|
+
<script setup>
|
|
92
|
+
import { onMounted, computed, ref, watch, inject, nextTick } from "vue";
|
|
93
|
+
import { selectEmits, selectProps } from "./index";
|
|
94
|
+
import { useNamespace, useBuriedParams } from "../../../hooks";
|
|
95
|
+
import { isFunction, isArray } from "../../../utils";
|
|
96
|
+
import Empty from "./empty.vue";
|
|
97
|
+
const baseDao = inject("$ctBaseDao");
|
|
98
|
+
const serviceConfig = inject("$ctServiceConfig");
|
|
99
|
+
const selectTooltip = inject("$selectTooltip");
|
|
100
|
+
|
|
101
|
+
const props = defineProps(selectProps);
|
|
102
|
+
const emit = defineEmits(selectEmits);
|
|
103
|
+
|
|
104
|
+
const ns = useNamespace("select");
|
|
105
|
+
const optionsByApi = ref([]);
|
|
106
|
+
const showOptions = computed(() => {
|
|
107
|
+
return optionsByApi.value;
|
|
108
|
+
});
|
|
109
|
+
const valueModel = computed({
|
|
110
|
+
get() {
|
|
111
|
+
return props.modelValue || (props.multiple ? [] : props.modelValue);
|
|
112
|
+
},
|
|
113
|
+
set(newValue) {
|
|
114
|
+
emit("update:modelValue", newValue);
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
const keyword = ref("");
|
|
118
|
+
const selectRef = ref(null);
|
|
119
|
+
const filterInput = ref(null);
|
|
120
|
+
|
|
121
|
+
const selectLength = computed(() => {
|
|
122
|
+
return valueModel.value.length;
|
|
123
|
+
});
|
|
124
|
+
const filterOptions = ref([]);
|
|
125
|
+
const noFilterOptions = ref(false);
|
|
126
|
+
const pageNo = ref(1);
|
|
127
|
+
const pageSize = computed(() => props.pageSize || 20);
|
|
128
|
+
const total = ref(0);
|
|
129
|
+
const loading = ref(false);
|
|
130
|
+
const selectObj = computed({
|
|
131
|
+
get() {
|
|
132
|
+
if (!props.multiple)
|
|
133
|
+
return showOptions.value.find((item) => item.value === valueModel.value);
|
|
134
|
+
return showOptions.value.filter((item) => {
|
|
135
|
+
return valueModel.value.includes(item.value);
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
set(newValue) {
|
|
139
|
+
if (!props.multiple) {
|
|
140
|
+
valueModel.value = newValue.value;
|
|
141
|
+
} else {
|
|
142
|
+
valueModel.value = newValue.map((item) => item.value);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
const selectText = computed(() => {
|
|
147
|
+
let result = "";
|
|
148
|
+
if (!props.multiple) {
|
|
149
|
+
return result;
|
|
150
|
+
} else {
|
|
151
|
+
if (
|
|
152
|
+
showOptions.value.length &&
|
|
153
|
+
showOptions.value.length === valueModel.value.length
|
|
154
|
+
) {
|
|
155
|
+
result = props.selectAllText;
|
|
156
|
+
} else {
|
|
157
|
+
const cnt = props.connectors;
|
|
158
|
+
result = selectObj.value.map((item) => item.label).join(cnt);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//nextTick(() => {
|
|
162
|
+
// if (selectRef.value) {
|
|
163
|
+
// selectRef.value.$refs.reference.input.value = result;
|
|
164
|
+
// }
|
|
165
|
+
//});
|
|
166
|
+
return result;
|
|
167
|
+
});
|
|
168
|
+
const emptyText = computed(() => {
|
|
169
|
+
return showOptions.value.length
|
|
170
|
+
? props.noMatchText || "暂无匹配数据"
|
|
171
|
+
: props.noDataText || "暂无数据";
|
|
172
|
+
});
|
|
173
|
+
const getUseLabel = (label) => {
|
|
174
|
+
return typeof label === "string" ? label : String(label);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
watch(
|
|
178
|
+
() => selectText.value,
|
|
179
|
+
(newVal) => {
|
|
180
|
+
if (!selectRef.value) return;
|
|
181
|
+
selectRef.value.selectedLabel = newVal;
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
watch(optionsByApi, () => {
|
|
185
|
+
const arr = optionsByApi.value || [];
|
|
186
|
+
if (arr.length) {
|
|
187
|
+
filterOptions.value = arr;
|
|
188
|
+
noFilterOptions.value = false;
|
|
189
|
+
} else {
|
|
190
|
+
filterOptions.value = [];
|
|
191
|
+
noFilterOptions.value = true;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const optionsRef = ref(null);
|
|
196
|
+
//针对多选时,已选的项要排在整个列表的最前面
|
|
197
|
+
const handleListSort = (val) => {
|
|
198
|
+
if (props.multiple) {
|
|
199
|
+
if (val) {
|
|
200
|
+
const selectedSet = new Set(valueModel.value);
|
|
201
|
+
filterOptions.value = [
|
|
202
|
+
...filterOptions.value.filter((item) => selectedSet.has(item.value)), // 选中的项
|
|
203
|
+
...filterOptions.value.filter((item) => !selectedSet.has(item.value)), // 未选中的项
|
|
204
|
+
];
|
|
205
|
+
nextTick(() => {
|
|
206
|
+
optionsRef.value.scrollTop = 0;
|
|
207
|
+
});
|
|
208
|
+
} else {
|
|
209
|
+
keyword.value = "";
|
|
210
|
+
if (!valueModel.value.length) {
|
|
211
|
+
filterOptions.value = [...showOptions.value];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const watchServiceHandle = async (reset = false) => {
|
|
217
|
+
// 通过api获取数据,会监听api以及serviceParams的改变(收集到的依赖改变)都会触发重新查询
|
|
218
|
+
const cbs = props.cbs || {};
|
|
219
|
+
if (props.api && baseDao) {
|
|
220
|
+
try {
|
|
221
|
+
const method = props.serviceMethod || serviceConfig.defaultMethod;
|
|
222
|
+
let params = { ...(props.serviceParams || {}) };
|
|
223
|
+
if (reset) {
|
|
224
|
+
pageNo.value = 1;
|
|
225
|
+
optionsByApi.value = [];
|
|
226
|
+
}
|
|
227
|
+
params.keyword = keyword.value;
|
|
228
|
+
params.page_no = pageNo.value;
|
|
229
|
+
params.page_size = pageSize.value;
|
|
230
|
+
if (isFunction(cbs.beforeSearch)) {
|
|
231
|
+
const paramsHandle = await cbs.beforeSearch(params);
|
|
232
|
+
if (paramsHandle === false) return;
|
|
233
|
+
params = paramsHandle || params;
|
|
234
|
+
}
|
|
235
|
+
loading.value = true;
|
|
236
|
+
baseDao[method](props.api, params)
|
|
237
|
+
.then((res) => {
|
|
238
|
+
const mapObj = props.mapObj || {};
|
|
239
|
+
const {
|
|
240
|
+
list,
|
|
241
|
+
label = "label",
|
|
242
|
+
value = "value",
|
|
243
|
+
self,
|
|
244
|
+
total: totalKey = "total",
|
|
245
|
+
} = mapObj;
|
|
246
|
+
let data = [];
|
|
247
|
+
if (list) {
|
|
248
|
+
data = res[list];
|
|
249
|
+
} else {
|
|
250
|
+
data = res;
|
|
251
|
+
}
|
|
252
|
+
data = data.map((item) => {
|
|
253
|
+
if (self) {
|
|
254
|
+
return { label: getUseLabel(item), value: item };
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
...item,
|
|
258
|
+
label: getUseLabel(item[label]),
|
|
259
|
+
value: item[value],
|
|
260
|
+
};
|
|
261
|
+
});
|
|
262
|
+
total.value = (res && res[totalKey]) || 0;
|
|
263
|
+
optionsByApi.value =
|
|
264
|
+
pageNo.value > 1 ? optionsByApi.value.concat(data) : data;
|
|
265
|
+
if (isFunction(cbs.afterSearch)) {
|
|
266
|
+
cbs.afterSearch(res, optionsByApi, valueModel);
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
.finally(() => {
|
|
270
|
+
loading.value = false;
|
|
271
|
+
});
|
|
272
|
+
} catch (error) {
|
|
273
|
+
console.error(error);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (isFunction(cbs.defineSearch)) {
|
|
277
|
+
try {
|
|
278
|
+
const defineSearchHandle = await cbs.defineSearch(
|
|
279
|
+
optionsByApi,
|
|
280
|
+
valueModel
|
|
281
|
+
);
|
|
282
|
+
if (defineSearchHandle === false) return;
|
|
283
|
+
if (defineSearchHandle) {
|
|
284
|
+
optionsByApi.value = defineSearchHandle;
|
|
285
|
+
}
|
|
286
|
+
} catch (error) {}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
watch(
|
|
290
|
+
[
|
|
291
|
+
() => props.api,
|
|
292
|
+
() => props.serviceParams,
|
|
293
|
+
() => props.serviceMethod,
|
|
294
|
+
() => props.mapObj,
|
|
295
|
+
],
|
|
296
|
+
(newVal, oldVal) => {
|
|
297
|
+
watchServiceHandle(true);
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
immediate: true,
|
|
301
|
+
}
|
|
302
|
+
);
|
|
303
|
+
// watch(
|
|
304
|
+
// () => keyword.value,
|
|
305
|
+
// () => {
|
|
306
|
+
|
|
307
|
+
// watchServiceHandle(true);
|
|
308
|
+
// }
|
|
309
|
+
// );
|
|
310
|
+
|
|
311
|
+
function debounce(fn, delay = 300) {
|
|
312
|
+
//防抖
|
|
313
|
+
var timer = null; //借助闭包
|
|
314
|
+
return function (...args) {
|
|
315
|
+
const context = this;
|
|
316
|
+
clearTimeout(timer);
|
|
317
|
+
timer = setTimeout(() => {
|
|
318
|
+
fn.apply(context, args);
|
|
319
|
+
}, delay);
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
const changeKeyword = debounce(() => {
|
|
323
|
+
watchServiceHandle(true);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
const handleScrollLoad = (e) => {
|
|
327
|
+
const el = e.target;
|
|
328
|
+
const reach = el.scrollTop + el.clientHeight >= el.scrollHeight - 2;
|
|
329
|
+
const hasMore = total.value > pageNo.value * pageSize.value;
|
|
330
|
+
if (reach && hasMore && !loading.value) {
|
|
331
|
+
pageNo.value += 1;
|
|
332
|
+
watchServiceHandle();
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const focusFilter = () => {
|
|
337
|
+
if (filterInput.value && filterInput.value.focus) {
|
|
338
|
+
filterInput.value.focus();
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const showSearch = ref(false);
|
|
343
|
+
const focusSearchInput = () => {
|
|
344
|
+
setTimeout(() => {
|
|
345
|
+
filterInput.value && filterInput.value.focus();
|
|
346
|
+
// keyword.value = "";
|
|
347
|
+
}, 300);
|
|
348
|
+
};
|
|
349
|
+
const showSearchPrefix = () => {
|
|
350
|
+
showSearch.value = true;
|
|
351
|
+
};
|
|
352
|
+
const hideSearchPrefix = () => {
|
|
353
|
+
showSearch.value = false;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
useBuriedParams(props, emit, {
|
|
357
|
+
getContent: () => {
|
|
358
|
+
const select = selectObj.value || {};
|
|
359
|
+
if (isArray(select)) {
|
|
360
|
+
return select.map((item) => item.label);
|
|
361
|
+
}
|
|
362
|
+
return select.label;
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
onMounted(() => {
|
|
367
|
+
if (!baseDao) {
|
|
368
|
+
console.error("请先配置baseDao");
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
defineExpose({
|
|
372
|
+
ref: selectRef,
|
|
373
|
+
keyword,
|
|
374
|
+
filterInput,
|
|
375
|
+
focusFilter,
|
|
376
|
+
baseDao,
|
|
377
|
+
serviceConfig,
|
|
378
|
+
noFilterOptions,
|
|
379
|
+
selectObj,
|
|
380
|
+
});
|
|
381
|
+
</script>
|
|
382
|
+
<style lang="less">
|
|
383
|
+
.ct-select {
|
|
384
|
+
width: 214px;
|
|
385
|
+
&.el-select {
|
|
386
|
+
position: relative;
|
|
387
|
+
}
|
|
388
|
+
&__top {
|
|
389
|
+
padding: 0 16px;
|
|
390
|
+
font-size: var(--ct-font-size);
|
|
391
|
+
}
|
|
392
|
+
&__options {
|
|
393
|
+
max-height: 274px;
|
|
394
|
+
overflow-y: auto;
|
|
395
|
+
}
|
|
396
|
+
&__select {
|
|
397
|
+
display: flex;
|
|
398
|
+
justify-content: space-between;
|
|
399
|
+
align-items: center;
|
|
400
|
+
margin-bottom: 10px;
|
|
401
|
+
&-title {
|
|
402
|
+
color: var(--ct-color-grey-sub);
|
|
403
|
+
line-height: 1;
|
|
404
|
+
}
|
|
405
|
+
.el-checkbox {
|
|
406
|
+
height: auto;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
&__filter {
|
|
410
|
+
margin-bottom: 16px;
|
|
411
|
+
.el-input {
|
|
412
|
+
--el-input-height: 28px;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
&__popper {
|
|
416
|
+
&.is-multiple {
|
|
417
|
+
min-width: 140px;
|
|
418
|
+
}
|
|
419
|
+
.el-select-dropdown__wrap {
|
|
420
|
+
max-height: unset;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
.el-select__tags {
|
|
424
|
+
display: none;
|
|
425
|
+
}
|
|
426
|
+
.el-input__prefix-inner {
|
|
427
|
+
& > :last-child {
|
|
428
|
+
margin-right: 0;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
&__filterable-icon {
|
|
432
|
+
position: absolute;
|
|
433
|
+
z-index: 3;
|
|
434
|
+
right: var(--ct-component-inner-padding);
|
|
435
|
+
top: 50%;
|
|
436
|
+
height: calc(var(--ct-component-size) - 2px);
|
|
437
|
+
transform: translateY(-50%);
|
|
438
|
+
background-color: #fff;
|
|
439
|
+
}
|
|
440
|
+
&__empty {
|
|
441
|
+
display: flex;
|
|
442
|
+
justify-content: center;
|
|
443
|
+
align-items: center;
|
|
444
|
+
padding: 15px 16px;
|
|
445
|
+
color: var(--ct-color-grey-sub);
|
|
446
|
+
}
|
|
447
|
+
&.is-multiple {
|
|
448
|
+
&::after {
|
|
449
|
+
content: attr(select-text);
|
|
450
|
+
position: absolute;
|
|
451
|
+
left: var(--ct-component-inner-padding);
|
|
452
|
+
right: calc(var(--ct-component-inner-padding) * 2);
|
|
453
|
+
top: 50%;
|
|
454
|
+
transform: translateY(-50%);
|
|
455
|
+
text-overflow: ellipsis;
|
|
456
|
+
overflow: hidden;
|
|
457
|
+
white-space: nowrap;
|
|
458
|
+
cursor: pointer;
|
|
459
|
+
pointer-events: none;
|
|
460
|
+
}
|
|
461
|
+
.el-select__placeholder.is-transparent {
|
|
462
|
+
display: block;
|
|
463
|
+
}
|
|
464
|
+
.el-select__selected-item {
|
|
465
|
+
display: none;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
</style>
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import CtSearchBox from
|
|
1
|
+
import CtSearchBox from "./src/search-box.vue";
|
|
2
2
|
|
|
3
|
-
import CtInput from
|
|
4
|
-
import CtSelect from
|
|
5
|
-
import CtDatePicker from
|
|
6
|
-
import CtCascader from
|
|
7
|
-
import CtYearSelect from
|
|
8
|
-
import CtRadio from
|
|
3
|
+
import CtInput from "../input";
|
|
4
|
+
import CtSelect from "../select";
|
|
5
|
+
import CtDatePicker from "../date-picker";
|
|
6
|
+
import CtCascader from "../cascader";
|
|
7
|
+
import CtYearSelect from "../year-select";
|
|
8
|
+
import CtRadio from "../radio";
|
|
9
|
+
import CtNumberInputRange from "../number-input-range";
|
|
10
|
+
import CtPagingSelect from "../paging-select";
|
|
9
11
|
|
|
10
12
|
export const searchComponents = {
|
|
11
13
|
CtInput,
|
|
@@ -13,15 +15,17 @@ export const searchComponents = {
|
|
|
13
15
|
CtDatePicker,
|
|
14
16
|
CtCascader,
|
|
15
17
|
CtYearSelect,
|
|
16
|
-
CtRadio
|
|
17
|
-
|
|
18
|
+
CtRadio,
|
|
19
|
+
CtNumberInputRange,
|
|
20
|
+
CtPagingSelect,
|
|
21
|
+
};
|
|
18
22
|
|
|
19
23
|
/* istanbul ignore next */
|
|
20
24
|
CtSearchBox.install = function (Vue) {
|
|
21
|
-
Vue.component(
|
|
25
|
+
Vue.component("CtSearchBox", CtSearchBox);
|
|
22
26
|
// for (const key in searchComponents) {
|
|
23
27
|
// Vue.component(key, searchComponents[key]);
|
|
24
28
|
// }
|
|
25
29
|
};
|
|
26
30
|
|
|
27
|
-
export default CtSearchBox;
|
|
31
|
+
export default CtSearchBox;
|
|
@@ -98,7 +98,7 @@ const judgeIsHideLabelTooltip = (item) => {
|
|
|
98
98
|
|
|
99
99
|
const clickItem = (item) => {
|
|
100
100
|
emit("clickItem", item);
|
|
101
|
-
}
|
|
101
|
+
};
|
|
102
102
|
const getComponentClass = (item) => {
|
|
103
103
|
const classList = [];
|
|
104
104
|
if (item.componentClass) {
|
|
@@ -117,8 +117,16 @@ const getComponentStyle = (item) => {
|
|
|
117
117
|
return style;
|
|
118
118
|
};
|
|
119
119
|
const componentAll = computed(() => {
|
|
120
|
-
const {
|
|
121
|
-
|
|
120
|
+
const {
|
|
121
|
+
CtInput,
|
|
122
|
+
CtSelect,
|
|
123
|
+
CtDatePicker,
|
|
124
|
+
CtCascader,
|
|
125
|
+
CtYearSelect,
|
|
126
|
+
CtRadio,
|
|
127
|
+
CtNumberInputRange,
|
|
128
|
+
CtPagingSelect,
|
|
129
|
+
} = searchComponents;
|
|
122
130
|
const componentMap = {
|
|
123
131
|
0: CtInput,
|
|
124
132
|
1: CtSelect,
|
|
@@ -127,6 +135,8 @@ const componentAll = computed(() => {
|
|
|
127
135
|
12: CtYearSelect,
|
|
128
136
|
13: "div",
|
|
129
137
|
20: CtRadio,
|
|
138
|
+
21: CtNumberInputRange,
|
|
139
|
+
22: CtPagingSelect,
|
|
130
140
|
...userDefinedSearchComponent,
|
|
131
141
|
};
|
|
132
142
|
return componentMap;
|
|
@@ -239,7 +249,8 @@ onMounted(() => {});
|
|
|
239
249
|
}
|
|
240
250
|
.el-input__wrapper,
|
|
241
251
|
.el-select__wrapper,
|
|
242
|
-
.ct-year-select__wrapper
|
|
252
|
+
.ct-year-select__wrapper,
|
|
253
|
+
.ct-number-input-range__wrapper {
|
|
243
254
|
--el-select-input-focus-border-color: var(
|
|
244
255
|
--ct-search-box-inner-border-color
|
|
245
256
|
);
|
|
@@ -183,7 +183,10 @@ watch(
|
|
|
183
183
|
watchEffect(async () => {
|
|
184
184
|
// 输入框过滤,触发的事件
|
|
185
185
|
let arr = showOptions.value.filter((item) => {
|
|
186
|
-
return
|
|
186
|
+
return (
|
|
187
|
+
item.label &&
|
|
188
|
+
item.label.toLowerCase().includes(keyword.value.toLowerCase())
|
|
189
|
+
);
|
|
187
190
|
});
|
|
188
191
|
const cbs = props.cbs || {};
|
|
189
192
|
if (isFunction(cbs.filterCallback)) {
|