-
Notifications
You must be signed in to change notification settings - Fork 310
feat: add remote control page, update next dependency #3501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<template> | ||
<div class="message-card" :class="role"> | ||
<div class="avatar"> | ||
<component :is="avatarIcon" class="avatar-icon" /> | ||
</div> | ||
<div class="content"> | ||
<div class="role-name">{{ roleName }}</div> | ||
<div class="message">{{ message }}</div> | ||
<div class="time">{{ formatTime }}</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
import { IconAi, IconUser } from '@opentiny/tiny-robot-svgs' | ||
|
||
interface Props { | ||
role: 'user' | 'assistant' | ||
message: string | ||
timestamp: number | ||
} | ||
|
||
const props = defineProps<Props>() | ||
|
||
const roleName = computed(() => (props.role === 'assistant' ? '智能助手' : '我')) | ||
|
||
const avatarIcon = computed(() => (props.role === 'assistant' ? IconAi : IconUser)) | ||
|
||
const formatTime = computed(() => { | ||
const date = new Date(props.timestamp) | ||
return date.toLocaleTimeString('zh-CN', { | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
hour12: false | ||
}) | ||
}) | ||
</script> | ||
|
||
<style scoped lang="less"> | ||
.message-card { | ||
display: flex; | ||
margin: 16px; | ||
gap: 12px; | ||
max-width: 80%; | ||
|
||
&.assistant { | ||
margin-right: auto; | ||
|
||
.content { | ||
background-color: #f0f2f5; | ||
} | ||
|
||
.avatar-icon { | ||
color: #2080f0; | ||
} | ||
} | ||
|
||
&.user { | ||
margin-left: auto; | ||
flex-direction: row-reverse; | ||
|
||
.content { | ||
background-color: #e8f5e9; | ||
} | ||
|
||
.avatar-icon { | ||
color: #18a058; | ||
} | ||
} | ||
|
||
.avatar { | ||
width: 40px; | ||
height: 40px; | ||
border-radius: 50%; | ||
overflow: hidden; | ||
flex-shrink: 0; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
background-color: #f5f7fa; | ||
|
||
.avatar-icon { | ||
width: 24px; | ||
height: 24px; | ||
} | ||
} | ||
|
||
.content { | ||
padding: 12px; | ||
border-radius: 12px; | ||
position: relative; | ||
min-width: 120px; | ||
max-width: calc(100% - 60px); | ||
|
||
.role-name { | ||
font-size: 14px; | ||
color: #666; | ||
margin-bottom: 4px; | ||
} | ||
|
||
.message { | ||
font-size: 16px; | ||
line-height: 1.5; | ||
word-break: break-word; | ||
white-space: pre-wrap; | ||
} | ||
|
||
.time { | ||
font-size: 12px; | ||
color: #999; | ||
margin-top: 4px; | ||
text-align: right; | ||
} | ||
} | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,63 @@ | ||||||||||||||||||
<script setup lang="ts"> | ||||||||||||||||||
// 导入 CryptoJS 库 | ||||||||||||||||||
import CryptoJS from 'crypto-js' | ||||||||||||||||||
import { reactive } from 'vue' | ||||||||||||||||||
import { TinyButton, TinyDrawer } from '@opentiny/vue' | ||||||||||||||||||
import RobotChat from '../../components/tiny-robot-chat.vue' | ||||||||||||||||||
import Sound from './sound.vue' | ||||||||||||||||||
import { globalConversation } from '../../composable/utils' | ||||||||||||||||||
|
||||||||||||||||||
// 加密密钥,需要和生成二维码的页面保持一致 | ||||||||||||||||||
const secretKey = 'secret-session-id' | ||||||||||||||||||
// 获取 URL 参数 | ||||||||||||||||||
const urlParams = new URLSearchParams(window.location.search) | ||||||||||||||||||
const encryptedId = urlParams.get('id') | ||||||||||||||||||
const state = reactive({ isShow: true, showChat: false, showSound: false }) | ||||||||||||||||||
|
||||||||||||||||||
if (encryptedId) { | ||||||||||||||||||
// 解密 id | ||||||||||||||||||
const bytes = CryptoJS.AES.decrypt(encryptedId, secretKey) | ||||||||||||||||||
const originalText = bytes.toString(CryptoJS.enc.Utf8) | ||||||||||||||||||
// 存储解密后的 id 到 window.sessionId | ||||||||||||||||||
globalConversation.sessionId = originalText | ||||||||||||||||||
} | ||||||||||||||||||
const showMoter = (type) => { | ||||||||||||||||||
state.isShow = false | ||||||||||||||||||
state[type] = true | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+24
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve function naming and parameter clarity The function name "showMoter" appears to be a typo, and the parameter name -const showMoter = (type) => {
+const showController = (controllerType: 'showChat' | 'showSound') => {
state.isShow = false
- state[type] = true
+ state[controllerType] = true
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||
</script> | ||||||||||||||||||
|
||||||||||||||||||
<template> | ||||||||||||||||||
<div> | ||||||||||||||||||
<RobotChat v-if="state.showChat" /> | ||||||||||||||||||
<Sound v-if="state.showSound" /> | ||||||||||||||||||
<tiny-drawer | ||||||||||||||||||
v-if="state.isShow" | ||||||||||||||||||
title="请选择控制器" | ||||||||||||||||||
placement="bottom" | ||||||||||||||||||
:mask-closable="false" | ||||||||||||||||||
:show-close="false" | ||||||||||||||||||
v-model:visible="state.isShow" | ||||||||||||||||||
height="400px" | ||||||||||||||||||
> | ||||||||||||||||||
<div class="link-box"> | ||||||||||||||||||
<tiny-button @click="showMoter('showSound')" type="info" size="large">语音控制器</tiny-button> | ||||||||||||||||||
|
||||||||||||||||||
<tiny-button @click="showMoter('showChat')" type="info" size="large">综合控制器</tiny-button> | ||||||||||||||||||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update function calls to match refactored name If you apply the suggested refactor above, update these function calls accordingly. - <tiny-button @click="showMoter('showSound')" type="info" size="large">语音控制器</tiny-button>
+ <tiny-button @click="showController('showSound')" type="info" size="large">语音控制器</tiny-button>
- <tiny-button @click="showMoter('showChat')" type="info" size="large">综合控制器</tiny-button>
+ <tiny-button @click="showController('showChat')" type="info" size="large">综合控制器</tiny-button> 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||
</div> | ||||||||||||||||||
</tiny-drawer> | ||||||||||||||||||
</div> | ||||||||||||||||||
</template> | ||||||||||||||||||
|
||||||||||||||||||
<style scoped lang="less"> | ||||||||||||||||||
.link-box { | ||||||||||||||||||
display: flex; | ||||||||||||||||||
flex-direction: column; | ||||||||||||||||||
justify-content: center; | ||||||||||||||||||
align-items: center; | ||||||||||||||||||
|
||||||||||||||||||
.tiny-button { | ||||||||||||||||||
margin-bottom: 20px; | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical security issue: Hardcoded encryption key
The secret key is hardcoded in the client-side code, which is a significant security vulnerability. Anyone can view this key and decrypt the session IDs.
Consider these more secure alternatives:
🤖 Prompt for AI Agents