wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<template>
    <div class="cl-number-range">
        <el-input-number
            v-model="value[0]"
            :controls="false"
            :placeholder="startPlaceholder || $t('起')"
            :min="min"
            :max="value[1] ?? max"
            @focus="onFocus"
            @change="onChange"
        />
        <span class="cl-number-range__separator">~</span>
        <el-input-number
            v-model="value[1]"
            :controls="false"
            :placeholder="endPlaceholder || $t('止')"
            :min="value[0] ?? min"
            :max="max"
            @focus="onFocus"
            @change="onChange"
        />
    </div>
</template>
 
<script setup lang="ts">
defineOptions({
    name: 'cl-number-range'
});
 
import { type PropType, useModel } from 'vue';
 
const props = defineProps({
    modelValue: {
        type: Array as PropType<any[]>
    },
    startPlaceholder: String,
    endPlaceholder: String,
    min: {
        type: Number,
        default: 0
    },
    max: {
        type: Number,
        default: 100000
    }
});
 
const emit = defineEmits(['update:modelValue']);
 
const value = useModel(props, 'modelValue', {
    get() {
        return props.modelValue ?? [];
    }
});
 
function onFocus() {
    emit('update:modelValue', value.value || []);
}
 
function onChange() {
    emit('update:modelValue', value.value);
}
</script>
 
<style lang="scss" scoped>
.cl-number-range {
    display: flex;
    align-items: center;
 
    &__separator {
        margin: 0 10px;
    }
 
    .el-input-number {
        width: 100px;
    }
}
</style>