Selaa lähdekoodia

单选组件双击编辑内容加入选项中,限1个

zhouna 6 vuotta sitten
vanhempi
commit
7f10e3a653

+ 1 - 0
src/components/MultSpread/index.jsx

@@ -54,6 +54,7 @@ class MultSpread extends Component{
         case +it.controlType===1:
           const list = it.questionDetailList&&it.questionDetailList.length>0?it.questionDetailList:it.questionMapping;
           return <RadioDrop data={list}
+                            boxMark={boxMark}
                             prefix={it.labelPrefix}
                             suffix={it.labelSuffix}
                             placeholder={it.name}

+ 3 - 2
src/containers/eleType.js

@@ -19,14 +19,15 @@ import Multiple from '@containers/Multiple';
  * *******/
 //单选类型
 export function singleRadio(params){
-  const data = params.item;//console.log(111,data);
+  const data = params.item;
   const {i,hideTag,boxMark,showArr,selecteds,boxTop,boxLeft} = params;
   const showInx = boxMark+i+'0';    //单括号多标签的情况下需要识别同一个标签内多个下拉组件的显示状态
   switch (+data.controlType){
     case 0:
     case 1:
+      const custom= JSON.parse(localStorage.getItem('radio'+data.id));
       const list = data.questionDetailList&&data.questionDetailList.length>0?data.questionDetailList:data.questionMapping;
-      return <RadioDrop data={list}
+      return <RadioDrop data={custom&&custom.length?[...custom,...list]:list}
                         prefix={data.labelPrefix}
                         suffix={data.labelSuffix}
                         placeholder={data.name}

+ 37 - 1
src/store/actions/checkBody.js

@@ -105,7 +105,11 @@ export function setRadioValue(state,action){
   }
   if(+item.tagType===1){      //独立单选组件
     item.value = text;
-    res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
+    const exist = JSON.parse(localStorage.getItem('radio'+item.id)||null);
+    if(exist){    //选中状态处理
+      exist[0].selected=exist[0].id==id;
+      localStorage.setItem('radio'+item.id,JSON.stringify(exist));
+    }
     item.questionDetailList.map((its)=>{
       if(its.id === id){
         its.selected = true;
@@ -113,6 +117,7 @@ export function setRadioValue(state,action){
         its.selected = false;
       }
     });
+    res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
   }else{      //组合组件中的单选组件
     item.questionMapping[subInx].value = text;
     let hasValue = false;
@@ -316,6 +321,33 @@ export const changeLabelVal = (state,action)=>{//双击标签输入改变值
   if(labText && labText.trim()){
     if(item){
       item.value = newVal;
+      const canAdd=hasNoSame(item.questionDetailList,labText);
+      //单选双击编辑的内容自动加到下拉选项中,双击编辑但未修改不添加
+      if(canAdd&&+item.tagType===1&&(+item.controlType===1||+item.controlType===0)){
+        const li = {
+          id:-Math.floor(Math.random()*1000),
+          name:labText,
+          questionId:item.id,
+          orderNo:0,
+          code:0,
+          defaultSelect:"0",
+          remark:null,
+          abnormal:0,
+          selected:true
+        };
+
+        const exist = JSON.parse(localStorage.getItem('radio'+item.id)||null);
+        //console.log(exist)
+        if(exist&&typeof exist=='object'){     //已添加过编辑的数据
+          //exist.push(li);
+          exist[0]=li;        //暂限添1条
+          localStorage.setItem('radio'+item.id,JSON.stringify(exist));
+        }else{
+          localStorage.setItem('radio'+item.id,JSON.stringify([li]));
+        }
+      }
+      //取消原选中状态
+      item.questionDetailList.find((it)=>it.selected==true).selected=false;
       item.labelPrefix = prefix||'';
       item.labelSuffix = suffix||'';
       // res.saveText[index] = totalVal;
@@ -331,6 +363,10 @@ export const changeLabelVal = (state,action)=>{//双击标签输入改变值
   return res;
 }
 
+function hasNoSame(arr,text){
+  return arr.findIndex((it)=>text==it.name)==-1;
+}
+
 // 数字键盘较特殊,有直接输入
 export const changeNumLabelVal = (state,action)=>{
   const res = Object.assign({},state);

+ 35 - 0
src/store/actions/currentIll.js

@@ -425,6 +425,11 @@ export function setRadioValue(state,action){
   if(+item.tagType===1){
     item.value = text;
     res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
+    const exist = JSON.parse(localStorage.getItem('radio'+item.id)||null);
+    if(exist){    //选中状态处理
+      exist[0].selected=exist[0].id==id;
+      localStorage.setItem('radio'+item.id,JSON.stringify(exist));
+    }
     item.questionDetailList.map((its)=>{
       if(its.id === id){
         its.selected = true;
@@ -517,6 +522,33 @@ export const changeLabelVal = (state,action)=>{
   if(labText.trim()){
     if(item){
       item.value = newVal;
+      const canAdd=hasNoSame(item.questionDetailList,labText);
+      //单选双击编辑的内容自动加到下拉选项中,双击编辑但未修改不添加
+      if(canAdd&&+item.tagType===1&&(+item.controlType===1||+item.controlType===0)){
+        const li = {
+          id:-Math.floor(Math.random()*1000),
+          name:labText,
+          questionId:item.id,
+          orderNo:0,
+          code:0,
+          defaultSelect:"0",
+          remark:null,
+          abnormal:0,
+          selected:true
+        };
+
+        const exist = JSON.parse(localStorage.getItem('radio'+item.id)||null);
+        //console.log(exist)
+        if(exist&&typeof exist=='object'){     //已添加过编辑的数据
+          //exist.push(li);
+          exist[0]=li;        //暂限添1条
+          localStorage.setItem('radio'+item.id,JSON.stringify(exist));
+        }else{
+          localStorage.setItem('radio'+item.id,JSON.stringify([li]));
+        }
+      }
+      //取消原选中状态
+      item.questionDetailList.find((it)=>it.selected==true).selected=false;
       item.labelPrefix = prefix||'';
       item.labelSuffix = suffix||'';
       res.saveText[index] = labText;
@@ -530,6 +562,9 @@ export const changeLabelVal = (state,action)=>{
   return res;
 }
 
+function hasNoSame(arr,text){
+  return arr.findIndex((it)=>text==it.name)==-1;
+}
 // 数字键盘较特殊,有直接输入
 export const changeNumLabelVal = (state,action)=>{
   const res = Object.assign({},state);

+ 36 - 0
src/store/actions/otherHistory.js

@@ -69,6 +69,11 @@ export function setRadioValue(state,action){
   if(+item.tagType===1){
     item.value = text;
     res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
+    const exist = JSON.parse(localStorage.getItem('radio'+item.id)||null);
+    if(exist){    //选中状态处理
+      exist[0].selected=exist[0].id==id;
+      localStorage.setItem('radio'+item.id,JSON.stringify(exist));
+    }
     item.questionDetailList.map((its)=>{
       if(its.id === id){
         its.selected = true;
@@ -278,6 +283,33 @@ export function changeTextLabel(state,action) {
       if(item.formulaCode){
         res[item.formulaCode] = newVal;
       }
+      const canAdd=hasNoSame(item.questionDetailList,labText);
+      //单选双击编辑的内容自动加到下拉选项中,双击编辑但未修改不添加
+      if(canAdd&&+item.tagType===1&&(+item.controlType===1||+item.controlType===0)){
+        const li = {
+          id:-Math.floor(Math.random()*1000),
+          name:labText,
+          questionId:item.id,
+          orderNo:0,
+          code:0,
+          defaultSelect:"0",
+          remark:null,
+          abnormal:0,
+          selected:true
+        };
+
+        const exist = JSON.parse(localStorage.getItem('radio'+item.id)||null);
+        //console.log(exist)
+        if(exist&&typeof exist=='object'){     //已添加过编辑的数据
+          //exist.push(li);
+          exist[0]=li;        //暂限添1条
+          localStorage.setItem('radio'+item.id,JSON.stringify(exist));
+        }else{
+          localStorage.setItem('radio'+item.id,JSON.stringify([li]));
+        }
+      }
+      //取消原选中状态
+      item.questionDetailList.find((it)=>it.selected==true).selected=false;
       item.labelPrefix = prefix||'';
       item.labelSuffix = suffix||'';
       res.saveText[index] = labText;
@@ -296,6 +328,10 @@ export function changeTextLabel(state,action) {
   return res;
 }
 
+function hasNoSame(arr,text){
+  return arr.findIndex((it)=>text==it.name)==-1;
+}
+
 // 数字键盘较特殊,有直接输入
 export const changeNumLabelVal = (state,action)=>{
   const res = Object.assign({},state);