@byan99/vue-base-table 0.1.0 → 0.3.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 +11 -3
- package/dist/index.css +1 -1
- package/dist/index.js +62 -25
- package/dist/src/components/Table/BaseTable.vue.d.ts +6 -3
- package/dist/src/components/Table/index.d.ts +1 -1
- package/dist/src/components/Table/types.d.ts +18 -0
- package/dist/src/index.d.ts +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
# @byan99/vue-base-table
|
|
2
2
|
|
|
3
|
-
基于 Vue 3 + TypeScript 的可复用表格组件。
|
|
3
|
+
基于 Vue 3 + Element Plus + TypeScript 的可复用表格组件。
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @byan99/vue-base-table
|
|
8
|
+
npm install @byan99/vue-base-table element-plus
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## 使用
|
|
12
12
|
|
|
13
|
+
在入口文件中注册 Element Plus 并引入样式:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import ElementPlus from 'element-plus'
|
|
17
|
+
import 'element-plus/dist/index.css'
|
|
18
|
+
|
|
19
|
+
app.use(ElementPlus)
|
|
20
|
+
```
|
|
21
|
+
|
|
13
22
|
```vue
|
|
14
23
|
<script setup lang="ts">
|
|
15
24
|
import { BaseTable } from '@byan99/vue-base-table'
|
|
16
25
|
import type { TableColumn } from '@byan99/vue-base-table'
|
|
17
|
-
import '@byan99/vue-base-table/style.css'
|
|
18
26
|
|
|
19
27
|
interface UserRow {
|
|
20
28
|
id: number
|
package/dist/index.css
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
.
|
|
1
|
+
.base-table[data-v-e3b643d1]{width:100%}
|
|
2
2
|
/*$vite$:1*/
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Fragment as e,
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Fragment as e, createBlock as t, createElementBlock as n, createTextVNode as r, defineComponent as i, openBlock as a, renderList as o, renderSlot as s, toDisplayString as c, unref as l, withCtx as u } from "vue";
|
|
2
|
+
import { ElTable as d, ElTableColumn as f } from "element-plus";
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/components/Table/BaseTable.vue
|
|
5
|
+
var p = /*#__PURE__*/ ((e, t) => {
|
|
4
6
|
let n = e.__vccOpts || e;
|
|
5
7
|
for (let [e, r] of t) n[e] = r;
|
|
6
8
|
return n;
|
|
@@ -12,33 +14,68 @@ var d = { key: 0 }, f = ["colspan"], p = { key: 1 }, m = ["colspan"], h = /*#__P
|
|
|
12
14
|
loading: { type: Boolean },
|
|
13
15
|
emptyText: {},
|
|
14
16
|
stripe: { type: Boolean },
|
|
15
|
-
bordered: { type: Boolean }
|
|
17
|
+
bordered: { type: Boolean },
|
|
18
|
+
defaultSort: {}
|
|
16
19
|
},
|
|
17
|
-
|
|
20
|
+
emits: ["sortChange"],
|
|
21
|
+
setup(i, { emit: p }) {
|
|
22
|
+
let m = p;
|
|
18
23
|
function h(e, t) {
|
|
19
24
|
let n = e[t];
|
|
20
25
|
return n == null ? "" : String(n);
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
function g(e) {
|
|
28
|
+
m("sortChange", {
|
|
29
|
+
prop: e.prop,
|
|
30
|
+
order: e.order
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return (p, m) => (a(), t(l(d), {
|
|
34
|
+
class: "base-table",
|
|
35
|
+
data: i.data,
|
|
36
|
+
stripe: i.stripe,
|
|
37
|
+
border: i.bordered,
|
|
38
|
+
loading: i.loading,
|
|
39
|
+
"empty-text": i.emptyText ?? "暂无数据",
|
|
40
|
+
"default-sort": i.defaultSort,
|
|
41
|
+
onSortChange: g
|
|
42
|
+
}, {
|
|
43
|
+
default: u(() => [(a(!0), n(e, null, o(i.columns, (e) => (a(), t(l(f), {
|
|
44
|
+
key: e.key,
|
|
45
|
+
prop: e.key,
|
|
46
|
+
label: e.label,
|
|
25
47
|
width: e.width,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
align: e.align ?? "left",
|
|
49
|
+
sortable: e.sortable,
|
|
50
|
+
"sort-method": e.sortMethod,
|
|
51
|
+
"sort-by": e.sortBy,
|
|
52
|
+
"sort-orders": e.sortOrders
|
|
53
|
+
}, {
|
|
54
|
+
default: u(({ row: t }) => [s(p.$slots, e.key, {
|
|
55
|
+
row: t,
|
|
56
|
+
value: t[e.key]
|
|
57
|
+
}, () => [r(c(h(t, e.key)), 1)], !0)]),
|
|
58
|
+
_: 2
|
|
59
|
+
}, 1032, [
|
|
60
|
+
"prop",
|
|
61
|
+
"label",
|
|
62
|
+
"width",
|
|
63
|
+
"align",
|
|
64
|
+
"sortable",
|
|
65
|
+
"sort-method",
|
|
66
|
+
"sort-by",
|
|
67
|
+
"sort-orders"
|
|
68
|
+
]))), 128))]),
|
|
69
|
+
_: 3
|
|
70
|
+
}, 8, [
|
|
71
|
+
"data",
|
|
72
|
+
"stripe",
|
|
73
|
+
"border",
|
|
74
|
+
"loading",
|
|
75
|
+
"empty-text",
|
|
76
|
+
"default-sort"
|
|
77
|
+
]));
|
|
41
78
|
}
|
|
42
|
-
}), [["__scopeId", "data-v-
|
|
79
|
+
}), [["__scopeId", "data-v-e3b643d1"]]);
|
|
43
80
|
//#endregion
|
|
44
|
-
export {
|
|
81
|
+
export { p as BaseTable };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { TableColumn } from './types';
|
|
1
|
+
import { TableColumn, TableDefaultSort, TableSortChangePayload } from './types';
|
|
2
2
|
declare const _default: <T extends object>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
3
|
-
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
|
|
3
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
|
|
4
|
+
readonly onSortChange?: ((payload: TableSortChangePayload) => any) | undefined;
|
|
5
|
+
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, "onSortChange"> & {
|
|
4
6
|
columns: TableColumn<T>[];
|
|
5
7
|
data: T[];
|
|
6
8
|
loading?: boolean;
|
|
7
9
|
emptyText?: string;
|
|
8
10
|
stripe?: boolean;
|
|
9
11
|
bordered?: boolean;
|
|
12
|
+
defaultSort?: TableDefaultSort;
|
|
10
13
|
} & Partial<{}>> & import('vue').PublicProps;
|
|
11
14
|
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
12
15
|
attrs: any;
|
|
@@ -14,7 +17,7 @@ declare const _default: <T extends object>(__VLS_props: NonNullable<Awaited<type
|
|
|
14
17
|
row: T;
|
|
15
18
|
value: T[keyof T & string];
|
|
16
19
|
}) => any>>;
|
|
17
|
-
emit:
|
|
20
|
+
emit: (evt: "sortChange", payload: TableSortChangePayload) => void;
|
|
18
21
|
}>) => import('vue').VNode & {
|
|
19
22
|
__ctx?: Awaited<typeof __VLS_setup>;
|
|
20
23
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as BaseTable } from './BaseTable.vue';
|
|
2
|
-
export type { TableAlign, TableColumn, TableProps } from './types';
|
|
2
|
+
export type { TableAlign, TableColumn, TableDefaultSort, TableProps, TableSortChangePayload, TableSortOrder, } from './types';
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
export type TableAlign = 'left' | 'center' | 'right';
|
|
2
|
+
export type TableSortOrder = 'ascending' | 'descending';
|
|
2
3
|
export interface TableColumn<T extends object = Record<string, unknown>> {
|
|
3
4
|
key: keyof T & string;
|
|
4
5
|
label: string;
|
|
5
6
|
width?: string;
|
|
6
7
|
align?: TableAlign;
|
|
8
|
+
/** 是否可排序;`custom` 表示远程排序,需监听 sort-change */
|
|
9
|
+
sortable?: boolean | 'custom';
|
|
10
|
+
/** 本地排序比较函数,sortable 为 true 时生效 */
|
|
11
|
+
sortMethod?: (a: T, b: T) => number;
|
|
12
|
+
/** 排序字段,默认使用 key */
|
|
13
|
+
sortBy?: string | string[];
|
|
14
|
+
/** 排序策略循环顺序,默认 ['ascending', 'descending', null] */
|
|
15
|
+
sortOrders?: (TableSortOrder | null)[];
|
|
16
|
+
}
|
|
17
|
+
export interface TableDefaultSort {
|
|
18
|
+
prop: string;
|
|
19
|
+
order: TableSortOrder;
|
|
20
|
+
}
|
|
21
|
+
export interface TableSortChangePayload {
|
|
22
|
+
prop: string | null;
|
|
23
|
+
order: TableSortOrder | null;
|
|
7
24
|
}
|
|
8
25
|
export interface TableProps<T extends object = Record<string, unknown>> {
|
|
9
26
|
columns: TableColumn<T>[];
|
|
@@ -12,4 +29,5 @@ export interface TableProps<T extends object = Record<string, unknown>> {
|
|
|
12
29
|
emptyText?: string;
|
|
13
30
|
stripe?: boolean;
|
|
14
31
|
bordered?: boolean;
|
|
32
|
+
defaultSort?: TableDefaultSort;
|
|
15
33
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { BaseTable } from './components/Table';
|
|
2
|
-
export type { TableAlign, TableColumn, TableProps } from './components/Table';
|
|
2
|
+
export type { TableAlign, TableColumn, TableDefaultSort, TableProps, TableSortChangePayload, TableSortOrder, } from './components/Table';
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@byan99/vue-base-table",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A reusable Vue 3 table component with TypeScript support",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "A reusable Vue 3 table component based on Element Plus with TypeScript support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vue",
|
|
8
8
|
"vue3",
|
|
9
9
|
"table",
|
|
10
10
|
"component",
|
|
11
|
-
"typescript"
|
|
11
|
+
"typescript",
|
|
12
|
+
"element-plus"
|
|
12
13
|
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
13
17
|
"license": "MIT",
|
|
14
18
|
"author": "byan99",
|
|
15
19
|
"repository": {
|
|
@@ -42,12 +46,14 @@
|
|
|
42
46
|
"prepublishOnly": "npm run build:lib"
|
|
43
47
|
},
|
|
44
48
|
"peerDependencies": {
|
|
49
|
+
"element-plus": "^2.9.0",
|
|
45
50
|
"vue": "^3.5.0"
|
|
46
51
|
},
|
|
47
52
|
"devDependencies": {
|
|
48
53
|
"@types/node": "^24.13.2",
|
|
49
54
|
"@vitejs/plugin-vue": "^6.0.7",
|
|
50
55
|
"@vue/tsconfig": "^0.9.1",
|
|
56
|
+
"element-plus": "^2.14.2",
|
|
51
57
|
"typescript": "~6.0.2",
|
|
52
58
|
"vite": "^8.1.1",
|
|
53
59
|
"vite-plugin-dts": "^4.5.4",
|