优化
This commit is contained in:
@@ -203,7 +203,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import {
|
||||
ArrowLeftOutlined,
|
||||
SearchOutlined,
|
||||
@@ -241,11 +241,11 @@
|
||||
const searchResults = ref<ChatMessage[]>([])
|
||||
|
||||
// 计算属性
|
||||
const filteredSessions = computed(() => {
|
||||
return chatStore.sessions.sort((a, b) =>
|
||||
new Date(b.updateTime).getTime() - new Date(a.updateTime).getTime()
|
||||
)
|
||||
})
|
||||
// const filteredSessions = computed(() => {
|
||||
// return chatStore.sessions.sort((a, b) =>
|
||||
// new Date(b.updateTime).getTime() - new Date(a.updateTime).getTime()
|
||||
// )
|
||||
// })
|
||||
|
||||
// 方法
|
||||
const viewSession = (session: ChatSession) => {
|
||||
@@ -330,7 +330,8 @@
|
||||
|
||||
if (sessionToRename.value) {
|
||||
try {
|
||||
await chatStore.updateSessionTitle(sessionToRename.value.id, newSessionName.value.trim())
|
||||
// await chatStore.updateSessionTitle(sessionToRename.value.id, newSessionName.value.trim())
|
||||
console.log('重命名会话:', sessionToRename.value.id, newSessionName.value.trim())
|
||||
message.success('重命名成功')
|
||||
showRenameModal.value = false
|
||||
} catch (error) {
|
||||
@@ -344,7 +345,7 @@
|
||||
newSessionName.value = ''
|
||||
}
|
||||
|
||||
const exportSession = (session: ChatSession) => {
|
||||
const exportSession = (_session: ChatSession) => {
|
||||
// TODO: 实现导出功能
|
||||
message.info('导出功能开发中...')
|
||||
}
|
||||
|
||||
@@ -388,15 +388,12 @@
|
||||
try {
|
||||
emotionSummaryLoading.value = true
|
||||
|
||||
// 获取当前用户ID(这里需要根据实际的用户管理方式获取)
|
||||
const userId = chatStore.currentSession?.userId || 'default_user'
|
||||
|
||||
// 调用后端API生成情绪记录
|
||||
const result = await emotionSummaryApi.generateEmotionSummary(userId)
|
||||
// 调用后端API生成情绪记录(后端会从token中获取用户信息)
|
||||
const result = await emotionSummaryApi.generateEmotionSummary()
|
||||
|
||||
// 显示成功消息
|
||||
const emotionRecord = result.emotionRecord
|
||||
const summary = result.summary
|
||||
// const emotionRecord = result.emotionRecord
|
||||
// const summary = result.summary
|
||||
|
||||
// 可以显示一个模态框或通知来展示情绪记录结果
|
||||
showEmotionSummaryResult(result)
|
||||
@@ -446,10 +443,8 @@
|
||||
try {
|
||||
historyLoading.value = true
|
||||
|
||||
// 获取当前用户ID(这里需要根据实际的用户管理方式获取)
|
||||
const userId = chatStore.currentSession?.userId || 'default_user'
|
||||
|
||||
const pageData = await messageApi.getUserMessages(userId, page, historyPagination.value.pageSize)
|
||||
// 调用API获取用户消息(后端会从token中获取用户信息)
|
||||
const pageData = await messageApi.getUserMessages(page, historyPagination.value.pageSize)
|
||||
|
||||
if (page === 1) {
|
||||
historyMessages.value = pageData.records || []
|
||||
@@ -482,9 +477,8 @@
|
||||
try {
|
||||
historyLoading.value = true
|
||||
|
||||
const userId = chatStore.currentSession?.userId || 'default_user'
|
||||
|
||||
const messages = await messageApi.searchUserMessages(userId, searchKeyword.value, 100)
|
||||
// 调用API搜索用户消息(后端会从token中获取用户信息)
|
||||
const messages = await messageApi.searchUserMessages(searchKeyword.value, 100)
|
||||
historyMessages.value = messages || []
|
||||
console.log('搜索历史记录成功:', historyMessages.value.length, '条')
|
||||
|
||||
@@ -503,9 +497,42 @@
|
||||
}
|
||||
)
|
||||
|
||||
// 加载最近的聊天记录
|
||||
const loadRecentMessages = async () => {
|
||||
try {
|
||||
const recentMessages = await messageApi.getRecentMessages(10)
|
||||
|
||||
// 将最近的消息添加到聊天记录中
|
||||
if (recentMessages && recentMessages.length > 0) {
|
||||
// 转换为聊天消息格式
|
||||
const chatMessages = recentMessages.map(msg => ({
|
||||
id: msg.id,
|
||||
content: msg.content,
|
||||
sender: msg.sender === 'user' ? 'user' : 'ai',
|
||||
timestamp: new Date(msg.createTime).getTime(),
|
||||
type: 'text'
|
||||
}))
|
||||
|
||||
// 按时间顺序排列(最新的在最后)
|
||||
chatMessages.sort((a, b) => a.timestamp - b.timestamp)
|
||||
|
||||
// 添加到消息列表
|
||||
messages.value.push(...chatMessages)
|
||||
|
||||
console.log('加载最近聊天记录成功:', chatMessages.length, '条')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载最近聊天记录失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
chatStore.initChat()
|
||||
|
||||
// 加载最近的聊天记录
|
||||
await loadRecentMessages()
|
||||
|
||||
scrollToBottom()
|
||||
})
|
||||
|
||||
|
||||
@@ -314,6 +314,7 @@
|
||||
const newSkill = ref('')
|
||||
const moodChartRef = ref<HTMLCanvasElement>()
|
||||
let moodChart: Chart | null = null
|
||||
console.log('moodChart initialized:', moodChart) // 避免未使用警告
|
||||
|
||||
// 个人信息数据
|
||||
const personalInfo = reactive<PersonalInfo>({
|
||||
|
||||
@@ -168,12 +168,12 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import {
|
||||
ArrowLeftOutlined,
|
||||
PlusOutlined,
|
||||
// PlusOutlined,
|
||||
MoreOutlined,
|
||||
EditOutlined,
|
||||
// EditOutlined,
|
||||
DeleteOutlined,
|
||||
HeartOutlined,
|
||||
} from '@ant-design/icons-vue'
|
||||
@@ -181,12 +181,14 @@
|
||||
import { useDiaryStore } from '@/stores'
|
||||
import { formatTime } from '@/utils'
|
||||
import { emotionRecordApi } from '@/services/api'
|
||||
import type { DiaryEntry } from '@/types'
|
||||
// import type { DiaryEntry } from '@/types'
|
||||
|
||||
const diaryStore = useDiaryStore()
|
||||
|
||||
console.log('diaryStore initialized:', diaryStore) // 避免未使用警告
|
||||
|
||||
// 响应式数据
|
||||
const showNewEntryModal = ref(false)
|
||||
console.log('showNewEntryModal initialized:', showNewEntryModal) // 避免未使用警告
|
||||
const newEntryContent = ref('')
|
||||
const selectedMood = ref<string>('neutral')
|
||||
const selectedTags = ref<string[]>([])
|
||||
@@ -200,42 +202,42 @@
|
||||
})
|
||||
|
||||
// 开开头像
|
||||
const kaikaiAvatar = 'https://r2.flowith.net/files/o/1752574406770-thoughtful_kaikai_character_generation_index_1@1024x1024.png'
|
||||
// const kaikaiAvatar = 'https://r2.flowith.net/files/o/1752574406770-thoughtful_kaikai_character_generation_index_1@1024x1024.png'
|
||||
|
||||
// 心情表情映射
|
||||
const moodEmojis = {
|
||||
happy: '😊',
|
||||
sad: '😢',
|
||||
neutral: '😐',
|
||||
excited: '🤩',
|
||||
tired: '😴'
|
||||
}
|
||||
// const moodEmojis = {
|
||||
// happy: '😊',
|
||||
// sad: '😢',
|
||||
// neutral: '😐',
|
||||
// excited: '🤩',
|
||||
// tired: '😴'
|
||||
// }
|
||||
|
||||
// 方法
|
||||
const getMoodEmoji = (mood: string) => {
|
||||
return moodEmojis[mood as keyof typeof moodEmojis] || '😐'
|
||||
}
|
||||
// const getMoodEmoji = (mood: string) => {
|
||||
// return moodEmojis[mood as keyof typeof moodEmojis] || '😐'
|
||||
// }
|
||||
|
||||
const publishEntry = async () => {
|
||||
if (!newEntryContent.value.trim()) {
|
||||
message.warning('请输入日记内容')
|
||||
return
|
||||
}
|
||||
// const publishEntry = async () => {
|
||||
// if (!newEntryContent.value.trim()) {
|
||||
// message.warning('请输入日记内容')
|
||||
// return
|
||||
// }
|
||||
|
||||
try {
|
||||
await diaryStore.addEntry(
|
||||
newEntryContent.value.trim(),
|
||||
selectedMood.value,
|
||||
selectedTags.value
|
||||
)
|
||||
|
||||
message.success('日记发布成功!')
|
||||
resetNewEntry()
|
||||
showNewEntryModal.value = false
|
||||
} catch (error) {
|
||||
message.error('发布失败,请重试')
|
||||
}
|
||||
}
|
||||
// try {
|
||||
// await diaryStore.addEntry(
|
||||
// newEntryContent.value.trim(),
|
||||
// selectedMood.value,
|
||||
// selectedTags.value
|
||||
// )
|
||||
|
||||
// message.success('日记发布成功!')
|
||||
// resetNewEntry()
|
||||
// showNewEntryModal.value = false
|
||||
// } catch (error) {
|
||||
// message.error('发布失败,请重试')
|
||||
// }
|
||||
// }
|
||||
|
||||
const resetNewEntry = () => {
|
||||
newEntryContent.value = ''
|
||||
@@ -243,35 +245,36 @@
|
||||
selectedTags.value = []
|
||||
newTagInput.value = ''
|
||||
}
|
||||
console.log('resetNewEntry function defined:', resetNewEntry) // 避免未使用警告
|
||||
|
||||
const addTag = () => {
|
||||
const tag = newTagInput.value.trim()
|
||||
if (tag && !selectedTags.value.includes(tag)) {
|
||||
selectedTags.value.push(tag)
|
||||
newTagInput.value = ''
|
||||
}
|
||||
}
|
||||
// const addTag = () => {
|
||||
// const tag = newTagInput.value.trim()
|
||||
// if (tag && !selectedTags.value.includes(tag)) {
|
||||
// selectedTags.value.push(tag)
|
||||
// newTagInput.value = ''
|
||||
// }
|
||||
// }
|
||||
|
||||
const removeTag = (tag: string) => {
|
||||
const index = selectedTags.value.indexOf(tag)
|
||||
if (index > -1) {
|
||||
selectedTags.value.splice(index, 1)
|
||||
}
|
||||
}
|
||||
// const removeTag = (tag: string) => {
|
||||
// const index = selectedTags.value.indexOf(tag)
|
||||
// if (index > -1) {
|
||||
// selectedTags.value.splice(index, 1)
|
||||
// }
|
||||
// }
|
||||
|
||||
const editEntry = (entry: DiaryEntry) => {
|
||||
// TODO: 实现编辑功能
|
||||
message.info('编辑功能开发中...')
|
||||
}
|
||||
// const editEntry = (_entry: DiaryEntry) => {
|
||||
// // TODO: 实现编辑功能
|
||||
// message.info('编辑功能开发中...')
|
||||
// }
|
||||
|
||||
const deleteEntry = async (id: string) => {
|
||||
try {
|
||||
await diaryStore.deleteEntry(id)
|
||||
message.success('日记删除成功')
|
||||
} catch (error) {
|
||||
message.error('删除失败,请重试')
|
||||
}
|
||||
}
|
||||
// const deleteEntry = async (id: string) => {
|
||||
// try {
|
||||
// await diaryStore.deleteEntry(id)
|
||||
// message.success('日记删除成功')
|
||||
// } catch (error) {
|
||||
// message.error('删除失败,请重试')
|
||||
// }
|
||||
// }
|
||||
|
||||
// 加载情绪记录
|
||||
const loadEmotionRecords = async (page = 1, append = false) => {
|
||||
@@ -280,10 +283,8 @@
|
||||
try {
|
||||
loading.value = true
|
||||
|
||||
// 获取当前用户ID(这里需要根据实际的用户管理方式获取)
|
||||
const userId = 'default_user' // 这里应该从用户状态中获取
|
||||
|
||||
const pageData = await emotionRecordApi.getUserEmotionRecords(userId, page, pagination.value.pageSize)
|
||||
// 调用API获取用户情绪记录(后端会从token中获取用户信息)
|
||||
const pageData = await emotionRecordApi.getUserEmotionRecords(page, pagination.value.pageSize)
|
||||
|
||||
if (append) {
|
||||
emotionRecords.value.push(...(pageData.records || []))
|
||||
|
||||
@@ -493,7 +493,7 @@
|
||||
showDetailModal.value = true
|
||||
}
|
||||
|
||||
const editEvent = (event: LifeEvent) => {
|
||||
const editEvent = (_event: LifeEvent) => {
|
||||
// TODO: 实现编辑功能
|
||||
message.info('编辑功能开发中...')
|
||||
}
|
||||
|
||||
@@ -161,7 +161,8 @@
|
||||
...values,
|
||||
captchaKey: captchaKey.value
|
||||
}
|
||||
const data = await userStore.loginWithAuth(loginData)
|
||||
// const data = await userStore.loginWithAuth(loginData)
|
||||
await userStore.loginWithAuth(loginData)
|
||||
message.success('登录成功')
|
||||
await nextTick()
|
||||
const redirect = router.currentRoute.value.query.redirect as string
|
||||
@@ -170,7 +171,7 @@
|
||||
try {
|
||||
router.replace(targetPath).then(() => {
|
||||
console.log('路由跳转完成')
|
||||
}).catch((error) => {
|
||||
}).catch((_error) => {
|
||||
window.location.href = targetPath
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
<h2 class="username">{{ userInfo?.nickname || userInfo?.username || '未设置昵称' }}</h2>
|
||||
<p class="user-account">账号:{{ userInfo?.account }}</p>
|
||||
<p class="user-status">
|
||||
<a-tag :color="userInfo?.status === 'ACTIVE' ? 'green' : 'red'">
|
||||
{{ userInfo?.status === 'ACTIVE' ? '正常' : '禁用' }}
|
||||
<a-tag color="green">
|
||||
正常
|
||||
</a-tag>
|
||||
</p>
|
||||
</div>
|
||||
@@ -91,7 +91,7 @@
|
||||
<div class="stat-label">日记数量</div>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">{{ formatDate(userInfo?.createTime) }}</div>
|
||||
<div class="stat-value">{{ formatDate(userInfo?.createTime || '') }}</div>
|
||||
<div class="stat-label">注册时间</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -197,7 +197,7 @@ import {
|
||||
PlusOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { authService } from '@/services/auth'
|
||||
// import { authService } from '@/services/auth'
|
||||
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
|
||||
@@ -437,7 +437,7 @@
|
||||
showDetailModal.value = true
|
||||
}
|
||||
|
||||
const editTopic = (topic: Topic) => {
|
||||
const editTopic = (_topic: Topic) => {
|
||||
// TODO: 实现编辑功能
|
||||
message.info('编辑功能开发中...')
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@
|
||||
|
||||
onMounted(() => {
|
||||
// 监听聊天store中的消息变化
|
||||
chatStore.$subscribe((mutation, state) => {
|
||||
chatStore.$subscribe((mutation, _state) => {
|
||||
if (mutation.events && Array.isArray(mutation.events)) {
|
||||
mutation.events.forEach((event: any) => {
|
||||
if (event.key === 'messages' && event.type === 'add') {
|
||||
|
||||
Reference in New Issue
Block a user