refactor(ai-chat): 重构AI聊天消息组件
This commit is contained in:
File diff suppressed because it is too large
Load Diff
226
pages_tool/ai-chat/components/ai-chat-avatar-selector.vue
Normal file
226
pages_tool/ai-chat/components/ai-chat-avatar-selector.vue
Normal file
@@ -0,0 +1,226 @@
|
||||
<template>
|
||||
<view class="avatar-selector-popup" v-if="visible">
|
||||
<view class="avatar-selector-mask" @click="close"></view>
|
||||
<view class="avatar-selector-panel">
|
||||
<view class="avatar-selector-header">
|
||||
<text>更换头像</text>
|
||||
<button class="close-btn" @click="close">
|
||||
<text class="iconfont icon-close"></text>
|
||||
</button>
|
||||
</view>
|
||||
<view class="avatar-selector-content">
|
||||
<view class="current-avatar-preview">
|
||||
<image :src="avatar" mode="aspectFill" show-menu-by-longpress />
|
||||
</view>
|
||||
<view class="avatar-selector-actions">
|
||||
<button class="avatar-select-action" @click="chooseAvatarFromAlbum">
|
||||
<text class="iconfont icon-album"></text>
|
||||
<text>从相册选择</text>
|
||||
</button>
|
||||
<button class="avatar-select-action cancel" @click="close">
|
||||
<text>取消</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* ai-chat-avatar-selector - 头像选择弹窗组件
|
||||
*
|
||||
* Props:
|
||||
* visible: Boolean - 控制显示/隐藏
|
||||
* avatar: String - 当前头像 URL
|
||||
*
|
||||
* Events:
|
||||
* update:visible - 同步关闭状态
|
||||
* avatar-change - 头像变更,参数:新头像 URL
|
||||
*/
|
||||
export default {
|
||||
name: 'AiChatAvatarSelector',
|
||||
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
avatar: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
close() {
|
||||
this.$emit('update:visible', false)
|
||||
},
|
||||
|
||||
chooseAvatarFromAlbum() {
|
||||
this.selectAvatar()
|
||||
},
|
||||
|
||||
selectAvatar() {
|
||||
// #ifdef H5
|
||||
const input = document.createElement('input')
|
||||
input.type = 'file'
|
||||
input.accept = 'image/*'
|
||||
input.style.display = 'none'
|
||||
|
||||
input.onchange = (e) => {
|
||||
const file = e.target.files[0]
|
||||
if (file) {
|
||||
const tempFilePath = URL.createObjectURL(file)
|
||||
const reader = new FileReader()
|
||||
reader.onload = (e) => {
|
||||
const base64 = e.target.result
|
||||
uni.setStorageSync('user_avatar', base64)
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
this.$emit('avatar-change', tempFilePath)
|
||||
this.close()
|
||||
uni.showToast({ title: '头像更换成功', icon: 'success', duration: 1500 })
|
||||
} else {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
|
||||
input.click()
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
sizeType: ['compressed'],
|
||||
sourceType: ['album'],
|
||||
success: (res) => {
|
||||
const tempFilePath = res.tempFilePaths[0]
|
||||
uni.setStorageSync('user_avatar', tempFilePath)
|
||||
this.$emit('avatar-change', tempFilePath)
|
||||
this.close()
|
||||
uni.showToast({ title: '头像更换成功', icon: 'success', duration: 1500 })
|
||||
},
|
||||
fail: (error) => {
|
||||
if (error.errMsg && error.errMsg.includes('deny')) {
|
||||
uni.showToast({ title: '请开启相册权限', icon: 'none', duration: 2000 })
|
||||
}
|
||||
this.close()
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 引入图标字体 */
|
||||
@import url('/common/css/iconfont.css');
|
||||
/* 引入全局变量 */
|
||||
@import '../styles/ai-chat-global.scss';
|
||||
|
||||
.avatar-selector-popup {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 1000;
|
||||
|
||||
.avatar-selector-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.avatar-selector-panel {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background-color: $bg-card;
|
||||
border-radius: $radius-lg;
|
||||
padding: 32rpx;
|
||||
width: calc(100% - 80rpx);
|
||||
max-width: 520rpx;
|
||||
box-shadow: 0 8rpx 36rpx rgba(0, 0, 0, 0.15);
|
||||
box-sizing: border-box;
|
||||
|
||||
.avatar-selector-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24rpx;
|
||||
border-bottom: 2rpx solid #f0f4f8;
|
||||
padding-bottom: 16rpx;
|
||||
|
||||
text {
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
border-radius: 50%;
|
||||
background-color: $bg-main;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
|
||||
.iconfont {
|
||||
font-size: 28rpx;
|
||||
color: $color-text-light;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.avatar-selector-content {
|
||||
.current-avatar-preview {
|
||||
width: 180rpx;
|
||||
height: 180rpx;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
margin: 0 auto 32rpx;
|
||||
box-shadow: $shadow-md;
|
||||
border: 4rpx solid #f0f4f8;
|
||||
|
||||
image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
.avatar-selector-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16rpx;
|
||||
|
||||
.avatar-select-action {
|
||||
padding: 24rpx;
|
||||
border-radius: $radius-lg;
|
||||
font-size: 28rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
border: 2rpx solid #f0f4f8;
|
||||
background-color: $bg-main;
|
||||
color: $color-text;
|
||||
|
||||
&.cancel {
|
||||
background-color: #f8fafc;
|
||||
border-color: #e9edf2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
160
pages_tool/ai-chat/components/ai-chat-emoji-panel.vue
Normal file
160
pages_tool/ai-chat/components/ai-chat-emoji-panel.vue
Normal file
@@ -0,0 +1,160 @@
|
||||
<template>
|
||||
<view class="emoji-popup" v-if="visible">
|
||||
<view class="emoji-mask" @click="hideEmojiPanel"></view>
|
||||
<view class="emoji-panel">
|
||||
<view class="emoji-header">
|
||||
<text>表情</text>
|
||||
<button class="close-btn" @click="hideEmojiPanel">
|
||||
<text>×</text>
|
||||
</button>
|
||||
</view>
|
||||
<view class="emoji-grid">
|
||||
<view
|
||||
v-for="(emoji, index) in emojiList"
|
||||
:key="index"
|
||||
class="emoji-item"
|
||||
@click="insertEmoji(emoji)">
|
||||
<text class="emoji-text">{{ emoji }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* ai-chat-emoji-panel - Emoji 面板组件
|
||||
*
|
||||
* Props:
|
||||
* visible: Boolean - 控制显示/隐藏
|
||||
*
|
||||
* Events:
|
||||
* update:visible - 同步关闭状态
|
||||
* emoji-selected - 选择表情,参数:emoji 字符串
|
||||
*/
|
||||
export default {
|
||||
name: 'AiChatEmojiPanel',
|
||||
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
emojiList: [
|
||||
'😀','😃','😄','😁','😆','😅','🤣','😂','🙂','🙃','😉','😊','😇','🥰','😍','🤩','😘','😗','😚','😋','😛','😜','🤪','😝','🤑','🤗','🤭','🤫','🤔','🤐','🤨','😐','😑','😶','😏','😒','🙄','😬','🤥','😌','😔','😪','🤤','😴','😷','🤒','🤕','🤢','🤮','🤧','🥵','🥶','🥴','😵','🤯','🤠','🥳','😎','🤓','🧐','😕','😟','🙁','😮','😯','😲','😳','🥺','😦','😧','😨','😰','😥','😢','😭','😱','😖','😣','😞','😓','😩','😫','🥱','😤','😡','😠','🤬','😈','👿','💀','💩','👻','👽','🤖','🎃','😺','😸','😹','😻','😼','😽','🙀','😿','😾','👋','🤚','🖐','✋','🖖','👌','🤏','✌','🤞','🤟','🤘','🤙','👈','👉','👆','🖕','👇','☝','👍','👎','✊','👊','🤛','🤜','👏','🙌','👐','🤲','🤝','🙏','✍','💅','🤳','💪','💗','💓','💕','💖','💝','💞','💘','💌','💟','💛','💙','💜','🖤','💔','💢','💣','💥','💫','💦','💨','👁','👀','👅','👄','👂','👃','👶','👦','👧','👨','👩','👴','👵','👱','👲','👳','👴','👵','👶','👼','👸','🎅','🤶','🦸','🦹','🧙','🧚','🧛','🧜','🧝','🧞','🧟','🦄','🐶','🐱','🐭','🐹','🐰','🦊','🐻','🐼','🐨','🐯','🦁','🐮','🐷','🐸','🐵','🙈','🙉','🙊','🐒','🐔','🐧','🐦','🐤','🐣','🐥','🦆','🦅','🦉','🦇','🐺','🐗','🐴','🦄','🐝','🐛','🦋','🐌','🐞','🐜','🦟','🦗','🕷','🦂','🐢','🐍','🦎','🦖','🦕','🐙','🦑','🦐','🦞','🦀','🐡','🐠','🐟','🐬','🐳','🐋','🦈','🐊','🐅','🐆','🦓','🦍','🦧','🐘','🦛','🦏','🐪','🐫','🦒','🦘','🐃','🐂','🐄','🐎','🐖','🐏','🐑','🐐','🐓','🦃','🦚','🦜','🦢','🦩','🕊','🐕','🐩','🐈','🐓','🐇','🐁','🐀','🐿','🦔','🐾','🐉','🐲'
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
hideEmojiPanel() {
|
||||
this.$emit('update:visible', false)
|
||||
},
|
||||
|
||||
insertEmoji(emoji) {
|
||||
this.$emit('emoji-selected', emoji)
|
||||
this.hideEmojiPanel()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 引入图标字体 */
|
||||
@import url('/common/css/iconfont.css');
|
||||
/* 引入全局变量 */
|
||||
@import '../styles/ai-chat-global.scss';
|
||||
|
||||
.emoji-popup {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 999;
|
||||
|
||||
.emoji-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.emoji-panel {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background-color: #fff;
|
||||
border-radius: 24rpx 24rpx 0 0;
|
||||
padding: 0;
|
||||
box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
|
||||
max-height: 55vh;
|
||||
|
||||
.emoji-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16rpx 20rpx;
|
||||
border-bottom: 1rpx solid #e5e5e5;
|
||||
background-color: #f7f7f7;
|
||||
|
||||
text {
|
||||
font-size: 30rpx;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
border-radius: 50%;
|
||||
background-color: transparent;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
|
||||
text {
|
||||
font-size: 36rpx;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.emoji-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(8, 1fr);
|
||||
gap: 8rpx;
|
||||
padding: 20rpx 16rpx;
|
||||
overflow-y: auto;
|
||||
max-height: 45vh;
|
||||
|
||||
.emoji-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
border-radius: 8rpx;
|
||||
background-color: transparent;
|
||||
|
||||
&:active {
|
||||
background-color: #e5e5e5;
|
||||
}
|
||||
|
||||
.emoji-text {
|
||||
font-size: 48rpx;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
234
pages_tool/ai-chat/components/ai-chat-nickname-editor.vue
Normal file
234
pages_tool/ai-chat/components/ai-chat-nickname-editor.vue
Normal file
@@ -0,0 +1,234 @@
|
||||
<template>
|
||||
<view class="nickname-editor-popup" v-if="visible">
|
||||
<view class="nickname-editor-mask" @click="close"></view>
|
||||
<view class="nickname-editor-panel">
|
||||
<view class="nickname-editor-header">
|
||||
<text>修改昵称</text>
|
||||
<button class="close-btn" @click="close">
|
||||
<text class="iconfont icon-close"></text>
|
||||
</button>
|
||||
</view>
|
||||
<view class="nickname-editor-content">
|
||||
<view class="nickname-input-container">
|
||||
<input
|
||||
v-model="tempNickname"
|
||||
class="nickname-input"
|
||||
placeholder="请输入您的新昵称"
|
||||
:maxlength="12"
|
||||
type="text" />
|
||||
</view>
|
||||
<view class="nickname-tip">昵称长度限制1-12个字符,仅自己可见</view>
|
||||
<view class="nickname-editor-actions">
|
||||
<button class="nickname-action-btn cancel" @click="close">
|
||||
<text>取消</text>
|
||||
</button>
|
||||
<button
|
||||
class="nickname-action-btn confirm"
|
||||
:class="{ disabled: !tempNickname.trim() }"
|
||||
:disabled="!tempNickname.trim()"
|
||||
@click="saveNickname">
|
||||
<text>保存</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* ai-chat-nickname-editor - 昵称编辑弹窗组件
|
||||
*
|
||||
* Props:
|
||||
* visible: Boolean - 控制显示/隐藏
|
||||
* nickname: String - 当前昵称
|
||||
*
|
||||
* Events:
|
||||
* update:visible - 同步关闭状态
|
||||
* nickname-change - 昵称变更,参数:新昵称
|
||||
*/
|
||||
export default {
|
||||
name: 'AiChatNicknameEditor',
|
||||
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
nickname: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
tempNickname: ''
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
visible(val) {
|
||||
if (val) {
|
||||
this.tempNickname = this.nickname
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
close() {
|
||||
this.tempNickname = ''
|
||||
this.$emit('update:visible', false)
|
||||
},
|
||||
|
||||
saveNickname() {
|
||||
if (!this.tempNickname.trim()) return
|
||||
const newNickname = this.tempNickname.trim()
|
||||
uni.setStorageSync('user_nickname', newNickname)
|
||||
this.$emit('nickname-change', newNickname)
|
||||
this.close()
|
||||
uni.showToast({ title: '昵称修改成功', icon: 'success', duration: 1500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 引入图标字体 */
|
||||
@import url('/common/css/iconfont.css');
|
||||
/* 引入全局变量 */
|
||||
@import '../styles/ai-chat-global.scss';
|
||||
|
||||
|
||||
.nickname-editor-popup {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 1001;
|
||||
|
||||
.nickname-editor-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.nickname-editor-panel {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background-color: $bg-card;
|
||||
border-radius: $radius-lg;
|
||||
padding: 24rpx 32rpx;
|
||||
width: calc(100% - 80rpx);
|
||||
max-width: 520rpx;
|
||||
box-shadow: 0 8rpx 36rpx rgba(0, 0, 0, 0.15);
|
||||
box-sizing: border-box;
|
||||
|
||||
.nickname-editor-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24rpx;
|
||||
border-bottom: 2rpx solid #f0f4f8;
|
||||
padding-bottom: 16rpx;
|
||||
|
||||
text {
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
border-radius: 50%;
|
||||
background-color: $bg-main;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
|
||||
.iconfont {
|
||||
font-size: 28rpx;
|
||||
color: $color-text-light;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.nickname-editor-content {
|
||||
.nickname-input-container {
|
||||
margin-bottom: 24rpx;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
|
||||
.nickname-input {
|
||||
width: 100%;
|
||||
height: 96rpx;
|
||||
padding: 0 24rpx;
|
||||
border-radius: $radius-lg;
|
||||
border: 2rpx solid #f0f4f8;
|
||||
font-size: 28rpx;
|
||||
color: $color-text;
|
||||
background-color: $bg-main;
|
||||
box-sizing: border-box;
|
||||
|
||||
&:focus {
|
||||
border-color: $color-primary;
|
||||
box-shadow: 0 0 0 4rpx rgba(108, 142, 191, 0.1);
|
||||
}
|
||||
|
||||
&::placeholder {
|
||||
color: $color-text-light;
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.nickname-tip {
|
||||
font-size: 24rpx;
|
||||
color: $color-text-light;
|
||||
margin-bottom: 32rpx;
|
||||
display: block;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.nickname-editor-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 16rpx;
|
||||
|
||||
.nickname-action-btn {
|
||||
padding: 16rpx 32rpx;
|
||||
border-radius: $radius-lg;
|
||||
font-size: 28rpx;
|
||||
font-weight: 500;
|
||||
border: none;
|
||||
|
||||
&.cancel {
|
||||
background-color: $bg-main;
|
||||
color: $color-text-light;
|
||||
}
|
||||
|
||||
&.confirm {
|
||||
background-color: $color-primary;
|
||||
color: white;
|
||||
box-shadow: 0 4rpx 12rpx rgba(108, 142, 191, 0.2);
|
||||
|
||||
&.disabled {
|
||||
background-color: $color-primary-light;
|
||||
opacity: 0.7;
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
400
pages_tool/ai-chat/components/ai-chat-search.vue
Normal file
400
pages_tool/ai-chat/components/ai-chat-search.vue
Normal file
@@ -0,0 +1,400 @@
|
||||
<template>
|
||||
<view class="ai-chat-search">
|
||||
<!-- 搜索入口按钮(浮动在消息区右上角) -->
|
||||
<view class="search-entrance" v-if="!showSearchBar" @click="toggleSearch">
|
||||
<text class="iconfont icon-sousuo search-entrance-icon"></text>
|
||||
<text class="search-entrance-label">搜索</text>
|
||||
</view>
|
||||
|
||||
<!-- 搜索浮条 -->
|
||||
<view class="search-bar" v-if="showSearchBar">
|
||||
<view class="search-bar-inner">
|
||||
<view class="search-bar-input-wrap">
|
||||
<text class="iconfont icon-sousuo search-bar-icon"></text>
|
||||
<input
|
||||
class="search-bar-input"
|
||||
v-model="searchKeyword"
|
||||
placeholder="搜索聊天记录"
|
||||
:focus="true"
|
||||
@input="onSearchInput"
|
||||
@confirm="doSearch" />
|
||||
<text class="search-bar-clear" v-if="searchKeyword" @click.stop="clearSearch">✕</text>
|
||||
</view>
|
||||
<view class="search-bar-actions" v-if="searchResults.length > 0">
|
||||
<text class="search-bar-count">{{ searchResultIndex + 1 }}/{{ searchResults.length }}</text>
|
||||
<view class="search-bar-nav-group">
|
||||
<text class="search-bar-nav" :class="{ disabled: searchResultIndex <= 0 }" @click="scrollToPrevResult">▲</text>
|
||||
<text class="search-bar-nav" :class="{ disabled: searchResultIndex >= searchResults.length - 1 }" @click="scrollToNextResult">▼</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="search-bar-close" @click="closeSearch">完成</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* ai-chat-search - 聊天记录搜索组件
|
||||
*
|
||||
* Props:
|
||||
* messages: Array - 原始消息列表
|
||||
*
|
||||
* Events:
|
||||
* scroll-to: (messageKey: string) => void - 请求父组件滚动到指定消息
|
||||
* active-change: (isActive: boolean) => void - 搜索激活状态变化
|
||||
* result-change: (filteredIndex: number) => void - 当前匹配结果在过滤后数组中的索引
|
||||
* keyword-change: (keyword: string) => void - 搜索关键词变化(用于高亮)
|
||||
*/
|
||||
export default {
|
||||
name: 'AiChatSearch',
|
||||
|
||||
props: {
|
||||
messages: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
showSearchBar: false,
|
||||
searchKeyword: '',
|
||||
searchResults: [], // 匹配结果在过滤后数组中的索引列表
|
||||
searchResultIndex: -1, // 当前在 searchResults 中的位置
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
// 过滤后的消息列表(与 v-for 保持一致)
|
||||
filteredMessages() {
|
||||
return this.messages.filter(
|
||||
msg => msg.type === 'loading' || (msg.content && msg.content.trim() !== '')
|
||||
)
|
||||
},
|
||||
|
||||
// 当前匹配结果在过滤后数组中的索引
|
||||
searchResultFilteredIndex() {
|
||||
if (this.searchResultIndex < 0 || this.searchResultIndex >= this.searchResults.length) {
|
||||
return -1
|
||||
}
|
||||
return this.searchResults[this.searchResultIndex]
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
// 生成消息唯一 key(与父组件 getMessageKey 保持一致)
|
||||
getMessageKey(message, index) {
|
||||
return `msg-${message.id || message.tempId || index}-${message.role}`
|
||||
},
|
||||
|
||||
toggleSearch() {
|
||||
this.showSearchBar = !this.showSearchBar
|
||||
if (!this.showSearchBar) {
|
||||
this.clearSearch()
|
||||
}
|
||||
this.$emit('active-change', this.showSearchBar)
|
||||
},
|
||||
|
||||
closeSearch() {
|
||||
this.showSearchBar = false
|
||||
this.clearSearch()
|
||||
this.$emit('active-change', false)
|
||||
},
|
||||
|
||||
clearSearch() {
|
||||
this.searchKeyword = ''
|
||||
this.searchResults = []
|
||||
this.searchResultIndex = -1
|
||||
this.$emit('result-change', -1)
|
||||
this.$emit('keyword-change', '')
|
||||
},
|
||||
|
||||
onSearchInput(e) {
|
||||
const val = e.detail ? e.detail.value : e
|
||||
if (val) {
|
||||
this.searchKeyword = val
|
||||
this.doSearch()
|
||||
} else {
|
||||
this.clearSearch()
|
||||
}
|
||||
},
|
||||
|
||||
doSearch() {
|
||||
const keyword = this.searchKeyword.trim().toLowerCase()
|
||||
if (!keyword) {
|
||||
this.searchResults = []
|
||||
this.searchResultIndex = -1
|
||||
this.$emit('result-change', -1)
|
||||
this.$emit('keyword-change', '')
|
||||
return
|
||||
}
|
||||
|
||||
const results = []
|
||||
this.filteredMessages.forEach((msg, index) => {
|
||||
const content = (msg.content || '').toLowerCase()
|
||||
if (content.includes(keyword)) {
|
||||
results.push(index)
|
||||
}
|
||||
})
|
||||
|
||||
this.searchResults = results
|
||||
this.searchResultIndex = results.length > 0 ? 0 : -1
|
||||
|
||||
const filteredIdx = results.length > 0 ? results[0] : -1
|
||||
this.$emit('result-change', filteredIdx)
|
||||
this.$emit('keyword-change', this.searchKeyword)
|
||||
|
||||
if (results.length > 0) {
|
||||
this.$nextTick(() => {
|
||||
this._emitScrollTo(filteredIdx)
|
||||
})
|
||||
} else {
|
||||
uni.showToast({ title: '未找到匹配结果', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
_emitScrollTo(filteredIdx) {
|
||||
const message = this.filteredMessages[filteredIdx]
|
||||
if (message) {
|
||||
this.$emit('scroll-to', this.getMessageKey(message, filteredIdx))
|
||||
}
|
||||
},
|
||||
|
||||
scrollToSearchResult(index) {
|
||||
if (index < 0 || index >= this.searchResults.length) return
|
||||
this.searchResultIndex = index
|
||||
const filteredIdx = this.searchResults[index]
|
||||
this.$emit('result-change', filteredIdx)
|
||||
this._emitScrollTo(filteredIdx)
|
||||
},
|
||||
|
||||
scrollToPrevResult() {
|
||||
const idx = this.searchResultIndex - 1
|
||||
if (idx >= 0) {
|
||||
this.scrollToSearchResult(idx)
|
||||
} else {
|
||||
uni.showToast({ title: '已到顶部', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
scrollToNextResult() {
|
||||
const idx = this.searchResultIndex + 1
|
||||
if (idx < this.searchResults.length) {
|
||||
this.scrollToSearchResult(idx)
|
||||
} else {
|
||||
uni.showToast({ title: '已到底部', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
// 关键词高亮(用于用户消息 rich-text)
|
||||
highlightContent(content) {
|
||||
if (!this.searchKeyword || !content) return content
|
||||
if (content.toLowerCase().indexOf(this.searchKeyword.toLowerCase()) === -1) return content
|
||||
return this._wrapHighlight(content, this.searchKeyword)
|
||||
},
|
||||
|
||||
// AI 消息渲染(含关键词高亮)
|
||||
getAIDisplayContent(content) {
|
||||
if (!this.searchKeyword || !content) {
|
||||
return this.parseMarkdown ? this.parseMarkdown(content) : content
|
||||
}
|
||||
if (content.toLowerCase().indexOf(this.searchKeyword.toLowerCase()) === -1) {
|
||||
return this.parseMarkdown ? this.parseMarkdown(content) : content
|
||||
}
|
||||
const mdHtml = this.parseMarkdown ? this.parseMarkdown(content) : content
|
||||
return this._wrapHighlightInHtml(mdHtml, this.searchKeyword)
|
||||
},
|
||||
|
||||
_wrapHighlight(text, keyword) {
|
||||
if (!keyword || !text) return text
|
||||
const parts = text.split(new RegExp('(' + this._escapeRegExp(keyword) + ')', 'gi'))
|
||||
return parts.map(part => {
|
||||
if (part.toLowerCase() === keyword.toLowerCase()) {
|
||||
return `<span style="background:#ffe066;color:#333;padding:0 2rpx;border-radius:4rpx;">${part}</span>`
|
||||
}
|
||||
return part
|
||||
}).join('')
|
||||
},
|
||||
|
||||
_wrapHighlightInHtml(html, keyword) {
|
||||
if (!keyword || !html) return html
|
||||
const escaped = this._escapeRegExp(keyword)
|
||||
return html.replace(/(>|^)([^<]+)(?=<|$)/g, (match, prefix, text) => {
|
||||
if (!text) return match
|
||||
const highlighted = text.replace(
|
||||
new RegExp('(' + escaped + ')', 'gi'),
|
||||
'<span style="background:#ffe066;color:#333;padding:0 2rpx;border-radius:4rpx;">$1</span>'
|
||||
)
|
||||
return prefix + highlighted
|
||||
})
|
||||
},
|
||||
|
||||
_escapeRegExp(str) {
|
||||
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 引入图标字体 */
|
||||
@import url('/common/css/iconfont.css');
|
||||
/* 引入全局变量 */
|
||||
@import '../styles/ai-chat-global.scss';
|
||||
|
||||
.ai-chat-search {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
// 搜索入口按钮
|
||||
.search-entrance {
|
||||
position: absolute;
|
||||
top: 88rpx;
|
||||
right: 16rpx;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4rpx;
|
||||
padding: 8rpx 16rpx;
|
||||
border-radius: 28rpx;
|
||||
background: rgba(255, 255, 255, 0.92);
|
||||
backdrop-filter: blur(8rpx);
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
|
||||
|
||||
.search-entrance-icon {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.search-entrance-label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索浮条
|
||||
.search-bar {
|
||||
position: relative;
|
||||
z-index: 20;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10rpx 16rpx;
|
||||
background: #f0f2f5;
|
||||
border-top: 1rpx solid #e0e4ea;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
|
||||
flex-shrink: 0;
|
||||
|
||||
.search-bar-inner {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.search-bar-input-wrap {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
border-radius: 10rpx;
|
||||
padding: 0 12rpx;
|
||||
height: 68rpx;
|
||||
border: 2rpx solid #d0d5dd;
|
||||
|
||||
.search-bar-icon {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
margin-right: 8rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.search-bar-input {
|
||||
flex: 1;
|
||||
height: 68rpx;
|
||||
font-size: 27rpx;
|
||||
background: transparent;
|
||||
border: none;
|
||||
outline: none;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.search-bar-clear {
|
||||
font-size: 26rpx;
|
||||
color: #c0c4cc;
|
||||
flex-shrink: 0;
|
||||
padding: 0 4rpx;
|
||||
line-height: 1;
|
||||
|
||||
&:active {
|
||||
color: #888;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.search-bar-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6rpx;
|
||||
flex-shrink: 0;
|
||||
|
||||
.search-bar-count {
|
||||
font-size: 24rpx;
|
||||
color: #555;
|
||||
font-weight: 500;
|
||||
min-width: 48rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.search-bar-nav-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3rpx;
|
||||
}
|
||||
|
||||
.search-bar-nav {
|
||||
font-size: 16rpx;
|
||||
color: #555;
|
||||
width: 38rpx;
|
||||
height: 28rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #fff;
|
||||
border-radius: 6rpx;
|
||||
line-height: 1;
|
||||
box-shadow: 0 1rpx 4rpx rgba(0, 0, 0, 0.06);
|
||||
|
||||
&:active {
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
color: #ccc;
|
||||
background: #f8f8f8;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.search-bar-close {
|
||||
font-size: 26rpx;
|
||||
color: #07c160;
|
||||
font-weight: 600;
|
||||
padding: 6rpx 4rpx;
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
|
||||
&:active {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
276
pages_tool/ai-chat/components/ai-chat-tools-panel.vue
Normal file
276
pages_tool/ai-chat/components/ai-chat-tools-panel.vue
Normal file
@@ -0,0 +1,276 @@
|
||||
<template>
|
||||
<view class="tools-popup" v-if="visible">
|
||||
<view class="tools-mask" @click="hideToolsPanel"></view>
|
||||
<view class="tools-panel">
|
||||
<view class="tools-header">
|
||||
<text>更多功能</text>
|
||||
<button class="close-btn" @click="hideToolsPanel">
|
||||
<text class="iconfont icon-close"></text>
|
||||
</button>
|
||||
</view>
|
||||
<view class="tools-grid">
|
||||
<view class="tool-item" @click="selectImage">
|
||||
<view class="tool-icon">
|
||||
<text class="iconfont icon-image"></text>
|
||||
</view>
|
||||
<text class="tool-text">图片</text>
|
||||
</view>
|
||||
<view class="tool-item" @click="selectFile">
|
||||
<view class="tool-icon">
|
||||
<text class="iconfont icon-file"></text>
|
||||
</view>
|
||||
<text class="tool-text">文件</text>
|
||||
</view>
|
||||
<view class="tool-item" @click="startRecord">
|
||||
<view class="tool-icon">
|
||||
<text class="iconfont icon-voice"></text>
|
||||
</view>
|
||||
<text class="tool-text">语音</text>
|
||||
</view>
|
||||
<view class="tool-item" @click="selectLocation">
|
||||
<view class="tool-icon">
|
||||
<text class="iconfont icon-location"></text>
|
||||
</view>
|
||||
<text class="tool-text">位置</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* ai-chat-tools-panel - 更多工具面板组件
|
||||
*
|
||||
* Props:
|
||||
* visible: Boolean - 控制显示/隐藏
|
||||
*
|
||||
* Events:
|
||||
* update:visible - 同步关闭状态
|
||||
* image-selected - 选择图片,参数:图片消息对象
|
||||
* file-selected - 选择文件,参数:文件消息对象
|
||||
* voice-start - 开始语音
|
||||
* location-selected - 选择位置,参数:位置消息对象
|
||||
*/
|
||||
export default {
|
||||
name: 'AiChatToolsPanel',
|
||||
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
messageId: 0
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
hideToolsPanel() {
|
||||
this.$emit('update:visible', false)
|
||||
},
|
||||
|
||||
selectImage() {
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
sizeType: ['compressed'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: (res) => {
|
||||
const imageMessage = {
|
||||
id: ++this.messageId,
|
||||
role: 'user',
|
||||
type: 'image',
|
||||
content: '',
|
||||
imageUrl: res.tempFilePaths[0],
|
||||
timestamp: Date.now()
|
||||
}
|
||||
this.hideToolsPanel()
|
||||
this.$emit('image-selected', imageMessage)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
selectFile() {
|
||||
// #ifdef H5
|
||||
const input = document.createElement('input')
|
||||
input.type = 'file'
|
||||
input.accept = '*/*'
|
||||
input.onchange = (e) => {
|
||||
const file = e.target.files[0]
|
||||
if (file) {
|
||||
const fileMessage = {
|
||||
id: ++this.messageId,
|
||||
role: 'user',
|
||||
type: 'file',
|
||||
content: '',
|
||||
fileName: file.name,
|
||||
fileSize: file.size,
|
||||
fileType: file.type,
|
||||
timestamp: Date.now()
|
||||
}
|
||||
this.hideToolsPanel()
|
||||
this.$emit('file-selected', fileMessage)
|
||||
}
|
||||
}
|
||||
input.click()
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
uni.chooseFile({
|
||||
count: 1,
|
||||
success: (res) => {
|
||||
const file = res.tempFiles[0]
|
||||
const fileMessage = {
|
||||
id: ++this.messageId,
|
||||
role: 'user',
|
||||
type: 'file',
|
||||
content: '',
|
||||
fileName: file.name,
|
||||
fileSize: file.size,
|
||||
fileType: file.type,
|
||||
url: file.path,
|
||||
timestamp: Date.now()
|
||||
}
|
||||
this.hideToolsPanel()
|
||||
this.$emit('file-selected', fileMessage)
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
},
|
||||
|
||||
startRecord() {
|
||||
this.$emit('voice-start')
|
||||
this.hideToolsPanel()
|
||||
},
|
||||
|
||||
selectLocation() {
|
||||
uni.chooseLocation({
|
||||
success: (res) => {
|
||||
const locationMessage = {
|
||||
id: ++this.messageId,
|
||||
role: 'user',
|
||||
type: 'location',
|
||||
content: '',
|
||||
latitude: res.latitude,
|
||||
longitude: res.longitude,
|
||||
address: res.address,
|
||||
name: res.name,
|
||||
timestamp: Date.now()
|
||||
}
|
||||
this.hideToolsPanel()
|
||||
this.$emit('location-selected', locationMessage)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
/* 引入图标字体 */
|
||||
@import url('/common/css/iconfont.css');
|
||||
/* 引入全局变量 */
|
||||
@import '../styles/ai-chat-global.scss';
|
||||
|
||||
.tools-popup {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 999;
|
||||
|
||||
.tools-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.tools-panel {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background-color: $bg-card;
|
||||
border-radius: $radius-lg $radius-lg 0 0;
|
||||
padding: 32rpx;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.08);
|
||||
|
||||
.tools-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 32rpx;
|
||||
border-bottom: 2rpx solid #f0f4f8;
|
||||
padding-bottom: 16rpx;
|
||||
|
||||
text {
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
border-radius: 50%;
|
||||
background-color: $bg-main;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
|
||||
.iconfont {
|
||||
font-size: 28rpx;
|
||||
color: $color-text-light;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tools-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 24rpx;
|
||||
|
||||
.tool-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 24rpx 16rpx;
|
||||
border-radius: $radius-md;
|
||||
background-color: $bg-main;
|
||||
|
||||
.tool-icon {
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
border-radius: 50%;
|
||||
background-color: $bg-card;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 16rpx;
|
||||
box-shadow: $shadow-sm;
|
||||
|
||||
.iconfont {
|
||||
font-size: 48rpx;
|
||||
color: $color-primary;
|
||||
}
|
||||
}
|
||||
|
||||
.tool-text {
|
||||
font-size: 24rpx;
|
||||
color: $color-text;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
241
pages_tool/ai-chat/components/ai-chat-voice-panel.vue
Normal file
241
pages_tool/ai-chat/components/ai-chat-voice-panel.vue
Normal file
@@ -0,0 +1,241 @@
|
||||
<template>
|
||||
<view class="voice-popup" v-if="visible">
|
||||
<view class="voice-mask" @click="hideVoicePanel"></view>
|
||||
<view class="voice-input-panel">
|
||||
<view class="voice-header">
|
||||
<text>语音输入</text>
|
||||
<button class="close-btn" @click="hideVoicePanel">
|
||||
<text class="iconfont icon-close"></text>
|
||||
</button>
|
||||
</view>
|
||||
<view class="voice-content">
|
||||
<view class="voice-wave" :class="{ recording: voiceInputing }">
|
||||
<view
|
||||
v-for="i in 8"
|
||||
:key="i"
|
||||
class="wave-bar"
|
||||
:style="{ animationDelay: (i * 0.1) + 's' }"></view>
|
||||
</view>
|
||||
<text class="voice-tip">{{ voiceInputing ? '正在录音,松开结束' : '点击开始录音' }}</text>
|
||||
</view>
|
||||
<view class="voice-actions">
|
||||
<button class="voice-btn" @click="toggleVoiceInput">
|
||||
<text class="iconfont" :class="voiceInputing ? 'icon-stop' : 'icon-voice'"></text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* ai-chat-voice-panel - 语音输入面板组件
|
||||
*
|
||||
* Props:
|
||||
* visible: Boolean - 控制显示/隐藏
|
||||
*
|
||||
* Events:
|
||||
* update:visible - 同步关闭状态
|
||||
* close - 请求关闭面板
|
||||
*/
|
||||
export default {
|
||||
name: 'AiChatVoicePanel',
|
||||
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
voiceInputing: false
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
visible(val) {
|
||||
if (!val) {
|
||||
this.voiceInputing = false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
hideVoicePanel() {
|
||||
this.voiceInputing = false
|
||||
this.$emit('update:visible', false)
|
||||
this.$emit('close')
|
||||
},
|
||||
|
||||
toggleVoiceInput() {
|
||||
this.voiceInputing = !this.voiceInputing
|
||||
if (this.voiceInputing) {
|
||||
this.startVoiceInput()
|
||||
} else {
|
||||
this.stopVoiceInput()
|
||||
}
|
||||
},
|
||||
|
||||
startVoiceInput() {
|
||||
// #ifdef H5
|
||||
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
||||
navigator.mediaDevices.getUserMedia({ audio: true })
|
||||
.then(stream => {
|
||||
// 录音中,可扩展实时转文字
|
||||
})
|
||||
.catch(error => {
|
||||
uni.showToast({ title: '语音输入失败', icon: 'none' })
|
||||
this.voiceInputing = false
|
||||
})
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
|
||||
stopVoiceInput() {
|
||||
this.voiceInputing = false
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
/* 引入图标字体 */
|
||||
@import url('/common/css/iconfont.css');
|
||||
/* 引入全局变量 */
|
||||
@import '../styles/ai-chat-global.scss';
|
||||
|
||||
.voice-popup {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 999;
|
||||
|
||||
.voice-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.voice-input-panel {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background-color: $bg-card;
|
||||
border-radius: $radius-lg;
|
||||
padding: 48rpx;
|
||||
width: 60%;
|
||||
max-width: 520rpx;
|
||||
box-shadow: 0 8rpx 36rpx rgba(0, 0, 0, 0.15);
|
||||
|
||||
.voice-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 32rpx;
|
||||
border-bottom: 2rpx solid #f0f4f8;
|
||||
padding-bottom: 16rpx;
|
||||
|
||||
text {
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
color: $color-text;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
border-radius: 50%;
|
||||
background-color: $bg-main;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
|
||||
.iconfont {
|
||||
font-size: 28rpx;
|
||||
color: $color-text-light;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.voice-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-bottom: 48rpx;
|
||||
|
||||
.voice-wave {
|
||||
width: 280rpx;
|
||||
height: 160rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 24rpx;
|
||||
|
||||
&.recording .wave-bar {
|
||||
animation: wave 1.2s infinite ease-in-out;
|
||||
}
|
||||
|
||||
.wave-bar {
|
||||
width: 8rpx;
|
||||
height: 40rpx;
|
||||
margin: 0 4rpx;
|
||||
background-color: $color-primary;
|
||||
border-radius: 4rpx;
|
||||
animation: none;
|
||||
|
||||
&:nth-child(1) { height: 60rpx; animation-delay: 0s; }
|
||||
&:nth-child(2) { height: 90rpx; animation-delay: 0.1s; }
|
||||
&:nth-child(3) { height: 50rpx; animation-delay: 0.2s; }
|
||||
&:nth-child(4) { height: 120rpx; animation-delay: 0.3s; }
|
||||
&:nth-child(5) { height: 70rpx; animation-delay: 0.4s; }
|
||||
&:nth-child(6) { height: 100rpx; animation-delay: 0.5s; }
|
||||
&:nth-child(7) { height: 80rpx; animation-delay: 0.6s; }
|
||||
&:nth-child(8) { height: 40rpx; animation-delay: 0.7s; }
|
||||
}
|
||||
}
|
||||
|
||||
.voice-tip {
|
||||
font-size: 28rpx;
|
||||
color: $color-text-light;
|
||||
}
|
||||
}
|
||||
|
||||
.voice-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
.voice-btn {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 50%;
|
||||
background-color: $color-primary;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 8rpx 24rpx rgba(108, 142, 191, 0.3);
|
||||
border: none;
|
||||
|
||||
.iconfont {
|
||||
font-size: 56rpx;
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes wave {
|
||||
0%, 100% { transform: scaleY(0.5); }
|
||||
50% { transform: scaleY(1.2); }
|
||||
}
|
||||
</style>
|
||||
13
pages_tool/ai-chat/styles/ai-chat-global.scss
Normal file
13
pages_tool/ai-chat/styles/ai-chat-global.scss
Normal file
@@ -0,0 +1,13 @@
|
||||
/* 全局变量:高级低饱和配色 */
|
||||
$bg-main: #f5f7fa;
|
||||
$bg-card: #ffffff;
|
||||
$color-primary: #6c8ebf;
|
||||
$color-primary-light: #8a9fb8;
|
||||
$color-user: #8675a9;
|
||||
$color-text: #4e5969;
|
||||
$color-text-light: #8492a6;
|
||||
$shadow-sm: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
|
||||
$shadow-md: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
|
||||
$radius-sm: 12rpx;
|
||||
$radius-md: 24rpx;
|
||||
$radius-lg: 36rpx;
|
||||
Reference in New Issue
Block a user