@manohub/ui 0.6.0
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/README.md +141 -0
- package/dist/components/avatar/index.d.ts +283 -0
- package/dist/components/avatar/index.js +167 -0
- package/dist/components/badge/index.d.ts +132 -0
- package/dist/components/badge/index.js +99 -0
- package/dist/components/button/index.d.ts +578 -0
- package/dist/components/button/index.js +191 -0
- package/dist/components/capsule/index.d.ts +161 -0
- package/dist/components/capsule/index.js +101 -0
- package/dist/components/card/index.d.ts +456 -0
- package/dist/components/card/index.js +231 -0
- package/dist/components/checkbox/index.d.ts +331 -0
- package/dist/components/checkbox/index.js +165 -0
- package/dist/components/code/index.d.ts +134 -0
- package/dist/components/code/index.js +117 -0
- package/dist/components/code-editor/index.d.ts +163 -0
- package/dist/components/code-editor/index.js +98 -0
- package/dist/components/collapse/index.d.ts +125 -0
- package/dist/components/collapse/index.js +95 -0
- package/dist/components/control-size.d.ts +8 -0
- package/dist/components/dialog/index.d.ts +224 -0
- package/dist/components/dialog/index.js +194 -0
- package/dist/components/divider/index.d.ts +64 -0
- package/dist/components/divider/index.js +62 -0
- package/dist/components/drawer/index.d.ts +226 -0
- package/dist/components/drawer/index.js +190 -0
- package/dist/components/filter/index.d.ts +391 -0
- package/dist/components/filter/index.js +203 -0
- package/dist/components/form/index.d.ts +704 -0
- package/dist/components/form/index.js +329 -0
- package/dist/components/input/index.d.ts +980 -0
- package/dist/components/input/index.js +334 -0
- package/dist/components/layout/index.d.ts +162 -0
- package/dist/components/layout/index.js +100 -0
- package/dist/components/list-view/index.d.ts +563 -0
- package/dist/components/list-view/index.js +221 -0
- package/dist/components/loading/index.d.ts +77 -0
- package/dist/components/loading/index.js +40 -0
- package/dist/components/nav/index.d.ts +293 -0
- package/dist/components/nav/index.js +164 -0
- package/dist/components/notice/index.d.ts +137 -0
- package/dist/components/notice/index.js +101 -0
- package/dist/components/notification/index.d.ts +118 -0
- package/dist/components/notification/index.js +99 -0
- package/dist/components/page/index.d.ts +276 -0
- package/dist/components/page/index.js +351 -0
- package/dist/components/page/split-resize.d.ts +42 -0
- package/dist/components/page/split-resize.js +36 -0
- package/dist/components/pagination/index.d.ts +171 -0
- package/dist/components/pagination/index.js +226 -0
- package/dist/components/panel/index.d.ts +401 -0
- package/dist/components/panel/index.js +193 -0
- package/dist/components/part-padding.d.ts +27 -0
- package/dist/components/part-padding.js +23 -0
- package/dist/components/query-state/index.d.ts +207 -0
- package/dist/components/query-state/index.js +181 -0
- package/dist/components/radio/index.d.ts +473 -0
- package/dist/components/radio/index.js +250 -0
- package/dist/components/search/index.d.ts +167 -0
- package/dist/components/search/index.js +105 -0
- package/dist/components/select/index.d.ts +252 -0
- package/dist/components/select/index.js +281 -0
- package/dist/components/skeleton/index.d.ts +88 -0
- package/dist/components/skeleton/index.js +56 -0
- package/dist/components/steps/index.d.ts +199 -0
- package/dist/components/steps/index.js +117 -0
- package/dist/components/switch/index.d.ts +150 -0
- package/dist/components/switch/index.js +103 -0
- package/dist/components/table/index.d.ts +351 -0
- package/dist/components/table/index.js +286 -0
- package/dist/components/tabs/index.d.ts +179 -0
- package/dist/components/tabs/index.js +153 -0
- package/dist/components/tabset/index.d.ts +105 -0
- package/dist/components/tabset/index.js +68 -0
- package/dist/components/tag/index.d.ts +203 -0
- package/dist/components/tag/index.js +144 -0
- package/dist/components/toast/index.d.ts +271 -0
- package/dist/components/toast/index.js +116 -0
- package/dist/components/tooltip/index.d.ts +126 -0
- package/dist/components/tooltip/index.js +97 -0
- package/dist/components/tree/index.d.ts +317 -0
- package/dist/components/tree/index.js +251 -0
- package/dist/components/upload/index.d.ts +384 -0
- package/dist/components/upload/index.js +172 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +102 -0
- package/dist/services/base.d.ts +21 -0
- package/dist/services/base.js +42 -0
- package/dist/services/dialog.d.ts +41 -0
- package/dist/services/dialog.js +83 -0
- package/dist/services/index.d.ts +12 -0
- package/dist/services/loading.d.ts +21 -0
- package/dist/services/loading.js +41 -0
- package/dist/services/toast.d.ts +40 -0
- package/dist/services/toast.js +74 -0
- package/dist/styles/components/avatar.css +128 -0
- package/dist/styles/components/avatar.tokens.css +24 -0
- package/dist/styles/components/badge.css +237 -0
- package/dist/styles/components/button.css +454 -0
- package/dist/styles/components/button.tokens.css +56 -0
- package/dist/styles/components/capsule.css +120 -0
- package/dist/styles/components/capsule.tokens.css +27 -0
- package/dist/styles/components/card.css +192 -0
- package/dist/styles/components/checkbox.css +145 -0
- package/dist/styles/components/checkbox.tokens.css +26 -0
- package/dist/styles/components/code-editor.css +91 -0
- package/dist/styles/components/code-editor.tokens.css +24 -0
- package/dist/styles/components/code.css +153 -0
- package/dist/styles/components/code.tokens.css +29 -0
- package/dist/styles/components/collapse.css +62 -0
- package/dist/styles/components/collapse.tokens.css +20 -0
- package/dist/styles/components/dialog.css +106 -0
- package/dist/styles/components/dialog.tokens.css +24 -0
- package/dist/styles/components/divider.css +71 -0
- package/dist/styles/components/divider.tokens.css +21 -0
- package/dist/styles/components/drawer.css +143 -0
- package/dist/styles/components/drawer.tokens.css +22 -0
- package/dist/styles/components/filter.css +41 -0
- package/dist/styles/components/filter.tokens.css +14 -0
- package/dist/styles/components/form.css +220 -0
- package/dist/styles/components/form.tokens.css +15 -0
- package/dist/styles/components/input.css +445 -0
- package/dist/styles/components/input.tokens.css +41 -0
- package/dist/styles/components/layout.css +198 -0
- package/dist/styles/components/list-view.css +244 -0
- package/dist/styles/components/loading.css +76 -0
- package/dist/styles/components/loading.tokens.css +23 -0
- package/dist/styles/components/nav.css +48 -0
- package/dist/styles/components/notice.css +153 -0
- package/dist/styles/components/notice.tokens.css +17 -0
- package/dist/styles/components/notification.css +159 -0
- package/dist/styles/components/notification.tokens.css +37 -0
- package/dist/styles/components/page.css +473 -0
- package/dist/styles/components/pagination.css +297 -0
- package/dist/styles/components/pagination.tokens.css +32 -0
- package/dist/styles/components/panel.css +77 -0
- package/dist/styles/components/query-state.css +88 -0
- package/dist/styles/components/radio.css +271 -0
- package/dist/styles/components/radio.tokens.css +26 -0
- package/dist/styles/components/search.css +30 -0
- package/dist/styles/components/select.css +242 -0
- package/dist/styles/components/select.tokens.css +33 -0
- package/dist/styles/components/skeleton.css +60 -0
- package/dist/styles/components/skeleton.tokens.css +27 -0
- package/dist/styles/components/steps.css +157 -0
- package/dist/styles/components/steps.tokens.css +42 -0
- package/dist/styles/components/switch.css +165 -0
- package/dist/styles/components/switch.tokens.css +26 -0
- package/dist/styles/components/table.css +439 -0
- package/dist/styles/components/table.tokens.css +41 -0
- package/dist/styles/components/tabs.css +234 -0
- package/dist/styles/components/tabs.tokens.css +30 -0
- package/dist/styles/components/tag.css +200 -0
- package/dist/styles/components/tag.tokens.css +30 -0
- package/dist/styles/components/toast.css +150 -0
- package/dist/styles/components/toast.tokens.css +26 -0
- package/dist/styles/components/tooltip.css +89 -0
- package/dist/styles/components/tooltip.tokens.css +25 -0
- package/dist/styles/components/tree.css +139 -0
- package/dist/styles/components/tree.tokens.css +20 -0
- package/dist/styles/components/upload.css +150 -0
- package/dist/styles/components/upload.tokens.css +27 -0
- package/dist/styles/index.css +149 -0
- package/dist/styles/operations/collapse.css +84 -0
- package/dist/styles/operations/popup.css +189 -0
- package/dist/styles/operations/tabset.css +57 -0
- package/dist/utils/state-illustration.d.ts +31 -0
- package/dist/utils/state-illustration.js +156 -0
- package/package.json +62 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const SPLIT_MIN_WIDTH = 160;
|
|
2
|
+
const SPLIT_MAX_WIDTH = 480;
|
|
3
|
+
const SPLIT_FALLBACK_WIDTH = 208;
|
|
4
|
+
function splitWidthBounds(min, max) {
|
|
5
|
+
const lo = Number.isFinite(min) ? min : SPLIT_MIN_WIDTH;
|
|
6
|
+
const hi = Number.isFinite(max) ? max : SPLIT_MAX_WIDTH;
|
|
7
|
+
return { min: Math.min(lo, hi), max: Math.max(lo, hi) };
|
|
8
|
+
}
|
|
9
|
+
function clampSplitWidth(value, min, max) {
|
|
10
|
+
const { min: lo, max: hi } = splitWidthBounds(min, max);
|
|
11
|
+
if (Number.isNaN(value)) return Math.round(lo);
|
|
12
|
+
return Math.round(Math.min(hi, Math.max(lo, value)));
|
|
13
|
+
}
|
|
14
|
+
function projectSplitWidth(base, deltaX, side) {
|
|
15
|
+
return side === "right" ? base - deltaX : base + deltaX;
|
|
16
|
+
}
|
|
17
|
+
function measureSidebarWidth(el, side, fallback) {
|
|
18
|
+
if (el) {
|
|
19
|
+
const padding = Number.parseFloat(
|
|
20
|
+
getComputedStyle(el)[side === "right" ? "paddingLeft" : "paddingRight"]
|
|
21
|
+
);
|
|
22
|
+
const content = el.clientWidth - (Number.isFinite(padding) ? padding : 0);
|
|
23
|
+
if (Number.isFinite(content) && content > 0) return content;
|
|
24
|
+
}
|
|
25
|
+
if (Number.isFinite(fallback) && fallback > 0) return fallback;
|
|
26
|
+
return SPLIT_FALLBACK_WIDTH;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
SPLIT_FALLBACK_WIDTH,
|
|
30
|
+
SPLIT_MAX_WIDTH,
|
|
31
|
+
SPLIT_MIN_WIDTH,
|
|
32
|
+
clampSplitWidth,
|
|
33
|
+
measureSidebarWidth,
|
|
34
|
+
projectSplitWidth,
|
|
35
|
+
splitWidthBounds
|
|
36
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { type PropType, type SlotsType, type VNodeChild } from 'vue';
|
|
2
|
+
import type { ControlSize } from '../control-size';
|
|
3
|
+
/** 页码窗口里的一项:页码,或省略号 */
|
|
4
|
+
export type PaginationPageItem = number | 'ellipsis';
|
|
5
|
+
/**
|
|
6
|
+
* 分页条(**自绘**;总数文案 + 每页条数 + 页码窗口 + 翻页箭头 + 跳页)。
|
|
7
|
+
*
|
|
8
|
+
* ## 四个形态的判据
|
|
9
|
+
*
|
|
10
|
+
* - `total === 0` → 只出「暂无数据」;
|
|
11
|
+
* - `hideOnSinglePage` 且只有一页 → **整件不渲染**(列表页常见:数据少时不要一条孤零零的分页条);
|
|
12
|
+
* - `simple` → 只出「1 / 5」(位置窄、不需要跳页时用);
|
|
13
|
+
* - 缺省 → 完整档(可加 `boxed` 出外框、`showQuickJumper` 出跳页框)。
|
|
14
|
+
*
|
|
15
|
+
* ## 页码窗口怎么算
|
|
16
|
+
*
|
|
17
|
+
* 总页数 ≤ 7 全铺;> 7 取**首末 + 当前页±1**、其余折成省略号(规范取向)。这个计算是 JS 该干的事
|
|
18
|
+
* (零 JS 表达不了"当前页",规范样张也是静态铺的)。
|
|
19
|
+
*
|
|
20
|
+
* ## 与 `QueryState` 的分工
|
|
21
|
+
*
|
|
22
|
+
* 本件只管"翻到第几页";**列表为空/加载中/出错**由 `QueryState` 承载(本件只在 `total === 0` 时给出一行
|
|
23
|
+
* 兜底文案,因为分页条自己也得说清"没数据"而不是显示 `共 0 条`)。
|
|
24
|
+
*
|
|
25
|
+
* @example 基本
|
|
26
|
+
* <Pagination :total="243" v-model="page" v-model:page-size="size" />
|
|
27
|
+
*
|
|
28
|
+
* @example 跳页 + 单页隐藏
|
|
29
|
+
* <Pagination :total="243" show-quick-jumper hide-on-single-page v-model="page" />
|
|
30
|
+
*/
|
|
31
|
+
export declare const Pagination: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
32
|
+
/** 总条数 */
|
|
33
|
+
total: {
|
|
34
|
+
type: NumberConstructor;
|
|
35
|
+
default: number;
|
|
36
|
+
};
|
|
37
|
+
/** 当前页(**1 起**) */
|
|
38
|
+
modelValue: {
|
|
39
|
+
type: NumberConstructor;
|
|
40
|
+
default: number;
|
|
41
|
+
};
|
|
42
|
+
/** 每页条数 */
|
|
43
|
+
pageSize: {
|
|
44
|
+
type: NumberConstructor;
|
|
45
|
+
default: number;
|
|
46
|
+
};
|
|
47
|
+
/** 每页条数可选项(只在需要时出选择器) */
|
|
48
|
+
pageSizeOptions: {
|
|
49
|
+
type: PropType<number[]>;
|
|
50
|
+
default: () => number[];
|
|
51
|
+
};
|
|
52
|
+
/** 是否显示「每页 n 条」选择器 */
|
|
53
|
+
showSizeChanger: {
|
|
54
|
+
type: BooleanConstructor;
|
|
55
|
+
default: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** 是否显示「跳至 n 页」输入框 */
|
|
58
|
+
showQuickJumper: {
|
|
59
|
+
type: BooleanConstructor;
|
|
60
|
+
default: boolean;
|
|
61
|
+
};
|
|
62
|
+
/** 只有一页时整件不渲染(列表页常见) */
|
|
63
|
+
hideOnSinglePage: {
|
|
64
|
+
type: BooleanConstructor;
|
|
65
|
+
default: boolean;
|
|
66
|
+
};
|
|
67
|
+
/** 简单档:只出「1 / 5」 */
|
|
68
|
+
simple: {
|
|
69
|
+
type: BooleanConstructor;
|
|
70
|
+
default: boolean;
|
|
71
|
+
};
|
|
72
|
+
/** 外框档 */
|
|
73
|
+
boxed: {
|
|
74
|
+
type: BooleanConstructor;
|
|
75
|
+
default: boolean;
|
|
76
|
+
};
|
|
77
|
+
/** 尺寸档:页码方块跟随全库控件三档(24 / 32 / 40) */
|
|
78
|
+
size: {
|
|
79
|
+
type: PropType<ControlSize>;
|
|
80
|
+
default: string;
|
|
81
|
+
};
|
|
82
|
+
disabled: {
|
|
83
|
+
type: BooleanConstructor;
|
|
84
|
+
default: boolean;
|
|
85
|
+
};
|
|
86
|
+
}>, () => import("vue/jsx-runtime").JSX.Element | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
87
|
+
'update:modelValue': (page: number) => true;
|
|
88
|
+
'update:pageSize': (size: number) => true;
|
|
89
|
+
change: (payload: {
|
|
90
|
+
page: number;
|
|
91
|
+
pageSize: number;
|
|
92
|
+
}) => true;
|
|
93
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
94
|
+
/** 总条数 */
|
|
95
|
+
total: {
|
|
96
|
+
type: NumberConstructor;
|
|
97
|
+
default: number;
|
|
98
|
+
};
|
|
99
|
+
/** 当前页(**1 起**) */
|
|
100
|
+
modelValue: {
|
|
101
|
+
type: NumberConstructor;
|
|
102
|
+
default: number;
|
|
103
|
+
};
|
|
104
|
+
/** 每页条数 */
|
|
105
|
+
pageSize: {
|
|
106
|
+
type: NumberConstructor;
|
|
107
|
+
default: number;
|
|
108
|
+
};
|
|
109
|
+
/** 每页条数可选项(只在需要时出选择器) */
|
|
110
|
+
pageSizeOptions: {
|
|
111
|
+
type: PropType<number[]>;
|
|
112
|
+
default: () => number[];
|
|
113
|
+
};
|
|
114
|
+
/** 是否显示「每页 n 条」选择器 */
|
|
115
|
+
showSizeChanger: {
|
|
116
|
+
type: BooleanConstructor;
|
|
117
|
+
default: boolean;
|
|
118
|
+
};
|
|
119
|
+
/** 是否显示「跳至 n 页」输入框 */
|
|
120
|
+
showQuickJumper: {
|
|
121
|
+
type: BooleanConstructor;
|
|
122
|
+
default: boolean;
|
|
123
|
+
};
|
|
124
|
+
/** 只有一页时整件不渲染(列表页常见) */
|
|
125
|
+
hideOnSinglePage: {
|
|
126
|
+
type: BooleanConstructor;
|
|
127
|
+
default: boolean;
|
|
128
|
+
};
|
|
129
|
+
/** 简单档:只出「1 / 5」 */
|
|
130
|
+
simple: {
|
|
131
|
+
type: BooleanConstructor;
|
|
132
|
+
default: boolean;
|
|
133
|
+
};
|
|
134
|
+
/** 外框档 */
|
|
135
|
+
boxed: {
|
|
136
|
+
type: BooleanConstructor;
|
|
137
|
+
default: boolean;
|
|
138
|
+
};
|
|
139
|
+
/** 尺寸档:页码方块跟随全库控件三档(24 / 32 / 40) */
|
|
140
|
+
size: {
|
|
141
|
+
type: PropType<ControlSize>;
|
|
142
|
+
default: string;
|
|
143
|
+
};
|
|
144
|
+
disabled: {
|
|
145
|
+
type: BooleanConstructor;
|
|
146
|
+
default: boolean;
|
|
147
|
+
};
|
|
148
|
+
}>> & Readonly<{
|
|
149
|
+
onChange?: ((payload: {
|
|
150
|
+
page: number;
|
|
151
|
+
pageSize: number;
|
|
152
|
+
}) => any) | undefined;
|
|
153
|
+
"onUpdate:modelValue"?: ((page: number) => any) | undefined;
|
|
154
|
+
"onUpdate:pageSize"?: ((size: number) => any) | undefined;
|
|
155
|
+
}>, {
|
|
156
|
+
size: ControlSize;
|
|
157
|
+
disabled: boolean;
|
|
158
|
+
modelValue: number;
|
|
159
|
+
total: number;
|
|
160
|
+
pageSize: number;
|
|
161
|
+
pageSizeOptions: number[];
|
|
162
|
+
showSizeChanger: boolean;
|
|
163
|
+
showQuickJumper: boolean;
|
|
164
|
+
hideOnSinglePage: boolean;
|
|
165
|
+
simple: boolean;
|
|
166
|
+
boxed: boolean;
|
|
167
|
+
}, SlotsType<{
|
|
168
|
+
total?: (context: {
|
|
169
|
+
total: number;
|
|
170
|
+
}) => VNodeChild;
|
|
171
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { defineComponent, ref, computed, createVNode, createTextVNode, mergeProps } from "vue";
|
|
2
|
+
import { Icon } from "@manohub/icon";
|
|
3
|
+
const Pagination = /* @__PURE__ */ defineComponent({
|
|
4
|
+
name: "Pagination",
|
|
5
|
+
inheritAttrs: false,
|
|
6
|
+
props: {
|
|
7
|
+
/** 总条数 */
|
|
8
|
+
total: {
|
|
9
|
+
type: Number,
|
|
10
|
+
default: 0
|
|
11
|
+
},
|
|
12
|
+
/** 当前页(**1 起**) */
|
|
13
|
+
modelValue: {
|
|
14
|
+
type: Number,
|
|
15
|
+
default: 1
|
|
16
|
+
},
|
|
17
|
+
/** 每页条数 */
|
|
18
|
+
pageSize: {
|
|
19
|
+
type: Number,
|
|
20
|
+
default: 10
|
|
21
|
+
},
|
|
22
|
+
/** 每页条数可选项(只在需要时出选择器) */
|
|
23
|
+
pageSizeOptions: {
|
|
24
|
+
type: Array,
|
|
25
|
+
default: () => [10, 20, 50]
|
|
26
|
+
},
|
|
27
|
+
/** 是否显示「每页 n 条」选择器 */
|
|
28
|
+
showSizeChanger: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: true
|
|
31
|
+
},
|
|
32
|
+
/** 是否显示「跳至 n 页」输入框 */
|
|
33
|
+
showQuickJumper: {
|
|
34
|
+
type: Boolean,
|
|
35
|
+
default: false
|
|
36
|
+
},
|
|
37
|
+
/** 只有一页时整件不渲染(列表页常见) */
|
|
38
|
+
hideOnSinglePage: {
|
|
39
|
+
type: Boolean,
|
|
40
|
+
default: false
|
|
41
|
+
},
|
|
42
|
+
/** 简单档:只出「1 / 5」 */
|
|
43
|
+
simple: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: false
|
|
46
|
+
},
|
|
47
|
+
/** 外框档 */
|
|
48
|
+
boxed: {
|
|
49
|
+
type: Boolean,
|
|
50
|
+
default: false
|
|
51
|
+
},
|
|
52
|
+
/** 尺寸档:页码方块跟随全库控件三档(24 / 32 / 40) */
|
|
53
|
+
size: {
|
|
54
|
+
type: String,
|
|
55
|
+
default: "md"
|
|
56
|
+
},
|
|
57
|
+
disabled: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: false
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
emits: {
|
|
63
|
+
"update:modelValue": (page) => true,
|
|
64
|
+
"update:pageSize": (size) => true,
|
|
65
|
+
change: (payload) => true
|
|
66
|
+
},
|
|
67
|
+
slots: Object,
|
|
68
|
+
setup(props, {
|
|
69
|
+
emit,
|
|
70
|
+
attrs,
|
|
71
|
+
slots
|
|
72
|
+
}) {
|
|
73
|
+
const menuId = `mh-pagination-${Math.random().toString(36).slice(2, 10)}`;
|
|
74
|
+
const jumpValue = ref("");
|
|
75
|
+
const pageCount = computed(() => Math.max(1, Math.ceil(props.total / Math.max(1, props.pageSize))));
|
|
76
|
+
const current = computed(() => Math.min(pageCount.value, Math.max(1, props.modelValue)));
|
|
77
|
+
const pages = computed(() => {
|
|
78
|
+
const count = pageCount.value;
|
|
79
|
+
if (count <= 7) return Array.from({
|
|
80
|
+
length: count
|
|
81
|
+
}, (_, index) => index + 1);
|
|
82
|
+
const window = [.../* @__PURE__ */ new Set([1, count, current.value - 1, current.value, current.value + 1])].filter((page) => page >= 1 && page <= count).sort((a, b) => a - b);
|
|
83
|
+
const items = [];
|
|
84
|
+
window.forEach((page, index) => {
|
|
85
|
+
if (index > 0 && page - window[index - 1] > 1) items.push("ellipsis");
|
|
86
|
+
items.push(page);
|
|
87
|
+
});
|
|
88
|
+
return items;
|
|
89
|
+
});
|
|
90
|
+
const commitPage = (page) => {
|
|
91
|
+
if (props.disabled) return;
|
|
92
|
+
const next = Math.min(pageCount.value, Math.max(1, page));
|
|
93
|
+
if (next === current.value) return;
|
|
94
|
+
emit("update:modelValue", next);
|
|
95
|
+
emit("change", {
|
|
96
|
+
page: next,
|
|
97
|
+
pageSize: props.pageSize
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
const commitSize = (size) => {
|
|
101
|
+
if (props.disabled) return;
|
|
102
|
+
emit("update:pageSize", size);
|
|
103
|
+
emit("change", {
|
|
104
|
+
page: current.value,
|
|
105
|
+
pageSize: size
|
|
106
|
+
});
|
|
107
|
+
closeMenu();
|
|
108
|
+
};
|
|
109
|
+
const applyJump = () => {
|
|
110
|
+
const parsed = Number.parseInt(jumpValue.value, 10);
|
|
111
|
+
jumpValue.value = "";
|
|
112
|
+
if (Number.isNaN(parsed)) return;
|
|
113
|
+
commitPage(parsed);
|
|
114
|
+
};
|
|
115
|
+
const closeMenu = () => {
|
|
116
|
+
const panel = document.getElementById(menuId);
|
|
117
|
+
panel?.hidePopover?.();
|
|
118
|
+
};
|
|
119
|
+
return () => {
|
|
120
|
+
const rootClass = [
|
|
121
|
+
"mh-pagination",
|
|
122
|
+
/* `mh-popup-host` 是操作层展开转向的**宿主标记**(popup.css 靠它 :has 反推面板是否打开):
|
|
123
|
+
少了它,条数选择器的 caret 永远不会翻向 —— 与 Select / Tooltip 同一分工。 */
|
|
124
|
+
"mh-popup-host",
|
|
125
|
+
props.boxed ? "mh-pagination--boxed" : "",
|
|
126
|
+
props.size === "md" ? "" : `mh-pagination--${props.size}`,
|
|
127
|
+
attrs.class
|
|
128
|
+
].filter(Boolean).join(" ");
|
|
129
|
+
const style = attrs.style;
|
|
130
|
+
const totalText = slots.total ? slots.total({
|
|
131
|
+
total: props.total
|
|
132
|
+
}) : `共 ${props.total} 条,`;
|
|
133
|
+
if (props.simple) {
|
|
134
|
+
return createVNode("span", {
|
|
135
|
+
"class": ["mh-pagination__plain", attrs.class].filter(Boolean).join(" "),
|
|
136
|
+
"style": style
|
|
137
|
+
}, [current.value, createTextVNode(" / "), pageCount.value]);
|
|
138
|
+
}
|
|
139
|
+
if (props.hideOnSinglePage && pageCount.value <= 1) return null;
|
|
140
|
+
if (props.total === 0) {
|
|
141
|
+
return createVNode("span", {
|
|
142
|
+
"class": ["mh-pagination__empty", attrs.class].filter(Boolean).join(" "),
|
|
143
|
+
"style": style
|
|
144
|
+
}, [createTextVNode("暂无数据")]);
|
|
145
|
+
}
|
|
146
|
+
return createVNode("footer", {
|
|
147
|
+
"class": rootClass,
|
|
148
|
+
"style": style
|
|
149
|
+
}, [createVNode("span", {
|
|
150
|
+
"class": "mh-pagination__total"
|
|
151
|
+
}, [totalText]), props.showSizeChanger ? createVNode("button", mergeProps({
|
|
152
|
+
"type": "button",
|
|
153
|
+
"class": "mh-pagination__size",
|
|
154
|
+
"disabled": props.disabled
|
|
155
|
+
}, {
|
|
156
|
+
popovertarget: menuId
|
|
157
|
+
}), [createTextVNode("每页 "), props.pageSize, createTextVNode(" 条"), createVNode(Icon, {
|
|
158
|
+
"name": "chevron-down",
|
|
159
|
+
"class": "mh-popup-caret"
|
|
160
|
+
}, null)]) : null, createVNode("div", mergeProps({
|
|
161
|
+
"id": menuId,
|
|
162
|
+
"class": "mh-popup mh-pagination__panel",
|
|
163
|
+
"data-side": "bottom",
|
|
164
|
+
"data-align": "start"
|
|
165
|
+
}, {
|
|
166
|
+
popover: "auto"
|
|
167
|
+
}), [props.pageSizeOptions.map((size) => createVNode("label", {
|
|
168
|
+
"key": size,
|
|
169
|
+
"class": "mh-pagination__size-option"
|
|
170
|
+
}, [createVNode("input", {
|
|
171
|
+
"type": "radio",
|
|
172
|
+
"name": menuId,
|
|
173
|
+
"checked": size === props.pageSize,
|
|
174
|
+
"disabled": props.disabled,
|
|
175
|
+
"onChange": () => commitSize(size)
|
|
176
|
+
}, null), createVNode("span", null, [size, createTextVNode(" 条/页")])]))]), createVNode("span", {
|
|
177
|
+
"class": "mh-pagination__pages"
|
|
178
|
+
}, [createVNode("button", {
|
|
179
|
+
"type": "button",
|
|
180
|
+
"class": "mh-pagination__btn mh-pagination__btn--arrow mh-pagination__btn--prev",
|
|
181
|
+
"disabled": props.disabled || current.value <= 1,
|
|
182
|
+
"aria-label": "上一页",
|
|
183
|
+
"onClick": () => commitPage(current.value - 1)
|
|
184
|
+
}, [createVNode(Icon, {
|
|
185
|
+
"name": "chevron-left"
|
|
186
|
+
}, null)]), pages.value.map((item, index) => item === "ellipsis" ? createVNode("span", {
|
|
187
|
+
"key": `e-${index}`,
|
|
188
|
+
"class": "mh-pagination__btn mh-pagination__btn--ellipsis"
|
|
189
|
+
}, [createTextVNode("···")]) : createVNode("button", {
|
|
190
|
+
"key": item,
|
|
191
|
+
"type": "button",
|
|
192
|
+
"class": "mh-pagination__btn",
|
|
193
|
+
"data-state": item === current.value ? "selected" : "idle",
|
|
194
|
+
"aria-current": item === current.value ? "page" : void 0,
|
|
195
|
+
"disabled": props.disabled,
|
|
196
|
+
"onClick": () => commitPage(item)
|
|
197
|
+
}, [item])), createVNode("button", {
|
|
198
|
+
"type": "button",
|
|
199
|
+
"class": "mh-pagination__btn mh-pagination__btn--arrow mh-pagination__btn--next",
|
|
200
|
+
"disabled": props.disabled || current.value >= pageCount.value,
|
|
201
|
+
"aria-label": "下一页",
|
|
202
|
+
"onClick": () => commitPage(current.value + 1)
|
|
203
|
+
}, [createVNode(Icon, {
|
|
204
|
+
"name": "chevron-right"
|
|
205
|
+
}, null)])]), props.showQuickJumper ? createVNode("span", {
|
|
206
|
+
"class": "mh-pagination__jump"
|
|
207
|
+
}, [createTextVNode("跳至"), createVNode("input", {
|
|
208
|
+
"class": "mh-pagination__jump-input",
|
|
209
|
+
"type": "number",
|
|
210
|
+
"min": "1",
|
|
211
|
+
"max": pageCount.value,
|
|
212
|
+
"value": jumpValue.value,
|
|
213
|
+
"disabled": props.disabled,
|
|
214
|
+
"aria-label": "跳至页码",
|
|
215
|
+
"onInput": (event) => jumpValue.value = event.target.value,
|
|
216
|
+
"onKeydown": (event) => {
|
|
217
|
+
if (event.key === "Enter") applyJump();
|
|
218
|
+
},
|
|
219
|
+
"onBlur": applyJump
|
|
220
|
+
}, null), createTextVNode("页")]) : null]);
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
export {
|
|
225
|
+
Pagination
|
|
226
|
+
};
|