Commit 98bd0230 authored by 水玉婷's avatar 水玉婷
Browse files

feat:调整参数配置结构

parent 344dc350
...@@ -121,9 +121,7 @@ ...@@ -121,9 +121,7 @@
:params="chatParams" :params="chatParams"
:dialogSessionId="currentSessionId" :dialogSessionId="currentSessionId"
:detailData="currentSessionDetail" :detailData="currentSessionDetail"
:apiBaseUrl="apiBaseUrl" :baseConfig="baseConfig"
:token="userToken"
:appCode="appCode"
customClass="chat-history" customClass="chat-history"
:key="sessionKey" :key="sessionKey"
/> />
...@@ -180,6 +178,14 @@ const userInfo = localStorage.getItem('wechat_user'); ...@@ -180,6 +178,14 @@ const userInfo = localStorage.getItem('wechat_user');
const { extMap = {} } = JSON.parse(userInfo || '{}'); const { extMap = {} } = JSON.parse(userInfo || '{}');
const userToken = extMap.sessionId; const userToken = extMap.sessionId;
const appCode = import.meta.env.VITE_APP_CODE || 'ped.qywx'; const appCode = import.meta.env.VITE_APP_CODE || 'ped.qywx';
// 基础配置对象
const baseConfig = {
apiBaseUrl,
token: userToken,
appCode
};
const chatParams = { const chatParams = {
appId: '83b2664019a945d0a438abe6339758d8', appId: '83b2664019a945d0a438abe6339758d8',
stage: 'wechat-demo', stage: 'wechat-demo',
...@@ -676,8 +682,6 @@ onMounted(() => { ...@@ -676,8 +682,6 @@ onMounted(() => {
padding: 20px; padding: 20px;
color: #999; color: #999;
font-size: 14px; font-size: 14px;
background: #fafafa;
border-top: 1px solid #f0f0f0;
.pull-up-icon { .pull-up-icon {
font-size: 20px; font-size: 20px;
...@@ -704,7 +708,9 @@ onMounted(() => { ...@@ -704,7 +708,9 @@ onMounted(() => {
align-items: center; align-items: center;
padding: 8px 20px; padding: 8px 20px;
cursor: pointer; cursor: pointer;
transition: background-color 0.2s ease; transition: all 0.2s ease;
will-change: background-color;
height:46px;
&:hover { &:hover {
background: #D5D8D8; background: #D5D8D8;
...@@ -746,12 +752,11 @@ onMounted(() => { ...@@ -746,12 +752,11 @@ onMounted(() => {
.delete-button { .delete-button {
background: none; background: none;
border: none; border: none;
padding: 4px; padding: 04px;
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
color: #323232; color: #323232;
opacity: 0; display: none;
transition: all 0.2s ease;
&:hover { &:hover {
color: #ff4d4f; color: #ff4d4f;
...@@ -759,7 +764,7 @@ onMounted(() => { ...@@ -759,7 +764,7 @@ onMounted(() => {
} }
&:hover .delete-button { &:hover .delete-button {
opacity: 1; display: block;
} }
} }
......
...@@ -2,10 +2,7 @@ ...@@ -2,10 +2,7 @@
<AiChat <AiChat
:params="chatParams" :params="chatParams"
:dialogSessionId="dialogSessionId" :dialogSessionId="dialogSessionId"
:detailData="detailData" :baseConfig="baseConfig"
:apiBaseUrl="apiBaseUrl"
:token="userToken"
:appCode="appCode"
customClass="chat-demo" customClass="chat-demo"
/> />
</template> </template>
...@@ -35,17 +32,19 @@ ...@@ -35,17 +32,19 @@
// 使用环境变量代替硬编码 // 使用环境变量代替硬编码
const appCode = import.meta.env.VITE_APP_CODE || 'ped.qywx'; const appCode = import.meta.env.VITE_APP_CODE || 'ped.qywx';
// 基础配置对象
const baseConfig = {
apiBaseUrl,
token: userToken,
appCode
};
const time = new Date().getTime(); const time = new Date().getTime();
const chatParams = { const chatParams = {
appId: appId || '83b2664019a945d0a438abe6339758d8', // 企业微信应用ID appId: appId || '83b2664019a945d0a438abe6339758d8', // 企业微信应用ID
stage: 'wechat-demo'+time, stage: 'wechat-demo'+time,
}; };
const dialogSessionId = ref('');
// const dialogSessionId = '20251127180914709-00043912';
const dialogSessionId = '';
const detailData = ref({
title: '国械小智',
});
</script> </script>
<style scoped> <style scoped>
......
...@@ -48,11 +48,11 @@ export default { ...@@ -48,11 +48,11 @@ export default {
onMounted(() => { onMounted(() => {
// 检查是否已登录 // 检查是否已登录
// const status = wechat.checkLoginStatus() const status = wechat.checkLoginStatus()
// if (status.isLoggedIn) { if (status.isLoggedIn) {
// router.replace('/') router.replace('/')
// return return
// } }
// 执行静默登录 // 执行静默登录
handleLogin() handleLogin()
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<img :src="props?.logoUrl || defaultAvatar" alt="avatar" class="avatar-image" /> <img :src="props?.logoUrl || defaultAvatar" alt="avatar" class="avatar-image" />
</div> </div>
<div class="header-info"> <div class="header-info">
<h2>{{ props?.dialogSessionId ? props?.detailData?.title || '继续对话' : '新建对话' }}</h2> <h2>{{ props?.dialogSessionId ? appData?.app_namee || '继续对话' : '新建对话' }}</h2>
</div> </div>
</div> </div>
...@@ -115,9 +115,7 @@ ...@@ -115,9 +115,7 @@
<div class="chat-input"> <div class="chat-input">
<!-- 语音识别按钮 --> <!-- 语音识别按钮 -->
<VoiceRecognitionText ref="voiceRecognitionRef" :disabled="loading" :debug="true" <VoiceRecognitionText ref="voiceRecognitionRef" :disabled="loading" :debug="true"
:token="props?.token" :baseConfig="baseConfig"
:appCode="props?.appCode"
:apiBaseUrl="props?.apiBaseUrl"
@text="handleVoiceText" @text="handleVoiceText"
@error="handleVoiceError" class="voice-recognition-wrapper" /> @error="handleVoiceError" class="voice-recognition-wrapper" />
...@@ -148,14 +146,13 @@ import { createContentTemplateService, type Message } from './utils/contentTempl ...@@ -148,14 +146,13 @@ import { createContentTemplateService, type Message } from './utils/contentTempl
interface Props { interface Props {
// 对话会话ID // 对话会话ID
dialogSessionId?: string dialogSessionId?: string
// API基础URL // 基础配置对象
apiBaseUrl?: string baseConfig?: {
// 应用代码 apiBaseUrl?: string
appCode?: string token?: string
token?: string appCode?: string
}
logoUrl?: string logoUrl?: string
// 对话详情数据
detailData?: Record<string, any>
onMessageSend?: (message: string | Blob) => Promise<void> onMessageSend?: (message: string | Blob) => Promise<void>
onGetChatRecord?: Function onGetChatRecord?: Function
customClass?: string customClass?: string
...@@ -169,11 +166,12 @@ interface Props { ...@@ -169,11 +166,12 @@ interface Props {
// 定义组件属性 // 定义组件属性
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
dialogSessionId: '', dialogSessionId: '',
apiBaseUrl: '', baseConfig: () => ({
appCode: '', apiBaseUrl: '',
token: '', token: '',
appCode: ''
}),
logoUrl: '', logoUrl: '',
detailData: () => ({}),
onMessageSend: undefined, onMessageSend: undefined,
onGetChatRecord: undefined, onGetChatRecord: undefined,
customClass: '', customClass: '',
...@@ -457,15 +455,15 @@ const sendMessage = async (type: MessageType = 'text', params: MessageParams = { ...@@ -457,15 +455,15 @@ const sendMessage = async (type: MessageType = 'text', params: MessageParams = {
dialogSessionId: dialogSessionId.value, dialogSessionId: dialogSessionId.value,
appId: props.params?.appId, appId: props.params?.appId,
}; };
const { token, appCode } = props.baseConfig || {};
const response = await fetch(`${import.meta.env.VITE_SSE_PATH}/sse/ask`, { const response = await fetch(`${import.meta.env.VITE_SSE_PATH}/sse/ask`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'token': props.token, 'token': token || '',
'x-session-id': props?.token, 'x-session-id': token || '',
'x-app-code': props.appCode || '' 'x-app-code': appCode || ''
}, } as HeadersInit,
body: JSON.stringify(requestData) body: JSON.stringify(requestData)
}); });
...@@ -670,13 +668,14 @@ const getChatRecord = async (dialogSessionId: string) => { ...@@ -670,13 +668,14 @@ const getChatRecord = async (dialogSessionId: string) => {
messages.value = [...recordList]; messages.value = [...recordList];
} }
} else { } else {
const response = await fetch(`${props.apiBaseUrl}/aiService/ask/list/chat/${dialogSessionId}`, { const { token, appCode } = props.baseConfig || {};
const response = await fetch(`${props.baseConfig?.apiBaseUrl || ''}/aiService/ask/list/chat/${dialogSessionId}`, {
method: 'GET', method: 'GET',
headers: { headers: {
'token': props.token, 'token': token || '',
'x-session-id': props.token, 'x-session-id': token || '',
'x-app-code': props.appCode || '' 'x-app-code': appCode || ''
} } as HeadersInit
}); });
const data = await response.json(); const data = await response.json();
...@@ -698,10 +697,10 @@ const getAppInfo = async () => { ...@@ -698,10 +697,10 @@ const getAppInfo = async () => {
const response = await fetch(`${import.meta.env.VITE_SSE_PATH}/apps/getAppInfoById/${props.params?.appId}`, { const response = await fetch(`${import.meta.env.VITE_SSE_PATH}/apps/getAppInfoById/${props.params?.appId}`, {
method: 'GET', method: 'GET',
headers: { headers: {
'token': props.token, 'token': props.baseConfig?.token || '',
'x-session-id': props.token, 'x-session-id': props.baseConfig?.token || '',
'x-app-code': props.appCode || '' 'x-app-code': props.baseConfig?.appCode || ''
} } as HeadersInit
}); });
const data = await response.json(); const data = await response.json();
if (data.code === 0) { if (data.code === 0) {
......
...@@ -58,18 +58,22 @@ interface Props { ...@@ -58,18 +58,22 @@ interface Props {
disabled?: boolean disabled?: boolean
debug?: boolean debug?: boolean
maxDuration?: number, // 添加最大时长参数 maxDuration?: number, // 添加最大时长参数
token?: string, baseConfig?: {
appCode?: string, token?: string,
apiBaseUrl?: string, appCode?: string,
apiBaseUrl?: string,
}
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
disabled: false, disabled: false,
debug: false, debug: false,
maxDuration: 30, // 默认最大时长为30秒 maxDuration: 30, // 默认最大时长为30秒
token: '', baseConfig: () => ({
appCode: '', token: '',
apiBaseUrl: '', appCode: '',
apiBaseUrl: '',
})
}) })
// 组件事件 // 组件事件
...@@ -408,14 +412,14 @@ const uploadAudioFile = async (audioBlob: Blob): Promise<{filePath: string, dura ...@@ -408,14 +412,14 @@ const uploadAudioFile = async (audioBlob: Blob): Promise<{filePath: string, dura
const formData = new FormData(); const formData = new FormData();
formData.append('file', audioBlob, 'recording.wav'); formData.append('file', audioBlob, 'recording.wav');
formData.append('fileFolder', 'AI_TEMP'); formData.append('fileFolder', 'AI_TEMP');
const { token, appCode } = props.baseConfig || {};
const response = await fetch(`${props.apiBaseUrl}/platformService/upload/v2`, { const response = await fetch(`${props.baseConfig?.apiBaseUrl || ''}/platformService/upload/v2`, {
method: 'POST', method: 'POST',
headers: { headers: {
'x-app-code': props.appCode, 'x-app-code': appCode || '',
'token': props.token, 'token': token || '',
'x-session-id': props.token, 'x-session-id': token || '',
}, } as HeadersInit,
body: formData body: formData
}); });
......
...@@ -58,18 +58,22 @@ interface Props { ...@@ -58,18 +58,22 @@ interface Props {
disabled?: boolean disabled?: boolean
debug?: boolean debug?: boolean
maxDuration?: number, // 添加最大时长参数 maxDuration?: number, // 添加最大时长参数
token?: string, baseConfig?: {
appCode?: string, token?: string,
apiBaseUrl?: string, appCode?: string,
apiBaseUrl?: string,
}
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
disabled: false, disabled: false,
debug: false, debug: false,
maxDuration: 30, // 默认最大时长为30秒 maxDuration: 30, // 默认最大时长为30秒
token: '', baseConfig: () => ({
appCode: '', token: '',
apiBaseUrl: '', appCode: '',
apiBaseUrl: '',
})
}) })
// 组件事件 // 组件事件
...@@ -409,13 +413,14 @@ const uploadAudioFile = async (audioBlob: Blob): Promise<string> => { ...@@ -409,13 +413,14 @@ const uploadAudioFile = async (audioBlob: Blob): Promise<string> => {
const formData = new FormData(); const formData = new FormData();
formData.append('file', audioBlob, 'recording.wav'); formData.append('file', audioBlob, 'recording.wav');
formData.append('fileFolder', 'AI_TEMP'); formData.append('fileFolder', 'AI_TEMP');
const { token, appCode } = props.baseConfig || {};
const response = await fetch(`/agentService/index/audio2txt`, { const response = await fetch(`/agentService/index/audio2txt`, {
method: 'POST', method: 'POST',
headers: { headers: {
'x-app-code': props.appCode, 'x-app-code': appCode || '',
'token': props.token, 'token': token || '',
'x-session-id': props.token, 'x-session-id': token || '',
}, } as HeadersInit,
body: formData body: formData
}); });
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment