Browse Source

feat(aiChat): 优化文件上传处理和URL验证逻辑

- 将硬编码的提示信息替换为多语言支持
- 使用lodash的debounce优化URL输入验证性能
- 简化URL验证正则表达式并添加防抖处理
- 调整部分UI元素的背景颜色
lsc 1 week ago
parent
commit
288b0b39c3

+ 4 - 4
src/components/CollapsibleToolbar/componets/aiChat.vue

@@ -188,7 +188,7 @@ const sendMessage = () => {
   // 检查是否有文件正在处理中
   const hasProcessingFile = files.value.some(file => file.isProcessing)
   if (hasProcessingFile) {
-    message.error('请等待文件上传完成后再发送消息')
+    message.error(lang.ssAiChatWaitUpload)
     return
   }
   if (inputText.value.trim() || files.value.length > 0) {
@@ -245,13 +245,13 @@ const handleFileUpload = async (files2: File[]) => {
   for (let i = 0; i < files2.length; i++) {
     const file = files2[i]
     if (file.size > maxSize) {
-      message.error('文件大小不能超过10MB')
+      message.error(lang.ssAiChatFileSizeLimit)
       continue
     }
     // 先添加文件到列表,显示解析中状态
     const fileIndex = files.value.length
     files.value.push({
-      title: file.name + ' (解析中...)',
+      title: file.name + ' (' + lang.ssAiChatParsing + ')',
       id: null,
       isProcessing: true,
       cancel: null
@@ -276,7 +276,7 @@ const handleFileUpload = async (files2: File[]) => {
       }
     }).catch(error => {
       if (error.name !== 'AbortError') {
-        console.error('文件上传失败:', error)
+        console.error(lang.ssAiChatUploadFailed, error)
         files.value.splice(fileIndex, 1)
       }
     })

+ 10 - 7
src/components/CollapsibleToolbar/index2.vue

@@ -560,19 +560,22 @@ const { currentSlide } = storeToRefs(slidesStore)
 const { createFrameElement } = useCreateElement()
 const { createSlide, createSlideByTemplate } = useSlideHandler()
 
-const handleUrlInput = () => {
+
+
+import _ from 'lodash'
+
+const handleUrlInput = _.debounce(() => {
   const url = webpageUrl.value.trim()
   if (!url) {
     isValidUrl.value = null
   }
   else {
-    // 改进的URL格式验证,支持查询参数
-    const urlRegex = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*(\?[\w=&-]+)?\/?$/i
+    // 简化的URL格式验证,支持各种复杂URL
+    const urlRegex = /^https?:\/\/.+/
     isValidUrl.value = urlRegex.test(url)
   }
   console.log('URL输入:', webpageUrl.value, '验证结果:', isValidUrl.value)
-}
-
+}, 300)
 const uploadWebpageLink = async () => {
   if (!webpageUrl.value || isValidUrl.value !== true) {
     // 可以添加提示信息
@@ -1019,7 +1022,7 @@ const handleParsingClose = () => {
   }
 
   &.active {
-    background: #eef3ff;
+    background: #fff5e5;
     box-shadow: 0 2px 8px rgba(40, 92, 245, 0.15);
   }
 
@@ -1065,7 +1068,7 @@ const handleParsingClose = () => {
   width: 0;
   min-width: 0;
   overflow: hidden;
-  transition: all 0.3s ease;
+  // transition: all 0.3s ease;
   background: #fff;
   border-radius: 0 12px 12px 0;
   z-index: 100;

+ 1 - 1
src/components/CreateCourseDialog.vue

@@ -267,7 +267,7 @@ const handleParsingClose = () => {
         .option-icon {
           width: 48px;
           height: 48px;
-          background: #eef3ff;
+          background: #fff;
           border-radius: 12px;
           display: flex;
           align-items: center;

+ 5 - 1
src/views/lang/cn.json

@@ -732,5 +732,9 @@
   "ssAiChatExample": "例如:创建45分钟的四年级教学内容为水的三态变化的课程",
   "ssAiChatShortcut": "输入 / 获取快捷操作短语",
   "ssAiChatQuickAction1": "为当前页面内容生成2道选择题",
-  "ssAiChatQuickAction2": "为当前页面生成2页内容页面"
+  "ssAiChatQuickAction2": "为当前页面生成2页内容页面",
+  "ssAiChatParsing": "解析中...",
+  "ssAiChatWaitUpload": "请等待文件上传完成后再发送消息",
+  "ssAiChatFileSizeLimit": "文件大小不能超过10MB",
+  "ssAiChatUploadFailed": "文件上传失败:"
 }

+ 5 - 1
src/views/lang/en.json

@@ -732,5 +732,9 @@
   "ssAiChatExample": "Example: Create a 45-minute lesson plan on water's three states of matter for 4th graders",
   "ssAiChatShortcut": "Type / for quick actions",
   "ssAiChatQuickAction1": "Generate 2 multiple choice questions for the current page content",
-  "ssAiChatQuickAction2": "Generate 2 content pages based on the current page"
+  "ssAiChatQuickAction2": "Generate 2 content pages based on the current page",
+  "ssAiChatParsing": "Parsing...",
+  "ssAiChatWaitUpload": "Please wait for the file upload to complete before sending a message",
+  "ssAiChatFileSizeLimit": "File size cannot exceed 10MB",
+  "ssAiChatUploadFailed": "File upload failed:"
 }

+ 5 - 1
src/views/lang/hk.json

@@ -732,5 +732,9 @@
   "ssAiChatExample": "例如:創建45分鐘的四年級教學內容為水的三態變化的課程",
   "ssAiChatShortcut": "輸入 / 獲取快捷操作短語",
   "ssAiChatQuickAction1": "為當前頁面內容生成2道選擇題",
-  "ssAiChatQuickAction2": "為當前頁面生成2頁內容頁面"
+  "ssAiChatQuickAction2": "為當前頁面生成2頁內容頁面",
+  "ssAiChatParsing": "解析中...",
+  "ssAiChatWaitUpload": "請等待文件上傳完成後再發送消息",
+  "ssAiChatFileSizeLimit": "文件大小不能超過10MB",
+  "ssAiChatUploadFailed": "文件上傳失敗:"
 }