瀏覽代碼

评卷分组图片设置允许为空;评卷图片加载时自动区分大小图;没有拼接规则时自动显示所有图片,但是针对大图自动一分为二

luoshi 4 年之前
父節點
當前提交
ec9f25f844

+ 2 - 2
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/MarkGroupController.java

@@ -472,7 +472,7 @@ public class MarkGroupController extends BaseExamController {
     @Transactional
     public String insert(HttpServletRequest request, Model model, RedirectAttributes redirectAttributes,
             @RequestParam String subjectCode, @RequestParam Integer number, @RequestParam String questionDetail,
-            @RequestParam String picList, @RequestParam(required = false) Double doubleRate,
+            @RequestParam(required = false) String picList, @RequestParam(required = false) Double doubleRate,
             @RequestParam(required = false) Double arbitrateThreshold,
             @RequestParam(required = false) Integer thirdPolicy, @RequestParam(required = false) Integer scorePolicy,
             @RequestParam(required = false) String markMode, @RequestParam(required = false) Integer trialCount,
@@ -584,7 +584,7 @@ public class MarkGroupController extends BaseExamController {
                 ObjectMapper mapper = new ObjectMapper();
                 json = mapper.writeValueAsString(group.getPictureConfigList());
             } catch (JsonProcessingException e) {
-                e.printStackTrace();
+                //e.printStackTrace();
             }
         }
         return json;

+ 0 - 2
stmms-web/src/main/webapp/WEB-INF/views/include/trackView.jsp

@@ -90,8 +90,6 @@
                     }
                 }
             }
-        }, function (error) {
-            console.log(error)
         })
     }
 </script>

+ 2 - 2
stmms-web/src/main/webapp/WEB-INF/views/modules/exam/inspected.jsp

@@ -197,6 +197,7 @@
         
         
         
+        
         ${fileServer}' + student.sheetUrls[0],
               zoom_delta: 1.2,
               zoom: 'fit',
@@ -225,6 +226,7 @@
         
         
         
+        
         ${fileServer}' + student.sheetUrls[0]);
     } */
         var pane = $('<canvas id="track-builder-canvas"></canvas>').appendTo($('#image-holder-track'));
@@ -301,8 +303,6 @@
                     }
                 }
             }
-        }, function (error) {
-            console.log(error)
         })
     }
 

+ 64 - 14
stmms-web/src/main/webapp/static/utils/image-utils.js

@@ -36,7 +36,8 @@ ImageLoader.prototype.load = function (urls, config, onSuccess, onError) {
     onError = onError || (function (error) {
         console.log(error)
     })
-    urls = (urls != undefined && Array.isArray(urls)) ? urls : []
+    urls = Array.isArray(urls) ? urls : []
+    config = Array.isArray(config) ? config : []
     let promises = []
     let images = []
     let self = this
@@ -49,7 +50,7 @@ ImageLoader.prototype.load = function (urls, config, onSuccess, onError) {
         promises.push(new Promise((resolve, reject) => {
             if (self.contain(image.index, config)) {
                 image.onload = function () {
-                    image.loaded = true
+                    this.loaded = true
                     resolve()
                 }
                 image.onerror = function () {
@@ -69,12 +70,37 @@ ImageLoader.prototype.load = function (urls, config, onSuccess, onError) {
     }
 
     Promise.all(promises).then(() => {
+        self.checkSize(images)
         onSuccess(images)
     }).catch(error => {
         onError(error)
     })
 }
 
+/**
+ * 遍历所有加载图片,根据宽高相互比较,判断是否大小图
+ * @param {array} images
+ */
+ImageLoader.prototype.checkSize = function (images) {
+    //let maxWidth = 0
+    for (let i = 0; i < images.length; i++) {
+        //宽度小于等于高度,自动判断为小图
+        if (images[i].width <= images[i].height) {
+            images[i].wide = false
+        } else {
+            //maxWidth = Math.max(maxWidth, images[i].width)
+            images[i].wide = true
+        }
+    }
+    // for (let i = 0; i < images.length; i++) {
+    //     if (images[i].width > images[i].height) {
+    //         //宽度大于高度,但是不到所有大图最大宽度的85%,也判定为小图
+    //         let diff = images[i].width / maxWidth
+    //         images[i].wide = diff >= 0.85
+    //     }
+    // }
+}
+
 /**
  * 判断指定序号的图片是否在拼接规则中存在,默认返回true
  *
@@ -82,7 +108,7 @@ ImageLoader.prototype.load = function (urls, config, onSuccess, onError) {
  * @param {array} config
  */
 ImageLoader.prototype.contain = function (number, config) {
-    if (config != undefined && config.length > 0) {
+    if (config.length > 0) {
         let find = false
         for (let i = 0; i < config.length; i++) {
             if (config[i].i == number) {
@@ -100,7 +126,7 @@ ImageLoader.prototype.contain = function (number, config) {
 /**
  * 使用指定画布,按照云阅卷拼接规则,加载图片并组合
  *
- * @param {array} images
+ * @param {array} urls
  * @param {canvas} canvas
  * @param {array} config
  * @param {function} onSuccess
@@ -112,18 +138,42 @@ ImageLoader.prototype.combine = function (urls, canvas, config, onSuccess, onErr
     onError = onError || (function (error) {
         console.log(error)
     })
+    urls = Array.isArray(urls) ? urls : []
+    config = Array.isArray(config) ? config : []
     this.load(urls, config, function (images) {
-        config = (config != undefined && Array.isArray(config)) ? config : []
         if (config.length == 0) {
             //不指定拼接配置时,默认按顺序显示所有图片
+            //区分大小图,小图原样显示,大图默认一分为二
             for (let i = 0; i < images.length; i++) {
-                config.push({
-                    i: i + 1,
-                    x: 0,
-                    y: 0,
-                    w: 0,
-                    h: 0
-                })
+                let image = images[i]
+                if (image.loaded === true) {
+                    if (image.wide === true) {
+                        //大图一分为二
+                        config.push({
+                            i: i + 1,
+                            x: 0,
+                            y: 0,
+                            w: image.width * 0.55,
+                            h: image.height
+                        })
+                        config.push({
+                            i: i + 1,
+                            x: image.width * 0.45,
+                            y: 0,
+                            w: image.width * 0.55,
+                            h: image.height
+                        })
+                    } else {
+                        //小图原样显示
+                        config.push({
+                            i: i + 1,
+                            x: 0,
+                            y: 0,
+                            w: image.width,
+                            h: image.height
+                        })
+                    }
+                }
             }
         }
         let maxWidth = 0
@@ -131,7 +181,7 @@ ImageLoader.prototype.combine = function (urls, canvas, config, onSuccess, onErr
         for (let i = 0; i < config.length; i++) {
             let image = images[config[i] - 1]
             //必须图片存在且正常加载配置才生效
-            if (image != undefined && image.loaded === true) {
+            if (image.loaded === true) {
                 //计算最大宽度与合计高度
                 if (config[i].w <= 0) {
                     config[i].w = image.width
@@ -186,7 +236,7 @@ ImageLoader.prototype.merge = function (urls, canvas, config, onSuccess, onError
         }
         image.config = array
         image.src = canvas.toDataURL()
-    })
+    }, null)
 }
 
 /**