@fzbykj/ai-chat-sdk-mp 1.0.2 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fzbykj/ai-chat-sdk-mp",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "AI 对话助手 SDK for 微信小程序 (uni-app)",
5
5
  "main": "sdk/index.js",
6
6
  "files": [
@@ -1,6 +1,6 @@
1
1
  <!-- components/ai-float/ai-float.vue -->
2
2
  <template>
3
- <view class="ai-float-wrapper">
3
+ <view class="ai-float-wrapper" v-if="isVisible">
4
4
  <!-- 折叠状态 -->
5
5
  <view v-if="isCollapsed" class="float-collapsed" :style="collapsedStyleStr" @click="expand">
6
6
  <text class="collapse-text">AI</text>
@@ -11,13 +11,15 @@
11
11
  <!-- 正常状态 -->
12
12
  <view v-else class="float-btn" :style="btnStyleStr" @touchstart="onTouchStart" @touchmove="onTouchMove"
13
13
  @touchend="onTouchEnd" @click="openChat">
14
- <image class="btn-icon" src="../../icon.png" mode="aspectFit" />
14
+ <image class="btn-icon" src="https://agent.fzbykj.com/logo.png" mode="aspectFit" />
15
15
  </view>
16
16
  </view>
17
17
  </template>
18
18
 
19
19
  <script>
20
- import { aichat } from '../../utils/sdk.js'
20
+ import {
21
+ aichat
22
+ } from '../../utils/sdk.js'
21
23
 
22
24
  export default {
23
25
  name: 'AiFloat',
@@ -59,13 +61,14 @@
59
61
 
60
62
  _apiKey: '',
61
63
  _userId: '',
62
- _baseUrl: ''
64
+ _baseUrl: '',
65
+ isVisible: true // ✅ 默认显示
63
66
  }
64
67
  },
65
68
 
66
69
  computed: {
67
70
  iconUrl() {
68
- return '/static/icon.png'
71
+ return '../../icon.png'
69
72
  },
70
73
 
71
74
  // ✅ 返回字符串模板,确保类型正确
@@ -85,7 +88,8 @@
85
88
  this._apiKey = this.apiKey || aichat.getApiKey()
86
89
  this._userId = this.userId || aichat.getUserId()
87
90
  this._baseUrl = this.baseUrl || aichat.getBaseUrl()
88
-
91
+ // ✅ 监听 SDK 的显示状态变化
92
+ this.isVisible = aichat.isFloatingVisible()
89
93
  const systemInfo = uni.getSystemInfoSync()
90
94
  this.screenWidth = systemInfo.windowWidth
91
95
  this.screenHeight = systemInfo.windowHeight
@@ -102,6 +106,12 @@
102
106
  },
103
107
 
104
108
  methods: {
109
+ /**
110
+ * ✅ 外部调用,更新显示状态
111
+ */
112
+ updateVisibility() {
113
+ this.isVisible = aichat.isFloatingVisible()
114
+ }
105
115
  onTouchStart(e) {
106
116
  const touch = e.touches[0]
107
117
  this.startX = touch.clientX
@@ -206,7 +216,7 @@
206
216
  const baseUrl = encodeURIComponent(this._baseUrl || aichat.getBaseUrl())
207
217
  const apiKey = encodeURIComponent(this._apiKey || aichat.getApiKey())
208
218
  const userId = encodeURIComponent(this._userId || aichat.getUserId())
209
- console.log(baseUrl,apiKey,userId)
219
+ console.log(baseUrl, apiKey, userId)
210
220
  uni.navigateTo({
211
221
  url: `/pages/chat/chat?baseUrl=${baseUrl}&apiKey=${apiKey}&userId=${userId}`
212
222
  })
package/sdk/utils/sdk.js CHANGED
@@ -10,7 +10,9 @@ class AIChatSDK {
10
10
  apiKey: '',
11
11
  userId: '',
12
12
  baseUrl: 'https://agent.fzbykj.com/app_chat.html',
13
- enableLog: false
13
+ enableLog: false,
14
+ // ✅ 新增:是否显示悬浮图标,默认显示
15
+ showFloating: true
14
16
  }
15
17
  }
16
18
 
@@ -62,6 +64,23 @@ class AIChatSDK {
62
64
  console.log('[AIChatSDK] ' + message)
63
65
  }
64
66
  }
67
+ /**
68
+ * 设置悬浮图标是否显示
69
+ * @param {boolean} show - true 显示,false 隐藏
70
+ */
71
+ setFloatingVisible(show) {
72
+ this.config.showFloating = show
73
+ this.log('悬浮图标显示状态: ' + (show ? '显示' : '隐藏'))
74
+ return this
75
+ }
76
+
77
+ /**
78
+ * 获取悬浮图标显示状态
79
+ * @returns {boolean}
80
+ */
81
+ isFloatingVisible() {
82
+ return this.config.showFloating
83
+ }
65
84
  }
66
85
 
67
86
  // 导出单例