af-mobile-client-vue3 1.4.47 → 1.4.48

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.
@@ -1,57 +1,57 @@
1
- /**
2
- * 根据类型获取日期区间字符串
3
- * @param type '当年' | 'curMonth' | '当日'
4
- * @param show 区分实际值还是显示值, true为实际值, false为显示值
5
- * @returns [start, end] 例:['2024-01-01 00:00:00', '2024-12-31 23:59:59']
6
- */
7
- export function getRangeByType(type: string, show: boolean): [string, string] {
8
- const now = new Date()
9
- const year = now.getFullYear()
10
- const month = (now.getMonth() + 1).toString().padStart(2, '0')
11
- const day = now.getDate().toString().padStart(2, '0')
12
-
13
- if (!show) {
14
- if (type === 'curYear') {
15
- return [
16
- `${year}-01-01 00:00:00`,
17
- `${year}-12-31 23:59:59`,
18
- ]
19
- }
20
- if (type === 'curMonth') {
21
- const lastDay = new Date(year, now.getMonth() + 1, 0).getDate()
22
- return [
23
- `${year}-${month}-01 00:00:00`,
24
- `${year}-${month}-${lastDay.toString().padStart(2, '0')} 23:59:59`,
25
- ]
26
- }
27
- if (type === 'curDay') {
28
- return [
29
- `${year}-${month}-${day} 00:00:00`,
30
- `${year}-${month}-${day} 23:59:59`,
31
- ]
32
- }
33
- }
34
- if (show) {
35
- if (type === 'curYear') {
36
- return [
37
- `${year}-01-01`,
38
- `${year}-12-31`,
39
- ]
40
- }
41
- if (type === 'curMonth') {
42
- const lastDay = new Date(year, now.getMonth() + 1, 0).getDate()
43
- return [
44
- `${year}-${month}-01`,
45
- `${year}-${month}-${lastDay.toString().padStart(2, '0')}`,
46
- ]
47
- }
48
- if (type === 'curDay') {
49
- return [
50
- `${year}-${month}-${day}`,
51
- `${year}-${month}-${day}`,
52
- ]
53
- }
54
- }
55
- // 兜底返回空字符串数组
56
- return ['', '']
57
- }
1
+ /**
2
+ * 根据类型获取日期区间字符串
3
+ * @param type '当年' | 'curMonth' | '当日'
4
+ * @param show 区分实际值还是显示值, true为实际值, false为显示值
5
+ * @returns [start, end] 例:['2024-01-01 00:00:00', '2024-12-31 23:59:59']
6
+ */
7
+ export function getRangeByType(type: string, show: boolean): [string, string] {
8
+ const now = new Date()
9
+ const year = now.getFullYear()
10
+ const month = (now.getMonth() + 1).toString().padStart(2, '0')
11
+ const day = now.getDate().toString().padStart(2, '0')
12
+
13
+ if (!show) {
14
+ if (type === 'curYear') {
15
+ return [
16
+ `${year}-01-01 00:00:00`,
17
+ `${year}-12-31 23:59:59`,
18
+ ]
19
+ }
20
+ if (type === 'curMonth') {
21
+ const lastDay = new Date(year, now.getMonth() + 1, 0).getDate()
22
+ return [
23
+ `${year}-${month}-01 00:00:00`,
24
+ `${year}-${month}-${lastDay.toString().padStart(2, '0')} 23:59:59`,
25
+ ]
26
+ }
27
+ if (type === 'curDay') {
28
+ return [
29
+ `${year}-${month}-${day} 00:00:00`,
30
+ `${year}-${month}-${day} 23:59:59`,
31
+ ]
32
+ }
33
+ }
34
+ if (show) {
35
+ if (type === 'curYear') {
36
+ return [
37
+ `${year}-01-01`,
38
+ `${year}-12-31`,
39
+ ]
40
+ }
41
+ if (type === 'curMonth') {
42
+ const lastDay = new Date(year, now.getMonth() + 1, 0).getDate()
43
+ return [
44
+ `${year}-${month}-01`,
45
+ `${year}-${month}-${lastDay.toString().padStart(2, '0')}`,
46
+ ]
47
+ }
48
+ if (type === 'curDay') {
49
+ return [
50
+ `${year}-${month}-${day}`,
51
+ `${year}-${month}-${day}`,
52
+ ]
53
+ }
54
+ }
55
+ // 兜底返回空字符串数组
56
+ return ['', '']
57
+ }
@@ -5,16 +5,16 @@ import wx from 'weixin-js-sdk'
5
5
  export interface WechatConfig {
6
6
  debug: boolean
7
7
  appId: string
8
- timestamp: string
8
+ timestamp: number
9
9
  nonceStr: string
10
10
  signature: string
11
- jsApiList: string[]
11
+ jsApiList: wx.ApiMethod[]
12
12
  }
