Browse Source

扫描标准答案流程逻辑优化更新

dengshaobo 1 month ago
parent
commit
06fc671df0
1 changed files with 10 additions and 68 deletions
  1. 10 68
      src/views/exam/question.vue

+ 10 - 68
src/views/exam/question.vue

@@ -208,7 +208,7 @@ const scanText=ref('开始扫描');
 const templateQuestionCount=ref(0);//模板题目总数量
 const showChooseTemplate=ref(false);// 弹出选择模板的弹窗
 const tableData = ref<QuestionItem[]>([])
-const tableLoading = ref(true)//表格loading状态
+const tableLoading = ref(false)//表格loading状态
 const enterStandardEdit=ref<HTMLElement>();//标准答案编辑组件实例
 
 const tableHeight = ref(400)// 表格高度
@@ -538,8 +538,8 @@ const GotoScan = useThrottleFn(() => {
         if(res.code==200)
         {
             StartScan();
-            //启动扫描答案成功后,开启轮询获取扫描答案状态(每2秒一次)
-            ScheduleScanStatePolling();
+            
+
         }
         else
         {
@@ -764,70 +764,12 @@ const HandleScanResult=(res:any)=>{
         return;
     }
 
-    if (res.action === 'scanTemplate') {
-        const img = new Image();
-        img.crossOrigin = 'Anonymous';
-
-        img.onload = () => {
-            console.log('图片宽度:', img.width);
-            console.log('图片高度:', img.height);
-
-            const paperInfo = {
-                width: img.width,
-                height: img.height
-            };
-
-            // 创建 canvas 来获取图片数据并转换为 File 对象
-            const canvas = document.createElement('canvas');
-            canvas.width = img.width;
-            canvas.height = img.height;
-            const ctx = canvas.getContext('2d');
-            console.log("加载图片ctx", ctx);
-            if (ctx) {
-                ctx.drawImage(img, 0, 0);
-
-                canvas.toBlob(async (blob) => {
-                    if (blob) {
-                        // 创建 File 对象
-                        const file = new File([blob], res.name, {
-                            type: blob.type || 'image/jpeg'
-                        });
-
-                        // 创建预览 URL
-                        const imageUrl = URL.createObjectURL(file);
-
-                        const fileObj = {
-                            url: imageUrl,
-                            file: file,
-                            name: res.name,
-                            pageInfo: JSON.stringify(paperInfo),
-                            rotateAngle: 0
-                        };
-
-                        // 更新响应式数据
-                        imageFilesList.value.push(fileObj);
-                        showScanAnswer.value=true;
-                        console.log("打印 imageFilesList", imageFilesList.value);
-                        scanLoading.value = false;
-                        scanText.value='开始扫描';
-                    }
-                }, 'image/jpeg');
-            } else {
-                ElMessage.error('无法获取画布上下文');
-                scanLoading.value = false;
-                scanText.value='开始扫描';
-            }
-        };
-
-        img.onerror = (error) => {
-            console.error('图片加载失败:', error);
-            ElMessage.error('图片加载失败');
-            scanLoading.value = false;
-            scanText.value='开始扫描';
-        };
-
-        img.src = res.url;
-        
+    if (res.action === 'uploadFinish') 
+    {
+       //扫描仪返回上传结束 开始启动轮询调用状态接口
+       scanText.value='上传中...';
+       ScheduleScanStatePolling();
+       
     }
 }
 
@@ -844,7 +786,7 @@ onMounted(() => {
     });
     ConfigRequestUrlByEnv();//配置请求地址
     GetScanAnswerStates();//获取扫描答案状态
-    
+    // GetSmartQuestionList();
     GetTemplateInfo();
     // 初始化计算
     nextTick(() => {