@syfei49/mini-dynamic-renderer 1.0.0 → 1.0.3

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 CHANGED
@@ -1,102 +1,94 @@
1
- # @syfei49/mini-dynamic-renderer
2
-
3
- 微信小程序对话接口动态渲染 SDK(v1.0.0 测试版)。
4
-
5
- 引入后自动注册 `wx.request` 拦截器;当匹配的接口返回成功(`statusCode === 200`)时,在当前页面弹出 `hello world` 测试弹窗。
6
-
7
- ## 安装
8
-
9
- ```bash
10
- cd your-miniprogram-project
11
- npm install @syfei49/mini-dynamic-renderer
12
- ```
13
-
14
- ## 接入
15
-
16
- ### 1. 在 `app.js` 顶部引入(自动注册拦截器)
17
-
18
- ```javascript
19
- require('@syfei49/mini-dynamic-renderer');
20
- ```
21
-
22
- ### 2. 微信开发者工具构建 npm
23
-
24
- 打开微信开发者工具 → **工具** → **构建 npm**
25
-
26
- ### 3. 正常发起请求即可触发弹窗
27
-
28
- ```javascript
29
- wx.request({
30
- url: 'https://your-domain.com/api/chat',
31
- method: 'POST',
32
- data: { query: '你好' },
33
- success(res) {
34
- // 原有业务逻辑不变
35
- }
36
- });
37
- ```
38
-
39
- ## 配置(可选)
40
-
41
- 如需自定义拦截规则,可在 `app.js` 中显式初始化:
42
-
43
- ```javascript
44
- const sdk = require('@syfei49/mini-dynamic-renderer');
45
-
46
- sdk.init({
47
- // URL 匹配规则:字符串为包含匹配,也支持 RegExp,'*' 表示全部
48
- urlPatterns: ['/api/chat'],
49
- debug: true
50
- });
51
- ```
52
-
53
- ### 配置项
54
-
55
- | 字段 | 类型 | 默认值 | 说明 |
56
- |------|------|--------|------|
57
- | `urlPatterns` | `Array<string\|RegExp>` | `['*']` | 需要拦截的 URL 规则 |
58
- | `debug` | `boolean` | `false` | 是否输出调试日志 |
59
-
60
- ## API
61
-
62
- | 方法 | 说明 |
63
- |------|------|
64
- | `init(config?)` | 初始化并注册拦截器 |
65
- | `getConfig()` | 获取当前配置 |
66
- | `isInitialized()` | 是否已初始化 |
67
- | `uninstall()` | 卸载拦截器,恢复原始 `wx.request` |
68
- | `parseRenderConfig(data)` | 解析响应中的渲染配置(预留) |
69
-
70
- ## 发布到 npm
71
-
72
- 在包根目录 `code/` 下执行:
73
-
74
- ```bash
75
- # 1. 确认已登录
76
- npm whoami
77
-
78
- # 2. 确认 registry
79
- npm config get registry
80
- # 应为 https://registry.npmjs.org/
81
-
82
- # 3. 检查包名是否可用(404 表示可用)
83
- npm view @syfei49/mini-dynamic-renderer
84
-
85
- # 4. 预览将要发布的文件
86
- npm pack --dry-run
87
-
88
- # 5. 正式发布(作用域包首次需 public)
89
- npm publish --access public
90
- ```
91
-
92
- 后续版本更新:
93
-
94
- ```bash
95
- npm version patch # 或 minor / major
96
- npm publish --access public
97
- ```
98
-
99
- ## 版本说明
100
-
101
- - **v1.0.0**:拦截 `wx.request` 成功响应,弹出 `hello world` 测试弹窗
102
- - 后续版本将支持根据后端 `renderConfig` 动态渲染图片上传、文本等组件
1
+ # @syfei49/mini-dynamic-renderer
2
+
3
+ uni-app 浮层 AI 客服插件(v1.0.3)。在指定页面右下角显示 AI 浮层图标,点击后从底部弹出抽屉聊天面板,支持文字、图片、拍照/相册上传及 `[NEED_ICON]` 分类图标引导。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ cd your-uniapp-project
9
+ npm install @syfei49/mini-dynamic-renderer
10
+ ```
11
+
12
+ 微信开发者工具 → **工具** → **构建 npm**
13
+
14
+ ## 接入
15
+
16
+ ### 1. App.vue 初始化
17
+
18
+ ```vue
19
+ <script setup>
20
+ import { init } from '@syfei49/mini-dynamic-renderer'
21
+
22
+ init({
23
+ baseUrl: 'https://your-api.com/prod-api',
24
+ chatApiPath: '/mini/ai/chat',
25
+ uploadApiPath: '/mini/common/upload',
26
+ getToken: () => uni.getStorageSync('token'),
27
+ visiblePages: ['pages/user/user'],
28
+ requireLogin: true,
29
+ loginPage: '/pages/login/login?noauto=1'
30
+ })
31
+ </script>
32
+ ```
33
+
34
+ ### 2. 在需要显示浮层的页面引入组件
35
+
36
+ 以 `pages/user/user.vue` 为例:
37
+
38
+ ```vue
39
+ <script setup>
40
+ import LyAiAssistant from '@syfei49/mini-dynamic-renderer/components/ly-ai-assistant/ly-ai-assistant.vue'
41
+ import { openChat } from '@syfei49/mini-dynamic-renderer'
42
+ </script>
43
+
44
+ <template>
45
+ <view>
46
+ <!-- 页面内容 -->
47
+ <LyAiAssistant />
48
+ </view>
49
+ </template>
50
+ ```
51
+
52
+ > 微信小程序 `App.vue` 的 template 不会被渲染,所以浮层组件需要放在具体页面里。
53
+
54
+ ### 2. 在任意页面打开抽屉(可选)
55
+
56
+ ```javascript
57
+ import { openChat } from '@syfei49/mini-dynamic-renderer'
58
+
59
+ openChat()
60
+ ```
61
+
62
+ ## 配置项
63
+
64
+ | 字段 | 类型 | 默认值 | 说明 |
65
+ |------|------|--------|------|
66
+ | `baseUrl` | `string` | `''` | API 根地址 |
67
+ | `chatApiPath` | `string` | `'/mini/ai/chat'` | 对话接口路径 |
68
+ | `uploadApiPath` | `string` | `'/mini/common/upload'` | 图片上传路径 |
69
+ | `getToken` | `Function` | `() => ''` | 返回 Authorization |
70
+ | `getHeaders` | `Function` | `() => ({})` | 额外请求头 |
71
+ | `visiblePages` | `string[]` | `['pages/user/user']` | 显示浮层图标的页面路由 |
72
+ | `floatIcon` | `string` | 内置默认图标 | 浮层按钮图片 URL |
73
+ | `requireLogin` | `boolean` | `true` | 打开前检查登录 |
74
+ | `loginPage` | `string` | `'/pages/login/login'` | 未登录跳转页 |
75
+ | `debug` | `boolean` | `false` | 调试日志 |
76
+ | `enableInterceptor` | `boolean` | `false` | 是否启用 wx.request 拦截(预留) |
77
+
78
+ ## API
79
+
80
+ | 方法 | 说明 |
81
+ |------|------|
82
+ | `init(config?)` | 初始化插件 |
83
+ | `openChat()` | 打开聊天抽屉 |
84
+ | `closeChat()` | 关闭聊天抽屉 |
85
+ | `getConfig()` | 获取当前配置 |
86
+ | `isInitialized()` | 是否已初始化 |
87
+ | `uninstall()` | 卸载拦截器,恢复原始 `wx.request` |
88
+ | `parseRenderConfig(data)` | 解析响应中的渲染配置(预留) |
89
+
90
+ ## 版本说明
91
+
92
+ - **v1.0.3**:uni-app 浮层 AI 插件、抽屉聊天、迁移 aiChat 全能力、文档拆分
93
+ - v1.0.0:wx.request 拦截 + hello world 弹窗(测试版)
94
+ - 后续版本将根据后端 `renderConfig` 动态渲染更多组件类型