13
13
 
14
14
  // 微信扫码配置
15
15
  export interface WechatScanConfig {
16
16
  needResult: 0 | 1
17
- scanType: string[]
17
+ scanType: wx.scanType[]
18
18
  }
19
19
 
20
20
  // 微信扫码结果
@@ -92,7 +92,7 @@ export function scanQRCode(config: WechatScanConfig): Promise<WechatScanResult>
92
92
  // 获取微信签名(模拟)
93
93
  export async function getWechatSignature(url: string): Promise<{
94
94
  appId: string
95
- timestamp: string
95
+ timestamp: number
96
96
  nonceStr: string
97
97
  signature: string
98
98
  }> {
@@ -0,0 +1,256 @@
1
+ <script setup lang="ts">
2
+ import liuliLogo from '@af-mobile-client-vue3/assets/img/component/liuli.png'
3
+ import { showToast } from 'vant'
4
+ import { ref } from 'vue'
5
+ import { Button } from 'vue-devui/button'
6
+ import { chatCompletions } from './apiService'
7
+ import 'vue-devui/button/style.css'
8
+ import 'vant/es/image-preview/style'
9
+ import '@devui-design/icons/icomoon/devui-icon.css'
10
+
11
+ const description = [
12
+ '我是【奥枫天然气公司】官方公众号专属 AI 客服小璃,可以为您提供专业、高效、易懂的天然气相关咨询服务。',
13
+ ]
14
+ const introPrompt = {
15
+ direction: 'horizontal',
16
+ list: [
17
+ {
18
+ value: 'howToPay',
19
+ label: '如何缴纳燃气费?',
20
+ iconConfig: { name: 'icon-info-o', color: '#5e7ce0' },
21
+ desc: '了解线上缴费方式和操作步骤',
22
+ },
23
+ {
24
+ value: 'howToRepair',
25
+ label: '燃气故障如何报修?',
26
+ iconConfig: { name: 'icon-star', color: 'rgb(255, 215, 0)' },
27
+ desc: '遇到燃气问题时的处理流程',
28
+ },
29
+ {
30
+ value: 'safetyTips',
31
+ label: '安全使用注意事项',
32
+ iconConfig: { name: 'icon-priority', color: '#3ac295' },
33
+ desc: '了解燃气安全使用常识',
34
+ },
35
+ ],
36
+ }
37
+ const simplePrompt = [
38
+ {
39
+ value: 'howToPay',
40
+ iconConfig: { name: 'icon-info-o', color: '#5e7ce0' },
41
+ label: '如何缴费',
42
+ },
43
+ {
44
+ value: 'howToRepair',
45
+ iconConfig: { name: 'icon-star', color: 'rgb(255, 215, 0)' },
46
+ label: '如何报修',
47
+ },
48
+ ]
49
+ const startPage = ref(true)
50
+ const inputValue = ref('')
51
+
52
+ const messages = ref<any[]>([])
53
+
54
+ function newConversation() {
55
+ startPage.value = true
56
+ messages.value = []
57
+ }
58
+
59
+ async function onSubmit(evt: string) {
60
+ if (!evt.trim()) {
61
+ return
62
+ }
63
+
64
+ inputValue.value = ''
65
+ startPage.value = false
66
+
67
+ // 用户发送消息
68
+ messages.value.push({
69
+ from: 'user',
70
+ content: evt,
71
+ })
72
+
73
+ // 添加 loading 状态的 model 消息
74
+ const loadingMessageIndex = messages.value.length
75
+ messages.value.push({
76
+ from: 'model',
77
+ content: '',
78
+ loading: true,
79
+ })
80
+
81
+ try {
82
+ // 调用 API
83
+ const response = await chatCompletions(evt)
84
+
85
+ // 更新 model 消息内容
86
+ if (response.choices && response.choices.length > 0) {
87
+ const content = response.choices[0].message.content
88
+
89
+ // 检测是否为转人工标识
90
+ try {
91
+ const parsedContent = JSON.parse(content)
92
+ if (parsedContent.msgType === 'transfer') {
93
+ // 移除 loading 消息
94
+ messages.value.splice(loadingMessageIndex, 1)
95
+ // 添加人工客服消息
96
+ messages.value.push({
97
+ from: 'service',
98
+ content: '您好,客服xxx工号xxx为你服务',
99
+ })
100
+ }
101
+ else {
102
+ // 正常消息
103
+ messages.value[loadingMessageIndex] = {
104
+ from: 'model',
105
+ content,
106
+ loading: false,
107
+ }
108
+ }
109
+ }
110
+ catch {
111
+ // 如果不是 JSON,按正常消息处理
112
+ messages.value[loadingMessageIndex] = {
113
+ from: 'model',
114
+ content,
115
+ loading: false,
116
+ }
117
+ }
118
+ }
119
+ else {
120
+ throw new Error('响应数据格式错误')
121
+ }
122
+ }
123
+ catch (error: any) {
124
+ // 处理错误
125
+ console.error('聊天请求失败:', error)
126
+ messages.value[loadingMessageIndex] = {
127
+ from: 'model',
128
+ content: '抱歉,服务暂时不可用,请稍后再试。',
129
+ loading: false,
130
+ }
131
+ showToast(error?.message || '请求失败,请稍后再试')
132
+ }
133
+ }
134
+ </script>
135
+
136
+ <template>
137
+ <McLayout class="container">
138
+ <McLayoutContent
139
+ v-if="startPage"
140
+ style="display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px"
141
+ >
142
+ <McIntroduction
143
+ :logo-img="liuliLogo"
144
+ title="小璃"
145
+ sub-title="Hi,我是小璃"
146
+ :description="description"
147
+ />
148
+ <McPrompt
149
+ :list="introPrompt.list"
150
+ :direction="introPrompt.direction"
151
+ @item-click="onSubmit($event.label)"
152
+ />
153
+ </McLayoutContent>
154
+ <McLayoutContent v-else class="content-container">
155
+ <template v-for="(msg, idx) in messages" :key="idx">
156
+ <McBubble
157
+ v-if="msg.from === 'user'"
158
+ :content="msg.content"
159
+ align="right"
160
+ :avatar-config="{ imgSrc: 'https://matechat.gitcode.com/png/demo/userAvatar.svg' }"
161
+ />
162
+ <McBubble
163
+ v-else-if="msg.from === 'service'"
164
+ :content="msg.content"
165
+ :avatar-config="{ imgSrc: 'https://matechat.gitcode.com/png/demo/userAvatar.svg' }"
166
+ />
167
+ <McBubble v-else :content="msg.content" :avatar-config="{ imgSrc: liuliLogo }" :loading="msg.loading">
168
+ <McMarkdownCard
169
+ :content="msg.content" :typing="true"
170
+ />
171
+ </McBubble>
172
+ </template>
173
+ </McLayoutContent>
174
+ <div class="shortcut" style="display: flex; align-items: center; gap: 8px">
175
+ <McPrompt
176
+ v-if="!startPage"
177
+ :list="simplePrompt"
178
+ direction="horizontal"
179
+ class="shortcut-prompt"
180
+ style="flex: 1"
181
+ @item-click="onSubmit($event.label)"
182
+ />
183
+ <Button
184
+ style="margin-left: auto"
185
+ icon="add"
186
+ shape="circle"
187
+ title="新建对话"
188
+ size="md"
189
+ @click="newConversation"
190
+ />
191
+ </div>
192
+ <McLayoutSender>
193
+ <McInput :value="inputValue" :autofocus="true" :max-length="2000" @change="(e) => (inputValue = e)" @submit="onSubmit" />
194
+ </McLayoutSender>
195
+ </McLayout>
196
+ </template>
197
+
198
+ <style>
199
+ .container {
200
+ width: 100%;
201
+ height: 100vh;
202
+ padding: 20px;
203
+ gap: 8px;
204
+ background: #fff;
205
+ }
206
+
207
+ .content-container {
208
+ display: flex;
209
+ flex-direction: column;
210
+ gap: 8px;
211
+ overflow: auto;
212
+ }
213
+
214
+ .input-foot-wrapper {
215
+ display: flex;
216
+ justify-content: space-between;
217
+ align-items: center;
218
+ width: 100%;
219
+ height: 100%;
220
+ margin-right: 8px;
221
+
222
+ .input-foot-left {
223
+ display: flex;
224
+ align-items: center;
225
+ gap: 8px;
226
+
227
+ span {
228
+ font-size: 14px;
229
+ line-height: 18px;
230
+ color: #252b3a;
231
+ cursor: pointer;
232
+ }
233
+
234
+ .input-foot-dividing-line {
235
+ width: 1px;
236
+ height: 14px;
237
+ background-color: #d7d8da;
238
+ }
239
+
240
+ .input-foot-maxlength {
241
+ font-size: 14px;
242
+ color: #71757f;
243
+ }
244
+ }
245
+
246
+ .input-foot-right {
247
+ .demo-button-content {
248
+ font-size: 14px;
249
+ }
250
+
251
+ & > *:not(:first-child) {
252
+ margin-left: 8px;
253
+ }
254
+ }
255
+ }
256
+ </style>
@@ -0,0 +1,104 @@
1
+ import type { AxiosInstance } from 'axios'
2
+ import axios from 'axios'
3
+
4
+ /**
5
+ * 聊天消息接口
6
+ */
7
+ export interface ChatMessage {
8
+ role: 'user' | 'assistant' | 'system'
9
+ content: string
10
+ }
11
+
12
+ /**
13
+ * 聊天请求参数接口
14
+ */
15
+ export interface ChatCompletionsRequest {
16
+ chatId: string
17
+ stream: boolean
18
+ detail: boolean
19
+ variables: {
20
+ uid: string
21
+ name: string
22
+ }
23
+ messages: ChatMessage[]
24
+ }
25
+
26
+ /**
27
+ * 聊天响应使用情况接口
28
+ */
29
+ export interface ChatUsage {
30
+ prompt_tokens: number
31
+ completion_tokens: number
32
+ total_tokens: number
33
+ }
34
+
35
+ /**
36
+ * 聊天响应选择项接口
37
+ */
38
+ export interface ChatChoice {
39
+ message: {
40
+ role: 'assistant'
41
+ content: string
42
+ }
43
+ finish_reason: string
44
+ index: number
45
+ }
46
+
47
+ /**
48
+ * 聊天响应接口
49
+ */
50
+ export interface ChatCompletionsResponse {
51
+ id: string
52
+ model: string
53
+ usage: ChatUsage
54
+ choices: ChatChoice[]
55
+ }
56
+
57
+ /**
58
+ * 创建独立的 axios 实例,不经过拦截器
59
+ */
60
+ const chatAxiosInstance: AxiosInstance = axios.create({
61
+ baseURL: import.meta.env.VITE_APP_API_BASE_URL || '',
62
+ timeout: 20000,
63
+ headers: {
64
+ 'Content-Type': 'application/json',
65
+ },
66
+ })
67
+
68
+ /**
69
+ * 发送聊天请求
70
+ * @param content 用户输入的内容
71
+ * @returns Promise<ChatCompletionsResponse>
72
+ */
73
+ /**
74
+ * 发送聊天请求
75
+ * @param content 用户输入的内容
76
+ * @returns Promise<ChatCompletionsResponse>
77
+ */
78
+ export function chatCompletions(content: string): Promise<ChatCompletionsResponse> {
79
+ const requestData: ChatCompletionsRequest = {
80
+ chatId: 'chatId13333113',
81
+ stream: false,
82
+ detail: false,
83
+ variables: {
84
+ uid: 'asdfadsfasfd2323',
85
+ name: '张三',
86
+ },
87
+ messages: [
88
+ {
89
+ role: 'user',
90
+ content,
91
+ },
92
+ ],
93
+ }
94
+
95
+ return chatAxiosInstance.post<ChatCompletionsResponse>(
96
+ '/v1/chat/completions',
97
+ requestData,
98
+ {
99
+ headers: {
100
+ Authorization: 'Bearer fastgpt-cmS6DpSmnrAWfH23iz3J4Dz9witLSKVmNgaRbh5fcVWpWG4dDJYgmGlW',
101
+ },
102
+ },
103
+ ).then(response => response.data)
104
+ }