sg-paisou 0.0.0 → 0.0.1
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.npm.md +322 -0
- package/dist/ai-chat-sdk.es.js +22610 -0
- package/dist/ai-chat-sdk.es.js.map +1 -0
- package/dist/ai-chat-sdk.umd.js +300 -0
- package/dist/ai-chat-sdk.umd.js.map +1 -0
- package/dist/style.css +1 -0
- package/dist/types/index.d.ts +48 -0
- package/package.json +58 -11
- package/.idea/GitCommitMessageStorage.xml +0 -8
- package/.idea/modules.xml +0 -8
- package/.idea/sg-paisou-web.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/.vscode/settings.json +0 -2
- package/auto-imports.d.ts +0 -10
- package/components.d.ts +0 -18
- package/index.html +0 -21
- package/src/App.vue +0 -38
- package/src/assets/images/Camera-icon.png +0 -0
- package/src/assets/images/anger.png +0 -0
- package/src/assets/images/answer-icon.png +0 -0
- package/src/assets/images/back.png +0 -0
- package/src/assets/images/bg-img.png +0 -0
- package/src/assets/images/collect.png +0 -0
- package/src/assets/images/collected.png +0 -0
- package/src/assets/images/empty-bookmark.png +0 -0
- package/src/assets/images/empty-history.png +0 -0
- package/src/assets/images/feedback-thinkie-img.png +0 -0
- package/src/assets/images/history.png +0 -0
- package/src/assets/images/image 5.png +0 -0
- package/src/assets/images/insolubility.png +0 -0
- package/src/assets/images/key-points.png +0 -0
- package/src/assets/images/photograph-icon.png +0 -0
- package/src/assets/images/praise-icon.png +0 -0
- package/src/assets/images/praiseing-icon.png +0 -0
- package/src/assets/images/question.png +0 -0
- package/src/assets/images/smiling.png +0 -0
- package/src/assets/images/solution-icon.png +0 -0
- package/src/assets/images/star-icon.png +0 -0
- package/src/assets/images/trample-icon.png +0 -0
- package/src/assets/images/trampleing-icon.png +0 -0
- package/src/assets/images/volume-icon.png +0 -0
- package/src/assets/images/volumeing-icon.png +0 -0
- package/src/components/AIChatSDK/AIChatComponent.vue +0 -963
- package/src/components/AIChatSDK/component/Dialogs.vue +0 -340
- package/src/components/AIChatSDK/component/SpecialQuestions.vue +0 -208
- package/src/components/AIChatSDK/index.ts +0 -146
- package/src/components/AIChatSDK/style.scss +0 -432
- package/src/components/AIChatSDK/utils/imageUtils.ts +0 -61
- package/src/components/AIChatSDK/utils/latex.ts +0 -34
- package/src/components/AIChatSDK/utils/mergeConfig.ts +0 -125
- package/src/components/ImagePreview.vue +0 -62
- package/src/components/PageHeader/index.vue +0 -121
- package/src/config.ts +0 -11
- package/src/env.d.ts +0 -11
- package/src/main.ts +0 -12
- package/src/router.ts +0 -20
- package/src/style.css +0 -33
- package/src/type.ts +0 -106
- package/src/utils/TTS_README.md +0 -232
- package/src/utils/bridge.ts +0 -42
- package/src/utils/index.ts +0 -8
- package/src/utils/listenOsEvent.ts +0 -3
- package/src/utils/messageToast.ts +0 -43
- package/src/utils/render.ts +0 -81
- package/src/utils/request.ts +0 -87
- package/src/utils/tts.ts +0 -319
- package/src/utils/typewriter.ts +0 -61
- package/src/utils/useSSE.ts +0 -113
- package/src/views/History/index.vue +0 -419
- package/src/views/QuestionChatPage/index.vue +0 -480
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.app.json +0 -24
- package/tsconfig.json +0 -7
- package/tsconfig.node.json +0 -22
- package/vite.config.ts +0 -41
- /package/{public → dist}/mathjax/all-packages.js +0 -0
- /package/{public → dist}/mathjax/talEditorConfig.js +0 -0
- /package/{public → dist}/mathjax/tex-svg.js +0 -0
- /package/{src/components/AIChatSDK/types.ts → dist/types/types.d.ts} +0 -0
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="dialogs" v-if="visible">
|
|
3
|
-
<!-- 无法解答弹窗 -->
|
|
4
|
-
<div class="insolubility-content" v-if="dialogType === 'insolubility'">
|
|
5
|
-
<img :src="insolubilityIcon" class="insolubility-content-img" alt="">
|
|
6
|
-
<div class="insolubility-content-text">
|
|
7
|
-
<span>Oops, Sorry</span>
|
|
8
|
-
<span class="insolubility-content-text-subtext">Thinkie can't explain this question.</span>
|
|
9
|
-
<div class="insolubility-content-button" @click="handleBack">
|
|
10
|
-
<img :src="photographIcon" alt="">
|
|
11
|
-
<span>Snap another one</span>
|
|
12
|
-
</div>
|
|
13
|
-
</div>
|
|
14
|
-
</div>
|
|
15
|
-
|
|
16
|
-
<!-- 反馈弹窗 -->
|
|
17
|
-
<div class="feedback-dialog" v-if="dialogType === 'feedback'">
|
|
18
|
-
<!-- 顶部图片和关闭按钮 -->
|
|
19
|
-
<div class="feedback-header">
|
|
20
|
-
<img :src="feedbackThinkieImg" class="feedback-robot-img" alt="Feedback">
|
|
21
|
-
<div class="close-button" @click="handleClose">
|
|
22
|
-
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
|
|
23
|
-
<path d="M18 6L6 18M6 6L18 18" stroke="#999999" stroke-width="2.4" stroke-linecap="round"/>
|
|
24
|
-
</svg>
|
|
25
|
-
</div>
|
|
26
|
-
</div>
|
|
27
|
-
<div class="feedback-content">
|
|
28
|
-
<!-- 标题 -->
|
|
29
|
-
<div class="feedback-title">Problem Feedback</div>
|
|
30
|
-
<div class="feedback-subtitle">Can you tell us what went wrong?</div>
|
|
31
|
-
|
|
32
|
-
<!-- 反馈选项 -->
|
|
33
|
-
<div class="feedback-tags">
|
|
34
|
-
<div
|
|
35
|
-
v-for="tag in feedbackOptions"
|
|
36
|
-
:key="tag.value"
|
|
37
|
-
class="feedback-tag"
|
|
38
|
-
:class="{ active: selectedTags.includes(tag.value) }"
|
|
39
|
-
@click="toggleTag(tag.value)"
|
|
40
|
-
>
|
|
41
|
-
{{ tag.label }}
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
|
|
45
|
-
<!-- 输入框 -->
|
|
46
|
-
<textarea
|
|
47
|
-
v-model="feedbackText"
|
|
48
|
-
class="feedback-textarea"
|
|
49
|
-
placeholder="Tell us more how we can improve"
|
|
50
|
-
rows="5"
|
|
51
|
-
></textarea>
|
|
52
|
-
|
|
53
|
-
<!-- 提交按钮 -->
|
|
54
|
-
<button
|
|
55
|
-
class="feedback-submit"
|
|
56
|
-
:class="{ disabled: !canSubmit }"
|
|
57
|
-
:disabled="!canSubmit"
|
|
58
|
-
@click="handleSubmit"
|
|
59
|
-
>
|
|
60
|
-
Submit
|
|
61
|
-
</button>
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
</template>
|
|
66
|
-
|
|
67
|
-
<script lang="ts" setup>
|
|
68
|
-
import { ref, computed } from 'vue'
|
|
69
|
-
import { backToClient } from '../../../utils/bridge'
|
|
70
|
-
import { feedbackApi } from '../../../utils/request'
|
|
71
|
-
import { showMessageToast } from '../../../utils/messageToast'
|
|
72
|
-
import insolubilityIcon from '@/assets/images/insolubility.png'
|
|
73
|
-
import photographIcon from '@/assets/images/photograph-icon.png'
|
|
74
|
-
import feedbackThinkieImg from '@/assets/images/feedback-thinkie-img.png'
|
|
75
|
-
|
|
76
|
-
// 反馈类型枚举
|
|
77
|
-
export type FeedbackType = 'angry' | 'thumbsDown' // 'angry' 对应😡,'thumbsDown' 对应👎
|
|
78
|
-
|
|
79
|
-
const props = withDefaults(defineProps<{
|
|
80
|
-
visible: boolean
|
|
81
|
-
dialogType: 'insolubility' | 'feedback'
|
|
82
|
-
feedbackType?: FeedbackType
|
|
83
|
-
currentLongPressMessageId?: string
|
|
84
|
-
}>(), {
|
|
85
|
-
visible: false,
|
|
86
|
-
dialogType: 'insolubility',
|
|
87
|
-
feedbackType: 'angry',
|
|
88
|
-
currentLongPressMessageId: ''
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
// Emits
|
|
92
|
-
const emit = defineEmits<{
|
|
93
|
-
(e: 'close', messageId?: string): void
|
|
94
|
-
(e: 'submit', data: { tags: string[], text: string }): void
|
|
95
|
-
}>()
|
|
96
|
-
|
|
97
|
-
// 反馈选项配置
|
|
98
|
-
const baseOptions = [
|
|
99
|
-
{ value: 'wrong_answer', label: 'Wrong answer' },
|
|
100
|
-
{ value: 'difficult_to_understand', label: 'Difficult to understand' },
|
|
101
|
-
{ value: 'too_much_detail', label: 'Too much detail' },
|
|
102
|
-
{ value: 'poor_formatting', label: 'Poor formatting' },
|
|
103
|
-
{ value: 'lacks_detail', label: 'Lacks detail' }
|
|
104
|
-
]
|
|
105
|
-
|
|
106
|
-
// 反馈选项
|
|
107
|
-
const feedbackOptions = computed(() =>
|
|
108
|
-
props.feedbackType === 'thumbsDown'
|
|
109
|
-
? [...baseOptions, { value: 'slow', label: 'Slow' }, { value: 'wrong_explanation', label: 'Wrong explanation' }]
|
|
110
|
-
: baseOptions
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
// 选中的标签
|
|
114
|
-
const selectedTags = ref<string[]>([])
|
|
115
|
-
// 反馈文本
|
|
116
|
-
const feedbackText = ref('')
|
|
117
|
-
// 是否可以提交
|
|
118
|
-
const canSubmit = computed(() => selectedTags.value.length > 0)
|
|
119
|
-
|
|
120
|
-
const resetState = () => {
|
|
121
|
-
selectedTags.value = []
|
|
122
|
-
feedbackText.value = ''
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const handleBack = () => backToClient()
|
|
126
|
-
|
|
127
|
-
const toggleTag = (value: string) => {
|
|
128
|
-
const index = selectedTags.value.indexOf(value)
|
|
129
|
-
index > -1 ? selectedTags.value.splice(index, 1) : selectedTags.value.push(value)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// 关闭弹窗
|
|
133
|
-
const handleClose = () => {
|
|
134
|
-
resetState()
|
|
135
|
-
emit('close')
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// 提交反馈
|
|
139
|
-
const handleSubmit = async () => {
|
|
140
|
-
if (!canSubmit.value) return
|
|
141
|
-
|
|
142
|
-
const subjectId = props.feedbackType === 'thumbsDown'
|
|
143
|
-
? props.currentLongPressMessageId
|
|
144
|
-
: JSON.parse(sessionStorage.getItem('questionInfo') || '{}')?.sessionId || ''
|
|
145
|
-
|
|
146
|
-
await feedbackApi({
|
|
147
|
-
subjectId,
|
|
148
|
-
tags: selectedTags.value,
|
|
149
|
-
content: feedbackText.value.trim(),
|
|
150
|
-
vote: 'downvote'
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
showMessageToast()
|
|
154
|
-
resetState()
|
|
155
|
-
emit('close', props.currentLongPressMessageId || '')
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
defineExpose({ handleClose, handleSubmit })
|
|
159
|
-
</script>
|
|
160
|
-
|
|
161
|
-
<style lang="scss" scoped>
|
|
162
|
-
.dialogs {
|
|
163
|
-
position: fixed;
|
|
164
|
-
inset: 0;
|
|
165
|
-
display: flex;
|
|
166
|
-
justify-content: center;
|
|
167
|
-
align-items: center;
|
|
168
|
-
background: rgba(0, 0, 0, 0.5);
|
|
169
|
-
z-index: 1000;
|
|
170
|
-
|
|
171
|
-
// 无法解答弹窗样式
|
|
172
|
-
.insolubility-content {
|
|
173
|
-
width: 350px;
|
|
174
|
-
|
|
175
|
-
.insolubility-content-img {
|
|
176
|
-
width: 100%;
|
|
177
|
-
vertical-align: top;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
.insolubility-content-text {
|
|
181
|
-
width: 100%;
|
|
182
|
-
font-weight: 500;
|
|
183
|
-
color: #222;
|
|
184
|
-
background: #FFF;
|
|
185
|
-
display: flex;
|
|
186
|
-
flex-direction: column;
|
|
187
|
-
align-items: center;
|
|
188
|
-
gap: 16px;
|
|
189
|
-
padding: 20px 0;
|
|
190
|
-
text-transform: capitalize;
|
|
191
|
-
border-radius: 0 0 20px 20px;
|
|
192
|
-
|
|
193
|
-
span {
|
|
194
|
-
font-size: 20px;
|
|
195
|
-
line-height: 24px;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
.insolubility-content-text-subtext {
|
|
199
|
-
font-size: 16px;
|
|
200
|
-
color: #999;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
.insolubility-content-button {
|
|
204
|
-
padding: 8px 16px;
|
|
205
|
-
background: linear-gradient(91.95deg, #FFCB00 0%, #FFAB03 100%);
|
|
206
|
-
border-radius: 70px;
|
|
207
|
-
display: flex;
|
|
208
|
-
align-items: center;
|
|
209
|
-
|
|
210
|
-
img {
|
|
211
|
-
width: 20px;
|
|
212
|
-
margin-right: 8px;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
span {
|
|
216
|
-
font-size: 16px;
|
|
217
|
-
color: #FFF;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// 反馈弹窗样式
|
|
224
|
-
.feedback-dialog {
|
|
225
|
-
width: 420px;
|
|
226
|
-
overflow: hidden;
|
|
227
|
-
display: flex;
|
|
228
|
-
flex-direction: column;
|
|
229
|
-
|
|
230
|
-
.feedback-header {
|
|
231
|
-
position: relative;
|
|
232
|
-
|
|
233
|
-
.feedback-robot-img {
|
|
234
|
-
width: 100%;
|
|
235
|
-
vertical-align: top;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
.close-button {
|
|
239
|
-
position: absolute;
|
|
240
|
-
top: 37px;
|
|
241
|
-
right: 12px;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
.feedback-content {
|
|
246
|
-
padding: 12px 20px 20px;
|
|
247
|
-
background: #FFF;
|
|
248
|
-
border-radius: 0 0 20px 20px;
|
|
249
|
-
display: flex;
|
|
250
|
-
flex-direction: column;
|
|
251
|
-
|
|
252
|
-
.feedback-title {
|
|
253
|
-
font-size: 20px;
|
|
254
|
-
font-weight: 500;
|
|
255
|
-
line-height: 24px;
|
|
256
|
-
color: #222;
|
|
257
|
-
text-align: center;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
.feedback-subtitle {
|
|
261
|
-
line-height: 24px;
|
|
262
|
-
color: #999;
|
|
263
|
-
text-align: center;
|
|
264
|
-
margin-top: 8px;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
.feedback-tags {
|
|
268
|
-
display: flex;
|
|
269
|
-
flex-wrap: wrap;
|
|
270
|
-
gap: 12px;
|
|
271
|
-
margin-top: 8px;
|
|
272
|
-
justify-content: center;
|
|
273
|
-
|
|
274
|
-
.feedback-tag {
|
|
275
|
-
font-size: 14px;
|
|
276
|
-
padding: 6px 8px 6px 12px;
|
|
277
|
-
background: rgba(0, 0, 0, 0.03);
|
|
278
|
-
border: 1px solid transparent;
|
|
279
|
-
border-radius: 38px;
|
|
280
|
-
color: #666;
|
|
281
|
-
user-select: none;
|
|
282
|
-
line-height: 100%;
|
|
283
|
-
|
|
284
|
-
&.active {
|
|
285
|
-
background: #FFF;
|
|
286
|
-
border-color: rgba(255, 157, 0, 0.3);
|
|
287
|
-
color: #FF9D00;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
&:active {
|
|
291
|
-
transform: scale(0.98);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
.feedback-textarea {
|
|
297
|
-
height: 94px;
|
|
298
|
-
margin-top: 12px;
|
|
299
|
-
padding: 12px;
|
|
300
|
-
background: #F7F7F7;
|
|
301
|
-
border: 1px solid transparent;
|
|
302
|
-
border-radius: 12px;
|
|
303
|
-
font-size: 14px;
|
|
304
|
-
line-height: 24px;
|
|
305
|
-
color: #222;
|
|
306
|
-
resize: none;
|
|
307
|
-
outline: none;
|
|
308
|
-
transition: all 0.2s;
|
|
309
|
-
font-family: inherit;
|
|
310
|
-
|
|
311
|
-
&::placeholder {
|
|
312
|
-
color: #999;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
&:focus {
|
|
316
|
-
background: #FFF;
|
|
317
|
-
border-color: #FFAB03;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
.feedback-submit {
|
|
322
|
-
margin-top: 16px;
|
|
323
|
-
padding: 8px 24px;
|
|
324
|
-
background: linear-gradient(91.95deg, #FFCB00 0%, #FFAB03 100%);
|
|
325
|
-
border: none;
|
|
326
|
-
border-radius: 70px;
|
|
327
|
-
font-size: 16px;
|
|
328
|
-
font-weight: 500;
|
|
329
|
-
line-height: 24px;
|
|
330
|
-
color: #FFF;
|
|
331
|
-
transition: all 0.2s;
|
|
332
|
-
|
|
333
|
-
&.disabled {
|
|
334
|
-
opacity: 0.2;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
</style>
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<!-- 特殊题 -->
|
|
3
|
-
<div class="special-questions">
|
|
4
|
-
<div class="solution-content">
|
|
5
|
-
<div class="solution-content-title">
|
|
6
|
-
<img :src="solutionIcon" alt="Solution">
|
|
7
|
-
<span class="solution-content-title-text">Solution</span>
|
|
8
|
-
</div>
|
|
9
|
-
<div
|
|
10
|
-
ref="solutionRef"
|
|
11
|
-
class="solution-content-description"
|
|
12
|
-
v-html="renderedSolution"
|
|
13
|
-
></div>
|
|
14
|
-
</div>
|
|
15
|
-
<div class="answer-content">
|
|
16
|
-
<div class="answer-content-title">
|
|
17
|
-
<img :src="answerIcon" alt="Answer">
|
|
18
|
-
<span class="answer-content-title-text">Answer</span>
|
|
19
|
-
</div>
|
|
20
|
-
<div
|
|
21
|
-
ref="answerRef"
|
|
22
|
-
class="answer-content-description"
|
|
23
|
-
v-html="renderedAnswer"
|
|
24
|
-
></div>
|
|
25
|
-
</div>
|
|
26
|
-
<div class="feedback-content">
|
|
27
|
-
<span class="feedback-content-title">Was this solution helpful?</span>
|
|
28
|
-
<img :src="smilingIcon" alt="Feedback" @click="handleFeedback('upvote')">
|
|
29
|
-
<img :src="angerIcon" alt="Feedback" @click="handleFeedback('downvote')">
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
</template>
|
|
33
|
-
|
|
34
|
-
<script lang="ts" setup>
|
|
35
|
-
import { ref, onMounted, watch, nextTick } from 'vue'
|
|
36
|
-
import solutionIcon from '@/assets/images/solution-icon.png'
|
|
37
|
-
import answerIcon from '@/assets/images/answer-icon.png'
|
|
38
|
-
import smilingIcon from '@/assets/images/smiling.png'
|
|
39
|
-
import angerIcon from '@/assets/images/anger.png'
|
|
40
|
-
|
|
41
|
-
// Props
|
|
42
|
-
const props = withDefaults(defineProps<{
|
|
43
|
-
solutionAnswer?: { solution: any, answer: any } // 解析数据
|
|
44
|
-
isDownVoted?: boolean
|
|
45
|
-
}>(), {
|
|
46
|
-
solutionAnswer: () => ({ solution: null, answer: null } as { solution: any, answer: any })
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
// Emits
|
|
50
|
-
const emit = defineEmits<{
|
|
51
|
-
(e: 'feedback', type: 'upvote' | 'downvote', isDownVoted: boolean): void
|
|
52
|
-
}>()
|
|
53
|
-
|
|
54
|
-
// Refs
|
|
55
|
-
const solutionRef = ref<HTMLElement>()
|
|
56
|
-
const answerRef = ref<HTMLElement>()
|
|
57
|
-
const renderedSolution = ref('')
|
|
58
|
-
const renderedAnswer = ref('')
|
|
59
|
-
|
|
60
|
-
// 声明全局 TalqsTemplate 和 MathJax
|
|
61
|
-
declare global {
|
|
62
|
-
interface Window {
|
|
63
|
-
TalqsTemplate: any
|
|
64
|
-
MathJax: any
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 渲染 Solution
|
|
69
|
-
const renderSolution = () => {
|
|
70
|
-
try {
|
|
71
|
-
// 使用 TalqsTemplate 渲染
|
|
72
|
-
if (window.TalqsTemplate) {
|
|
73
|
-
renderedSolution.value = window.TalqsTemplate.render(props.solutionAnswer.solution, {
|
|
74
|
-
// 可以添加配置选项
|
|
75
|
-
})
|
|
76
|
-
console.log(renderedSolution.value);
|
|
77
|
-
nextTick(() => {
|
|
78
|
-
renderMathJax(solutionRef.value)
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
} catch (error) {
|
|
82
|
-
console.error('Solution 渲染失败:', error)
|
|
83
|
-
renderedSolution.value = '<div>渲染失败</div>'
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 渲染 Answer
|
|
88
|
-
const renderAnswer = () => {
|
|
89
|
-
try {
|
|
90
|
-
// 使用 TalqsTemplate 渲染
|
|
91
|
-
if (window.TalqsTemplate) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
renderedAnswer.value = window.TalqsTemplate.render(props.solutionAnswer.solution, {
|
|
95
|
-
analyzeVersion: 2, // 解析显示版本
|
|
96
|
-
entryTemplate: window.TalqsTemplate.components.AnalyzeWrapper, // 入口组件
|
|
97
|
-
// 可以添加配置选项
|
|
98
|
-
})
|
|
99
|
-
console.log(renderedAnswer.value);
|
|
100
|
-
nextTick(() => {
|
|
101
|
-
renderMathJax(answerRef.value)
|
|
102
|
-
})
|
|
103
|
-
}
|
|
104
|
-
} catch (error) {
|
|
105
|
-
console.error('Answer 渲染失败:', error)
|
|
106
|
-
renderedAnswer.value = '<div>渲染失败</div>'
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// 使用 MathJax 渲染公式
|
|
111
|
-
const renderMathJax = (element: HTMLElement | undefined) => {
|
|
112
|
-
if (!element) return
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
if (window.MathJax && window.MathJax.Hub) {
|
|
116
|
-
window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, element])
|
|
117
|
-
} else if (window.MathJax && window.MathJax.typesetPromise) {
|
|
118
|
-
// MathJax 3.x
|
|
119
|
-
window.MathJax.typesetPromise([element]).catch((err: any) => {
|
|
120
|
-
console.error('MathJax 渲染失败:', err)
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
} catch (error) {
|
|
124
|
-
console.error('MathJax 渲染失败:', error)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// 反馈处理
|
|
129
|
-
const handleFeedback = (type: 'upvote' | 'downvote') => {
|
|
130
|
-
emit('feedback', type, props.isDownVoted || false)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// 监听数据变化,重新渲染
|
|
134
|
-
watch(() => props.solutionAnswer.solution, () => {
|
|
135
|
-
renderSolution()
|
|
136
|
-
}, { deep: true })
|
|
137
|
-
|
|
138
|
-
watch(() => props.solutionAnswer.answer, () => {
|
|
139
|
-
renderAnswer()
|
|
140
|
-
}, { deep: true })
|
|
141
|
-
|
|
142
|
-
// 组件挂载时渲染
|
|
143
|
-
onMounted(() => {
|
|
144
|
-
renderSolution()
|
|
145
|
-
renderAnswer()
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
// 暴露方法供外部调用
|
|
149
|
-
defineExpose({
|
|
150
|
-
renderSolution,
|
|
151
|
-
renderAnswer,
|
|
152
|
-
renderMathJax
|
|
153
|
-
})
|
|
154
|
-
</script>
|
|
155
|
-
|
|
156
|
-
<style lang="scss" scoped>
|
|
157
|
-
.special-questions {
|
|
158
|
-
padding: 20px;
|
|
159
|
-
display: flex;
|
|
160
|
-
flex-direction: column;
|
|
161
|
-
gap: 20px;
|
|
162
|
-
|
|
163
|
-
img {
|
|
164
|
-
width: 24px;
|
|
165
|
-
transition: transform 0.1s ease;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
.solution-content, .answer-content {
|
|
171
|
-
display: flex;
|
|
172
|
-
flex-direction: column;
|
|
173
|
-
justify-content: center;
|
|
174
|
-
gap: 12px;
|
|
175
|
-
|
|
176
|
-
.solution-content-title,
|
|
177
|
-
.answer-content-title {
|
|
178
|
-
display: flex;
|
|
179
|
-
align-items: center;
|
|
180
|
-
gap: 8px;
|
|
181
|
-
|
|
182
|
-
.solution-content-title-text, .answer-content-title-text {
|
|
183
|
-
font-size: 20px;
|
|
184
|
-
font-weight: 600;
|
|
185
|
-
line-height: 32px;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
.solution-content-description, .answer-content-description {
|
|
190
|
-
padding: 12px 16px;
|
|
191
|
-
background: #F8F7F6;
|
|
192
|
-
border-radius: 12px;
|
|
193
|
-
line-height: 24px;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
.feedback-content {
|
|
198
|
-
display: flex;
|
|
199
|
-
align-items: center;
|
|
200
|
-
justify-content: flex-end;
|
|
201
|
-
gap: 12px;
|
|
202
|
-
|
|
203
|
-
img:active {
|
|
204
|
-
transform: scale(1.2);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
</style>
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
// AI聊天SDK入口文件
|
|
2
|
-
|
|
3
|
-
import AIChatComponent from './AIChatComponent.vue'
|
|
4
|
-
import type {
|
|
5
|
-
IAIChatConfig,
|
|
6
|
-
IAIChatSDKProps,
|
|
7
|
-
IMessage,
|
|
8
|
-
IAvatarConfig,
|
|
9
|
-
IAIInfoConfig,
|
|
10
|
-
IMuteButtonConfig,
|
|
11
|
-
IFeedbackButton,
|
|
12
|
-
IFeedbackConfig,
|
|
13
|
-
IInputConfig,
|
|
14
|
-
IStyleConfig,
|
|
15
|
-
IMessageStyle
|
|
16
|
-
} from './types'
|
|
17
|
-
import { DEFAULT_CONFIG } from './types'
|
|
18
|
-
import { IMAGE_ASSETS, getImageUrl, hasImage, createImageConfig } from './utils/imageUtils'
|
|
19
|
-
|
|
20
|
-
// 导出组件
|
|
21
|
-
export { AIChatComponent }
|
|
22
|
-
|
|
23
|
-
// 导出图片工具
|
|
24
|
-
export { IMAGE_ASSETS, getImageUrl, hasImage, createImageConfig }
|
|
25
|
-
|
|
26
|
-
// 导出类型
|
|
27
|
-
export type {
|
|
28
|
-
IAIChatConfig,
|
|
29
|
-
IAIChatSDKProps,
|
|
30
|
-
IMessage,
|
|
31
|
-
IAvatarConfig,
|
|
32
|
-
IAIInfoConfig,
|
|
33
|
-
IMuteButtonConfig,
|
|
34
|
-
IFeedbackButton,
|
|
35
|
-
IFeedbackConfig,
|
|
36
|
-
IInputConfig,
|
|
37
|
-
IStyleConfig,
|
|
38
|
-
IMessageStyle
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 导出默认配置
|
|
42
|
-
export { DEFAULT_CONFIG }
|
|
43
|
-
|
|
44
|
-
// 创建AI聊天实例的工厂函数
|
|
45
|
-
export function createAIChatConfig(config?: Partial<IAIChatConfig>): IAIChatConfig {
|
|
46
|
-
const mergedConfig = { ...DEFAULT_CONFIG }
|
|
47
|
-
|
|
48
|
-
if (config) {
|
|
49
|
-
// 深度合并配置
|
|
50
|
-
Object.keys(config).forEach(key => {
|
|
51
|
-
const configKey = key as keyof IAIChatConfig
|
|
52
|
-
const configValue = config[configKey]
|
|
53
|
-
const mergedValue = mergedConfig[configKey]
|
|
54
|
-
|
|
55
|
-
if (typeof configValue === 'object' && configValue !== null && !Array.isArray(configValue) &&
|
|
56
|
-
typeof mergedValue === 'object' && mergedValue !== null) {
|
|
57
|
-
mergedConfig[configKey] = { ...mergedValue, ...configValue } as any
|
|
58
|
-
} else if (configValue !== undefined) {
|
|
59
|
-
mergedConfig[configKey] = configValue as any
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return mergedConfig
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// 预设配置
|
|
68
|
-
export const PRESET_CONFIGS = {
|
|
69
|
-
// 默认配置
|
|
70
|
-
default: DEFAULT_CONFIG,
|
|
71
|
-
|
|
72
|
-
// 简洁模式
|
|
73
|
-
minimal: createAIChatConfig({
|
|
74
|
-
feedback: {
|
|
75
|
-
show: false
|
|
76
|
-
},
|
|
77
|
-
styles: {
|
|
78
|
-
container: {
|
|
79
|
-
borderRadius: '8px',
|
|
80
|
-
boxShadow: 'none'
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}),
|
|
84
|
-
|
|
85
|
-
// 暗色主题
|
|
86
|
-
dark: createAIChatConfig({
|
|
87
|
-
styles: {
|
|
88
|
-
container: {
|
|
89
|
-
background: '#1a1a1a',
|
|
90
|
-
color: '#ffffff'
|
|
91
|
-
},
|
|
92
|
-
header: {
|
|
93
|
-
borderBottom: '1px solid #333333',
|
|
94
|
-
background: '#1a1a1a'
|
|
95
|
-
},
|
|
96
|
-
messages: {
|
|
97
|
-
aiMessage: {
|
|
98
|
-
background: '#2d2d2d',
|
|
99
|
-
color: '#ffffff',
|
|
100
|
-
border: '1px solid #333333'
|
|
101
|
-
},
|
|
102
|
-
userMessage: {
|
|
103
|
-
background: '#0066cc',
|
|
104
|
-
color: '#ffffff'
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
aiInfo: {
|
|
109
|
-
nameStyle: {
|
|
110
|
-
color: '#ffffff'
|
|
111
|
-
},
|
|
112
|
-
titleStyle: {
|
|
113
|
-
color: '#cccccc'
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}),
|
|
117
|
-
|
|
118
|
-
// 紧凑模式
|
|
119
|
-
compact: createAIChatConfig({
|
|
120
|
-
styles: {
|
|
121
|
-
header: {
|
|
122
|
-
padding: '8px 16px'
|
|
123
|
-
},
|
|
124
|
-
inputContainer: {
|
|
125
|
-
padding: '8px 16px 16px'
|
|
126
|
-
},
|
|
127
|
-
messages: {
|
|
128
|
-
messageGap: '8px'
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
feedback: {
|
|
132
|
-
containerStyle: {
|
|
133
|
-
padding: '0 0 8px 0',
|
|
134
|
-
gap: '8px'
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// 默认导出
|
|
141
|
-
export default {
|
|
142
|
-
AIChatComponent,
|
|
143
|
-
createAIChatConfig,
|
|
144
|
-
PRESET_CONFIGS,
|
|
145
|
-
DEFAULT_CONFIG
|
|
146
|
-
}
|