CardLayoutButton.vue
1.29 KB
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
<script lang="ts" setup>
import { Popover, Slider, Button } from 'ant-design-vue';
import { LayoutOutlined } from '@ant-design/icons-vue';
import { computed } from 'vue';
const props = withDefaults(
defineProps<{
min?: number;
max?: number;
value?: number;
}>(),
{
min: 4,
max: 12,
value: 4,
}
);
const emit = defineEmits(['change', 'update:value']);
const generateLayoutMarks = (min: number, max: number) => {
const marks = {};
Array.from({ length: max - min + 1 }).forEach((_, index) => {
const key = index + min;
marks[key] = key;
});
return marks;
};
const getMarks = computed(() => {
const { min, max } = props;
return generateLayoutMarks(min, max);
});
const handleChange = (value: number) => {
emit('update:value', value);
emit('change', value);
};
</script>
<template>
<Popover :trigger="['hover']">
<template #content>
<div class="w-60">
<div>每行显示数量</div>
<Slider
:value="props.value"
:max="props.max"
:min="props.min"
:marks="getMarks"
@change="handleChange"
/>
</div>
</template>
<Button type="primary">
<LayoutOutlined />
</Button>
</Popover>
</template>