mi-float-robot 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,149 @@
1
+ # mi-float-robot
2
+
3
+ 跨框架浮窗智能问答机器人 Web Component。零运行时依赖,任何前端技术栈(Vue2 / Vue3 / React / 纯 HTML)均可使用。
4
+
5
+ 特性:
6
+
7
+ - 悬浮机器人图标,可拖拽、拖到垃圾桶隐藏
8
+ - 点击弹出 iframe 抽屉,抽屉可拖拽移动、边缘缩放、最小化
9
+ - 位置/尺寸记忆(localStorage)
10
+ - 通过适配器注入开关与样式配置,无内网接口耦合
11
+ - Shadow DOM 样式隔离,不污染宿主页面
12
+
13
+ ## 安装
14
+
15
+ ```bash
16
+ npm i mi-float-robot
17
+ ```
18
+
19
+ ## 快速开始
20
+
21
+ ### 方式一:ESM 引入
22
+
23
+ ```js
24
+ import 'mi-float-robot'
25
+
26
+ // 可选:全局配置
27
+ import { configure } from 'mi-float-robot'
28
+ configure({
29
+ chatUrl: 'https://your-host/chat?isPure=true',
30
+ avatar: 'https://your-host/avatar.png'
31
+ })
32
+ ```
33
+
34
+ ```html
35
+ <x-float-robot></x-float-robot>
36
+ ```
37
+
38
+ ### 方式二:通过 HTML 属性配置(无需 JS)
39
+
40
+ ```html
41
+ <script src="https://unpkg.com/mi-float-robot"></script>
42
+ <x-float-robot
43
+ chat-url="https://your-host/chat?isPure=true"
44
+ avatar="https://your-host/avatar.png"
45
+ ></x-float-robot>
46
+ ```
47
+
48
+ ## 配置
49
+
50
+ 配置优先级:`<x-float-robot>` 属性 > `configure()` > 适配器返回。
51
+
52
+ ### HTML 属性
53
+
54
+ | 属性 | 说明 |
55
+ | --- | --- |
56
+ | `chat-url` | 聊天页 iframe 地址 |
57
+ | `avatar` | 头像完整 URL(缺省用内置默认头像) |
58
+ | `switch-url` | 开关接口地址(未提供 adapter 时生效) |
59
+ | `config-url` | 配置接口地址(未提供 adapter 时生效) |
60
+
61
+ ### configure(options)
62
+
63
+ | 字段 | 类型 | 说明 |
64
+ | --- | --- | --- |
65
+ | `chatUrl` | string | 聊天页 iframe 地址 |
66
+ | `avatar` | string | 头像完整 URL |
67
+ | `adapter` | FloatRobotAdapter | 自定义适配器实例 |
68
+ | `switchUrl` | string | 开关接口地址 |
69
+ | `configUrl` | string | 配置接口地址 |
70
+ | `fetch` | Function | 自定义 fetch 函数 |
71
+
72
+ ## 适配器
73
+
74
+ 机器人「是否显示」和「头像/样式」由适配器提供,方便对接你自己的后端接口。
75
+
76
+ ```js
77
+ import { configure, FloatRobotAdapter } from 'mi-float-robot'
78
+
79
+ class MyAdapter extends FloatRobotAdapter {
80
+ async getSwitch() {
81
+ // 返回是否显示机器人
82
+ return true
83
+ }
84
+ async getConfig() {
85
+ // 返回 null 表示不显示
86
+ return {
87
+ showRobot: true,
88
+ avatar: 'https://your-host/avatar.png',
89
+ style: {
90
+ scale: 1,
91
+ width: 80,
92
+ height: 100,
93
+ opacity: 1,
94
+ border: 'none',
95
+ shadowLevel: 'light', // none | light | medium | strong
96
+ borderRadius: 0,
97
+ borderRadiusUnit: 'px'
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ configure({ chatUrl: 'https://your-host/chat', adapter: new MyAdapter() })
104
+ ```
105
+
106
+ 若不想写适配器,提供一个简单 JSON 接口即可(默认 `FetchFloatRobotAdapter` 用 GET 请求):
107
+
108
+ ```js
109
+ configure({
110
+ chatUrl: 'https://your-host/chat',
111
+ switchUrl: 'https://your-host/api/robot/switch', // 返回 boolean 或 { showRobot: true }
112
+ configUrl: 'https://your-host/api/robot/config' // 返回上方 getConfig 的结构
113
+ })
114
+ ```
115
+
116
+ ## 在 Vue 中使用
117
+
118
+ ```vue
119
+ <template>
120
+ <x-float-robot chat-url="https://your-host/chat?isPure=true"></x-float-robot>
121
+ </template>
122
+
123
+ <script>
124
+ import 'mi-float-robot'
125
+ </script>
126
+ ```
127
+
128
+ ## 本地开发
129
+
130
+ ```bash
131
+ npm i
132
+ npm run dev
133
+ ```
134
+
135
+ ## 构建
136
+
137
+ ```bash
138
+ npm run build
139
+ # 产出 dist/mi-float-robot.js (ESM) 与 dist/mi-float-robot.umd.cjs (UMD)
140
+ ```
141
+
142
+ ## 发布
143
+
144
+ ```bash
145
+ npm login
146
+ npm publish
147
+ ```
148
+
149
+ > 发布到 npm 公共源前,请确认没有把内网地址、密钥、公司 Logo 等敏感信息硬编码进代码。