baai-components 1.0.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 ADDED
@@ -0,0 +1,201 @@
1
+ # baai-components
2
+
3
+ 基于 Vue 3 和 TypeScript 的业务组件库,提供高质量、可复用的 UI 组件。
4
+
5
+ ## 功能特点
6
+
7
+ - 基于 Vue 3 和 TypeScript 开发
8
+ - 集成 UnoCSS 原子化 CSS 框架
9
+ - 支持 Tree Shaking,按需引入
10
+ - 包含丰富的业务组件
11
+ - 提供组件演示和调试环境
12
+
13
+ ## 安装
14
+
15
+ ```bash
16
+ # 使用 npm
17
+ npm install baai-components
18
+
19
+ # 使用 yarn
20
+ yarn add baai-components
21
+
22
+ # 使用 pnpm
23
+ pnpm add baai-components
24
+ ```
25
+
26
+ ## 使用方法
27
+
28
+ ### 全量引入
29
+
30
+ ```javascript
31
+ import { createApp } from 'vue';
32
+ import BaaiComponents from 'baai-components';
33
+ import 'baai-components/dist/style.css';
34
+ import App from './App.vue';
35
+
36
+ const app = createApp(App);
37
+ app.use(BaaiComponents);
38
+ app.mount('#app');
39
+ ```
40
+
41
+ ### 按需引入
42
+
43
+ ```javascript
44
+ import { createApp } from 'vue';
45
+ import { MyButton, MyTable } from 'baai-components';
46
+ import 'baai-components/dist/style.css';
47
+ import App from './App.vue';
48
+
49
+ const app = createApp(App);
50
+ app.component('MyButton', MyButton);
51
+ app.component('MyTable', MyTable);
52
+ app.mount('#app');
53
+ ```
54
+
55
+ ## 组件列表
56
+
57
+ ### MyButton
58
+
59
+ 按钮组件,支持多种类型和状态。
60
+
61
+ ```vue
62
+ <template>
63
+ <MyButton type="primary">主要按钮</MyButton>
64
+ <MyButton type="success">成功按钮</MyButton>
65
+ <MyButton type="warning">警告按钮</MyButton>
66
+ <MyButton type="danger">危险按钮</MyButton>
67
+ <MyButton type="info">信息按钮</MyButton>
68
+ <MyButton disabled>禁用按钮</MyButton>
69
+ <MyButton loading>加载中</MyButton>
70
+ </template>
71
+ ```
72
+
73
+ #### 属性
74
+
75
+ | 属性名 | 类型 | 默认值 | 说明 |
76
+ |----------|---------|-----------|--------------|
77
+ | type | string | 'default' | 按钮类型 |
78
+ | disabled | boolean | false | 是否禁用 |
79
+ | loading | boolean | false | 是否加载中 |
80
+
81
+ #### 事件
82
+
83
+ | 事件名 | 说明 | 回调参数 |
84
+ |--------|----------------|----------|
85
+ | click | 点击按钮时触发 | event |
86
+
87
+ ### MyTable
88
+
89
+ 表格组件,用于展示结构化数据。
90
+
91
+ ```vue
92
+ <template>
93
+ <MyTable :columns="columns" :data="data" row-key="id">
94
+ <!-- 自定义列内容 -->
95
+ <template #action="{ row }">
96
+ <MyButton @click="handleEdit(row)">编辑</MyButton>
97
+ <MyButton type="danger" @click="handleDelete(row)">删除</MyButton>
98
+ </template>
99
+ </MyTable>
100
+ </template>
101
+
102
+ <script>
103
+ export default {
104
+ setup() {
105
+ const columns = [
106
+ { key: 'name', title: '姓名' },
107
+ { key: 'age', title: '年龄' },
108
+ { key: 'address', title: '地址' },
109
+ { key: 'action', title: '操作', width: '150px' }
110
+ ];
111
+
112
+ const data = [
113
+ { id: 1, name: '张三', age: 25, address: '北京市朝阳区' },
114
+ { id: 2, name: '李四', age: 30, address: '上海市浦东新区' }
115
+ ];
116
+
117
+ const handleEdit = (row) => {
118
+ console.log('编辑', row);
119
+ };
120
+
121
+ const handleDelete = (row) => {
122
+ console.log('删除', row);
123
+ };
124
+
125
+ return {
126
+ columns,
127
+ data,
128
+ handleEdit,
129
+ handleDelete
130
+ };
131
+ }
132
+ };
133
+ </script>
134
+ ```
135
+
136
+ #### 属性
137
+
138
+ | 属性名 | 类型 | 默认值 | 说明 |
139
+ |---------|-------|--------|----------------|
140
+ | columns | array | [] | 表格列配置 |
141
+ | data | array | [] | 表格数据 |
142
+ | rowKey | string| '' | 行唯一标识的键名 |
143
+
144
+ ## 开发指南
145
+
146
+ ### 项目结构
147
+
148
+ ```
149
+ components/
150
+ ├── demo/ # 组件演示和调试环境
151
+ │ ├── src/ # 演示代码
152
+ │ │ ├── App.vue # 演示主页面
153
+ │ │ └── main.ts # 演示入口
154
+ │ └── index.html # 演示 HTML
155
+ ├── src/
156
+ │ ├── components/ # 组件源码
157
+ │ │ ├── Button/ # 按钮组件
158
+ │ │ └── Table/ # 表格组件
159
+ │ ├── types.d.ts # 类型声明
160
+ │ └── index.ts # 入口文件
161
+ ├── vite.config.ts # 组件库 Vite 配置
162
+ ├── vite.demo.config.ts # 演示环境 Vite 配置
163
+ ├── package.json
164
+ ├── tsconfig.json
165
+ └── README.md
166
+ ```
167
+
168
+ ### UnoCSS 集成
169
+
170
+ 组件库使用 [UnoCSS](https://unocss.dev/) 作为 CSS 解决方案,这是一个原子化 CSS 引擎,可以让组件样式更加灵活和高效。
171
+
172
+ 主要特性:
173
+ - 原子化 CSS 类(类似 Tailwind CSS)
174
+ - 支持属性化模式
175
+ - 内置图标支持
176
+ - 可自定义颜色主题和规则
177
+
178
+ ### 开发与调试
179
+
180
+ ```bash
181
+ # 安装依赖
182
+ npm install
183
+
184
+ # 运行演示环境(用于调试组件)
185
+ npm run demo
186
+
187
+ # 开发模式
188
+ npm run dev
189
+
190
+ # 构建
191
+ npm run build
192
+ ```
193
+
194
+ #### 使用演示环境
195
+
196
+ 演示环境提供了一个完整的页面,展示了所有组件的使用方式和效果。这对于组件的开发和调试非常有帮助。
197
+
198
+ 1. 运行 `npm run demo` 启动演示环境
199
+ 2. 在浏览器中访问 http://localhost:3000
200
+ 3. 修改 `src/components` 下的组件代码,演示页面会自动热更新
201
+ 4. 需要添加新组件时,先在 `src/components` 下开发,然后在 `demo/src/App.vue` 中添加演示代码
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ export default _default;
@@ -0,0 +1,39 @@
1
+ import { PropType } from 'vue';
2
+ type ButtonType = 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'default';
3
+ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
+ type: {
5
+ type: PropType<ButtonType>;
6
+ default: string;
7
+ };
8
+ disabled: {
9
+ type: BooleanConstructor;
10
+ default: boolean;
11
+ };
12
+ loading: {
13
+ type: BooleanConstructor;
14
+ default: boolean;
15
+ };
16
+ }>, {
17
+ typeClasses: import("vue").ComputedRef<"bg-primary hover:bg-blue-500 text-white border-transparent" | "bg-success hover:bg-green-500 text-white border-transparent" | "bg-warning hover:bg-yellow-500 text-white border-transparent" | "bg-danger hover:bg-red-500 text-white border-transparent" | "bg-info hover:bg-gray-500 text-white border-transparent" | "bg-white hover:bg-gray-100 text-gray-700 border border-gray-300">;
18
+ handleClick: (e: MouseEvent) => void;
19
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "click"[], "click", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
20
+ type: {
21
+ type: PropType<ButtonType>;
22
+ default: string;
23
+ };
24
+ disabled: {
25
+ type: BooleanConstructor;
26
+ default: boolean;
27
+ };
28
+ loading: {
29
+ type: BooleanConstructor;
30
+ default: boolean;
31
+ };
32
+ }>> & Readonly<{
33
+ onClick?: ((...args: any[]) => any) | undefined;
34
+ }>, {
35
+ type: ButtonType;
36
+ disabled: boolean;
37
+ loading: boolean;
38
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
39
+ export default _default;
@@ -0,0 +1,16 @@
1
+ interface Props {
2
+ userNickName: string;
3
+ currentPath: string;
4
+ logout: () => void;
5
+ }
6
+ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Props>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Props>>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
7
+ export default _default;
8
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
9
+ type __VLS_TypePropsToRuntimeProps<T> = {
10
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
11
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
12
+ } : {
13
+ type: import('vue').PropType<T[K]>;
14
+ required: true;
15
+ };
16
+ };
@@ -0,0 +1,27 @@
1
+ import { LocaleTypeEnum } from './constants/locale';
2
+ import type { NavMenuItem, NavChildItem } from './config/menus';
3
+ import 'uno.css';
4
+ interface Props {
5
+ routePath: string;
6
+ menuList: NavMenuItem[];
7
+ isWhiteTheme: boolean;
8
+ isScrolledTheme: boolean;
9
+ currentLocale: LocaleTypeEnum;
10
+ userName?: string;
11
+ userNickName: string;
12
+ onLogoClick: () => void;
13
+ onJumpPage: (menu: NavMenuItem, childMenu?: NavChildItem) => void;
14
+ onChangeLanguage: (locale: LocaleTypeEnum) => void;
15
+ onLogout: () => void;
16
+ }
17
+ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Props>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Props>>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
18
+ export default _default;
19
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
20
+ type __VLS_TypePropsToRuntimeProps<T> = {
21
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
22
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
23
+ } : {
24
+ type: import('vue').PropType<T[K]>;
25
+ required: true;
26
+ };
27
+ };
@@ -0,0 +1,48 @@
1
+ import { LocaleTypeEnum } from './constants/locale';
2
+ interface LocaleOption {
3
+ value: LocaleTypeEnum;
4
+ label: string;
5
+ }
6
+ interface Props {
7
+ isWhiteTheme?: boolean;
8
+ currentLocale: LocaleTypeEnum;
9
+ localeOptions?: LocaleOption[];
10
+ }
11
+ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
12
+ isWhiteTheme: boolean;
13
+ localeOptions: () => {
14
+ value: LocaleTypeEnum;
15
+ label: string;
16
+ }[];
17
+ }>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
18
+ "change-language": (locale: LocaleTypeEnum) => void;
19
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
20
+ isWhiteTheme: boolean;
21
+ localeOptions: () => {
22
+ value: LocaleTypeEnum;
23
+ label: string;
24
+ }[];
25
+ }>>> & Readonly<{
26
+ "onChange-language"?: ((locale: LocaleTypeEnum) => any) | undefined;
27
+ }>, {
28
+ isWhiteTheme: boolean;
29
+ localeOptions: LocaleOption[];
30
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
31
+ export default _default;
32
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
33
+ type __VLS_TypePropsToRuntimeProps<T> = {
34
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
35
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
36
+ } : {
37
+ type: import('vue').PropType<T[K]>;
38
+ required: true;
39
+ };
40
+ };
41
+ type __VLS_WithDefaults<P, D> = {
42
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
43
+ default: D[K];
44
+ }> : P[K];
45
+ };
46
+ type __VLS_Prettify<T> = {
47
+ [K in keyof T]: T[K];
48
+ } & {};
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import { LocaleTypeEnum } from '../constants/locale';
2
+ export declare const NAV_LOCALE_OPTIONS: {
3
+ value: LocaleTypeEnum;
4
+ label: string;
5
+ }[];
6
+ export declare const NAV_LOCALE_TO_LANG: Record<LocaleTypeEnum, string>;
7
+ export declare const NAV_LANG_TO_LOCALE: Record<string, LocaleTypeEnum>;
8
+ export declare const NAV_WIKI_LANG_BY_LOCALE: Record<LocaleTypeEnum, string>;
@@ -0,0 +1,29 @@
1
+ import { LocaleTypeEnum } from '../constants/locale';
2
+ export interface NavChildItem {
3
+ id: string;
4
+ label: string;
5
+ path: string;
6
+ desc?: string;
7
+ type: 'route' | 'link' | 'unopen';
8
+ }
9
+ export interface NavDropdownGroup {
10
+ id: string;
11
+ label: string;
12
+ list: NavChildItem[];
13
+ }
14
+ export interface NavMenuItem {
15
+ id: string;
16
+ label: string;
17
+ path?: string;
18
+ active?: boolean;
19
+ /** flat items (tools / learn) */
20
+ dropdownList?: NavChildItem[];
21
+ /** grouped items (projects) */
22
+ dropdownGroups?: NavDropdownGroup[];
23
+ }
24
+ /**
25
+ * Fetch nav menu by lang.
26
+ * Replace the mock body with a real HTTP call when the backend is ready:
27
+ * return request({ method: 'get', url: '/nav/menus', params: { lang } }).then(res => res.data);
28
+ */
29
+ export declare const getNavMenuApi: (lang: LocaleTypeEnum) => NavMenuItem[];
@@ -0,0 +1,8 @@
1
+ import type { InjectionKey, ComputedRef } from 'vue';
2
+ import { LocaleTypeEnum } from '../constants/locale';
3
+ export interface NavTexts {
4
+ loginText: string;
5
+ logoutText: string;
6
+ }
7
+ export declare const NAV_TEXTS_KEY: InjectionKey<ComputedRef<NavTexts>>;
8
+ export declare const buildNavTexts: (lang: LocaleTypeEnum) => NavTexts;
@@ -0,0 +1,4 @@
1
+ export declare enum LocaleTypeEnum {
2
+ English = "en",
3
+ Chinese = "zh-CN"
4
+ }
@@ -0,0 +1,56 @@
1
+ import type { Ref } from 'vue';
2
+ import type { LocaleTypeEnum } from '../constants/locale';
3
+ import { type NavMenuItem, type NavChildItem } from '../config/menus';
4
+ export declare function useHeaderMenu(currentLocale: Ref<LocaleTypeEnum>, route: any, router: any,
5
+ /** String shown when user clicks an unavailable item (e.g. t('projects.unopentip')) */
6
+ unopenTip: Ref<string> | string): {
7
+ menuList: Ref<{
8
+ id: string;
9
+ label: string;
10
+ path?: string | undefined;
11
+ active?: boolean | undefined;
12
+ dropdownList?: {
13
+ id: string;
14
+ label: string;
15
+ path: string;
16
+ desc?: string | undefined;
17
+ type: "link" | "route" | "unopen";
18
+ }[] | undefined;
19
+ dropdownGroups?: {
20
+ id: string;
21
+ label: string;
22
+ list: {
23
+ id: string;
24
+ label: string;
25
+ path: string;
26
+ desc?: string | undefined;
27
+ type: "link" | "route" | "unopen";
28
+ }[];
29
+ }[] | undefined;
30
+ }[], NavMenuItem[] | {
31
+ id: string;
32
+ label: string;
33
+ path?: string | undefined;
34
+ active?: boolean | undefined;
35
+ dropdownList?: {
36
+ id: string;
37
+ label: string;
38
+ path: string;
39
+ desc?: string | undefined;
40
+ type: "link" | "route" | "unopen";
41
+ }[] | undefined;
42
+ dropdownGroups?: {
43
+ id: string;
44
+ label: string;
45
+ list: {
46
+ id: string;
47
+ label: string;
48
+ path: string;
49
+ desc?: string | undefined;
50
+ type: "link" | "route" | "unopen";
51
+ }[];
52
+ }[] | undefined;
53
+ }[]>;
54
+ syncActiveMenu: () => void;
55
+ handleJumpPage: (menu: NavMenuItem, childMenu?: NavChildItem) => any;
56
+ };
@@ -0,0 +1,8 @@
1
+ export declare function useHeaderTheme(route: any): {
2
+ lastScrollTop: import("vue").Ref<number, number>;
3
+ isWhiteTheme: import("vue").Ref<boolean, boolean>;
4
+ isScrolledTheme: import("vue").Ref<boolean, boolean>;
5
+ bindByRoute: () => void;
6
+ handleScroll: import("lodash").DebouncedFuncLeading<() => void>;
7
+ handleEventsScroll: import("lodash").DebouncedFuncLeading<() => void>;
8
+ };
@@ -0,0 +1,11 @@
1
+ export { default as NavHeader } from './Header.vue';
2
+ export { default as NavAvatar } from './Avatar.vue';
3
+ export { default as NavLogin } from './Login.vue';
4
+ export { default as NavLocale } from './Locale.vue';
5
+ export * from './constants/locale';
6
+ export * from './config/locale';
7
+ export * from './config/texts';
8
+ export * from './config/menus';
9
+ export * from './utils/path';
10
+ export * from './hooks/useHeaderMenu';
11
+ export * from './hooks/useHeaderTheme';
@@ -0,0 +1 @@
1
+ export declare const openLink: (url: string) => void;
@@ -0,0 +1,2 @@
1
+ export declare const matchPath: (path: string, targetPath: string) => boolean;
2
+ export declare const matchAnyPath: (path: string, targetPaths: string[]) => boolean;
@@ -0,0 +1,37 @@
1
+ import { PropType } from 'vue';
2
+ export interface TableColumn {
3
+ key: string;
4
+ title: string;
5
+ width?: string;
6
+ }
7
+ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
8
+ columns: {
9
+ type: PropType<TableColumn[]>;
10
+ required: true;
11
+ };
12
+ data: {
13
+ type: PropType<Record<string, any>[]>;
14
+ default: () => never[];
15
+ };
16
+ rowKey: {
17
+ type: StringConstructor;
18
+ default: string;
19
+ };
20
+ }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
21
+ columns: {
22
+ type: PropType<TableColumn[]>;
23
+ required: true;
24
+ };
25
+ data: {
26
+ type: PropType<Record<string, any>[]>;
27
+ default: () => never[];
28
+ };
29
+ rowKey: {
30
+ type: StringConstructor;
31
+ default: string;
32
+ };
33
+ }>> & Readonly<{}>, {
34
+ data: Record<string, any>[];
35
+ rowKey: string;
36
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
37
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import type { App } from 'vue';
2
+ import MyTable from './components/Table/index.vue';
3
+ import MyButton from './components/Button/index.vue';
4
+ import Header from './components/Header/src/Header.vue';
5
+ export * from './components/Header/src/index';
6
+ export { MyTable, MyButton, Header };
7
+ declare const _default: {
8
+ install(app: App): void;
9
+ };
10
+ export default _default;