@zhin.js/client 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 凉菜
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # @zhin.js/client
2
+
3
+ 基于 Vue 3 和 PrimeVue 的 Zhin 机器人 Web 客户端,提供现代化的 Web 管理界面。
4
+
5
+ ## 功能特性
6
+
7
+ - 🎨 基于 Vue 3 和 PrimeVue 的现代界面
8
+ - 📊 机器人状态监控和管理
9
+ - 🔧 插件管理和配置
10
+ - 📝 日志查看和分析
11
+ - 🛠️ 开发工具和调试支持
12
+ - 📱 响应式设计,支持移动端
13
+
14
+ ## 技术栈
15
+
16
+ - **前端框架**: Vue 3 + TypeScript
17
+ - **UI 组件**: PrimeVue 4.x
18
+ - **状态管理**: Pinia
19
+ - **路由**: Vue Router
20
+ - **构建工具**: Vite
21
+ - **主题**: PrimeUI 主题系统
22
+
23
+ ## 安装
24
+
25
+ ```bash
26
+ npm install @zhin.js/client
27
+ ```
28
+
29
+ ## 使用
30
+
31
+ 这个包通常与 `@zhin.js/console` 插件一起使用:
32
+
33
+ ```javascript
34
+ // 插件中
35
+ import '@zhin.js/console' // 这会自动加载客户端
36
+ ```
37
+
38
+ ## 开发
39
+
40
+ ### 项目结构
41
+
42
+ ```
43
+ app/
44
+ ├── src/
45
+ │ ├── App.vue # 主应用组件
46
+ │ ├── main.ts # 应用入口
47
+ │ └── pages/ # 页面组件
48
+ │ ├── $.vue # 动态路由
49
+ │ ├── 404.vue # 404页面
50
+ │ └── dashboard.vue # 仪表板
51
+ ├── index.html # HTML模板
52
+ └── components.d.ts # 组件类型声明
53
+ ```
54
+
55
+ ### 开发命令
56
+
57
+ ```bash
58
+ npm run build # 构建
59
+ npm run clean # 清理构建文件
60
+ ```
61
+
62
+ ## API 集成
63
+
64
+ 客户端通过以下方式与后端通信:
65
+ - 📡 WebSocket 实时通信
66
+ - 🌐 REST API 调用
67
+ - 📊 状态同步机制
68
+
69
+ ## 路由配置
70
+
71
+ - `/` - 仪表板首页
72
+ - `/plugins` - 插件管理
73
+ - `/logs` - 日志查看
74
+ - `/settings` - 系统设置
75
+ - `/404` - 错误页面
76
+
77
+ ## 依赖项
78
+
79
+ - `pinia` - 状态管理
80
+ - `primevue` - UI组件库
81
+ - `@primeuix/themes` - 主题系统
82
+ - `vue-router` - 路由管理
83
+
84
+ ## 自定义扩展
85
+
86
+ 支持通过插件系统扩展:
87
+ - 自定义页面组件
88
+ - 自定义主题样式
89
+ - 自定义功能模块
90
+
91
+ ## 浏览器支持
92
+
93
+ - Chrome/Edge 88+
94
+ - Firefox 85+
95
+ - Safari 14+
96
+
97
+ ## 许可证
98
+
99
+ MIT License
@@ -0,0 +1,33 @@
1
+ /* eslint-disable */
2
+ // @ts-nocheck
3
+ // Generated by unplugin-vue-components
4
+ // Read more: https://github.com/vuejs/core/pull/3399
5
+ // biome-ignore lint: disable
6
+ export {}
7
+
8
+ /* prettier-ignore */
9
+ declare module 'vue' {
10
+ export interface GlobalComponents {
11
+ Badge: typeof import('primevue/badge')['default']
12
+ Breadcrumb: typeof import('primevue/breadcrumb')['default']
13
+ Button: typeof import('primevue/button')['default']
14
+ Card: typeof import('primevue/card')['default']
15
+ Dialog: typeof import('primevue/dialog')['default']
16
+ Divider: typeof import('primevue/divider')['default']
17
+ Dropdown: typeof import('primevue/dropdown')['default']
18
+ InputText: typeof import('primevue/inputtext')['default']
19
+ OverlayPanel: typeof import('primevue/overlaypanel')['default']
20
+ PanelMenu: typeof import('primevue/panelmenu')['default']
21
+ Password: typeof import('primevue/password')['default']
22
+ ProgressBar: typeof import('primevue/progressbar')['default']
23
+ RouterLink: typeof import('vue-router')['RouterLink']
24
+ RouterView: typeof import('vue-router')['RouterView']
25
+ Sidebar: typeof import('primevue/sidebar')['default']
26
+ StyleGuide: typeof import('./src/components/StyleGuide.vue')['default']
27
+ Tag: typeof import('primevue/tag')['default']
28
+ }
29
+ export interface GlobalDirectives {
30
+ Ripple: typeof import('primevue/ripple')['default']
31
+ Tooltip: typeof import('primevue/tooltip')['default']
32
+ }
33
+ }
package/app/index.html ADDED
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang='en'>
3
+ <head>
4
+ <meta charset='UTF-8'>
5
+ <meta name='viewport' content='width=device-width, initial-scale=1.0'>
6
+ <title>Zhin</title>
7
+ </head>
8
+ <body>
9
+ <div id='app'></div>
10
+ <script src='/src/main.ts' type='module'></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,7 @@
1
+ <template>
2
+ <router-view/>
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ </script>
7
+ <style></style>
@@ -0,0 +1,127 @@
1
+ import { createApp } from 'vue';
2
+ import { createPinia } from 'pinia';
3
+ import PrimeVue from "primevue/config";
4
+ import { addPage, router, useCommonStore } from '@zhin.js/client';
5
+ import { updateAllData, DataService } from './services/api';
6
+ import App from './App.vue';
7
+ // 引入通用样式
8
+ import './styles/common.css';
9
+
10
+ // 全局暴露数据管理方法,供外部模块使用
11
+ declare global {
12
+ interface Window {
13
+ ZhinDataAPI: {
14
+ updateAllData: () => Promise<void>
15
+ getSystemStatus: () => Promise<any>
16
+ getPlugins: () => Promise<any>
17
+ getAdapters: () => Promise<any>
18
+ reloadPlugin: (pluginName: string) => Promise<any>
19
+ sendMessage: (payload: any) => Promise<any>
20
+ }
21
+ ZhinStore: {
22
+ getCommonStore: () => any
23
+ }
24
+ }
25
+ }
26
+
27
+ const pinia = createPinia();
28
+
29
+ // 暴露全局API,供外部模块和适配器使用
30
+ window.ZhinDataAPI = {
31
+ updateAllData: () => updateAllData().then(() => Promise.resolve()),
32
+ getSystemStatus: DataService.getSystemStatus,
33
+ getPlugins: DataService.getPlugins,
34
+ getAdapters: DataService.getAdapters,
35
+ reloadPlugin: DataService.reloadPlugin,
36
+ sendMessage: DataService.sendMessage,
37
+ }
38
+
39
+ // 暴露全局Store访问器
40
+ window.ZhinStore = {
41
+ getCommonStore: () => useCommonStore(pinia)
42
+ }
43
+
44
+ // 🌍 Zhin 全局API已暴露到 window 对象
45
+
46
+ const wsUrl = `${window.location.protocol.replace(/^http?/, 'ws')}${window.location.host}/server`;
47
+ const ws = new WebSocket(wsUrl);
48
+
49
+ ws.onopen = () => {
50
+ // WebSocket连接已建立
51
+ };
52
+
53
+ ws.onmessage = message => {
54
+ const payload = JSON.parse(message.data || '{}');
55
+ const commonStore = useCommonStore(pinia);
56
+
57
+ switch (payload.type) {
58
+ case 'sync':
59
+ return commonStore.syncData(payload.data);
60
+ case 'add':
61
+ return commonStore.addData(payload.data);
62
+ case 'delete':
63
+ return commonStore.deleteData(payload.data);
64
+ case 'init-data':
65
+ // 初始化时获取数据
66
+ // 🚀 收到初始化数据通知
67
+ updateAllData();
68
+ break;
69
+ case 'data-update':
70
+ // 收到更新通知时获取最新数据
71
+ // 🔄 收到数据更新通知
72
+ updateAllData();
73
+ break;
74
+ default:
75
+ return;
76
+ }
77
+ };
78
+
79
+ ws.onclose = () => {
80
+ // WebSocket连接已关闭
81
+ };
82
+ const app = createApp(App);
83
+ app.use(pinia).use(router).use(PrimeVue, {
84
+ // 临时移除主题配置以修复类型错误
85
+ });
86
+ app.config.globalProperties.$ws = ws;
87
+ // 注册主布局路由
88
+ router.addRoute({
89
+ path: '/',
90
+ name: 'Zhin',
91
+ component: () => import('./pages/$.vue'),
92
+ });
93
+
94
+ // 注册所有内置页面(addPage 会自动添加路由和菜单)
95
+ addPage({
96
+ parentName: 'Zhin',
97
+ path: '/dashboard',
98
+ name: 'Dashboard',
99
+ component: () => import('./pages/dashboard.vue'),
100
+ });
101
+
102
+ addPage({
103
+ parentName: 'Zhin',
104
+ path: '/system/status',
105
+ name: 'Status',
106
+ component: () => import('./pages/system/status.vue'),
107
+ });
108
+
109
+ addPage({
110
+ parentName: 'Zhin',
111
+ path: '/contexts/overview',
112
+ name: 'Overview',
113
+ component: () => import('./pages/contexts/overview.vue'),
114
+ });
115
+
116
+
117
+
118
+ addPage({
119
+ parentName: 'Zhin',
120
+ path: '/plugins/installed',
121
+ name: 'Installed',
122
+ component: () => import('./pages/plugins/installed.vue'),
123
+ });
124
+
125
+ // 📝 所有内置页面已通过 addPage 注册
126
+
127
+ app.mount('#app');