yh-mobile-components 1.3.3 → 1.4.0
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/CHANGELOG.md +1 -0
- package/form/yhmSelect.vue +63 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/form/yhmSelect.vue
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<van-field
|
|
3
|
-
class="yhm-
|
|
3
|
+
class="yhm-select-container"
|
|
4
4
|
:disabled="disabled"
|
|
5
5
|
v-bind="$attrs"
|
|
6
6
|
:error="error"
|
|
7
7
|
:error-message="errorMessage">
|
|
8
8
|
<template #input>
|
|
9
9
|
<div
|
|
10
|
-
class="yhm-
|
|
10
|
+
class="yhm-select-value"
|
|
11
11
|
:class="valueClass"
|
|
12
12
|
@click="toChoose">
|
|
13
13
|
{{ valueString }}
|
|
@@ -16,27 +16,42 @@
|
|
|
16
16
|
</van-field>
|
|
17
17
|
<van-popup
|
|
18
18
|
v-model:show="show"
|
|
19
|
-
class="yhm-
|
|
19
|
+
class="yhm-select-container"
|
|
20
20
|
position="bottom">
|
|
21
21
|
<van-picker
|
|
22
22
|
:title="palceholder"
|
|
23
|
-
:columns="
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@
|
|
23
|
+
:columns="filterOptionData"
|
|
24
|
+
:modelValue="[modelValue]"
|
|
25
|
+
ref="pickerRef"
|
|
26
|
+
@confirm="onComfirm"
|
|
27
|
+
@cancel="onCancel">
|
|
28
|
+
<template
|
|
29
|
+
#title
|
|
30
|
+
v-if="filterabled">
|
|
31
|
+
<input
|
|
32
|
+
class="yhm-select-filter-input"
|
|
33
|
+
placeholder="输入关键词筛选"
|
|
34
|
+
type="text"
|
|
35
|
+
v-model="filterKeyword"
|
|
36
|
+
@input="filterChange" />
|
|
37
|
+
</template>
|
|
38
|
+
</van-picker>
|
|
27
39
|
</van-popup>
|
|
28
40
|
</template>
|
|
29
41
|
<script setup lang="ts">
|
|
30
42
|
import { ref, computed } from "vue";
|
|
31
43
|
|
|
32
|
-
const props = withDefaults(defineProps<{ error?: boolean; errorMessage?: string; modelValue?: any; disabled?: boolean; palceholder?: string; optionData: any[] }>(), {
|
|
44
|
+
const props = withDefaults(defineProps<{ error?: boolean; errorMessage?: string; modelValue?: any; disabled?: boolean; palceholder?: string; optionData: any[]; filterabled: boolean; remoteFilter: boolean }>(), {
|
|
33
45
|
disabled: false,
|
|
46
|
+
filterabled: false,
|
|
47
|
+
remoteFilter: false,
|
|
34
48
|
palceholder: "请选择",
|
|
35
49
|
});
|
|
36
50
|
|
|
37
51
|
const emits = defineEmits<{
|
|
38
52
|
(e: "update:modelValue", val: string);
|
|
39
53
|
(e: "change", val: string);
|
|
54
|
+
(e: "filter", val: string);
|
|
40
55
|
}>();
|
|
41
56
|
|
|
42
57
|
const valueString = computed(() => {
|
|
@@ -55,6 +70,29 @@ const valueClass = computed(() => {
|
|
|
55
70
|
});
|
|
56
71
|
|
|
57
72
|
const show = ref(false);
|
|
73
|
+
const pickerRef = ref();
|
|
74
|
+
|
|
75
|
+
const filterKeyword = ref("");
|
|
76
|
+
const filterOptionData = computed(() => {
|
|
77
|
+
if (props.filterabled && !props.remoteFilter) {
|
|
78
|
+
return props.optionData.filter(({ text, value }) => {
|
|
79
|
+
return text.indexOf(filterKeyword.value) > -1 || value.indexOf(filterKeyword.value) > -1;
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
return props.optionData;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
let filterTimer = null;
|
|
86
|
+
function filterChange() {
|
|
87
|
+
if (filterTimer) {
|
|
88
|
+
clearTimeout(filterTimer);
|
|
89
|
+
filterTimer = null;
|
|
90
|
+
}
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
filterTimer = setTimeout(() => {
|
|
93
|
+
emits("filter", filterKeyword.value);
|
|
94
|
+
}, 300);
|
|
95
|
+
}
|
|
58
96
|
|
|
59
97
|
function toChoose() {
|
|
60
98
|
if (props.disabled) {
|
|
@@ -63,17 +101,22 @@ function toChoose() {
|
|
|
63
101
|
show.value = true;
|
|
64
102
|
}
|
|
65
103
|
|
|
66
|
-
function onChange({ selectedValues }) {
|
|
67
|
-
|
|
68
|
-
}
|
|
104
|
+
// function onChange({ selectedValues }) {
|
|
105
|
+
// emits("update:modelValue", selectedValues[0]);
|
|
106
|
+
// }
|
|
69
107
|
function onCancel() {
|
|
70
108
|
show.value = false;
|
|
71
109
|
}
|
|
110
|
+
|
|
111
|
+
function onComfirm({ selectedValues }) {
|
|
112
|
+
emits("update:modelValue", selectedValues[0]);
|
|
113
|
+
onCancel();
|
|
114
|
+
}
|
|
72
115
|
</script>
|
|
73
116
|
<style lang="scss">
|
|
74
|
-
.yhm-
|
|
117
|
+
.yhm-select-container {
|
|
75
118
|
--van-switch-width: calc(3em + 4px);
|
|
76
|
-
.yhm-
|
|
119
|
+
.yhm-select-value {
|
|
77
120
|
flex: 1;
|
|
78
121
|
width: 100%;
|
|
79
122
|
text-align: right;
|
|
@@ -83,6 +126,13 @@ function onCancel() {
|
|
|
83
126
|
}
|
|
84
127
|
&.van-popup {
|
|
85
128
|
height: 560px;
|
|
129
|
+
.yhm-select-filter-input {
|
|
130
|
+
flex: 1;
|
|
131
|
+
line-height: 30px;
|
|
132
|
+
font-size: 12px;
|
|
133
|
+
border: 1px solid var(--van-border-color);
|
|
134
|
+
padding: 0 8px;
|
|
135
|
+
}
|
|
86
136
|
}
|
|
87
137
|
}
|
|
88
138
|
</style>
|