Procházet zdrojové kódy

优化组件导入,简化代码逻辑,移除未使用的错误处理函数,更新图片加载处理方式,提升代码可读性和维护性。

wui před 7 měsíci
rodič
revize
8e43e877d1

+ 2 - 2
src/components/NavMenu.vue

@@ -5,9 +5,9 @@
 </template>
 
 <script setup>
-import { ref } from 'vue'
 import NavMenuItem from './NavMenuItem.vue'
-const props = defineProps({
+
+defineProps({
   model: {
     type: Array,
     required: true

+ 4 - 3
src/components/NavMenuItem.vue

@@ -12,9 +12,9 @@
 </template>
 
 <script setup>
-import { ref, computed } from 'vue'
-import { useRouter, useRoute } from 'vue-router'
-const router = useRouter()
+import { computed } from 'vue'
+import { useRoute } from 'vue-router'
+
 const route = useRoute()
 const props = defineProps({
   item: {
@@ -22,6 +22,7 @@ const props = defineProps({
     required: true
   }
 })
+
 const isActive = computed(() => {
   return route.name === props.item.name
 })

+ 1 - 11
src/views/ChatRecordsView.vue

@@ -274,7 +274,7 @@ const processMessageContent = (message) => {
     content += `
       <div class="message-text">${escapeHtml(message.text)}</div>
       <div class="message-image-container">
-        <img class="message-image" data-image-path="${message.imagePath}" alt="图片" loading="lazy" @error="handleImageError">
+        <img class="message-image" data-image-path="${message.imagePath}" alt="图片" loading="lazy">
       </div>
       <div class="message-time">${messageTime}</div>
     `
@@ -300,16 +300,6 @@ const processMessageContent = (message) => {
   return content
 }
 
-// 处理图片错误
-const handleImageError = (event) => {
-  const img = event.target
-  img.style.display = 'none'
-  const errorDiv = document.createElement('div')
-  errorDiv.className = 'message-image-error'
-  errorDiv.textContent = '图片加载失败'
-  img.parentNode.appendChild(errorDiv)
-}
-
 // 在DOM更新后处理图片加载
 const handleImagesAfterUpdate = async () => {
   await nextTick()

+ 5 - 0
src/views/Login.vue

@@ -32,6 +32,11 @@ import { ref } from 'vue'
 import { useRouter } from 'vue-router'
 import { useUserStore } from '@/stores/user'
 
+// 定义组件名称
+defineOptions({
+  name: 'UserLogin'
+})
+
 const router = useRouter()
 const userStore = useUserStore()
 const username = ref('')

+ 1 - 4
src/views/MainView.vue

@@ -1,5 +1,5 @@
 <script setup>
-import { ref, computed, onMounted } from 'vue'
+import { ref } from 'vue'
 import { useRouter } from 'vue-router'
 import Button from 'primevue/button'
 import Menu from 'primevue/menu'
@@ -121,9 +121,6 @@ const handleResetPassword = async ({ valid, values }) => {
     })
   }
 }
-
-// 根据视口大小计算布局类
-const isMobile = computed(() => window.innerWidth < 768)
 </script>
 
 <template>

+ 14 - 34
src/views/RecordsView.vue

@@ -2,7 +2,6 @@
 import { createRecord, deleteRecord, getRecordById, listRecords, updateRecord, uploadFile, downloadFile } from '@/services/api'
 import { Form } from '@primevue/forms'
 import { zodResolver } from '@primevue/forms/resolvers/zod'
-import { useUserStore } from '@/stores/user'
 import { useDateFormat } from '@vueuse/core'
 import Button from 'primevue/button'
 import Column from 'primevue/column'
@@ -17,7 +16,7 @@ import Message from 'primevue/message'
 import Textarea from 'primevue/textarea'
 import { useConfirm } from 'primevue/useconfirm'
 import { useToast } from 'primevue/usetoast'
-import { computed, onMounted, ref, nextTick } from 'vue'
+import { computed, onMounted, ref } from 'vue'
 import { z } from 'zod'
 
 const toast = useToast()
@@ -92,7 +91,7 @@ const displayDescription = computed({
         // 否则直接保存原文本
         recordForm.value.description = value
       }
-    } catch (e) {
+    } catch {
       // 如果转换失败,直接保存原文本
       recordForm.value.description = value
     }
@@ -109,7 +108,7 @@ const fetchData = async () => {
       search.value || undefined
     )
     tableData.value = response
-  } catch (error) {
+  } catch {
     toast.add({
       severity: 'error',
       summary: '错误',
@@ -131,13 +130,6 @@ const formatDate = (date) => {
   return useDateFormat(new Date(date), 'YYYY-MM-DD HH:mm:ss').value
 }
 
-// 格式化URL,优先展示头尾
-function formatUrl(url) {
-  if (!url) return ''
-  if (url.length <= 30) return url
-  return url.slice(0, 15) + '...' + url.slice(-20)
-}
-
 // 格式化描述内容
 function formatDescription(description) {
   if (!description) return ''
@@ -153,7 +145,7 @@ function formatDescription(description) {
       console.log('JSON格式化结果:', formatted)
       return formatted
     }
-  } catch (e) {
+  } catch {
     // 如果不是JSON,返回原文本
     console.log('非JSON文本:', description)
   }
@@ -185,7 +177,7 @@ const openEditRecordDialog = async (record) => {
     recordDialog.value = true
     // 更新formKey来强制表单重新渲染
     formKey.value++
-  } catch (error) {
+  } catch {
     toast.add({
       severity: 'error',
       summary: '错误',
@@ -228,8 +220,8 @@ const saveRecord = async ({ valid, values }) => {
 
     recordDialog.value = false
     fetchData() // 刷新列表
-  } catch (error) {
-    const errorMsg = error.message || (isEditMode.value ? '更新记录失败' : '创建记录失败')
+  } catch {
+    const errorMsg = isEditMode.value ? '更新记录失败' : '创建记录失败'
     toast.add({
       severity: 'error',
       summary: '错误',
@@ -257,7 +249,7 @@ const handleDeleteRecord = (record) => {
           life: 3000
         })
         fetchData() // 刷新列表
-      } catch (error) {
+      } catch {
         toast.add({
           severity: 'error',
           summary: '错误',
@@ -269,18 +261,6 @@ const handleDeleteRecord = (record) => {
   })
 }
 
-// 复制URL到剪贴板
-const copyUrl = (url) => {
-  navigator.clipboard.writeText(url).then(() => {
-    toast.add({
-      severity: 'info',
-      summary: '已复制',
-      detail: 'URL已复制到剪贴板',
-      life: 2000
-    })
-  })
-}
-
 // 从URL中提取OSS key
 const extractKeyFromUrl = (url) => {
   try {
@@ -288,7 +268,7 @@ const extractKeyFromUrl = (url) => {
     const urlObj = new URL(url)
     // 移除开头的斜杠
     return urlObj.pathname.substring(1)
-  } catch (e) {
+  } catch {
     console.error('无法解析URL:', url)
     return null
   }
@@ -319,7 +299,7 @@ const extractFileNameFromDescription = (description) => {
         return userName
       }
     }
-  } catch (e) {
+  } catch {
     // 如果不是JSON,返回原描述(去除特殊字符)
     return description.replace(/[<>:"/\\|?*]/g, '_').substring(0, 50)
   }
@@ -356,11 +336,11 @@ const handleFileDownload = async (url, description) => {
       detail: '文件下载完成',
       life: 3000
     })
-  } catch (error) {
+  } catch {
     toast.add({
       severity: 'error',
       summary: '下载失败',
-      detail: error.message || '文件下载失败',
+      detail: '文件下载失败',
       life: 3000
     })
   }
@@ -396,11 +376,11 @@ const handleFileUpload = async (event) => {
       detail: '文件上传成功,URL已自动填充',
       life: 3000
     })
-  } catch (error) {
+  } catch {
     toast.add({
       severity: 'error',
       summary: '上传失败',
-      detail: error.message || '文件上传失败',
+      detail: '文件上传失败',
       life: 3000
     })
   } finally {