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
|
@@ -37,11 +37,13 @@
|
|
|
37
37
|
transform: translateX(-50%) translateY(-50%);
|
|
38
38
|
outline: 2px solid transparent;
|
|
39
39
|
outline-offset: 1px;
|
|
40
|
+
z-index: 0;
|
|
40
41
|
&:focus {
|
|
41
42
|
outline-color: var(--kui-color-main-80);
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
&.is-dragging {
|
|
44
45
|
border: 1px solid var(--kui-color-main);
|
|
46
|
+
z-index: 1;
|
|
45
47
|
cursor: grabbing;
|
|
46
48
|
}
|
|
47
49
|
}
|
|
@@ -82,12 +84,14 @@
|
|
|
82
84
|
position: absolute;
|
|
83
85
|
width: 100%;
|
|
84
86
|
top: 12px;
|
|
85
|
-
left: 0;
|
|
86
87
|
font-size: 14px;
|
|
87
88
|
z-index: 0;
|
|
88
89
|
}
|
|
90
|
+
.k-slider-mark-item {
|
|
91
|
+
position: absolute;
|
|
92
|
+
}
|
|
89
93
|
|
|
90
|
-
.k-slider-mark-
|
|
94
|
+
.k-slider-mark-dot {
|
|
91
95
|
position: absolute;
|
|
92
96
|
height: 4px;
|
|
93
97
|
width: 4px;
|
|
@@ -98,7 +102,7 @@
|
|
|
98
102
|
pointer-events: none;
|
|
99
103
|
box-sizing: content-box;
|
|
100
104
|
|
|
101
|
-
|
|
105
|
+
&.is-active {
|
|
102
106
|
border-color: var(--kui-color-main);
|
|
103
107
|
}
|
|
104
108
|
}
|
|
@@ -130,7 +134,7 @@
|
|
|
130
134
|
.k-slider-track {
|
|
131
135
|
width: 4px;
|
|
132
136
|
left: 14px;
|
|
133
|
-
top:
|
|
137
|
+
top: auto;
|
|
134
138
|
}
|
|
135
139
|
|
|
136
140
|
.k-slider-rail {
|
|
@@ -149,15 +153,11 @@
|
|
|
149
153
|
|
|
150
154
|
.k-slider-thumb {
|
|
151
155
|
transform: translateY(-50%);
|
|
152
|
-
margin: 0 0 0 3px;
|
|
153
156
|
top: auto;
|
|
157
|
+
left: 50%;
|
|
154
158
|
}
|
|
155
159
|
|
|
156
|
-
.k-slider-
|
|
157
|
-
margin-left: 9px;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
.k-slider-mark-symbol,
|
|
160
|
+
.k-slider-mark-dot,
|
|
161
161
|
.k-slider-mark-text {
|
|
162
162
|
transform: translateY(-50%);
|
|
163
163
|
}
|
|
@@ -174,7 +174,6 @@
|
|
|
174
174
|
.k-slider-thumb,
|
|
175
175
|
.k-slider-thumb:active {
|
|
176
176
|
cursor: not-allowed;
|
|
177
|
-
// border-color: inherit;
|
|
178
177
|
}
|
|
179
178
|
|
|
180
179
|
.k-slider-rail {
|
|
@@ -1,166 +1,88 @@
|
|
|
1
|
+
import { defineComponent, ref, computed } from "vue";
|
|
1
2
|
import Tooltip from "../tooltip";
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
export default defineComponent({
|
|
4
5
|
props: {
|
|
6
|
+
value: Number,
|
|
7
|
+
min: Number,
|
|
8
|
+
max: Number,
|
|
5
9
|
vertical: Boolean,
|
|
6
|
-
disabled: Boolean,
|
|
7
10
|
reverse: Boolean,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
size: String,
|
|
11
|
-
step: Number,
|
|
12
|
-
value: [Number, String],
|
|
13
|
-
tipFormatter: [Function, Object],
|
|
14
|
-
type: String,
|
|
11
|
+
disabled: Boolean,
|
|
12
|
+
size: [String, Number],
|
|
15
13
|
tooltipVisible: Boolean,
|
|
14
|
+
tipFormatter: Function,
|
|
15
|
+
dragging: Boolean, // 接收父组件传入的拖拽状态
|
|
16
16
|
},
|
|
17
|
-
emits: ["
|
|
18
|
-
setup(
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const index = ref(1);
|
|
22
|
-
const showTip = ref(ps.tooltipVisible);
|
|
23
|
-
const touch = !!(
|
|
24
|
-
"ontouchstart" in window ||
|
|
25
|
-
(window.DocumentTouch && document instanceof window.DocumentTouch)
|
|
26
|
-
);
|
|
27
|
-
const mouseMove = (e) => {
|
|
28
|
-
if (isMousePressed.value) {
|
|
29
|
-
e.preventDefault();
|
|
30
|
-
emit("thumbMove", e, ps.type);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
17
|
+
emits: ["dragStart", "keydownUpdate"],
|
|
18
|
+
setup(props, { emit, expose }) {
|
|
19
|
+
const isHover = ref(false);
|
|
20
|
+
const elRef = ref(null);
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
};
|
|
22
|
+
expose({
|
|
23
|
+
focus: () => {
|
|
24
|
+
elRef.value?.focus();
|
|
25
|
+
},
|
|
26
|
+
});
|
|
41
27
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
28
|
+
// 计算位置百分比
|
|
29
|
+
const percent = computed(() => {
|
|
30
|
+
const diff = props.max - props.min;
|
|
31
|
+
if (diff === 0) return 0;
|
|
32
|
+
return Math.max(
|
|
33
|
+
0,
|
|
34
|
+
Math.min(100, ((props.value - props.min) / diff) * 100)
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const thumbStyle = computed(() => {
|
|
39
|
+
const p = percent.value;
|
|
40
|
+
if (props.vertical) {
|
|
41
|
+
return props.reverse
|
|
42
|
+
? { top: `${p}%`, transform: "translate(-50%, -50%)" } // 垂直反向:Top
|
|
43
|
+
: { bottom: `${p}%`, transform: "translate(-50%, 50%)" }; // 垂直标准:Bottom
|
|
51
44
|
}
|
|
52
|
-
|
|
53
|
-
?
|
|
54
|
-
:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
e.preventDefault();
|
|
45
|
+
return props.reverse
|
|
46
|
+
? { right: `${p}%`, transform: "translate(50%, -50%)" } // 水平反向:Right
|
|
47
|
+
: { left: `${p}%`, transform: "translate(-50%, -50%)" }; // 水平标准:Left
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const handleDown = (e) => {
|
|
51
|
+
if (props.disabled) return;
|
|
52
|
+
e.preventDefault(); // 防止选中文本
|
|
60
53
|
e.stopPropagation();
|
|
61
|
-
|
|
62
|
-
// emit("updatePos", 123123123);
|
|
63
|
-
if (ps.disabled) return;
|
|
64
|
-
isMousePressed.value = true;
|
|
65
|
-
showTip.value = true;
|
|
66
|
-
index.value = 2;
|
|
67
|
-
let [e1, e2] = touch
|
|
68
|
-
? ["touchmove", "touchend"]
|
|
69
|
-
: ["mousemove", "mouseup"];
|
|
70
|
-
document.addEventListener(e1, mouseMove);
|
|
71
|
-
document.addEventListener(e2, mouseUp);
|
|
54
|
+
emit("dragStart", e);
|
|
72
55
|
};
|
|
73
56
|
|
|
74
57
|
return () => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
value
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
min,
|
|
81
|
-
size,
|
|
82
|
-
tipFormatter,
|
|
83
|
-
reverse,
|
|
84
|
-
tooltipVisible,
|
|
85
|
-
} = ps;
|
|
86
|
-
const props = {
|
|
87
|
-
attrs: { tabindex: "0" },
|
|
88
|
-
class: ["k-slider-thumb", { "k-slider-thumb-sm": size == "small" }],
|
|
89
|
-
style: {
|
|
90
|
-
// left: `${percent}%`,
|
|
91
|
-
zIndex: index.value,
|
|
92
|
-
},
|
|
93
|
-
on: {
|
|
94
|
-
keydown: onKeydown,
|
|
95
|
-
mousedown: onMouseDown,
|
|
96
|
-
touchstart: onMouseDown,
|
|
97
|
-
mouseenter: () => {
|
|
98
|
-
if (!disabled) showTip.value = true;
|
|
99
|
-
},
|
|
100
|
-
mouseleave: (e) => {
|
|
101
|
-
if (ps.tooltipVisible == true) {
|
|
102
|
-
showTip.value = true;
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (!isMousePressed.value) {
|
|
106
|
-
showTip.value = false;
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
// onKeydown: onKeydown, //for 3
|
|
111
|
-
// onMousedown: onMouseDown,
|
|
112
|
-
// onTouchstart: onMouseDown,
|
|
113
|
-
// onMouseenter: () => {
|
|
114
|
-
// if (!disabled) showTip.value = true;
|
|
115
|
-
// },
|
|
116
|
-
// onMouseleave: (e) => {
|
|
117
|
-
// if (ps.tooltipVisible == true) {
|
|
118
|
-
// showTip.value = true;
|
|
119
|
-
// return;
|
|
120
|
-
// }
|
|
121
|
-
// if (!isMousePressed.value) {
|
|
122
|
-
// showTip.value = false;
|
|
123
|
-
// }
|
|
124
|
-
// },
|
|
125
|
-
};
|
|
126
|
-
let percent,
|
|
127
|
-
diff = max - min;
|
|
128
|
-
|
|
129
|
-
percent = ((value - min) / diff) * 100;
|
|
130
|
-
let sty = {};
|
|
131
|
-
if (vertical) {
|
|
132
|
-
sty = reverse
|
|
133
|
-
? { bottom: `${percent}%`, transform: "translateY(50%)" }
|
|
134
|
-
: { top: `${percent}%` };
|
|
135
|
-
} else {
|
|
136
|
-
sty = reverse
|
|
137
|
-
? {
|
|
138
|
-
right: `${percent}%`,
|
|
139
|
-
transform: "translateX(50%) translateY(-50%)",
|
|
140
|
-
}
|
|
141
|
-
: { left: `${percent}%` };
|
|
142
|
-
}
|
|
143
|
-
props.style = Object.assign(props.style, sty);
|
|
144
|
-
|
|
145
|
-
if (tipFormatter === null || tooltipVisible === null)
|
|
146
|
-
return <div {...props}></div>;
|
|
147
|
-
|
|
148
|
-
let tip = value?.toString();
|
|
149
|
-
|
|
150
|
-
if (tipFormatter !== undefined) {
|
|
151
|
-
tip = tipFormatter(tip);
|
|
152
|
-
}
|
|
153
|
-
const tipProps = {
|
|
154
|
-
ref: refThumb,
|
|
155
|
-
props: {
|
|
156
|
-
title: tip,
|
|
157
|
-
show: showTip.value,
|
|
158
|
-
disabled: ps.disabled,
|
|
159
|
-
},
|
|
160
|
-
};
|
|
58
|
+
const displayValue = props.tipFormatter
|
|
59
|
+
? props.tipFormatter(props.value)
|
|
60
|
+
: String(props.value);
|
|
61
|
+
const showTooltip =
|
|
62
|
+
props.tooltipVisible === true ? true : props.dragging || isHover.value;
|
|
161
63
|
return (
|
|
162
|
-
<Tooltip
|
|
163
|
-
|
|
64
|
+
<Tooltip
|
|
65
|
+
title={displayValue}
|
|
66
|
+
show={showTooltip && !props.disabled}
|
|
67
|
+
placement={props.vertical ? "right" : "top"}
|
|
68
|
+
>
|
|
69
|
+
<div
|
|
70
|
+
class={[
|
|
71
|
+
"k-slider-thumb",
|
|
72
|
+
{
|
|
73
|
+
"is-dragging": props.dragging,
|
|
74
|
+
"k-slider-thumb-sm": props.size === "small",
|
|
75
|
+
},
|
|
76
|
+
]}
|
|
77
|
+
style={thumbStyle.value}
|
|
78
|
+
ref={elRef}
|
|
79
|
+
tabindex={props.disabled ? -1 : 0}
|
|
80
|
+
onMousedown={handleDown}
|
|
81
|
+
onTouchstart={handleDown}
|
|
82
|
+
onKeydown={(e) => emit("keydownUpdate", e)}
|
|
83
|
+
onMouseenter={() => (isHover.value = true)}
|
|
84
|
+
onMouseleave={() => (isHover.value = false)}
|
|
85
|
+
/>
|
|
164
86
|
</Tooltip>
|
|
165
87
|
);
|
|
166
88
|
};
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// from countUp.js
|
|
2
|
+
// thanks Jamie Perkins!
|
|
3
|
+
|
|
4
|
+
export class CountUp {
|
|
5
|
+
constructor(target, endVal, options = {}) {
|
|
6
|
+
this.defaults = {
|
|
7
|
+
startVal: 0,
|
|
8
|
+
decimalPlaces: 0,
|
|
9
|
+
duration: 2,
|
|
10
|
+
useEasing: true,
|
|
11
|
+
useGrouping: true,
|
|
12
|
+
useIndianSeparators: false,
|
|
13
|
+
smartEasingThreshold: 999,
|
|
14
|
+
smartEasingAmount: 333,
|
|
15
|
+
separator: ",",
|
|
16
|
+
decimal: ".",
|
|
17
|
+
prefix: "",
|
|
18
|
+
suffix: "",
|
|
19
|
+
enableScrollSpy: false,
|
|
20
|
+
scrollSpyDelay: 200,
|
|
21
|
+
scrollSpyOnce: false,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
this.options = Object.assign({}, this.defaults, options);
|
|
25
|
+
|
|
26
|
+
this.el =
|
|
27
|
+
typeof target === "string" ? document.getElementById(target) : target;
|
|
28
|
+
|
|
29
|
+
this.error = "";
|
|
30
|
+
this.paused = true;
|
|
31
|
+
this.once = false;
|
|
32
|
+
this.finalEndVal = null;
|
|
33
|
+
|
|
34
|
+
this.formattingFn =
|
|
35
|
+
this.options.formattingFn || this.formatNumber.bind(this);
|
|
36
|
+
this.easingFn = this.options.easingFn || this.easeOutExpo.bind(this);
|
|
37
|
+
|
|
38
|
+
endVal = endVal == null ? this.parse(this.el?.innerHTML || "0") : endVal;
|
|
39
|
+
|
|
40
|
+
this.startVal = this.validateValue(this.options.startVal);
|
|
41
|
+
this.frameVal = this.startVal;
|
|
42
|
+
this.endVal = this.validateValue(endVal);
|
|
43
|
+
|
|
44
|
+
this.options.decimalPlaces = Math.max(0, this.options.decimalPlaces);
|
|
45
|
+
this.options.separator = String(this.options.separator);
|
|
46
|
+
|
|
47
|
+
this.useEasing = this.options.useEasing;
|
|
48
|
+
if (this.options.separator === "") {
|
|
49
|
+
this.options.useGrouping = false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.resetDuration();
|
|
53
|
+
|
|
54
|
+
if (this.el) {
|
|
55
|
+
this.printValue(this.startVal);
|
|
56
|
+
} else {
|
|
57
|
+
this.error = "[CountUp] target is null or undefined";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (typeof window !== "undefined" && this.options.enableScrollSpy) {
|
|
61
|
+
window.__countUpScrollFns ||= [];
|
|
62
|
+
window.__countUpScrollFns.push(() => this.handleScroll());
|
|
63
|
+
|
|
64
|
+
window.onscroll = () => {
|
|
65
|
+
window.__countUpScrollFns.forEach((fn) => fn());
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
this.handleScroll();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
count = (timestamp) => {
|
|
73
|
+
if (!this.startTime) this.startTime = timestamp;
|
|
74
|
+
|
|
75
|
+
const progress = timestamp - this.startTime;
|
|
76
|
+
this.remaining = this.duration - progress;
|
|
77
|
+
|
|
78
|
+
if (this.useEasing) {
|
|
79
|
+
this.frameVal = this.countDown
|
|
80
|
+
? this.startVal -
|
|
81
|
+
this.easingFn(progress, 0, this.startVal - this.endVal, this.duration)
|
|
82
|
+
: this.easingFn(
|
|
83
|
+
progress,
|
|
84
|
+
this.startVal,
|
|
85
|
+
this.endVal - this.startVal,
|
|
86
|
+
this.duration
|
|
87
|
+
);
|
|
88
|
+
} else {
|
|
89
|
+
this.frameVal =
|
|
90
|
+
this.startVal +
|
|
91
|
+
(this.endVal - this.startVal) * (progress / this.duration);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const wentPast = this.countDown
|
|
95
|
+
? this.frameVal < this.endVal
|
|
96
|
+
: this.frameVal > this.endVal;
|
|
97
|
+
|
|
98
|
+
this.frameVal = wentPast ? this.endVal : this.frameVal;
|
|
99
|
+
this.frameVal = Number(this.frameVal.toFixed(this.options.decimalPlaces));
|
|
100
|
+
|
|
101
|
+
this.printValue(this.frameVal);
|
|
102
|
+
|
|
103
|
+
if (progress < this.duration) {
|
|
104
|
+
this.rAF = requestAnimationFrame(this.count);
|
|
105
|
+
} else if (this.finalEndVal !== null) {
|
|
106
|
+
this.update(this.finalEndVal);
|
|
107
|
+
} else {
|
|
108
|
+
this.options.onCompleteCallback?.();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
start(callback) {
|
|
113
|
+
if (this.error) return;
|
|
114
|
+
|
|
115
|
+
this.options.onStartCallback?.();
|
|
116
|
+
if (callback) this.options.onCompleteCallback = callback;
|
|
117
|
+
|
|
118
|
+
if (this.duration > 0) {
|
|
119
|
+
this.determineDirectionAndSmartEasing();
|
|
120
|
+
this.paused = false;
|
|
121
|
+
this.rAF = requestAnimationFrame(this.count);
|
|
122
|
+
} else {
|
|
123
|
+
this.printValue(this.endVal);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
pauseResume() {
|
|
128
|
+
if (!this.paused) {
|
|
129
|
+
cancelAnimationFrame(this.rAF);
|
|
130
|
+
} else {
|
|
131
|
+
this.startTime = null;
|
|
132
|
+
this.duration = this.remaining;
|
|
133
|
+
this.startVal = this.frameVal;
|
|
134
|
+
this.determineDirectionAndSmartEasing();
|
|
135
|
+
this.rAF = requestAnimationFrame(this.count);
|
|
136
|
+
}
|
|
137
|
+
this.paused = !this.paused;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
reset() {
|
|
141
|
+
cancelAnimationFrame(this.rAF);
|
|
142
|
+
this.paused = true;
|
|
143
|
+
this.resetDuration();
|
|
144
|
+
this.startVal = this.validateValue(this.options.startVal);
|
|
145
|
+
this.frameVal = this.startVal;
|
|
146
|
+
this.printValue(this.startVal);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
update(newEndVal) {
|
|
150
|
+
cancelAnimationFrame(this.rAF);
|
|
151
|
+
this.startTime = null;
|
|
152
|
+
this.endVal = this.validateValue(newEndVal);
|
|
153
|
+
if (this.endVal === this.frameVal) return;
|
|
154
|
+
|
|
155
|
+
this.startVal = this.frameVal;
|
|
156
|
+
if (this.finalEndVal == null) this.resetDuration();
|
|
157
|
+
|
|
158
|
+
this.finalEndVal = null;
|
|
159
|
+
this.determineDirectionAndSmartEasing();
|
|
160
|
+
this.rAF = requestAnimationFrame(this.count);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* ---------------- helpers ---------------- */
|
|
164
|
+
|
|
165
|
+
determineDirectionAndSmartEasing() {
|
|
166
|
+
const end = this.finalEndVal ?? this.endVal;
|
|
167
|
+
this.countDown = this.startVal > end;
|
|
168
|
+
|
|
169
|
+
const animateAmount = end - this.startVal;
|
|
170
|
+
if (
|
|
171
|
+
Math.abs(animateAmount) > this.options.smartEasingThreshold &&
|
|
172
|
+
this.options.useEasing
|
|
173
|
+
) {
|
|
174
|
+
this.finalEndVal = end;
|
|
175
|
+
const up = this.countDown ? 1 : -1;
|
|
176
|
+
this.endVal = end + up * this.options.smartEasingAmount;
|
|
177
|
+
this.duration /= 2;
|
|
178
|
+
this.useEasing = false;
|
|
179
|
+
} else {
|
|
180
|
+
this.finalEndVal = null;
|
|
181
|
+
this.useEasing = this.options.useEasing;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
formatNumber(num) {
|
|
186
|
+
const neg = num < 0 ? "-" : "";
|
|
187
|
+
let result = Math.abs(num).toFixed(this.options.decimalPlaces);
|
|
188
|
+
let [x1, x2] = result.split(".");
|
|
189
|
+
x2 = x2 ? this.options.decimal + x2 : "";
|
|
190
|
+
|
|
191
|
+
if (this.options.useGrouping) {
|
|
192
|
+
x1 = x1.replace(/\B(?=(\d{3})+(?!\d))/g, this.options.separator);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return `${neg}${this.options.prefix}${x1}${x2}${this.options.suffix}`;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
easeOutExpo(t, b, c, d) {
|
|
199
|
+
return (c * (-Math.pow(2, (-10 * t) / d) + 1) * 1024) / 1023 + b;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
printValue(val) {
|
|
203
|
+
if (!this.el) return;
|
|
204
|
+
const result = this.formattingFn(val);
|
|
205
|
+
|
|
206
|
+
if (this.options.plugin?.render) {
|
|
207
|
+
this.options.plugin.render(this.el, result);
|
|
208
|
+
} else if (this.el.tagName === "INPUT") {
|
|
209
|
+
this.el.value = result;
|
|
210
|
+
} else {
|
|
211
|
+
this.el.textContent = result;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
validateValue(value) {
|
|
216
|
+
const n = Number(value);
|
|
217
|
+
if (Number.isNaN(n)) {
|
|
218
|
+
this.error = `[CountUp] invalid value: ${value}`;
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
return n;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
resetDuration() {
|
|
225
|
+
this.startTime = null;
|
|
226
|
+
this.duration = Number(this.options.duration) * 1000;
|
|
227
|
+
this.remaining = this.duration;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
parse(str) {
|
|
231
|
+
const sep = this.options.separator.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
232
|
+
const dec = this.options.decimal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
233
|
+
return parseFloat(
|
|
234
|
+
str.replace(new RegExp(sep, "g"), "").replace(new RegExp(dec), ".")
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
handleScroll() {
|
|
239
|
+
if (this.once || !this.el) return;
|
|
240
|
+
|
|
241
|
+
const bottom = window.innerHeight + window.scrollY;
|
|
242
|
+
const rect = this.el.getBoundingClientRect();
|
|
243
|
+
const top = rect.top + window.pageYOffset;
|
|
244
|
+
const elBottom = top + rect.height;
|
|
245
|
+
|
|
246
|
+
if (elBottom < bottom && elBottom > window.scrollY && this.paused) {
|
|
247
|
+
this.paused = false;
|
|
248
|
+
setTimeout(() => this.start(), this.options.scrollSpyDelay);
|
|
249
|
+
if (this.options.scrollSpyOnce) this.once = true;
|
|
250
|
+
} else if ((window.scrollY > elBottom || top > bottom) && !this.paused) {
|
|
251
|
+
this.reset();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CountUp } from "./countup.js";
|
|
2
|
+
import { ref, watch, onMounted, defineComponent, onUnmounted } from "vue";
|
|
3
|
+
import { withInstall } from "../utils/vue.js";
|
|
4
|
+
const CountUpNumber = defineComponent({
|
|
5
|
+
name: "CountUpNumber",
|
|
6
|
+
props: {
|
|
7
|
+
value: {
|
|
8
|
+
type: Number,
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
separator: String,
|
|
12
|
+
duration: {
|
|
13
|
+
type: Number,
|
|
14
|
+
default: 1.2,
|
|
15
|
+
},
|
|
16
|
+
precision: { type: Number, default: 0 },
|
|
17
|
+
},
|
|
18
|
+
setup(props) {
|
|
19
|
+
const el = ref(null);
|
|
20
|
+
let countUp;
|
|
21
|
+
onMounted(() => {
|
|
22
|
+
countUp = new CountUp(el.value, props.value, {
|
|
23
|
+
duration: props.duration,
|
|
24
|
+
separator: props.separator || ",",
|
|
25
|
+
decimalPlaces: props.precision,
|
|
26
|
+
});
|
|
27
|
+
countUp.start();
|
|
28
|
+
});
|
|
29
|
+
onUnmounted(() => {
|
|
30
|
+
countUp = null;
|
|
31
|
+
});
|
|
32
|
+
watch(
|
|
33
|
+
() => props.value,
|
|
34
|
+
(newVal) => {
|
|
35
|
+
if (countUp) {
|
|
36
|
+
countUp.update(newVal);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return () => <span class="k-stat-countup-number" ref={el}></span>;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export default withInstall(CountUpNumber);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<cn>
|
|
2
|
+
### 只展示数字
|
|
3
|
+
</cn>
|
|
4
|
+
|
|
5
|
+
```vue
|
|
6
|
+
<template>
|
|
7
|
+
<Space vertical>
|
|
8
|
+
<Button @click="change">change</Button>
|
|
9
|
+
<code>default</code>
|
|
10
|
+
<StatNumber v-model="value" />
|
|
11
|
+
<code>type=`rollup`</code>
|
|
12
|
+
<StatNumber v-model="value" type="rollup" />
|
|
13
|
+
<br />
|
|
14
|
+
<code>precision=`3`</code>
|
|
15
|
+
<StatNumber v-model="value" :precision="3" />
|
|
16
|
+
<StatNumber v-model="value" type="rollup" :precision="3" />
|
|
17
|
+
<br />
|
|
18
|
+
<code>prefix & suffix</code>
|
|
19
|
+
<StatNumber v-model="value" prefix="$" />
|
|
20
|
+
<StatNumber v-model="value" type="rollup" suffix="元" />
|
|
21
|
+
</Space>
|
|
22
|
+
</template>
|
|
23
|
+
<script setup>
|
|
24
|
+
import { ref } from "vue";
|
|
25
|
+
const value = ref(Math.random() * 100000);
|
|
26
|
+
|
|
27
|
+
const change = () => {
|
|
28
|
+
value.value = Math.random() * 10000000;
|
|
29
|
+
};
|
|
30
|
+
</script>
|
|
31
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<cn>
|
|
2
|
+
### 卡片展示
|
|
3
|
+
用于 Dashboard 场景
|
|
4
|
+
</cn>
|
|
5
|
+
|
|
6
|
+
```vue
|
|
7
|
+
<template>
|
|
8
|
+
<Space vertical block>
|
|
9
|
+
<StatCard title="今日订单" :items="items" />
|
|
10
|
+
<StatCard statNumberType="rollup" title="今日进账" :items="items1" />
|
|
11
|
+
<StatCard statNumberType="rollup" title="媒体数据" :items="items2">
|
|
12
|
+
</StatCard>
|
|
13
|
+
</Space>
|
|
14
|
+
</template>
|
|
15
|
+
<script setup>
|
|
16
|
+
import { ref, h } from "vue";
|
|
17
|
+
import { Star, Heart } from "kui-icons";
|
|
18
|
+
const items = [
|
|
19
|
+
{ value: 5872, desc: "订单数" },
|
|
20
|
+
{ value: 9873672, desc: "订单总金额", prefix: "¥" },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const items1 = [
|
|
24
|
+
{ value: 5872, desc: "支付宝收入", prefix: "$" },
|
|
25
|
+
{ value: 9873672, desc: "微信收入", prefix: "¥" },
|
|
26
|
+
];
|
|
27
|
+
const items2 = [
|
|
28
|
+
{
|
|
29
|
+
value: 5872,
|
|
30
|
+
desc: "点赞人数",
|
|
31
|
+
prefix: h("Icon", { props: { type: Heart } }),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
value: 9873672,
|
|
35
|
+
desc: "收藏人数",
|
|
36
|
+
prefix: h("Icon", { props: { type: Star } }),
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
</script>
|
|
40
|
+
```
|