Bladeren bron

查体收起bug修改

zhouna 6 jaren geleden
bovenliggende
commit
f5a41e0f9e
1 gewijzigde bestanden met toevoegingen van 11 en 6 verwijderingen
  1. 11 6
      src/utils/tools.js

+ 11 - 6
src/utils/tools.js

@@ -1022,12 +1022,15 @@ function fullfillText(arr,noPre=false,noEnd=false,ifEmpty=true){
     tempText = '',
     value = '',
     item={},
-    checkHiddenDefault=false;
+    cNum = 0,
+    checkHiddenDefault=false;//console.log(arr)
   arr&&arr.map((it,i)=>{
     notText = notTextLabel(it);
+    cNum = i;
     value = it.value||'';
     textLabel = !ifEmpty&&i==0?Object.assign({},JSON.parse(config.textLabel),{showInCheck:true}):JSON.parse(config.textLabel);
-    _textLabel = !ifEmpty&&i<config.showCheckNum+1?Object.assign({},JSON.parse(config._textLabel),{showInCheck:true}):JSON.parse(config._textLabel);
+    //n个显示的标签最后一个标签后面要落关标,所以+1
+    _textLabel = !ifEmpty&&cNum<config.showCheckNum+1?Object.assign({},JSON.parse(config._textLabel),{showInCheck:true}):JSON.parse(config._textLabel);
     if(i===0){
       //第一个标签不是文本标签时在前面添加文本标签
       if(!noPre&&notText){
@@ -1043,15 +1046,16 @@ function fullfillText(arr,noPre=false,noEnd=false,ifEmpty=true){
         tempText = getSaveText(it);
       }
       saveText.push(tempText);
-      if(arr.length==1){
+      // 模板只有一个标签时第一项后面也要加空标签
+      if(arr.length==1&&notText){
         newArr.push(textLabel);
         saveText.push('');
       }
     }else{
       pre = arr[i-1];
-      item = !ifEmpty&&i<config.showCheckNum?Object.assign({},it,{showInCheck:true}):it;
+      item = !ifEmpty&&cNum<config.showCheckNum?Object.assign({},it,{showInCheck:true}):it;
       //判断单选项是否有默认选中,位置在隐藏区域时,查体所有标签展示
-      if(!ifEmpty&&!checkHiddenDefault&&i>config.showCheckNum&&+it.tagType===1&&(+it.controlType===0||+it.controlType===1)){
+      if(!ifEmpty&&!checkHiddenDefault&&cNum>config.showCheckNum&&+it.tagType===1&&(+it.controlType===0||+it.controlType===1)){
         if(it.questionDetailList.find((it)=>it.defaultSelect=='1')){
           checkHiddenDefault=true;
         }
@@ -1079,7 +1083,8 @@ function fullfillText(arr,noPre=false,noEnd=false,ifEmpty=true){
       }
       if(notText&&!noEnd&&i===arr.length-1){//最后一个非文本标签,后面添加一个文本标签
         //不能用上面的变量textLabel,因为上一个if可能也进了,这样就是同一个对象,值改变时会同步
-        newArr.push(JSON.parse(config.textLabel));
+        const _text = arr.length>config.showCheckNum?JSON.parse(config._textLabel):_textLabel;
+        newArr.push(ifEmpty?textLabel:_text);
         saveText.push("");
       }
     }