kui-vue 3.6.2 → 3.6.4
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/components/card/card.jsx +19 -9
- package/components/card/demo/basic.md +3 -3
- package/components/card/demo/border.md +1 -7
- package/components/card/demo/index.jsx +9 -7
- package/components/card/demo/notitle.md +23 -0
- package/components/card/styles/index.less +5 -3
- package/components/checkbox/styles/index.less +1 -0
- package/components/collapse/styles/index.less +2 -2
- package/components/colorPicker/mode.jsx +1 -1
- package/components/components.js +3 -0
- package/components/drawer/demo/target.md +2 -2
- package/components/drawer/drawer.jsx +48 -74
- package/components/drawer/styles/index.less +38 -67
- package/components/dropdown/demo/basic.md +1 -1
- package/components/dropdown/demo/rightmenu.md +1 -1
- package/components/dropdown/styles/index.less +181 -24
- package/components/flex/demo/size.md +14 -5
- package/components/form/demo/customvalid.md +1 -1
- package/components/form/demo/dynamicvalid.md +1 -1
- package/components/form/demo/length.md +1 -13
- package/components/form/demo/valid.md +10 -1
- package/components/form/form.jsx +1 -1
- package/components/grid/demo/align.md +5 -5
- package/components/grid/demo/basic.md +2 -2
- package/components/grid/demo/fill.md +8 -8
- package/components/grid/demo/flex.md +7 -7
- package/components/grid/demo/gutter.md +2 -4
- package/components/grid/demo/offset.md +5 -5
- package/components/input/demo/icon.md +9 -2
- package/components/input/demo/theme.md +1 -1
- package/components/input/input.jsx +12 -10
- package/components/inputNumber/demo/basic.md +1 -0
- package/components/inputNumber/demo/format.md +3 -8
- package/components/inputNumber/inputNumber.jsx +116 -139
- package/components/inputNumber/styles/index.less +3 -3
- package/components/layout/demo/layout2.md +0 -12
- package/components/layout/demo/layout5.md +0 -1
- package/components/locale/de.js +1 -0
- package/components/locale/el.js +1 -0
- package/components/locale/en.js +1 -0
- package/components/locale/fr.js +1 -0
- package/components/locale/it.js +1 -0
- package/components/locale/ja.js +1 -0
- package/components/locale/ko.js +1 -0
- package/components/locale/ru.js +1 -0
- package/components/locale/th.js +1 -0
- package/components/locale/uk.js +1 -0
- package/components/locale/vi.js +1 -0
- package/components/locale/zh-CN.js +1 -0
- package/components/locale/zh-TW.js +1 -0
- package/components/menu/demo/collapsed.md +9 -9
- package/components/menu/index.md +1 -0
- package/components/menu/styles/index.less +229 -375
- package/components/message/group.jsx +11 -4
- package/components/rate/rate.jsx +7 -2
- package/components/rate/star.jsx +20 -5
- package/components/select/demo/filterable.md +1 -0
- package/components/select/demo/multiple.md +3 -0
- package/components/select/select.jsx +23 -19
- package/components/slider/demo/vertical.md +2 -1
- package/components/slider/demo/withNumber.md +0 -2
- package/components/slider/index.md +2 -3
- package/components/slider/slider.jsx +296 -291
- package/components/slider/styles/index.less +11 -12
- package/components/slider/thumb.jsx +70 -148
- package/components/spin/demo/container.md +1 -1
- package/components/spin/demo/mode.md +1 -1
- package/components/statCard/countup.js +254 -0
- package/components/statCard/countup.jsx +45 -0
- package/components/statCard/demo/basic.md +31 -0
- package/components/statCard/demo/card.md +40 -0
- package/components/statCard/demo/index.jsx +19 -0
- package/components/statCard/demo/info.md +9 -0
- package/components/statCard/demo/with-card.md +43 -0
- package/components/statCard/index.js +3 -0
- package/components/statCard/index.md +28 -0
- package/components/statCard/rollup.jsx +64 -0
- package/components/statCard/statCard.jsx +42 -0
- package/components/statCard/statNumber.jsx +53 -0
- package/components/statCard/styles/index.less +76 -0
- package/components/styles/color.less +4 -2
- package/components/styles/index.less +1 -0
- package/components/styles/sys.less +2 -3
- package/components/styles/var.less +1 -0
- package/components/table/demo/col-row-span.md +1 -1
- package/components/table/demo/custom-header.md +1 -1
- package/components/table/demo/fixed-col-head.md +1 -1
- package/components/table/demo/head-span.md +2 -2
- package/components/table/demo/size.md +1 -1
- package/components/table/demo/table-check.md +11 -1
- package/components/table/index.md +13 -12
- package/components/table/styles/index.less +67 -58
- package/components/table/table.jsx +7 -5
- package/components/tabs/demo/sample.md +1 -8
- package/components/tabs/index.md +9 -9
- package/components/tabs/tabs.jsx +6 -4
- package/components/treeselect/treeselect.jsx +17 -17
- package/components/upload/demo/custom.md +5 -2
- package/components/upload/demo/exceed.md +1 -1
- package/components/upload/demo/pictures.md +14 -0
- package/components/upload/fileList.jsx +24 -47
- package/components/upload/index.md +13 -4
- package/components/upload/selector.jsx +37 -117
- package/components/upload/styles/index.less +2 -3
- package/components/upload/upload.jsx +189 -116
- package/components/utils/number.js +79 -65
- package/components/utils/placement.js +4 -4
- package/components/utils/vnode.jsx +46 -25
- package/dist/k-ui.cjs.js +2 -2
- package/dist/k-ui.css +2 -2
- package/dist/k-ui.d.ts +242 -200
- package/dist/k-ui.esm.js +2 -2
- package/dist/k-ui.umd.js +2 -2
- package/dist/locale/de.js +2 -2
- package/dist/locale/el.js +2 -2
- package/dist/locale/en.js +2 -2
- package/dist/locale/fr.js +2 -2
- package/dist/locale/it.js +2 -2
- package/dist/locale/ja.js +2 -2
- package/dist/locale/ko.js +2 -2
- package/dist/locale/ru.js +2 -2
- package/dist/locale/th.js +2 -2
- package/dist/locale/uk.js +2 -2
- package/dist/locale/vi.js +2 -2
- package/dist/locale/zh-CN.js +2 -2
- package/dist/locale/zh-TW.js +2 -2
- package/package.json +3 -1
- package/types/affix/Affix.d.ts +1 -1
- package/types/alert/Alert.d.ts +1 -1
- package/types/avatar/Avatar.d.ts +1 -1
- package/types/backtop/BackTop.d.ts +1 -1
- package/types/badge/Badge.d.ts +1 -1
- package/types/breadcrumb/Breadcrumb.d.ts +1 -1
- package/types/breadcrumb/BreadcrumbItem.d.ts +1 -1
- package/types/button/Button.d.ts +1 -1
- package/types/button/ButtonGroup.d.ts +1 -1
- package/types/card/Card.d.ts +1 -1
- package/types/carousel/Carousel.d.ts +1 -1
- package/types/carousel/CarouselItem.d.ts +1 -1
- package/types/checkbox/Checkbox.d.ts +1 -1
- package/types/checkbox/CheckboxGroup.d.ts +1 -1
- package/types/collapse/Collapse.d.ts +1 -1
- package/types/collapse/CollapsePanel.d.ts +1 -1
- package/types/colorPicker/ColorPicker.d.ts +1 -1
- package/types/datePicker/DatePicker.d.ts +1 -1
- package/types/descriptions/Descriptions.d.ts +1 -1
- package/types/descriptions/DescriptionsItem.d.ts +1 -1
- package/types/divider/Divider.d.ts +1 -1
- package/types/drawer/Drawer.d.ts +2 -2
- package/types/dropdown/Dropdown.d.ts +1 -1
- package/types/dropdown/DropdownButton.d.ts +1 -1
- package/types/empty/Empty.d.ts +1 -1
- package/types/flex/Flex.d.ts +1 -1
- package/types/form/Form.d.ts +1 -1
- package/types/form/formitem.d.ts +1 -1
- package/types/grid/Col.d.ts +1 -1
- package/types/grid/Row.d.ts +1 -1
- package/types/icon/Icon.d.ts +1 -1
- package/types/image/ImageGroup.d.ts +1 -1
- package/types/image/KImage.d.ts +1 -1
- package/types/index.d.ts +16 -12
- package/types/input/Input.d.ts +1 -1
- package/types/input/InputGroup.d.ts +1 -1
- package/types/input/TextArea.d.ts +1 -1
- package/types/inputNumber/InputNumber.d.ts +1 -1
- package/types/layout/sider.d.ts +1 -1
- package/types/loading/loading.d.ts +1 -1
- package/types/menu/Menu.d.ts +1 -1
- package/types/menu/MenuDivider.d.ts +1 -1
- package/types/menu/MenuGroup.d.ts +1 -1
- package/types/menu/MenuItem.d.ts +1 -1
- package/types/menu/SubMenu.d.ts +1 -1
- package/types/modal/Modal.d.ts +1 -1
- package/types/page/Page.d.ts +1 -1
- package/types/popconfirm/Popconfirm.d.ts +1 -1
- package/types/poptip/Poptip.d.ts +1 -1
- package/types/progress/Progress.d.ts +1 -1
- package/types/radio/Radio.d.ts +1 -1
- package/types/radio/RadioButton.d.ts +1 -1
- package/types/radio/RadioGroup.d.ts +1 -1
- package/types/rate/Rate.d.ts +2 -2
- package/types/select/Option.d.ts +1 -1
- package/types/select/Select.d.ts +1 -1
- package/types/skeleton/Skeleton.d.ts +1 -1
- package/types/skeleton/SkeletonAvatar.d.ts +1 -1
- package/types/skeleton/SkeletonButton.d.ts +1 -1
- package/types/skeleton/SkeletonImage.d.ts +1 -1
- package/types/skeleton/SkeletonText.d.ts +1 -1
- package/types/slider/Slider.d.ts +8 -7
- package/types/space/Space.d.ts +1 -1
- package/types/spin/Spin.d.ts +1 -1
- package/types/statCard/StatCard.d.ts +20 -0
- package/types/statCard/StatNumber.d.ts +26 -0
- package/types/switch/Switch.d.ts +1 -1
- package/types/table/Table.d.ts +2 -1
- package/types/tabs/TabPanel.d.ts +1 -1
- package/types/tabs/Tabs.d.ts +1 -1
- package/types/tag/Tag.d.ts +1 -1
- package/types/timeline/TimeLine.d.ts +1 -1
- package/types/timeline/TimeLineItem.d.ts +1 -1
- package/types/tooltip/Tooltip.d.ts +1 -1
- package/types/tree/Tree.d.ts +1 -1
- package/types/treeselect/TreeSelect.d.ts +1 -1
- package/types/upload/Upload.d.ts +1 -1
|
@@ -1,367 +1,372 @@
|
|
|
1
|
+
import { defineComponent, ref, watch, nextTick, inject } from "vue";
|
|
1
2
|
import Thumb from "./thumb";
|
|
2
|
-
import { multiply, add, subtract } from "../utils/number";
|
|
3
|
-
import { defineComponent, ref, provide, watch } from "vue";
|
|
4
3
|
import { withInstall } from "../utils/vue";
|
|
4
|
+
import Big from "big.js";
|
|
5
|
+
import { getClosestStep } from "../utils/number";
|
|
6
|
+
|
|
5
7
|
const Slider = defineComponent({
|
|
6
8
|
name: "Slider",
|
|
7
9
|
props: {
|
|
8
|
-
value: [Array, Number,
|
|
10
|
+
value: { type: [Array, Number], default: 0 },
|
|
9
11
|
min: { type: Number, default: 0 },
|
|
10
12
|
max: { type: Number, default: 100 },
|
|
13
|
+
step: { type: [Number, Object], default: 1 },
|
|
11
14
|
disabled: Boolean,
|
|
12
|
-
step: {
|
|
13
|
-
type: Number,
|
|
14
|
-
default: 1,
|
|
15
|
-
validator: (val) => val !== 0,
|
|
16
|
-
},
|
|
17
|
-
size: String,
|
|
18
15
|
vertical: Boolean,
|
|
19
|
-
range: Boolean,
|
|
20
16
|
reverse: Boolean,
|
|
17
|
+
range: Boolean,
|
|
21
18
|
marks: Object,
|
|
19
|
+
size: [String, Number],
|
|
22
20
|
included: { type: Boolean, default: true },
|
|
23
|
-
tipFormatter:
|
|
21
|
+
tipFormatter: Function,
|
|
24
22
|
tooltipVisible: Boolean,
|
|
25
23
|
},
|
|
26
|
-
|
|
24
|
+
emits: ["input", "change"],
|
|
25
|
+
|
|
26
|
+
setup(props, { emit }) {
|
|
27
|
+
const size = inject("size", null);
|
|
28
|
+
const thumbRefs = ref([]);
|
|
29
|
+
const setThumbRef = (el, index) => {
|
|
30
|
+
if (el) thumbRefs.value[index] = el;
|
|
31
|
+
};
|
|
32
|
+
|
|
27
33
|
const railRef = ref();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
value = ps.value;
|
|
31
|
-
}
|
|
32
|
-
let { min, max } = ps,
|
|
33
|
-
v = 0;
|
|
34
|
-
// let diff = max - min;
|
|
35
|
-
if (!ps.range) {
|
|
36
|
-
v = value;
|
|
37
|
-
if (value >= max) v = max;
|
|
38
|
-
else if (value <= min) v = min;
|
|
39
|
-
// let percent = (v - min) * 100 / diff
|
|
40
|
-
// v = this.getMinStep(percent)
|
|
41
|
-
} else {
|
|
42
|
-
if (!Array.isArray(value)) {
|
|
43
|
-
v = [0, 0];
|
|
44
|
-
} else {
|
|
45
|
-
v = [].concat(value);
|
|
46
|
-
}
|
|
47
|
-
let [x, y] = v;
|
|
34
|
+
// 记录当前正在拖拽的是哪一个滑块 (0 或 1,-1表示未拖拽)
|
|
35
|
+
const draggingIndex = ref(-1);
|
|
48
36
|
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
// 内部值始终保持排序状态
|
|
38
|
+
const internalValue = ref(props.range ? [props.min, props.min] : props.min);
|
|
51
39
|
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
const sortValue = (val) => {
|
|
41
|
+
if (Array.isArray(val)) {
|
|
42
|
+
return [...val].sort((a, b) => a - b);
|
|
43
|
+
}
|
|
44
|
+
return val;
|
|
45
|
+
};
|
|
54
46
|
|
|
55
|
-
|
|
47
|
+
const formatValue = (val) => {
|
|
48
|
+
if (props.range) {
|
|
49
|
+
const arr = Array.isArray(val) ? [...val] : [props.min, props.min];
|
|
50
|
+
return sortValue(arr.map((v) => getClosestStep(v, props)));
|
|
56
51
|
}
|
|
57
|
-
return
|
|
52
|
+
return getClosestStep(val, props);
|
|
58
53
|
};
|
|
59
|
-
|
|
60
|
-
const defaultValue = ref(value);
|
|
54
|
+
|
|
61
55
|
watch(
|
|
62
|
-
() =>
|
|
63
|
-
(nv
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
() => props.value,
|
|
57
|
+
(nv) => {
|
|
58
|
+
// 只有当不在拖拽状态时,才响应外部变化,防止拖拽时的抖动
|
|
59
|
+
if (draggingIndex.value === -1) {
|
|
60
|
+
internalValue.value = formatValue(nv);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{ immediate: true }
|
|
66
64
|
);
|
|
67
65
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let [a, b] = defaultValue.value;
|
|
74
|
-
let v;
|
|
75
|
-
if (plus) {
|
|
76
|
-
v = type === "right" ? [a, add(b, step)] : [add(a, step), b];
|
|
77
|
-
} else {
|
|
78
|
-
v =
|
|
79
|
-
type === "right" ? [a, subtract(b, step)] : [subtract(a, step), b];
|
|
80
|
-
}
|
|
81
|
-
defaultValue.value = getValue(v);
|
|
82
|
-
} else {
|
|
83
|
-
let v = defaultValue.value;
|
|
84
|
-
if (plus) {
|
|
85
|
-
v = add(v, step);
|
|
86
|
-
} else {
|
|
87
|
-
v = subtract(v, step) * 1;
|
|
88
|
-
}
|
|
89
|
-
defaultValue.value = getValue(v);
|
|
90
|
-
}
|
|
91
|
-
// emit("update:value", defaultValue.value);
|
|
92
|
-
emit("input", defaultValue.value);
|
|
66
|
+
const getPercent = (val) => {
|
|
67
|
+
const diff = props.max - props.min;
|
|
68
|
+
return diff === 0
|
|
69
|
+
? 0
|
|
70
|
+
: Math.max(0, Math.min(100, ((val - props.min) / diff) * 100));
|
|
93
71
|
};
|
|
94
72
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
73
|
+
// 计算鼠标位置对应的数值
|
|
74
|
+
const getValueFromEvent = (e) => {
|
|
75
|
+
const rect = railRef.value.getBoundingClientRect();
|
|
76
|
+
const clientX = e.touches ? e.touches[0].clientX : e.clientX;
|
|
77
|
+
const clientY = e.touches ? e.touches[0].clientY : e.clientY;
|
|
78
|
+
|
|
79
|
+
let percent;
|
|
80
|
+
if (props.vertical) {
|
|
81
|
+
// 垂直模式:CSS bottom 是 0%,top 是 100%
|
|
82
|
+
// clientY 越小(越靠上),percent 越大
|
|
83
|
+
percent = (rect.bottom - clientY) / rect.height;
|
|
84
|
+
if (props.reverse) percent = 1 - percent;
|
|
100
85
|
} else {
|
|
101
|
-
|
|
102
|
-
|
|
86
|
+
// 水平模式:CSS left 是 0%,right 是 100%
|
|
87
|
+
percent = (clientX - rect.left) / rect.width;
|
|
88
|
+
if (props.reverse) percent = 1 - percent;
|
|
103
89
|
}
|
|
104
90
|
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
const rawValue = new Big(props.max - props.min)
|
|
92
|
+
.times(percent)
|
|
93
|
+
.plus(props.min);
|
|
94
|
+
return getClosestStep(Number(rawValue), props);
|
|
95
|
+
};
|
|
107
96
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
percent = vertical
|
|
112
|
-
? (height - (clientY - top)) / height
|
|
113
|
-
: (width - (clientX - left)) / width;
|
|
114
|
-
} else {
|
|
115
|
-
percent = vertical
|
|
116
|
-
? (clientY - top) / height
|
|
117
|
-
: (clientX - left) / width;
|
|
118
|
-
}
|
|
119
|
-
if (percent >= 1) percent = 1;
|
|
120
|
-
else if (percent <= 0) percent = 0;
|
|
97
|
+
// 处理滑块拖动
|
|
98
|
+
const handleThumbMove = (e) => {
|
|
99
|
+
if (props.disabled || draggingIndex.value === -1) return;
|
|
121
100
|
|
|
122
|
-
|
|
101
|
+
const newValue = getValueFromEvent(e);
|
|
102
|
+
let nextInternal = null;
|
|
123
103
|
|
|
124
|
-
if (
|
|
125
|
-
|
|
104
|
+
if (props.range) {
|
|
105
|
+
const oldValues = [...internalValue.value];
|
|
106
|
+
// 暂时更新当前拖动的那个值,不去排序
|
|
107
|
+
oldValues[draggingIndex.value] = newValue;
|
|
126
108
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
109
|
+
// 检查是否发生交错 (Crossover)
|
|
110
|
+
// 如果拖动的是 index 0 (左滑块),但它现在比 index 1 (右滑块) 大
|
|
111
|
+
// 那么它们需要交换值,并且我也要交换 draggingIndex,这样鼠标就依然抓着那个数值
|
|
112
|
+
if (oldValues[0] > oldValues[1]) {
|
|
113
|
+
// 交换值
|
|
114
|
+
nextInternal = [oldValues[1], oldValues[0]];
|
|
115
|
+
// 交换控制权
|
|
116
|
+
draggingIndex.value = draggingIndex.value === 0 ? 1 : 0;
|
|
134
117
|
} else {
|
|
135
|
-
|
|
118
|
+
nextInternal = oldValues;
|
|
136
119
|
}
|
|
137
120
|
} else {
|
|
138
|
-
|
|
121
|
+
nextInternal = newValue;
|
|
139
122
|
}
|
|
140
123
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
124
|
+
if (
|
|
125
|
+
JSON.stringify(nextInternal) !== JSON.stringify(internalValue.value)
|
|
126
|
+
) {
|
|
127
|
+
internalValue.value = nextInternal;
|
|
128
|
+
emit("input", nextInternal);
|
|
129
|
+
emit("change", nextInternal);
|
|
130
|
+
}
|
|
144
131
|
};
|
|
145
132
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
steps = steps.map((x) => x - min);
|
|
151
|
-
if (step) {
|
|
152
|
-
steps.push(multiply(Math.round(percent / step), step));
|
|
153
|
-
}
|
|
133
|
+
// 处理轨道点击
|
|
134
|
+
const handleRailClick = (e) => {
|
|
135
|
+
if (props.disabled) return;
|
|
136
|
+
const newValue = getValueFromEvent(e);
|
|
154
137
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
138
|
+
if (props.range) {
|
|
139
|
+
const [v1, v2] = internalValue.value;
|
|
140
|
+
// 移动离点击点最近的那个滑块
|
|
141
|
+
const dist1 = Math.abs(newValue - v1);
|
|
142
|
+
const dist2 = Math.abs(newValue - v2);
|
|
143
|
+
const targetIndex = dist1 <= dist2 ? 0 : 1;
|
|
144
|
+
|
|
145
|
+
const nextValues = [...internalValue.value];
|
|
146
|
+
nextValues[targetIndex] = newValue;
|
|
162
147
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (disabled) return;
|
|
166
|
-
let { width, height } = e.target.getBoundingClientRect();
|
|
167
|
-
let { layerX, layerY } = e;
|
|
168
|
-
|
|
169
|
-
let percent = 0,
|
|
170
|
-
diff = max - min;
|
|
171
|
-
if (reverse) {
|
|
172
|
-
percent = vertical
|
|
173
|
-
? ((height - layerY) / height) * diff
|
|
174
|
-
: ((width - layerX) / width) * diff;
|
|
148
|
+
// 点击导致跳变时,也要保证顺序
|
|
149
|
+
internalValue.value = sortValue(nextValues);
|
|
175
150
|
} else {
|
|
176
|
-
|
|
151
|
+
internalValue.value = newValue;
|
|
177
152
|
}
|
|
178
|
-
|
|
153
|
+
emit("input", internalValue.value);
|
|
154
|
+
emit("change", internalValue.value);
|
|
155
|
+
};
|
|
179
156
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
value = value >= half && y > x ? [x, value] : [value, y];
|
|
184
|
-
}
|
|
157
|
+
const handleThumbDown = (index) => {
|
|
158
|
+
if (props.disabled) return;
|
|
159
|
+
draggingIndex.value = index;
|
|
185
160
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
161
|
+
const onMove = (e) => handleThumbMove(e);
|
|
162
|
+
const onUp = () => {
|
|
163
|
+
draggingIndex.value = -1;
|
|
164
|
+
document.removeEventListener("mousemove", onMove);
|
|
165
|
+
document.removeEventListener("mouseup", onUp);
|
|
166
|
+
document.removeEventListener("touchmove", onMove);
|
|
167
|
+
document.removeEventListener("touchend", onUp);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
document.addEventListener("mousemove", onMove);
|
|
171
|
+
document.addEventListener("mouseup", onUp);
|
|
172
|
+
document.addEventListener("touchmove", onMove, { passive: false });
|
|
173
|
+
document.addEventListener("touchend", onUp);
|
|
189
174
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
175
|
+
|
|
176
|
+
const handleKeydown = (e, index) => {
|
|
177
|
+
if (props.disabled) return;
|
|
178
|
+
const isPlus = ["ArrowRight", "ArrowUp"].includes(e.key);
|
|
179
|
+
const isMinus = ["ArrowLeft", "ArrowDown"].includes(e.key);
|
|
180
|
+
if (!isPlus && !isMinus) return;
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
|
|
183
|
+
let nextValue;
|
|
184
|
+
const currentValues = props.range
|
|
185
|
+
? [...internalValue.value]
|
|
186
|
+
: [internalValue.value];
|
|
187
|
+
const targetValue = currentValues[index];
|
|
188
|
+
|
|
189
|
+
if (props.step === null || props.step === undefined) {
|
|
190
|
+
if (props.marks) {
|
|
191
|
+
const mKeys = Object.keys(props.marks)
|
|
192
|
+
.map(Number)
|
|
193
|
+
.sort((a, b) => a - b);
|
|
194
|
+
const currIdx = mKeys.indexOf(getClosestStep(targetValue, props));
|
|
195
|
+
let nextIdx = isPlus ? currIdx + 1 : currIdx - 1;
|
|
196
|
+
nextIdx = Math.max(0, Math.min(mKeys.length - 1, nextIdx));
|
|
197
|
+
nextValue = mKeys[nextIdx];
|
|
198
|
+
}
|
|
206
199
|
} else {
|
|
207
|
-
|
|
200
|
+
nextValue = Number(
|
|
201
|
+
new Big(targetValue).plus(isPlus ? props.step : -props.step)
|
|
202
|
+
);
|
|
208
203
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
204
|
+
|
|
205
|
+
// 理键盘交错逻辑 ---
|
|
206
|
+
if (props.range) {
|
|
207
|
+
const otherIndex = index === 0 ? 1 : 0;
|
|
208
|
+
const otherValue = currentValues[otherIndex];
|
|
209
|
+
|
|
210
|
+
// 检查是否发生越界交换
|
|
211
|
+
const isCrossForward = index === 0 && nextValue > otherValue;
|
|
212
|
+
const isCrossBackward = index === 1 && nextValue < otherValue;
|
|
213
|
+
|
|
214
|
+
if (isCrossForward || isCrossBackward) {
|
|
215
|
+
// 交换数据
|
|
216
|
+
const nextInternal = [];
|
|
217
|
+
nextInternal[index] = otherValue;
|
|
218
|
+
nextInternal[otherIndex] = getClosestStep(nextValue, props);
|
|
219
|
+
internalValue.value = nextInternal.sort((a, b) => a - b);
|
|
220
|
+
|
|
221
|
+
// 转移焦点
|
|
222
|
+
nextTick(() => {
|
|
223
|
+
// 找到另一个 Thumb 的原生 DOM 并聚焦
|
|
224
|
+
const targetThumb = thumbRefs.value[otherIndex];
|
|
225
|
+
if (targetThumb) {
|
|
226
|
+
targetThumb.focus();
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
} else {
|
|
230
|
+
// 正常非交错移动
|
|
231
|
+
currentValues[index] = nextValue;
|
|
232
|
+
internalValue.value = formatValue(currentValues);
|
|
233
|
+
}
|
|
214
234
|
} else {
|
|
215
|
-
|
|
216
|
-
return t == 0 ? a * 1 : b * 1;
|
|
235
|
+
internalValue.value = formatValue(nextValue);
|
|
217
236
|
}
|
|
237
|
+
|
|
238
|
+
emit("input", internalValue.value);
|
|
239
|
+
emit("change", internalValue.value);
|
|
218
240
|
};
|
|
219
241
|
|
|
220
242
|
return () => {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
let
|
|
243
|
+
const { vertical, reverse, min, max, disabled, marks, included } = props;
|
|
244
|
+
|
|
245
|
+
const renderTrack = () => {
|
|
246
|
+
if (!included && marks) return null;
|
|
247
|
+
|
|
248
|
+
// 确保 v1 是小的,v2 是大的
|
|
249
|
+
const [rawV1, rawV2] = props.range
|
|
250
|
+
? internalValue.value
|
|
251
|
+
: [min, internalValue.value];
|
|
252
|
+
const v1 = Math.min(rawV1, rawV2);
|
|
253
|
+
const v2 = Math.max(rawV1, rawV2);
|
|
254
|
+
|
|
255
|
+
const p1 = getPercent(v1);
|
|
256
|
+
const p2 = getPercent(v2);
|
|
257
|
+
const length = p2 - p1;
|
|
258
|
+
|
|
259
|
+
let style = {};
|
|
260
|
+
if (vertical) {
|
|
261
|
+
// 垂直模式
|
|
262
|
+
// reverse=false: bottom=p1, height=len
|
|
263
|
+
// reverse=true: top=p1, height=len
|
|
264
|
+
style = reverse
|
|
265
|
+
? { top: `${p1}%`, height: `${length}%` }
|
|
266
|
+
: { bottom: `${p1}%`, height: `${length}%` };
|
|
267
|
+
} else {
|
|
268
|
+
// 水平模式
|
|
269
|
+
// reverse=false: left=p1, width=len
|
|
270
|
+
// reverse=true: right=p1, width=len
|
|
271
|
+
style = reverse
|
|
272
|
+
? { right: `${p1}%`, width: `${length}%` }
|
|
273
|
+
: { left: `${p1}%`, width: `${length}%` };
|
|
274
|
+
}
|
|
275
|
+
return <div class="k-slider-track" style={style}></div>;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const renderMarks = () => {
|
|
279
|
+
if (!marks) return null;
|
|
280
|
+
const mKeys = Object.keys(marks).map(Number);
|
|
281
|
+
|
|
238
282
|
return (
|
|
239
|
-
<div
|
|
240
|
-
{
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
]
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
283
|
+
<div class="k-slider-marks">
|
|
284
|
+
{mKeys.map((val) => {
|
|
285
|
+
const p = getPercent(val);
|
|
286
|
+
// 判断激活状态:值是否在当前选中范围内
|
|
287
|
+
let isActive = false;
|
|
288
|
+
if (props.range) {
|
|
289
|
+
isActive =
|
|
290
|
+
val >= internalValue.value[0] &&
|
|
291
|
+
val <= internalValue.value[1];
|
|
292
|
+
} else {
|
|
293
|
+
isActive = val <= internalValue.value;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
let style = {};
|
|
297
|
+
if (vertical) {
|
|
298
|
+
style = reverse ? { top: `${p}%` } : { bottom: `${p}%` };
|
|
299
|
+
} else {
|
|
300
|
+
style = reverse ? { right: `${p}%` } : { left: `${p}%` };
|
|
301
|
+
}
|
|
302
|
+
|
|
254
303
|
return (
|
|
255
|
-
<div
|
|
256
|
-
|
|
257
|
-
"k-slider-mark-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
304
|
+
<div key={val} class="k-slider-mark-item" style={style}>
|
|
305
|
+
<span
|
|
306
|
+
class={["k-slider-mark-dot", { "is-active": isActive }]}
|
|
307
|
+
></span>
|
|
308
|
+
<div
|
|
309
|
+
class={["k-slider-mark-text", { "is-active": isActive }]}
|
|
310
|
+
>
|
|
311
|
+
{marks[val]}
|
|
312
|
+
</div>
|
|
263
313
|
</div>
|
|
264
314
|
);
|
|
265
315
|
})}
|
|
266
316
|
</div>
|
|
267
317
|
);
|
|
268
318
|
};
|
|
269
|
-
const renderTrack = () => {
|
|
270
|
-
let { vertical, max, min, reverse } = ps;
|
|
271
|
-
let percent1 = 0,
|
|
272
|
-
percent2 = 0,
|
|
273
|
-
diff = max - min;
|
|
274
|
-
let w, l;
|
|
275
|
-
|
|
276
|
-
if (!ps.range) {
|
|
277
|
-
percent2 = ((defaultValue.value - min) / diff) * 100;
|
|
278
|
-
} else {
|
|
279
|
-
let [x, y] = defaultValue.value;
|
|
280
|
-
percent1 = ((x - min) / diff) * 100;
|
|
281
|
-
percent2 = ((y - min) / diff) * 100;
|
|
282
|
-
}
|
|
283
|
-
let trackSty = {};
|
|
284
|
-
if (percent2 > percent1) {
|
|
285
|
-
w = percent2 - percent1;
|
|
286
|
-
l = percent1;
|
|
287
|
-
} else {
|
|
288
|
-
w = percent1 - percent2;
|
|
289
|
-
l = percent2;
|
|
290
|
-
}
|
|
291
|
-
if (reverse) {
|
|
292
|
-
trackSty = vertical
|
|
293
|
-
? {
|
|
294
|
-
height: `${w}%`,
|
|
295
|
-
top: "auto",
|
|
296
|
-
bottom: `${l}%`,
|
|
297
|
-
}
|
|
298
|
-
: {
|
|
299
|
-
width: `${w}%`,
|
|
300
|
-
left: "auto",
|
|
301
|
-
right: `${l}%`,
|
|
302
|
-
};
|
|
303
|
-
} else {
|
|
304
|
-
trackSty = vertical
|
|
305
|
-
? {
|
|
306
|
-
height: `${w}%`,
|
|
307
|
-
top: `${l}%`,
|
|
308
|
-
}
|
|
309
|
-
: {
|
|
310
|
-
width: `${w}%`,
|
|
311
|
-
left: `${l}%`,
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
return <div class="k-slider-track" style={{ ...trackSty }}></div>;
|
|
315
|
-
};
|
|
316
319
|
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
let v = getThumbValue(0);
|
|
343
|
-
children.push(<Thumb {...thumbProps} value={v} />);
|
|
344
|
-
}
|
|
345
|
-
let v2 = getThumbValue(1);
|
|
346
|
-
children.push(<Thumb {...thumbProps} type="right" value={v2} />);
|
|
347
|
-
if (marks) {
|
|
348
|
-
const mark = renderMark();
|
|
349
|
-
children.push(mark);
|
|
350
|
-
}
|
|
320
|
+
const thumbs = (props.range ? [0, 1] : [0]).map((idx) => {
|
|
321
|
+
// 单滑块模式下,index 为 0,值取 internalValue
|
|
322
|
+
const val = props.range
|
|
323
|
+
? internalValue.value[idx]
|
|
324
|
+
: internalValue.value;
|
|
325
|
+
return (
|
|
326
|
+
<Thumb
|
|
327
|
+
key={idx}
|
|
328
|
+
ref={(el) => setThumbRef(el, idx)}
|
|
329
|
+
value={val}
|
|
330
|
+
min={min}
|
|
331
|
+
max={max}
|
|
332
|
+
size={props.size || size}
|
|
333
|
+
vertical={vertical}
|
|
334
|
+
reverse={reverse}
|
|
335
|
+
disabled={disabled}
|
|
336
|
+
tooltipVisible={props.tooltipVisible}
|
|
337
|
+
tipFormatter={props.tipFormatter}
|
|
338
|
+
dragging={draggingIndex.value === idx} // 告诉子组件是否被激活
|
|
339
|
+
onDragStart={() => handleThumbDown(idx)}
|
|
340
|
+
onKeydownUpdate={(e) => handleKeydown(e, idx)}
|
|
341
|
+
/>
|
|
342
|
+
);
|
|
343
|
+
});
|
|
344
|
+
|
|
351
345
|
return (
|
|
352
346
|
<div
|
|
353
347
|
class={[
|
|
354
348
|
"k-slider",
|
|
355
|
-
{
|
|
349
|
+
{
|
|
350
|
+
"k-slider-disabled": disabled,
|
|
351
|
+
"k-slider-vertical": vertical,
|
|
352
|
+
"k-slider-reverse": reverse,
|
|
353
|
+
},
|
|
356
354
|
]}
|
|
357
355
|
>
|
|
358
356
|
<div class="k-slider-bar">
|
|
359
|
-
<div
|
|
360
|
-
|
|
357
|
+
<div
|
|
358
|
+
class="k-slider-rail"
|
|
359
|
+
ref={railRef}
|
|
360
|
+
onClick={handleRailClick}
|
|
361
|
+
></div>
|
|
362
|
+
{renderTrack()}
|
|
363
|
+
{renderMarks()}
|
|
364
|
+
{thumbs}
|
|
361
365
|
</div>
|
|
362
366
|
</div>
|
|
363
367
|
);
|
|
364
368
|
};
|
|
365
369
|
},
|
|
366
370
|
});
|
|
371
|
+
|
|
367
372
|
export default withInstall(Slider);
|