Просмотр исходного кода

feat(canvas-tool,student): add undo/redo buttons and adjust token update logic

1. add undo and redo toolbar buttons in canvas tool component
2. comment out the 30min token auto-update and change to 10s temporarily
3. add websocket closed event handler to trigger token update then reconnect
lsc 4 дней назад
Родитель
Сommit
db140c365a
2 измененных файлов с 18 добавлено и 9 удалено
  1. 2 0
      src/views/Editor/CanvasTool/index2.vue
  2. 16 9
      src/views/Student/index.vue

+ 2 - 0
src/views/Editor/CanvasTool/index2.vue

@@ -1,6 +1,8 @@
 <template>
 <template>
   <div class="canvas-tool">
   <div class="canvas-tool">
     <div class="left-handler">
     <div class="left-handler">
+      <IconBack class="handler-item" :class="{ 'disable': !canUndo }" v-tooltip="lang.ssUndoTip" @click="undo()" />
+      <IconNext class="handler-item" :class="{ 'disable': !canRedo }" v-tooltip="lang.ssRedoTip" @click="redo()" />
       <Popover trigger="click" v-model:value="toolVisible" style="height: 100%;display: flex;align-items: center;"
       <Popover trigger="click" v-model:value="toolVisible" style="height: 100%;display: flex;align-items: center;"
         :offset="10" v-if="hasInteractiveTool">
         :offset="10" v-if="hasInteractiveTool">
         <template #content>
         <template #content>

+ 16 - 9
src/views/Student/index.vue

@@ -4113,10 +4113,11 @@ const updateAuthToken = async () => {
     console.log('🔐 认证 token 已更新')
     console.log('🔐 认证 token 已更新')
     
     
     // 30分钟后再次更新
     // 30分钟后再次更新
-    if (authTokenUpdateTimer.value) {
-      clearTimeout(authTokenUpdateTimer.value)
-    }
-    authTokenUpdateTimer.value = setTimeout(updateAuthToken, 30 * 60 * 1000) as unknown as NodeJS.Timeout
+    // if (authTokenUpdateTimer.value) {
+    //   clearTimeout(authTokenUpdateTimer.value)
+    // }
+    // authTokenUpdateTimer.value = setTimeout(updateAuthToken, 30 * 60 * 1000) as unknown as NodeJS.Timeout
+    // authTokenUpdateTimer.value = setTimeout(updateAuthToken, 10 * 1000) as unknown as NodeJS.Timeout
   }
   }
   catch (error) {
   catch (error) {
     console.error('🔐 更新认证 token 失败:', error)
     console.error('🔐 更新认证 token 失败:', error)
@@ -4124,7 +4125,7 @@ const updateAuthToken = async () => {
     if (authTokenUpdateTimer.value) {
     if (authTokenUpdateTimer.value) {
       clearTimeout(authTokenUpdateTimer.value)
       clearTimeout(authTokenUpdateTimer.value)
     }
     }
-    authTokenUpdateTimer.value = setTimeout(updateAuthToken, 1000) as unknown as NodeJS.Timeout
+    authTokenUpdateTimer.value = setTimeout(updateAuthToken, 10 * 1000) as unknown as NodeJS.Timeout
   }
   }
 }
 }
 
 
@@ -4180,10 +4181,11 @@ const createWebSocketConnection = async (type = 1) => {
     
     
     // 启动定期更新 token
     // 启动定期更新 token
     // 30分钟后再次更新
     // 30分钟后再次更新
-    if (authTokenUpdateTimer.value) {
-      clearTimeout(authTokenUpdateTimer.value)
-    }
-    authTokenUpdateTimer.value = setTimeout(updateAuthToken, 30 * 60 * 1000) as unknown as NodeJS.Timeout
+    // if (authTokenUpdateTimer.value) {
+    //   clearTimeout(authTokenUpdateTimer.value)
+    // }
+    // authTokenUpdateTimer.value = setTimeout(updateAuthToken, 30 * 60 * 1000) as unknown as NodeJS.Timeout
+    // authTokenUpdateTimer.value = setTimeout(updateAuthToken, 10 * 1000) as unknown as NodeJS.Timeout
 
 
     providerSocket.value.on('status', (event: any) => {
     providerSocket.value.on('status', (event: any) => {
       console.log('👉 WebSocket状态:', event.status)
       console.log('👉 WebSocket状态:', event.status)
@@ -4260,6 +4262,11 @@ const createWebSocketConnection = async (type = 1) => {
           createWebSocketConnection(2)
           createWebSocketConnection(2)
         }, 5000)
         }, 5000)
       }
       }
+      else if (event.status === 'closed') {
+        updateAuthToken().then(() => {
+          providerSocket.value.connect() // 尝试重新连接
+        })
+      }
     })
     })
     
     
     // 监听连接错误
     // 监听连接错误