@byan99/vue-base-table 0.1.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 +83 -0
- package/dist/index.css +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +44 -0
- package/dist/src/components/Table/BaseTable.vue.d.ts +24 -0
- package/dist/src/components/Table/index.d.ts +2 -0
- package/dist/src/components/Table/types.d.ts +15 -0
- package/dist/src/index.d.ts +2 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @byan99/vue-base-table
|
|
2
|
+
|
|
3
|
+
基于 Vue 3 + TypeScript 的可复用表格组件。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @byan99/vue-base-table
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
```vue
|
|
14
|
+
<script setup lang="ts">
|
|
15
|
+
import { BaseTable } from '@byan99/vue-base-table'
|
|
16
|
+
import type { TableColumn } from '@byan99/vue-base-table'
|
|
17
|
+
import '@byan99/vue-base-table/style.css'
|
|
18
|
+
|
|
19
|
+
interface UserRow {
|
|
20
|
+
id: number
|
|
21
|
+
name: string
|
|
22
|
+
role: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const columns: TableColumn<UserRow>[] = [
|
|
26
|
+
{ key: 'id', label: 'ID', width: '80px', align: 'center' },
|
|
27
|
+
{ key: 'name', label: '姓名' },
|
|
28
|
+
{ key: 'role', label: '角色' },
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
const data: UserRow[] = [
|
|
32
|
+
{ id: 1, name: '张三', role: '管理员' },
|
|
33
|
+
{ id: 2, name: '李四', role: '编辑' },
|
|
34
|
+
]
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<template>
|
|
38
|
+
<BaseTable :columns="columns" :data="data" stripe bordered />
|
|
39
|
+
</template>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 本地开发
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm run dev
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 构建组件库
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm run build:lib
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 发布到 npm
|
|
55
|
+
|
|
56
|
+
1. 在 [npmjs.com](https://www.npmjs.com/) 注册账号
|
|
57
|
+
2. 修改 `package.json` 中的 `name`(必须全局唯一,建议使用 `@your-scope/vue-base-table`)
|
|
58
|
+
3. 填写 `author`、`repository` 等字段
|
|
59
|
+
4. 登录并发布:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm login
|
|
63
|
+
npm publish
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
如果是 scoped 包且需公开访问:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm publish --access public
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API
|
|
73
|
+
|
|
74
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
75
|
+
|------|------|--------|------|
|
|
76
|
+
| columns | `TableColumn[]` | - | 列配置 |
|
|
77
|
+
| data | `T[]` | - | 表格数据 |
|
|
78
|
+
| loading | `boolean` | `false` | 加载状态 |
|
|
79
|
+
| emptyText | `string` | `'暂无数据'` | 空数据提示 |
|
|
80
|
+
| stripe | `boolean` | `false` | 斑马纹 |
|
|
81
|
+
| bordered | `boolean` | `false` | 边框 |
|
|
82
|
+
|
|
83
|
+
支持通过 `#columnKey="{ row, value }"` 插槽自定义单元格。
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.table-wrapper[data-v-c67b71ed]{border-radius:8px;width:100%;overflow-x:auto}.table-wrapper--bordered[data-v-c67b71ed]{border:1px solid var(--border)}.base-table[data-v-c67b71ed]{border-collapse:collapse;text-align:left;width:100%;font-size:15px}.base-table th[data-v-c67b71ed],.base-table td[data-v-c67b71ed]{border-bottom:1px solid var(--border);padding:12px 16px}.base-table th[data-v-c67b71ed]{color:var(--text-h);background:var(--code-bg);font-weight:500}.base-table td[data-v-c67b71ed]{color:var(--text)}.base-table tbody tr:last-child td[data-v-c67b71ed]{border-bottom:none}.base-table--stripe tbody tr[data-v-c67b71ed]:nth-child(2n){background:var(--social-bg)}.base-table tbody tr:hover td[data-v-c67b71ed]{background:var(--accent-bg)}.base-table__state[data-v-c67b71ed]{text-align:center;color:var(--text);padding:32px 16px}
|
|
2
|
+
/*$vite$:1*/
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index"
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Fragment as e, createElementBlock as t, createElementVNode as n, createTextVNode as r, defineComponent as i, normalizeClass as a, normalizeStyle as o, openBlock as s, renderList as c, renderSlot as l, toDisplayString as u } from "vue";
|
|
2
|
+
//#region src/components/Table/BaseTable.vue?vue&type=script&setup=true&lang.ts
|
|
3
|
+
var d = { key: 0 }, f = ["colspan"], p = { key: 1 }, m = ["colspan"], h = /*#__PURE__*/ ((e, t) => {
|
|
4
|
+
let n = e.__vccOpts || e;
|
|
5
|
+
for (let [e, r] of t) n[e] = r;
|
|
6
|
+
return n;
|
|
7
|
+
})(/* @__PURE__ */ i({
|
|
8
|
+
__name: "BaseTable",
|
|
9
|
+
props: {
|
|
10
|
+
columns: {},
|
|
11
|
+
data: {},
|
|
12
|
+
loading: { type: Boolean },
|
|
13
|
+
emptyText: {},
|
|
14
|
+
stripe: { type: Boolean },
|
|
15
|
+
bordered: { type: Boolean }
|
|
16
|
+
},
|
|
17
|
+
setup(i) {
|
|
18
|
+
function h(e, t) {
|
|
19
|
+
let n = e[t];
|
|
20
|
+
return n == null ? "" : String(n);
|
|
21
|
+
}
|
|
22
|
+
return (g, _) => (s(), t("div", { class: a(["table-wrapper", { "table-wrapper--bordered": i.bordered }]) }, [n("table", { class: a(["base-table", { "base-table--stripe": i.stripe }]) }, [n("thead", null, [n("tr", null, [(s(!0), t(e, null, c(i.columns, (e) => (s(), t("th", {
|
|
23
|
+
key: e.key,
|
|
24
|
+
style: o({
|
|
25
|
+
width: e.width,
|
|
26
|
+
textAlign: e.align ?? "left"
|
|
27
|
+
})
|
|
28
|
+
}, u(e.label), 5))), 128))])]), n("tbody", null, [i.loading ? (s(), t("tr", d, [n("td", {
|
|
29
|
+
colspan: i.columns.length,
|
|
30
|
+
class: "base-table__state"
|
|
31
|
+
}, " 加载中... ", 8, f)])) : i.data.length ? (s(!0), t(e, { key: 2 }, c(i.data, (n, a) => (s(), t("tr", { key: a }, [(s(!0), t(e, null, c(i.columns, (e) => (s(), t("td", {
|
|
32
|
+
key: e.key,
|
|
33
|
+
style: o({ textAlign: e.align ?? "left" })
|
|
34
|
+
}, [l(g.$slots, e.key, {
|
|
35
|
+
row: n,
|
|
36
|
+
value: n[e.key]
|
|
37
|
+
}, () => [r(u(h(n, e.key)), 1)], !0)], 4))), 128))]))), 128)) : (s(), t("tr", p, [n("td", {
|
|
38
|
+
colspan: i.columns.length,
|
|
39
|
+
class: "base-table__state"
|
|
40
|
+
}, u(i.emptyText ?? "暂无数据"), 9, m)]))])], 2)], 2));
|
|
41
|
+
}
|
|
42
|
+
}), [["__scopeId", "data-v-c67b71ed"]]);
|
|
43
|
+
//#endregion
|
|
44
|
+
export { h as BaseTable };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TableColumn } from './types';
|
|
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<{} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, never> & {
|
|
4
|
+
columns: TableColumn<T>[];
|
|
5
|
+
data: T[];
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
emptyText?: string;
|
|
8
|
+
stripe?: boolean;
|
|
9
|
+
bordered?: boolean;
|
|
10
|
+
} & Partial<{}>> & import('vue').PublicProps;
|
|
11
|
+
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
12
|
+
attrs: any;
|
|
13
|
+
slots: Partial<Record<NonNullable<keyof T & string>, (_: {
|
|
14
|
+
row: T;
|
|
15
|
+
value: T[keyof T & string];
|
|
16
|
+
}) => any>>;
|
|
17
|
+
emit: {};
|
|
18
|
+
}>) => import('vue').VNode & {
|
|
19
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
20
|
+
};
|
|
21
|
+
export default _default;
|
|
22
|
+
type __VLS_PrettifyLocal<T> = {
|
|
23
|
+
[K in keyof T]: T[K];
|
|
24
|
+
} & {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type TableAlign = 'left' | 'center' | 'right';
|
|
2
|
+
export interface TableColumn<T extends object = Record<string, unknown>> {
|
|
3
|
+
key: keyof T & string;
|
|
4
|
+
label: string;
|
|
5
|
+
width?: string;
|
|
6
|
+
align?: TableAlign;
|
|
7
|
+
}
|
|
8
|
+
export interface TableProps<T extends object = Record<string, unknown>> {
|
|
9
|
+
columns: TableColumn<T>[];
|
|
10
|
+
data: T[];
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
emptyText?: string;
|
|
13
|
+
stripe?: boolean;
|
|
14
|
+
bordered?: boolean;
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@byan99/vue-base-table",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A reusable Vue 3 table component with TypeScript support",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"vue",
|
|
8
|
+
"vue3",
|
|
9
|
+
"table",
|
|
10
|
+
"component",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "byan99",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": ""
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./style.css": "./dist/index.css"
|
|
31
|
+
},
|
|
32
|
+
"sideEffects": [
|
|
33
|
+
"**/*.css",
|
|
34
|
+
"**/*.vue"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"dev": "vite",
|
|
38
|
+
"build": "npm run build:lib",
|
|
39
|
+
"build:lib": "vue-tsc -b && vite build --mode lib",
|
|
40
|
+
"build:demo": "vue-tsc -b && vite build",
|
|
41
|
+
"preview": "vite preview",
|
|
42
|
+
"prepublishOnly": "npm run build:lib"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"vue": "^3.5.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^24.13.2",
|
|
49
|
+
"@vitejs/plugin-vue": "^6.0.7",
|
|
50
|
+
"@vue/tsconfig": "^0.9.1",
|
|
51
|
+
"typescript": "~6.0.2",
|
|
52
|
+
"vite": "^8.1.1",
|
|
53
|
+
"vite-plugin-dts": "^4.5.4",
|
|
54
|
+
"vue": "^3.5.39",
|
|
55
|
+
"vue-tsc": "^3.3.5"
|
|
56
|
+
}
|
|
57
|
+
}
|