zhengyiming
2025-02-10 958b79ed89b9e742540f714a80261d222c0fc09b
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
<template>
  <ProFieldCustom>
    <FieldInputNumber v-model="innerLeft" :controls="false" v-bind="leftProps" />
    <div class="form-input-separator">{{ separator }}</div>
    <FieldInputNumber v-model="innerRight" :controls="false" v-bind="rightProps" />
    <div class="form-input-unit" v-if="unit">{{ unit }}</div>
    <template #readContent>{{ readContent }}</template>
  </ProFieldCustom>
</template>
 
<script setup lang="ts">
import { ProFieldCustom, FieldInputNumber } from '@bole-core/components';
import { useVModel } from '@/hooks';
 
defineOptions({
  name: 'ProFormRangeInputNumber',
});
 
type Props = {
  left: number;
  right: number;
  leftProps?: object;
  rightProps?: object;
  separator?: string;
  unit?: string;
};
 
const props = withDefaults(defineProps<Props>(), {
  leftProps: () => ({}),
  rightProps: () => ({}),
  separator: '至',
});
 
const emit = defineEmits<{
  (e: 'update:left', val: number): void;
  (e: 'update:right', val: number): void;
}>();
 
const innerLeft = useVModel(props, 'left', emit);
const innerRight = useVModel(props, 'right', emit);
 
const readContent = computed(() => {
  return `${innerLeft.value}${props.separator}${innerRight.value}${props.unit ?? ''}`;
});
</script>