ifelse.vue 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009
  1. <template>
  2. <div class="ifelse-box">
  3. <div class="flex jc-al-c">
  4. <span v-if="symbol!=='|'">IF条件执行</span>
  5. <el-select v-model="symbol" @change="setCondition()" size="medium" placeholder="请选择" >
  6. <el-option label="大于等于" value=">="></el-option>
  7. <el-option label="小于等于" value="<="></el-option>
  8. <el-option label="大于" value=">"></el-option>
  9. <el-option label="小于" value="<"></el-option>
  10. <el-option label="等于" value="="></el-option>
  11. <el-option label="小于且大于" value="<&&<"></el-option>
  12. <el-option label="小于等于且大于等于" value="<=&&<="></el-option>
  13. <el-option label="试验判断" value="|"></el-option>
  14. <el-option label="多条件" value="more"></el-option>
  15. <el-option label="数据获取" value="getData"></el-option>
  16. </el-select>
  17. <span class="mg-l-20 mg-r-10" v-if="symbol!=='|'">执行结果</span>
  18. <el-select v-model="result" @change="setTF()" size="medium" placeholder="请选择" v-if="symbol!=='|'&&symbol!=='getData'" >
  19. <el-option label="真假值" value="1"></el-option>
  20. <el-option label="运算" value="2"></el-option>
  21. </el-select>
  22. <el-select v-model="result" size="medium" placeholder="请选择" v-if="symbol=='getData'">
  23. <el-option label="数据获取" value="3"></el-option>
  24. </el-select>
  25. <el-button class="mg-l-10" size="small" type="info" @click="showSelectEle">选择参数</el-button>
  26. </div>
  27. <!-- 多条件其他的 -->
  28. <template v-if="symbol !== 'more'&&symbol !== 'getData'">
  29. <div class="mg-t-20 flex jc-al-c">
  30. <span class="textblod mg-r-20" v-if="symbol!=='|'">IF</span>
  31. <div class="flex jc-al-c" v-if="symbol == '<&&<' || symbol == '<=&&<='">
  32. <vue-tags-input v-model="tag1" :tags="tags1" @focus="curFocusIndex = 1" @blur="inputBlur(1)" placeholder="输入/参数111" @before-adding-tag="beforeAddingTag"/>
  33. <span v-if="symbol == '<&&<'" class="mg-l-20 mg-r-20">&lt;</span>
  34. <span v-if="symbol == '<=&&<='" class="mg-l-20 mg-r-20">≤</span>
  35. </div>
  36. <vue-tags-input v-model="tag2" :tags="tags2" @focus="curFocusIndex = 2" @blur="inputBlur(2)" placeholder="输入/参数222" @before-adding-tag="beforeAddingTag" @tag-clicked="handleTagClick($event,2)" ref="tagsInput2"/>
  37. <span class="mg-l-20 mg-r-20">
  38. <span v-if="symbol == '>='">≥</span>
  39. <span v-if="symbol == '<='">≤</span>
  40. <span v-if="symbol == '>'">&gt;</span>
  41. <span v-if="symbol == '<'">&lt;</span>
  42. <span v-if="symbol == '='">=</span>
  43. <span v-if="symbol == '<&&<'">&lt;</span>
  44. <span v-if="symbol == '|'">|</span>
  45. </span>
  46. <vue-tags-input v-model="tag3" :tags="tags3" @focus="curFocusIndex = 3" @blur="inputBlur(3)" placeholder="输入/参数" @before-adding-tag="beforeAddingTag" @tag-clicked="handleTagClick($event,3)" ref="tagsInput3"/>
  47. </div>
  48. <div class="flex jc-al-c mg-t-20" v-if="result == 1">
  49. <span class="textblod mg-r-10">真值</span>
  50. <vue-tags-input v-model="tag4" :tags="tags4" @focus="curFocusIndex = 4" @blur="inputBlur(4)" placeholder="输入/参数" @before-adding-tag="beforeAddingTag" @keyup.native="btKeyUp" @tag-clicked="handleTagClick($event,4)" ref="tagsInput4"/>
  51. <span class="textblod mg-r-10 mg-l-20">假值</span>
  52. <vue-tags-input v-model="tag5" :tags="tags5" @focus="curFocusIndex = 5" @blur="inputBlur(5)" placeholder="输入/参数" @before-adding-tag="beforeAddingTag" @keyup.native="btKeyUp" @tag-clicked="handleTagClick($event,5)" ref="tagsInput5"/>
  53. </div>
  54. <div class="mg-t-20" v-if="result == 2">
  55. <div class="flex">
  56. <span class="textblod mg-r-10">真值</span>
  57. <div class="border-grey sele-ele-box flex1" :class="{'border-green':curFocusIndex == 6}" @click="curFocusIndex = 6">
  58. <div class="flex jc-sb mg-b-20">
  59. <div class="icon-box">
  60. <el-link :underline="false" icon="el-icon-delete" type="danger" @click="removeSelect"></el-link>
  61. <el-link :underline="false" type="primary" @click="addOperator('+')" icon="el-icon-circle-plus-outline"></el-link>
  62. <el-link :underline="false" type="primary" @click="addOperator('-')" icon="el-icon-remove-outline"></el-link>
  63. <el-link :underline="false" type="primary" @click="addOperator('*')" icon="el-icon-circle-close"></el-link>
  64. <el-link :underline="false" type="primary" @click="addOperator('%')">÷</el-link>
  65. </div>
  66. <div>
  67. <el-link :underline="false" type="primary" class="mg-r-10" @click="addBrackets('(',false)">(</el-link>
  68. <el-link :underline="false" type="primary" class="mg-r-10" @click="addBrackets(')',true)">)</el-link>
  69. <el-link :underline="false" type="primary" @click="addText">输入值</el-link>
  70. </div>
  71. </div>
  72. <draggable v-model="selectEleFormula">
  73. <formula-item
  74. v-for="(item,index) in selectEleFormula" :key="index"
  75. :item="item" @click="obj => eleFormulaClick(obj,index)"
  76. >
  77. </formula-item>
  78. </draggable>
  79. </div>
  80. </div>
  81. <div class="flex mg-t-10">
  82. <span class="textblod mg-r-10">假值</span>
  83. <div class="border-grey sele-ele-box flex1" :class="{'border-green':curFocusIndex == 7}" @click="curFocusIndex = 7">
  84. <div class="flex jc-sb mg-b-20">
  85. <div class="icon-box">
  86. <el-link :underline="false" icon="el-icon-delete" type="danger" @click="removeSelect"></el-link>
  87. <el-link :underline="false" type="primary" @click="addOperator('+')" icon="el-icon-circle-plus-outline"></el-link>
  88. <el-link :underline="false" type="primary" @click="addOperator('-')" icon="el-icon-remove-outline"></el-link>
  89. <el-link :underline="false" type="primary" @click="addOperator('*')" icon="el-icon-circle-close"></el-link>
  90. <el-link :underline="false" type="primary" @click="addOperator('%')">÷</el-link>
  91. </div>
  92. <div>
  93. <el-link :underline="false" type="primary" class="mg-r-10" @click="addBrackets('(',false)">(</el-link>
  94. <el-link :underline="false" type="primary" class="mg-r-10" @click="addBrackets(')',true)">)</el-link>
  95. <el-link :underline="false" type="primary" @click="addText">输入值</el-link>
  96. </div>
  97. </div>
  98. <draggable v-model="selectEleFormula2">
  99. <formula-item
  100. v-for="(item,index) in selectEleFormula2" :key="index"
  101. :item="item" @click="obj => eleFormulaClick(obj,index)"
  102. >
  103. </formula-item>
  104. </draggable>
  105. </div>
  106. </div>
  107. </div>
  108. </template>
  109. <!-- 多条件 -->
  110. <template v-if="symbol == 'more'">
  111. <div v-for="(item, conditionIndex) in conditionList" :key="conditionIndex">
  112. <!-- 从第二个条件开始显示“条件X”和删除按钮 -->
  113. <div v-if="conditionIndex >= 1" class="condition-header flex al-c mg-t-20">
  114. <span class="textblod">条件{{ conditionIndex + 1 }}</span>
  115. <el-button type="danger" size="mini" @click="removeCondition(conditionIndex)" class=" mg-l-20">删除</el-button>
  116. </div>
  117. <div v-for="(innerItem, innerIndex) in conditionList[conditionIndex].formulaIfElse">
  118. <!-- 逻辑符号选择框 - 从第二个条件开始显示(innerIndex >= 1) -->
  119. <div v-if="innerIndex >= 1" style="margin-left: 25%;" class="mg-t-10 mg-b-10">
  120. <el-select
  121. v-model="conditionList[conditionIndex].formulaIfElse[innerIndex].logicSymbol"
  122. @change="setConditionMulti(conditionIndex, innerIndex)"
  123. size="medium"
  124. placeholder="请选择"
  125. style="width:120px"
  126. >
  127. <el-option label="或者" value="||"></el-option>
  128. <el-option label="并且" value="&&"></el-option>
  129. </el-select>
  130. </div>
  131. <!-- if条件内容 -->
  132. <div class="mg-t-20 flex jc-al-c" :key="innerIndex">
  133. <span class="textblod mg-r-20" >IF</span>
  134. <vue-tags-input
  135. :ref="`multiTagsInput_${conditionIndex}_${innerIndex}_tag2`"
  136. v-model="conditionList[conditionIndex].formulaIfElse[innerIndex].tag2"
  137. :tags="conditionList[conditionIndex].formulaIfElse[innerIndex].tags2"
  138. @focus="setMultiFocus(conditionIndex, innerIndex, 'tag2')"
  139. @blur="inputBlurMulti(conditionIndex, innerIndex, 'tag2')"
  140. placeholder="输入/参数"
  141. @before-adding-tag="beforeAddingTag"
  142. @tag-clicked="handleMultiTagClick($event, conditionIndex, innerIndex, 'tag2')"
  143. />
  144. <span class="mg-l-20 mg-r-20">
  145. <el-select
  146. v-model="conditionList[conditionIndex].formulaIfElse[innerIndex].symbol1"
  147. @change="setConditionMulti(conditionIndex, innerIndex)"
  148. size="medium"
  149. placeholder="请选择"
  150. style="width:120px"
  151. >
  152. <el-option label=">=" value=">="></el-option>
  153. <el-option label="<=" value="<="></el-option>
  154. <el-option label="=" value="="></el-option>
  155. <el-option label=">" value=">"></el-option>
  156. <el-option label="<" value="<"></el-option>
  157. <el-option label="≠" value="!= "></el-option>
  158. <el-option label="包含" value="包含"></el-option>
  159. <el-option label="不包含" value="不包含"></el-option>
  160. </el-select>
  161. </span>
  162. <vue-tags-input
  163. :ref="`multiTagsInput_${conditionIndex}_${innerIndex}_tag3`"
  164. v-model="conditionList[conditionIndex].formulaIfElse[innerIndex].tag3"
  165. :tags="conditionList[conditionIndex].formulaIfElse[innerIndex].tags3"
  166. @focus="setMultiFocus(conditionIndex, innerIndex, 'tag3')"
  167. @blur="inputBlurMulti(conditionIndex, innerIndex, 'tag3')"
  168. placeholder="输入/参数"
  169. @before-adding-tag="beforeAddingTag"
  170. @tag-clicked="handleMultiTagClick($event, conditionIndex, innerIndex, 'tag3')"
  171. />
  172. <i class="el-icon-circle-plus-outline mg-l-20" style="color: #409EFF;cursor: pointer;" @click="addConditionItem(conditionIndex, innerIndex)"></i>
  173. <i class="el-icon-delete mg-l-20" style="color: red;cursor: pointer;" @click="removeConditionItem(conditionIndex, innerIndex)" v-if="innerIndex > 0 || conditionIndex > 0"></i>
  174. </div>
  175. </div>
  176. <div class="flex jc-al-c mg-t-20" v-if="result == 1">
  177. <span class="textblod mg-r-10">满足</span>
  178. <vue-tags-input
  179. :ref="`multiTagsInput_${conditionIndex}_${innerIndex}_tag4`"
  180. v-model="conditionList[conditionIndex].tag4"
  181. :tags="conditionList[conditionIndex].tags4"
  182. @focus="setMultiFocus(conditionIndex, null, 'tag4')"
  183. @blur="inputBlurMulti(conditionIndex, null, 'tag4')"
  184. placeholder="输入/参数"
  185. @before-adding-tag="beforeAddingTag"
  186. @keyup.native="btKeyUp"
  187. @tag-clicked="handleMultiTagClick($event, conditionIndex, innerIndex, 'tag4')"
  188. />
  189. <!-- 只在最后一个条件显示"不满足"输入框 -->
  190. <template v-if="conditionIndex === conditionList.length - 1">
  191. <span class="textblod mg-r-10 mg-l-20">不满足</span>
  192. <vue-tags-input
  193. :ref="`multiTagsInput_${conditionIndex}_${innerIndex}_tag5`"
  194. v-model="conditionList[conditionIndex].tag5"
  195. :tags="conditionList[conditionIndex].tags5"
  196. @focus="setMultiFocus(conditionIndex, null, 'tag5')"
  197. @blur="inputBlurMulti(conditionIndex, null, 'tag5')"
  198. placeholder="输入/参数"
  199. @before-adding-tag="beforeAddingTag"
  200. @keyup.native="btKeyUp"
  201. @tag-clicked="handleMultiTagClick($event, conditionIndex, innerIndex, 'tag5')"
  202. />
  203. </template>
  204. <!-- 只在最后一个条件显示"添加其他条件"按钮 -->
  205. <div class="mg-l-20" v-if="conditionIndex === conditionList.length - 1">
  206. <el-button size="small" type="primary" @click="addCondition(conditionIndex)">添加其他条件</el-button>
  207. </div>
  208. </div>
  209. <template v-if="result == 2">
  210. <div class="mg-t-20" >
  211. <div class="flex">
  212. <span class="textblod mg-r-10">满足</span>
  213. <div class="border-grey sele-ele-box flex1"
  214. :class="{'border-green': isCurFocus(conditionIndex, null, 'formula1')}"
  215. @click="setMultiFocus(conditionIndex, null, 'formula1')">
  216. <div class="flex jc-sb mg-b-20">
  217. <div class="icon-box">
  218. <el-link :underline="false" icon="el-icon-delete" type="danger" @click="removeSelectMulti(conditionIndex, 'formula1')"></el-link>
  219. <el-link :underline="false" type="primary" @click="addOperatorMulti(conditionIndex, '+', 'formula1')" icon="el-icon-circle-plus-outline"></el-link>
  220. <el-link :underline="false" type="primary" @click="addOperatorMulti(conditionIndex, '-', 'formula1')" icon="el-icon-remove-outline"></el-link>
  221. <el-link :underline="false" type="primary" @click="addOperatorMulti(conditionIndex, '*', 'formula1')" icon="el-icon-circle-close"></el-link>
  222. <el-link :underline="false" type="primary" @click="addOperatorMulti(conditionIndex, '%', 'formula1')">÷</el-link>
  223. </div>
  224. <div>
  225. <el-link :underline="false" type="primary" class="mg-r-10" @click="addBracketsMulti(conditionIndex, '(', false, 'formula1')">(</el-link>
  226. <el-link :underline="false" type="primary" class="mg-r-10" @click="addBracketsMulti(conditionIndex, ')', true, 'formula1')">)</el-link>
  227. <el-link :underline="false" type="primary" @click="addTextMulti(conditionIndex, 'formula1')">输入值</el-link>
  228. </div>
  229. </div>
  230. <draggable v-model="conditionList[conditionIndex].formula1">
  231. <formula-item
  232. v-for="(item,index) in conditionList[conditionIndex].formula1" :key="index"
  233. :item="item" @click="obj => eleFormulaClickMulti(obj, index, conditionIndex, 'formula1')"
  234. >
  235. </formula-item>
  236. </draggable>
  237. </div>
  238. </div>
  239. <!-- 只在最后一个条件显示"不满足"公式框 -->
  240. <div class="flex mg-t-10" v-if="conditionIndex === conditionList.length - 1">
  241. <span class="textblod mg-r-10">不满足</span>
  242. <div class="border-grey sele-ele-box flex1"
  243. :class="{'border-green': isCurFocus(conditionIndex, null, 'formula2')}"
  244. @click="setMultiFocus(conditionIndex, null, 'formula2')">
  245. <div class="flex jc-sb mg-b-20">
  246. <div class="icon-box">
  247. <el-link :underline="false" icon="el-icon-delete" type="danger" @click="removeSelectMulti(conditionIndex, 'formula2')"></el-link>
  248. <el-link :underline="false" type="primary" @click="addOperatorMulti(conditionIndex, '+', 'formula2')" icon="el-icon-circle-plus-outline"></el-link>
  249. <el-link :underline="false" type="primary" @click="addOperatorMulti(conditionIndex, '-', 'formula2')" icon="el-icon-remove-outline"></el-link>
  250. <el-link :underline="false" type="primary" @click="addOperatorMulti(conditionIndex, '*', 'formula2')" icon="el-icon-circle-close"></el-link>
  251. <el-link :underline="false" type="primary" @click="addOperatorMulti(conditionIndex, '%', 'formula2')">÷</el-link>
  252. </div>
  253. <div>
  254. <el-link :underline="false" type="primary" class="mg-r-10" @click="addBracketsMulti(conditionIndex, '(', false, 'formula2')">(</el-link>
  255. <el-link :underline="false" type="primary" class="mg-r-10" @click="addBracketsMulti(conditionIndex, ')', true, 'formula2')">)</el-link>
  256. <el-link :underline="false" type="primary" @click="addTextMulti(conditionIndex, 'formula2')">输入值</el-link>
  257. </div>
  258. </div>
  259. <draggable v-model="conditionList[conditionIndex].formula2">
  260. <formula-item
  261. v-for="(item,index) in conditionList[conditionIndex].formula2" :key="index"
  262. :item="item" @click="obj => eleFormulaClickMulti(obj, index, conditionIndex, 'formula2')"
  263. >
  264. </formula-item>
  265. </draggable>
  266. </div>
  267. </div>
  268. <!-- 只在最后一个条件显示"添加条件"按钮 -->
  269. <el-button size="small" @click="addCondition(conditionIndex)" type="primary" v-if="conditionIndex === conditionList.length - 1">添加条件</el-button>
  270. </div>
  271. </template>
  272. </div>
  273. </template>
  274. <!-- 数据获取配置框 - 修改部分 -->
  275. <template v-if="symbol==='getData'">
  276. <div class="mg-t-10">
  277. <div v-for="(item, index) in getDataList" :key="index" class="mg-t-10">
  278. <div class="flex jc-al-c">
  279. <div class="textblod mg-r-10" :style="{ opacity: index === 0 ? 1 : 0 }">
  280. </div>
  281. <div class="mg-r-10" :style="{ opacity: index === 0 ? 1 : 0 }">
  282. <vue-tags-input
  283. v-model="item.tagWhenLeft"
  284. :tags="item.tagsWhenLeft"
  285. @focus="setDataFocus(index, 'tagWhenLeft')"
  286. @blur="dataInputBlur(index, 'tagWhenLeft')"
  287. placeholder="输入/参数"
  288. @before-adding-tag="beforeAddingTag"
  289. @keyup.native="btKeyUp"
  290. @tag-clicked="handleDataTagClick($event, index, 'tagWhenLeft')"
  291. :ref="`dataTag_${index}_tagWhenLeft`"
  292. />
  293. </div>
  294. <div class="mg-r-10">
  295. <el-select
  296. v-model="item.condition"
  297. @change="setDataCondition(index)"
  298. size="medium"
  299. placeholder="请选择"
  300. style="width:120px"
  301. >
  302. <el-option label=">=" value=">="></el-option>
  303. <el-option label="<=" value="<="></el-option>
  304. <el-option label="=" value="="></el-option>
  305. <el-option label=">" value=">"></el-option>
  306. <el-option label="<" value="<"></el-option>
  307. <el-option label="≠" value="≠"></el-option>
  308. <el-option label="包含" value="包含"></el-option>
  309. <el-option label="不包含" value="不包含"></el-option>
  310. </el-select>
  311. </div>
  312. <div class="mg-r-10">
  313. <vue-tags-input
  314. v-model="item.tagWhenRight"
  315. :tags="item.tagsWhenRight"
  316. @focus="setDataFocus(index, 'tagWhenRight')"
  317. @blur="dataInputBlur(index, 'tagWhenRight')"
  318. placeholder="输入/参数"
  319. @before-adding-tag="beforeAddingTag"
  320. @keyup.native="btKeyUp"
  321. @tag-clicked="handleDataTagClick($event, index, 'tagWhenRight')"
  322. :ref="`dataTag_${index}_tagWhenRight`"
  323. />
  324. </div>
  325. <div class="mg-r-10 textblod">则</div>
  326. <vue-tags-input
  327. v-model="item.tagThenLeft"
  328. :tags="item.tagsThenLeft"
  329. @focus="setDataFocus(index, 'tagThenLeft')"
  330. @blur="dataInputBlur(index, 'tagThenLeft')"
  331. placeholder="输入/参数"
  332. @before-adding-tag="beforeAddingTag"
  333. @keyup.native="btKeyUp"
  334. @tag-clicked="handleDataTagClick($event, index, 'tagThenLeft')"
  335. :ref="`dataTag_${index}_tagThenLeft`"
  336. />
  337. <span class="mg-r-10 mg-l-10">=</span>
  338. <div class="mg-r-10">
  339. <vue-tags-input
  340. v-model="item.tagThenRight"
  341. :tags="item.tagsThenRight"
  342. @focus="setDataFocus(index, 'tagThenRight')"
  343. @blur="dataInputBlur(index, 'tagThenRight')"
  344. placeholder="输入/参数"
  345. @before-adding-tag="beforeAddingTag"
  346. @keyup.native="btKeyUp"
  347. @tag-clicked="handleDataTagClick($event, index, 'tagThenRight')"
  348. :ref="`dataTag_${index}_tagThenRight`"
  349. />
  350. </div>
  351. <i class="el-icon-circle-plus-outline mg-l-20" style="color: #409EFF;cursor: pointer;" @click="addDataItem(index)"></i>
  352. <i class="el-icon-delete mg-l-20" style="color: red;cursor: pointer;" @click="removeDataItem(index)" v-if="getDataList.length > 1"></i>
  353. </div>
  354. </div>
  355. <div class="mg-t-10 ">
  356. <div class="textblod " >否则</div>
  357. <div class="flex jc-al-c " style="float: right; margin-top: -28px;" >
  358. <vue-tags-input
  359. v-model="elseTagLeft"
  360. :tags="elseTagsLeft"
  361. @focus="setElseFocus('left')"
  362. @blur="elseInputBlur('left')"
  363. placeholder="请选择参数"
  364. @before-adding-tag="beforeAddingTag"
  365. @keyup.native="btKeyUp"
  366. class="mg-r-10"
  367. @tag-clicked="handleElseTagClick($event, 'left')"
  368. ref="elseTagLeft"
  369. />
  370. <span class="mg-r-10">=</span>
  371. <vue-tags-input
  372. v-model="elseTagRight"
  373. :tags="elseTagsRight"
  374. @focus="setElseFocus('right')"
  375. @blur="elseInputBlur('right')"
  376. placeholder="请选择/输入参数"
  377. @before-adding-tag="beforeAddingTag"
  378. @keyup.native="btKeyUp"
  379. @tag-clicked="handleElseTagClick($event, 'left')"
  380. ref="elseTagLeft"
  381. />
  382. </div>
  383. </div>
  384. </div>
  385. </template>
  386. <el-dialog title="输入值" :visible.sync="inputVisible" width="300px" append-to-body :close-on-click-modal="false">
  387. <el-input v-model="inputText" placeholder="请输入内容"></el-input>
  388. <div class="text-align-c mg-t-10">
  389. <el-button size="small" @click="addTextHandle" type="primary">保存</el-button>
  390. <el-button size="small" @click="inputVisible = false">取消</el-button>
  391. </div>
  392. </el-dialog>
  393. </div>
  394. </template>
  395. <script>
  396. import VueTagsInput from '@johmun/vue-tags-input';
  397. import formulaItem from "../formulaItem";
  398. import draggable from 'vuedraggable';
  399. import {transformData,generateElementMap,restoreData} from './multiIfElseTools'
  400. export default {
  401. name: "ifelse",
  402. components: {
  403. draggable,
  404. VueTagsInput,
  405. formulaItem,
  406. },
  407. props: {
  408. formulainfo: {
  409. type: Object,
  410. default: function () {
  411. return {};
  412. }
  413. },
  414. curele: {
  415. type: Object,
  416. default: function () {
  417. return {};
  418. }
  419. },
  420. formulamap:{
  421. type: Object,
  422. default: function () {
  423. return {};
  424. }
  425. },
  426. isMore:{
  427. type: Boolean,
  428. default: false
  429. },
  430. moreConditions:{
  431. type: Array,
  432. default: function () {
  433. return [];
  434. }
  435. },
  436. conditionIndex:{//当前是多条件中的哪一个
  437. type: Number,
  438. default: 0
  439. },
  440. isGetData:{
  441. type: Boolean,
  442. default: false
  443. },
  444. dataListGet:{
  445. type: String,
  446. default:''
  447. },
  448. map:{
  449. type: String,
  450. default:''
  451. },
  452. remark:{
  453. type: String,
  454. default:'',
  455. },
  456. },
  457. data(){
  458. return{
  459. symbol:'>=',
  460. result:'1',
  461. selectEleFormula:[],
  462. selectEleFormula2:[],
  463. curFocusIndex:0,//当前在哪个输入框
  464. curSeleEleIndex:-1,//公式文字里面选中的元素索引
  465. // 多条件下的焦点信息
  466. multiFocus: {
  467. conditionIndex: -1,
  468. innerIndex: -1,
  469. field: ''
  470. },
  471. // 数据获取部分的焦点信息
  472. dataFocus: {
  473. index: -1,
  474. field: ''
  475. },
  476. symbolReg:/(\+|-|\*|\/)(.+)/,
  477. inputVisible:false,
  478. inputText:'',
  479. tag1: '',
  480. tags1: [],
  481. tag2: '',
  482. tags2: [],
  483. tag3: '',
  484. tags3: [],
  485. tag4: '',
  486. tags4: [],
  487. tag5: '',
  488. tags5: [],
  489. symbol1:'',
  490. // 重构多条件列表结构,包含独立的tags和公式
  491. conditionList:[
  492. {
  493. formulaIfElse: [
  494. {
  495. tag2: '',
  496. tags2: [],
  497. tag3: '',
  498. tags3: [],
  499. symbol1: '',
  500. logicSymbol: ''
  501. }
  502. ],
  503. tag4: '',
  504. tags4: [],
  505. tag5: '',
  506. tags5: [],
  507. formula1: [],
  508. formula2: []
  509. }
  510. ],//多条件的条件列表
  511. // 修改getDataList结构,为每个项添加独立属性
  512. getDataList:[
  513. {
  514. tagWhenLeft: '',
  515. tagsWhenLeft: [],
  516. condition: '',
  517. tagWhenRight: '',
  518. tagsWhenRight: [],
  519. tagThenLeft: '',
  520. tagsThenLeft: [],
  521. tagThenRight: '',
  522. tagsThenRight: []
  523. }
  524. ],//数据获取列表
  525. // 否则部分的属性
  526. elseTagLeft: '',
  527. elseTagsLeft: [],
  528. elseTagRight: '',
  529. elseTagsRight: [],
  530. elseFocus: '' // 用于跟踪否则部分的焦点
  531. }
  532. },
  533. watch: {
  534. // 监视getDataList的变化
  535. getDataList: {
  536. deep: true,
  537. handler(newVal) {
  538. // 只有当数组中有至少一个元素时才处理
  539. if (newVal.length > 0) {
  540. // 获取第一个元素的tagWhenLeft值
  541. const firstTagWhenLeft = newVal[0].tagWhenLeft;
  542. const firstTagsWhenLeft = newVal[0].tagsWhenLeft;
  543. // 如果第一个元素有值,同步到其他元素
  544. if ((firstTagWhenLeft && firstTagWhenLeft.trim() !== '') ||
  545. (firstTagsWhenLeft && firstTagsWhenLeft.length > 0)) {
  546. // 遍历从第二个元素开始的所有元素
  547. for (let i = 1; i < newVal.length; i++) {
  548. // 避免触发不必要的watch循环
  549. if (newVal[i].tagWhenLeft !== firstTagWhenLeft ||
  550. JSON.stringify(newVal[i].tagsWhenLeft) !== JSON.stringify(firstTagsWhenLeft)) {
  551. this.$set(newVal[i], 'tagWhenLeft', firstTagWhenLeft);
  552. this.$set(newVal[i], 'tagsWhenLeft', [...firstTagsWhenLeft]);
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. },
  560. mounted(){
  561. console.log(this.formulainfo,'this.formulainfo333333');
  562. let args0 = this.formulainfo.arguments[0];
  563. let args1 = this.formulainfo.arguments[1];
  564. let args2 = this.formulainfo.arguments[2];
  565. this.initCondition(args0);
  566. if((typeof args1 == 'string' || (typeof args1 == 'object' && (args1.type == 'Element' || args1.type == 'ParamData'))) &&
  567. (typeof args2 == 'string' || (typeof args2 == 'object' && (args2.type == 'Element' || args2.type == 'ParamData')))
  568. ){
  569. this.initTFInput(args1,args2);
  570. }else if(Array.isArray(args1) || Array.isArray(args2)){
  571. //
  572. if(!this.isMore){
  573. this.result = '2';
  574. }
  575. this.initTFFormula(args1,args2)
  576. }
  577. if(this.isMore){
  578. this.symbol = 'more';
  579. console.log( this.moreConditions,' this.moreConditions;');
  580. // if(formula1.length>1 || formula2>1){
  581. // this.result = '2';
  582. // }else{
  583. // this.result = '1';
  584. // }
  585. this.result=this.remark||'1'
  586. this.conditionList = this.moreConditions.map(item => this.clearTagsIfHasValue(item));
  587. }else if(this.isGetData){
  588. this.symbol = 'getData';
  589. this.result = '3';
  590. console.log(this.dataListGet,'dataListGet');
  591. const str=this.dataListGet;
  592. let resultStr=''
  593. // 找到第一个左括号的位置
  594. const startIndex = str.indexOf('(');
  595. // 找到最后一个右括号的位置
  596. const endIndex = str.lastIndexOf(')');
  597. // 提取括号内的内容
  598. if (startIndex !== -1 && endIndex !== -1 && startIndex < endIndex) {
  599. const result = str.substring(startIndex + 1, endIndex);
  600. resultStr=result
  601. console.log(result);
  602. } else {
  603. console.log("未找到有效的括号对");
  604. }
  605. const resObj=restoreData(resultStr,JSON.parse(this.map))
  606. console.log(resObj,'resObj');
  607. this.getDataList=resObj.getDataList
  608. this.elseTagLeft = resObj.elseTagLeft;
  609. this.elseTagsLeft = resObj.elseTagsLeft;
  610. this.elseTagRight = resObj.elseTagRight;
  611. this.elseTagsRight = resObj.elseTagsRight;
  612. }
  613. else{
  614. // this.conditionList=[]
  615. }
  616. // // 初始化数据获取列表
  617. // if (this.symbol === 'getData' && this.formulainfo.arguments && this.formulainfo.arguments.length > 0) {
  618. // console.log(this.dataListGet,'dataListGet');
  619. // // this.initGetDataList(this.formulainfo.arguments[0]);
  620. // }
  621. },
  622. methods:{
  623. // 初始化数据获取列表
  624. initGetDataList(data) {
  625. if (Array.isArray(data)) {
  626. this.getDataList = data.map(item => ({
  627. tagWhenLeft: item.tagWhenLeft || '',
  628. tagsWhenLeft: item.tagsWhenLeft || [],
  629. condition: item.condition || '',
  630. tagWhenRight: item.tagWhenRight || '',
  631. tagsWhenRight: item.tagsWhenRight || [],
  632. tagThenLeft: item.tagThenLeft || '',
  633. tagsThenLeft: item.tagsThenLeft || [],
  634. tagThenRight: item.tagThenRight || '',
  635. tagsThenRight: item.tagsThenRight || []
  636. }));
  637. }
  638. },
  639. // 设置数据获取部分的焦点
  640. setDataFocus(index, field) {
  641. this.elseFocus=false
  642. this.dataFocus = { index, field };
  643. },
  644. // 数据获取部分输入框失焦处理
  645. dataInputBlur(index, field) {
  646. const item = this.getDataList[index];
  647. const tagNumber = field.replace('tag', '');
  648. if (item[field]) {
  649. if (item[`tags${tagNumber}`] && item[`tags${tagNumber}`][0]) {
  650. this.$emit('uncheck', item[`tags${tagNumber}`][0].id);
  651. }
  652. item[`tags${tagNumber}`] = [];
  653. }
  654. this.setGetDataCondition();
  655. },
  656. // 添加数据获取项
  657. addDataItem(index) {
  658. // 获取第一个元素的值作为模板
  659. const firstItem = this.getDataList[0];
  660. const newItem = {
  661. // 新添加的项直接使用第一个元素的tagWhenLeft相关值
  662. tagWhenLeft: firstItem.tagWhenLeft,
  663. tagsWhenLeft: [...firstItem.tagsWhenLeft],
  664. condition: '',
  665. tagWhenRight: '',
  666. tagsWhenRight: [],
  667. tagThenLeft: '',
  668. tagsThenLeft: [],
  669. tagThenRight: '',
  670. tagsThenRight: []
  671. };
  672. this.getDataList.splice(index + 1, 0, newItem);
  673. this.setGetDataCondition();
  674. },
  675. // 删除数据获取项
  676. removeDataItem(index) {
  677. if (this.getDataList.length > 1) {
  678. this.getDataList.splice(index, 1);
  679. this.setGetDataCondition();
  680. } else {
  681. this.$message({ type: "warning", message: "至少保留一个数据获取条件" });
  682. }
  683. },
  684. // 设置数据获取条件
  685. setDataCondition(index) {
  686. this.setGetDataCondition();
  687. },
  688. // 保存数据获取条件到公式信息
  689. setGetDataCondition() {
  690. this.formulainfo.arguments[0] = {
  691. conditions: this.getDataList.map(item => ({
  692. tagWhenLeft: item.tagWhenLeft,
  693. tagsWhenLeft: item.tagsWhenLeft,
  694. condition: item.condition,
  695. tagWhenRight: item.tagWhenRight,
  696. tagsWhenRight: item.tagsWhenRight,
  697. tagThenLeft: item.tagThenLeft,
  698. tagsThenLeft: item.tagsThenLeft,
  699. tagThenRight: item.tagThenRight,
  700. tagsThenRight: item.tagsThenRight
  701. })),
  702. elseCase: {
  703. tagLeft: this.elseTagLeft,
  704. tagsLeft: this.elseTagsLeft,
  705. tagRight: this.elseTagRight,
  706. tagsRight: this.elseTagsRight
  707. }
  708. };
  709. },
  710. clearTagsIfHasValue(obj) {
  711. // 复制对象以避免修改原对象
  712. const result = JSON.parse(JSON.stringify(obj));
  713. // 检查tags数组中是否存在name不为空的元素
  714. const hasNonEmptyNameElement = (tagsArray) => {
  715. return tagsArray && Array.isArray(tagsArray) &&
  716. tagsArray.length > 0 &&
  717. tagsArray.some(item => typeof item.name === 'string' && item.name.trim() !== '');
  718. };
  719. // 检查tags数组中是否存在name为空字符串的元素
  720. const hasEmptyNameElement = (tagsArray) => {
  721. return tagsArray && Array.isArray(tagsArray) &&
  722. tagsArray.length > 0 &&
  723. tagsArray.some(item => typeof item.name === 'string' && item.name.trim() === '');
  724. };
  725. // 处理顶层的tags4和tags5
  726. if (hasEmptyNameElement(result.tags4)) {
  727. result.tags4 = []; // 赋值为null
  728. }
  729. if (hasEmptyNameElement(result.tags5)) {
  730. result.tags5 = []; // 赋值为null
  731. }
  732. // 处理顶层的tag4和tag5
  733. if (hasNonEmptyNameElement(result.tags4)) {
  734. result.tag4 = ""; // 清空对应的tag值
  735. }
  736. if (hasNonEmptyNameElement(result.tags5)) {
  737. result.tag5 = ""; // 清空对应的tag值
  738. }
  739. // 处理formulaIfElse数组中的tag2和tag3
  740. if (result.formulaIfElse && Array.isArray(result.formulaIfElse)) {
  741. result.formulaIfElse.forEach(item => {
  742. if (hasNonEmptyNameElement(item.tags2)) {
  743. item.tag2 = ""; // 清空对应的tag值
  744. }
  745. if (hasNonEmptyNameElement(item.tags3)) {
  746. item.tag3 = ""; // 清空对应的tag值
  747. }
  748. if (hasEmptyNameElement(item.tags2)) {
  749. item.tags2 = []; // 赋值为null
  750. }
  751. if (hasEmptyNameElement(item.tags3)) {
  752. item.tags3 = []; // 赋值为null
  753. }
  754. });
  755. }
  756. return result;
  757. },
  758. showSelectEle(){
  759. this.$set(this.formulainfo,'showSelectEle',!this.formulainfo.showSelectEle);
  760. },
  761. beforeAddingTag(){
  762. },
  763. btKeyUp(e) {
  764. //把中文标点符号转换成英文的
  765. e.target.value = e.target.value.replace(/“/g,'"');
  766. e.target.value = e.target.value.replace(/”/g,'"');
  767. e.target.value = e.target.value.replace(/’/g,"'");
  768. e.target.value = e.target.value.replace(/‘/g,"'");
  769. },
  770. inputHook(){
  771. console.log(111)
  772. },
  773. inputBlur(num){
  774. if(this['tag'+num]){
  775. if(this['tags'+num] && this['tags'+num][0]){
  776. this.$emit('uncheck',this['tags'+num][0].id)
  777. }
  778. this['tags'+num] = [];
  779. }
  780. if(num>=1&&num<=3){
  781. this.setCondition();
  782. }else if(num>=4&&num<=5){
  783. this.setTF();
  784. }
  785. },
  786. // 多条件下的输入框失焦处理
  787. inputBlurMulti(conditionIndex, innerIndex, field) {
  788. const conditionItem = this.conditionList[conditionIndex];
  789. let target;
  790. if (innerIndex !== null) {
  791. target = conditionItem.formulaIfElse[innerIndex];
  792. } else {
  793. target = conditionItem;
  794. }
  795. if (target[field]) {
  796. if (target[`tags${field.charAt(3)}`] && target[`tags${field.charAt(3)}`][0]) {
  797. this.$emit('uncheck', target[`tags${field.charAt(3)}`][0].id);
  798. }
  799. target[`tags${field.charAt(3)}`] = [];
  800. }
  801. this.setConditionMulti(conditionIndex, innerIndex);
  802. },
  803. addText(){
  804. this.inputVisible = true;
  805. },
  806. //把元素加到公式里
  807. eleAddFormulaHandle(ele){
  808. let eleFormula;
  809. if(this.curFocusIndex == 6){
  810. eleFormula = this.selectEleFormula;
  811. }else if(this.curFocusIndex == 7){
  812. eleFormula = this.selectEleFormula2;
  813. }else{
  814. return;
  815. }
  816. if(ele.tableElementKey){
  817. //元素
  818. //简单语法判断
  819. if(eleFormula.length != 0){
  820. let lastEle = eleFormula[eleFormula.length-1];
  821. if(lastEle.type == 'Element'){
  822. this.$message({
  823. type: "warning",
  824. message: "元素无法连续出现在元素后面"
  825. });
  826. return;
  827. }
  828. if(lastEle.type == 'Text'){
  829. this.$message({
  830. type: "warning",
  831. message: "元素无法连续出现在输入值后面"
  832. });
  833. return;
  834. }
  835. if(lastEle.type == 'Brackets' && lastEle.name == ')'){
  836. this.$message({
  837. type: "warning",
  838. message: "元素无法连续出现在右括号后面"
  839. });
  840. return;
  841. }
  842. }
  843. eleFormula.push({
  844. type:'Element',
  845. name:ele.eName,
  846. id:ele.id,
  847. selected:false,
  848. tableElementKey:ele.tableElementKey,
  849. children:[],
  850. })
  851. }else if(ele.template && ele.example){
  852. //运算符号
  853. //简单语法判断
  854. if(eleFormula.length == 0){
  855. this.$message({
  856. type: "warning",
  857. message: "公式开头不能是运算符号"
  858. });
  859. return;
  860. }else{
  861. let lastEle = eleFormula[eleFormula.length-1];
  862. if(lastEle.type == 'Operator'){
  863. this.$message({
  864. type: "warning",
  865. message: "运算符号无法连续出现在运算符号后面"
  866. });
  867. return;
  868. }
  869. if(lastEle.type == 'Brackets' && lastEle.name == '('){
  870. this.$message({
  871. type: "warning",
  872. message: "运算符号无法连续出现在左括号后面"
  873. });
  874. return;
  875. }
  876. }
  877. eleFormula.push({
  878. type:'Operator',
  879. name:this.symbolReg.exec(ele.name)[1],
  880. selected:false,
  881. template:ele.template
  882. })
  883. }else if(ele.type == 'Brackets'){
  884. //括号
  885. eleFormula.splice(ele.selectIndex,0,{
  886. type:'Brackets',
  887. name:ele.name,
  888. selected:false,
  889. })
  890. }else if(ele.type == 'Text'){
  891. //输入值
  892. eleFormula.push({
  893. type:'Text',
  894. name:ele.name,
  895. selected:false,
  896. })
  897. }else if(ele.k){
  898. //节点参数
  899. eleFormula.push({
  900. type:'ParamData',
  901. name:ele.name,
  902. selected:false,
  903. id:ele.id,
  904. v:ele.v,
  905. k:ele.k,
  906. })
  907. }
  908. this.setTF();
  909. },
  910. // 多条件下添加元素到公式
  911. eleAddFormulaHandleMulti(ele, conditionIndex, formulaType) {
  912. const eleFormula = this.conditionList[conditionIndex][formulaType];
  913. if(ele.tableElementKey){
  914. //元素的简单语法判断
  915. if(eleFormula.length != 0){
  916. let lastEle = eleFormula[eleFormula.length-1];
  917. if(lastEle.type == 'Element'){
  918. this.$message({ type: "warning", message: "元素无法连续出现在元素后面" });
  919. return;
  920. }
  921. if(lastEle.type == 'Text'){
  922. this.$message({ type: "warning", message: "元素无法连续出现在输入值后面" });
  923. return;
  924. }
  925. if(lastEle.type == 'Brackets' && lastEle.name == ')'){
  926. this.$message({ type: "warning", message: "元素无法连续出现在右括号后面" });
  927. return;
  928. }
  929. }
  930. eleFormula.push({
  931. type:'Element',
  932. name:ele.eName,
  933. id:ele.id,
  934. selected:false,
  935. tableElementKey:ele.tableElementKey,
  936. children:[],
  937. })
  938. }else if(ele.template && ele.example){
  939. //运算符号的简单语法判断
  940. if(eleFormula.length == 0){
  941. this.$message({ type: "warning", message: "公式开头不能是运算符号" });
  942. return;
  943. }else{
  944. let lastEle = eleFormula[eleFormula.length-1];
  945. if(lastEle.type == 'Operator'){
  946. this.$message({ type: "warning", message: "运算符号无法连续出现在运算符号后面" });
  947. return;
  948. }
  949. if(lastEle.type == 'Brackets' && lastEle.name == '('){
  950. this.$message({ type: "warning", message: "运算符号无法连续出现在左括号后面" });
  951. return;
  952. }
  953. }
  954. eleFormula.push({
  955. type:'Operator',
  956. name:this.symbolReg.exec(ele.name)[1],
  957. selected:false,
  958. template:ele.template
  959. })
  960. }else if(ele.type == 'Brackets'){
  961. //括号
  962. eleFormula.splice(ele.selectIndex,0,{
  963. type:'Brackets',
  964. name:ele.name,
  965. selected:false,
  966. })
  967. }else if(ele.type == 'Text'){
  968. //输入值
  969. eleFormula.push({
  970. type:'Text',
  971. name:ele.name,
  972. selected:false,
  973. })
  974. }else if(ele.k){
  975. //节点参数
  976. eleFormula.push({
  977. type:'ParamData',
  978. name:ele.name,
  979. selected:false,
  980. id:ele.id,
  981. v:ele.v,
  982. k:ele.k,
  983. })
  984. }
  985. this.setTFMulti(conditionIndex);
  986. },
  987. //点选公式中的元素
  988. eleFormulaClick({selected,item},index){
  989. let eleFormula;
  990. if(this.curFocusIndex == 6){
  991. eleFormula = this.selectEleFormula;
  992. }else if(this.curFocusIndex == 7){
  993. eleFormula = this.selectEleFormula2;
  994. }else{
  995. return;
  996. }
  997. if(selected){
  998. eleFormula.forEach((ele)=>{
  999. ele.selected = false;
  1000. })
  1001. item.selected = true;
  1002. this.curSeleEleIndex = index;
  1003. }else{
  1004. this.curSeleEleIndex = -1;
  1005. }
  1006. },
  1007. // 多条件下点选公式中的元素
  1008. eleFormulaClickMulti({selected,item}, index, conditionIndex, formulaType) {
  1009. const eleFormula = this.conditionList[conditionIndex][formulaType];
  1010. console.log(eleFormula,'eleFormula');
  1011. if(selected){
  1012. eleFormula.forEach((ele)=>{
  1013. ele.selected = false;
  1014. })
  1015. item.selected = true;
  1016. this.curSeleEleIndex = index;
  1017. }else{
  1018. this.curSeleEleIndex = -1;
  1019. }
  1020. },
  1021. //快捷添加运算符号
  1022. addOperator(operator){
  1023. this.eleAddFormulaHandle(this.formulamap[operator]);
  1024. },
  1025. // 多条件下快捷添加运算符号
  1026. addOperatorMulti(conditionIndex, operator, formulaType) {
  1027. this.eleAddFormulaHandleMulti(this.formulamap[operator], conditionIndex, formulaType);
  1028. },
  1029. //删除点选公式中的元素
  1030. removeSelect(){
  1031. let eleFormula;
  1032. if(this.curFocusIndex == 6){
  1033. eleFormula = this.selectEleFormula;
  1034. }else if(this.curFocusIndex == 7){
  1035. eleFormula = this.selectEleFormula2;
  1036. }else{
  1037. return;
  1038. }
  1039. if(this.curSeleEleIndex > -1){
  1040. eleFormula.splice(this.curSeleEleIndex,1);
  1041. this.curSeleEleIndex = -1;
  1042. }
  1043. this.setTF();
  1044. },
  1045. // 多条件下删除点选公式中的元素
  1046. removeSelectMulti(conditionIndex, formulaType) {
  1047. const eleFormula = this.conditionList[conditionIndex][formulaType];
  1048. if(this.curSeleEleIndex > -1){
  1049. eleFormula.splice(this.curSeleEleIndex,1);
  1050. this.curSeleEleIndex = -1;
  1051. }
  1052. this.setTFMulti(conditionIndex);
  1053. },
  1054. //添加括号
  1055. addBrackets(text,type){
  1056. //type 是true 表示在元素右边插入
  1057. if(this.curSeleEleIndex == Number(this.curSeleEleIndex)){
  1058. this.eleAddFormulaHandle({
  1059. type:'Brackets',
  1060. name:text,
  1061. selectIndex:type?Number(this.curSeleEleIndex)+1:this.curSeleEleIndex
  1062. })
  1063. //如果在左边插入index要增1
  1064. if(!type){
  1065. this.curSeleEleIndex = Number(this.curSeleEleIndex)+1;
  1066. }
  1067. }
  1068. },
  1069. // 多条件下添加括号
  1070. addBracketsMulti(conditionIndex, text, type, formulaType) {
  1071. if(this.curSeleEleIndex == Number(this.curSeleEleIndex)){
  1072. this.eleAddFormulaHandleMulti({
  1073. type:'Brackets',
  1074. name:text,
  1075. selectIndex:type?Number(this.curSeleEleIndex)+1:this.curSeleEleIndex
  1076. }, conditionIndex, formulaType);
  1077. //如果在左边插入index要增1
  1078. if(!type){
  1079. this.curSeleEleIndex = Number(this.curSeleEleIndex)+1;
  1080. }
  1081. }
  1082. },
  1083. //添加输入值
  1084. addTextHandle(){
  1085. let eleFormula;
  1086. if(this.curFocusIndex == 6){
  1087. eleFormula = this.selectEleFormula;
  1088. }else if(this.curFocusIndex == 7){
  1089. eleFormula = this.selectEleFormula2;
  1090. }else if(this.symbol === 'more' && this.multiFocus.conditionIndex !== -1 &&
  1091. (this.multiFocus.field === 'formula1' || this.multiFocus.field === 'formula2')){
  1092. // 多条件下处理
  1093. eleFormula = this.conditionList[this.multiFocus.conditionIndex][this.multiFocus.field];
  1094. //简单语法判断
  1095. if(eleFormula.length != 0){
  1096. let lastEle = eleFormula[eleFormula.length-1];
  1097. if(lastEle.type == 'Element'){
  1098. this.$message({ type: "warning", message: "输入值无法连续出现在元素后面" });
  1099. this.inputVisible = false;
  1100. return;
  1101. }
  1102. if(lastEle.type == 'Text'){
  1103. this.$message({ type: "warning", message: "输入值无法连续出现在输入值后面" });
  1104. this.inputVisible = false;
  1105. return;
  1106. }
  1107. if(lastEle.type == 'Brackets' && lastEle.name == ')'){
  1108. this.$message({ type: "warning", message: "输入值无法连续出现在右括号后面" });
  1109. this.inputVisible = false;
  1110. return;
  1111. }
  1112. }
  1113. eleFormula.push({
  1114. type:'Text',
  1115. name:this.inputText,
  1116. selected:false,
  1117. });
  1118. this.setTFMulti(this.multiFocus.conditionIndex);
  1119. this.inputVisible = false;
  1120. this.inputText = '';
  1121. return;
  1122. }else if(this.symbol === 'getData' && this.dataFocus.index !== -1) {
  1123. // 数据获取部分处理
  1124. const { index, field } = this.dataFocus;
  1125. const item = this.getDataList[index];
  1126. const formulaType = field;
  1127. //简单语法判断
  1128. if(item[formulaType] && item[formulaType].length != 0){
  1129. let lastEle = item[formulaType][item[formulaType].length-1];
  1130. if(lastEle.type == 'Element'){
  1131. this.$message({ type: "warning", message: "输入值无法连续出现在元素后面" });
  1132. this.inputVisible = false;
  1133. return;
  1134. }
  1135. if(lastEle.type == 'Text'){
  1136. this.$message({ type: "warning", message: "输入值无法连续出现在输入值后面" });
  1137. this.inputVisible = false;
  1138. return;
  1139. }
  1140. if(lastEle.type == 'Brackets' && lastEle.name == ')'){
  1141. this.$message({ type: "warning", message: "输入值无法连续出现在右括号后面" });
  1142. this.inputVisible = false;
  1143. return;
  1144. }
  1145. }
  1146. // 添加输入值到相应字段
  1147. const tagField = field;
  1148. const tagsField = `tags${field.replace('tag', '')}`;
  1149. item[tagsField].push({
  1150. type: 'Text',
  1151. name: this.inputText,
  1152. text: this.inputText,
  1153. style: 'background-color: #409EFF'
  1154. });
  1155. item[tagField] = '';
  1156. this.setGetDataCondition();
  1157. this.inputVisible = false;
  1158. this.inputText = '';
  1159. return;
  1160. }else{
  1161. return;
  1162. }
  1163. //简单语法判断
  1164. if(eleFormula.length != 0){
  1165. let lastEle = eleFormula[eleFormula.length-1];
  1166. if(lastEle.type == 'Element'){
  1167. this.$message({
  1168. type: "warning",
  1169. message: "输入值无法连续出现在元素后面"
  1170. });
  1171. return;
  1172. }
  1173. if(lastEle.type == 'Text'){
  1174. this.$message({
  1175. type: "warning",
  1176. message: "输入值无法连续出现在输入值后面"
  1177. });
  1178. return;
  1179. }
  1180. if(lastEle.type == 'Brackets' && lastEle.name == ')'){
  1181. this.$message({
  1182. type: "warning",
  1183. message: "输入值无法连续出现在右括号后面"
  1184. });
  1185. return;
  1186. }
  1187. }
  1188. this.eleAddFormulaHandle({
  1189. type:'Text',
  1190. name:this.inputText
  1191. });
  1192. this.inputVisible = false;
  1193. this.inputText = '';
  1194. },
  1195. // 多条件下添加输入值
  1196. addTextMulti(conditionIndex, formulaType) {
  1197. this.multiFocus.conditionIndex = conditionIndex;
  1198. this.multiFocus.field = formulaType;
  1199. this.inputVisible = true;
  1200. },
  1201. setELe(ele){
  1202. if (this.symbol === 'getData' && this.elseFocus) {
  1203. let obj = {};
  1204. if(ele.k){
  1205. obj = {
  1206. type:'ParamData',
  1207. name:ele.name,
  1208. id:ele.id,
  1209. selected:false,
  1210. v:ele.v,
  1211. k:ele.k,
  1212. children:[],
  1213. }
  1214. }else{
  1215. obj = {
  1216. type:'Element',
  1217. name:ele.eName,
  1218. id:ele.id,
  1219. selected:false,
  1220. tableElementKey:ele.tableElementKey,
  1221. children:[],
  1222. }
  1223. }
  1224. // 根据当前焦点位置设置对应的标签
  1225. const position = this.elseFocus;
  1226. const tagField = `elseTag${position.charAt(0).toUpperCase() + position.slice(1)}`;
  1227. const tagsField = `elseTags${position.charAt(0).toUpperCase() + position.slice(1)}`;
  1228. // 清除之前选择的元素
  1229. if (this[tagsField] && this[tagsField][0]) {
  1230. this.$emit('uncheck', this[tagsField][0].id);
  1231. }
  1232. // 设置新选择的元素
  1233. obj.text = obj.name;
  1234. obj.style = 'background-color: #409EFF';
  1235. this[tagsField] = [obj];
  1236. this[tagField] = '';
  1237. this.setGetDataCondition();
  1238. return;
  1239. }
  1240. // 处理数据获取情况
  1241. if (this.symbol === 'getData' && this.dataFocus.index !== -1) {
  1242. const { index, field } = this.dataFocus;
  1243. const item = this.getDataList[index];
  1244. let obj = {};
  1245. if(ele.k){
  1246. obj = {
  1247. type:'ParamData',
  1248. name:ele.name,
  1249. id:ele.id,
  1250. selected:false,
  1251. v:ele.v,
  1252. k:ele.k,
  1253. children:[],
  1254. }
  1255. }else{
  1256. obj = {
  1257. type:'Element',
  1258. name:ele.eName,
  1259. id:ele.id,
  1260. selected:false,
  1261. tableElementKey:ele.tableElementKey,
  1262. children:[],
  1263. }
  1264. }
  1265. // 清除之前选择的元素
  1266. const tagsField = `tags${field.replace('tag', '')}`;
  1267. if (item[tagsField] && item[tagsField][0]) {
  1268. this.$emit('uncheck', item[tagsField][0].id);
  1269. }
  1270. // 设置新选择的元素
  1271. obj.text = obj.name;
  1272. obj.style = 'background-color: #409EFF';
  1273. item[tagsField] = [obj];
  1274. item[field] = '';
  1275. this.setGetDataCondition();
  1276. return;
  1277. }
  1278. // 处理多条件情况
  1279. if (this.symbol === 'more' && this.multiFocus.conditionIndex !== -1) {
  1280. const { conditionIndex, innerIndex, field } = this.multiFocus;
  1281. const conditionItem = this.conditionList[conditionIndex];
  1282. let target;
  1283. // 确定目标对象
  1284. if (innerIndex !== null) {
  1285. target = conditionItem.formulaIfElse[innerIndex];
  1286. } else {
  1287. target = conditionItem;
  1288. }
  1289. // 处理公式类型的字段
  1290. if (field === 'formula1' || field === 'formula2') {
  1291. this.eleAddFormulaHandleMulti(ele, conditionIndex, field);
  1292. return;
  1293. }
  1294. // 处理标签类型的字段
  1295. if (target && field) {
  1296. let obj = {};
  1297. if(ele.k){
  1298. obj = {
  1299. type:'ParamData',
  1300. name:ele.name,
  1301. id:ele.id,
  1302. selected:false,
  1303. v:ele.v,
  1304. k:ele.k,
  1305. children:[],
  1306. }
  1307. }else{
  1308. obj = {
  1309. type:'Element',
  1310. name:ele.eName,
  1311. id:ele.id,
  1312. selected:false,
  1313. tableElementKey:ele.tableElementKey,
  1314. children:[],
  1315. }
  1316. }
  1317. // 清除之前选择的元素
  1318. if (target[`tags${field.charAt(3)}`] && target[`tags${field.charAt(3)}`][0]) {
  1319. this.$emit('uncheck', target[`tags${field.charAt(3)}`][0].id);
  1320. }
  1321. // 设置新选择的元素
  1322. obj.text = obj.name;
  1323. obj.style = 'background-color: #409EFF';
  1324. target[`tags${field.charAt(3)}`] = [obj];
  1325. target[field] = '';
  1326. // 更新条件
  1327. this.setConditionMulti(conditionIndex, innerIndex);
  1328. }
  1329. return;
  1330. }
  1331. // 原逻辑处理单条件情况
  1332. if(this.curFocusIndex){
  1333. let obj = {};
  1334. if(ele.k){
  1335. obj = {
  1336. type:'ParamData',
  1337. name:ele.name,
  1338. id:ele.id,
  1339. selected:false,
  1340. v:ele.v,
  1341. k:ele.k,
  1342. children:[],
  1343. }
  1344. }else{
  1345. obj = {
  1346. type:'Element',
  1347. name:ele.eName,
  1348. id:ele.id,
  1349. selected:false,
  1350. tableElementKey:ele.tableElementKey,
  1351. children:[],
  1352. }
  1353. }
  1354. if(this.curFocusIndex == 6 || this.curFocusIndex ==7){
  1355. this.eleAddFormulaHandle(ele)
  1356. }else{
  1357. if(this['tags'+this.curFocusIndex] && this['tags'+this.curFocusIndex][0]){
  1358. this.$emit('uncheck',this['tags'+this.curFocusIndex][0].id)
  1359. }
  1360. obj.text = obj.name;
  1361. obj.style = 'background-color: #409EFF';
  1362. this['tags'+this.curFocusIndex] = [obj];
  1363. this['tag'+this.curFocusIndex] = '';
  1364. if(this.curFocusIndex == 4 || this.curFocusIndex == 5){
  1365. this.setTF();
  1366. }else{
  1367. this.setCondition();
  1368. }
  1369. }
  1370. }
  1371. },
  1372. // 设置多条件下的焦点
  1373. setMultiFocus(conditionIndex, innerIndex, field) {
  1374. this.multiFocus = {
  1375. conditionIndex,
  1376. innerIndex,
  1377. field
  1378. };
  1379. },
  1380. // 检查是否是当前焦点
  1381. isCurFocus(conditionIndex, innerIndex, field) {
  1382. return this.multiFocus.conditionIndex === conditionIndex &&
  1383. this.multiFocus.innerIndex === innerIndex &&
  1384. this.multiFocus.field === field;
  1385. },
  1386. //初始化真假值判断if(xxx)部分
  1387. initCondition(args0){
  1388. if(args0){
  1389. if(args0.length == 3){
  1390. //运算符号
  1391. this.symbol = args0[1];
  1392. //第二个空
  1393. if((typeof args0[0]) == 'object' && (args0[0].type == 'Element' || args0[0].type == 'ParamData')){
  1394. let ele = args0[0];
  1395. this.tags2 = [
  1396. Object.assign({
  1397. text:ele.name,
  1398. style:'background-color: #409EFF',
  1399. },ele)]
  1400. }else if((typeof args0[0]) == 'string'){
  1401. this.tag2 = args0[0];
  1402. }
  1403. //第三个空
  1404. if((typeof args0[2]) == 'object' && (args0[2].type == 'Element' || args0[2].type == 'ParamData')){
  1405. let ele = args0[2];
  1406. this.tags3 = [
  1407. Object.assign({
  1408. text:ele.name,
  1409. style:'background-color: #409EFF',
  1410. },ele)]
  1411. }else if((typeof args0[2]) == 'string'){
  1412. this.tag3 = args0[2];
  1413. }
  1414. }else if(args0.length == 7){
  1415. //运算符号
  1416. this.symbol = args0[1]+args0[3]+args0[5];
  1417. //第一个空
  1418. if((typeof args0[0]) == 'object' && (args0[0].type == 'Element' || args0[0].type == 'ParamData')){
  1419. let ele = args0[0];
  1420. this.tags1 = [
  1421. Object.assign({
  1422. text:ele.name,
  1423. style:'background-color: #409EFF',
  1424. },ele)]
  1425. }else if((typeof args0[0]) == 'string'){
  1426. this.tag1 = args0[0];
  1427. }
  1428. //第二个空
  1429. if((typeof args0[2]) == 'object' && (args0[2].type == 'Element' || args0[2].type == 'ParamData')){
  1430. let ele = args0[2];
  1431. this.tags2 = [
  1432. Object.assign({
  1433. text:ele.name,
  1434. style:'background-color: #409EFF',
  1435. },ele)]
  1436. }else if((typeof args0[2]) == 'string'){
  1437. this.tag2 = args0[2];
  1438. }
  1439. //第三个空
  1440. if((typeof args0[6]) == 'object' && (args0[6].type == 'Element' || args0[6].type == 'ParamData')){
  1441. let ele = args0[6];
  1442. this.tags3 = [
  1443. Object.assign({
  1444. text:ele.name,
  1445. style:'background-color: #409EFF',
  1446. },ele)]
  1447. }else if((typeof args0[6]) == 'string'){
  1448. this.tag3 = args0[6];
  1449. }
  1450. }else if(typeof args0 == 'object' && (args0.type == 'Element' || args0.type == 'ParamData')){
  1451. let ele = args0;
  1452. this.tags2 = [
  1453. Object.assign({
  1454. text:ele.name,
  1455. style:'background-color: #409EFF',
  1456. },ele)]
  1457. }
  1458. }
  1459. },
  1460. // 初始化多条件数据
  1461. initMultiConditions(args0) {
  1462. if (Array.isArray(args0)) {
  1463. this.conditionList = args0.map(condition => {
  1464. // 处理内部条件列表
  1465. const formulaIfElse = Array.isArray(condition.formulaIfElse) ?
  1466. condition.formulaIfElse.map(inner => ({
  1467. tag2: inner.tag2 || '',
  1468. tags2: inner.tags2 || [],
  1469. tag3: inner.tag3 || '',
  1470. tags3: inner.tags3 || [],
  1471. symbol1: inner.symbol1 || '',
  1472. logicSymbol: inner.logicSymbol || ''
  1473. })) : [{
  1474. tag2: '',
  1475. tags2: [],
  1476. tag3: '',
  1477. tags3: [],
  1478. symbol1: '',
  1479. logicSymbol: ''
  1480. }];
  1481. return {
  1482. formulaIfElse,
  1483. tag4: condition.tag4 || '',
  1484. tags4: condition.tags4 || [],
  1485. tag5: condition.tag5 || '',
  1486. tags5: condition.tags5 || [],
  1487. formula1: condition.formula1 || [],
  1488. formula2: condition.formula2 || []
  1489. };
  1490. });
  1491. }
  1492. },
  1493. //写入参数真假值判断if(xxx)部分
  1494. setCondition(){
  1495. if(this.symbol == '<&&<' || this.symbol == '<=&&<=' || this.symbol !== 'more' && this.symbol !== 'getData') {
  1496. // 处理单条件情况
  1497. if(this.symbol == '<&&<' || this.symbol == '<=&&<='){
  1498. let arr = new Array(7).fill('');
  1499. let symbolArr = this.symbol.split('&&');
  1500. if(this.tags1.length == 0){
  1501. arr[0] = this.tag1;
  1502. }else{
  1503. arr[0] = this.tags1[0];
  1504. }
  1505. arr[1] = symbolArr[0];
  1506. if(this.tags2.length == 0){
  1507. arr[2] = this.tag2;
  1508. arr[4] = this.tag2;
  1509. }else{
  1510. arr[2] = this.tags2[0];
  1511. arr[4] = this.tags2[0];
  1512. }
  1513. arr[3] = '&&';
  1514. arr[5] = symbolArr[1];
  1515. if(this.tags3.length == 0){
  1516. arr[6] = this.tag3;
  1517. }else{
  1518. arr[6] = this.tags3[0];
  1519. }
  1520. this.formulainfo.arguments[0] = arr;
  1521. }else{
  1522. let arr = new Array(3).fill('');
  1523. if(this.tags2.length == 0){
  1524. arr[0] = this.tag2;
  1525. }else{
  1526. arr[0] = this.tags2[0];
  1527. }
  1528. arr[1] = this.symbol;
  1529. if(this.tags3.length == 0){
  1530. arr[2] = this.tag3;
  1531. }else{
  1532. arr[2] = this.tags3[0];
  1533. }
  1534. this.formulainfo.arguments[0] = arr;
  1535. }
  1536. } else if(this.symbol == 'more'){
  1537. // this.result=this.remark||'1'
  1538. // 处理多条件情况
  1539. this.formulainfo.arguments[0] = this.conditionList.map(condition => ({
  1540. formulaIfElse: condition.formulaIfElse.map(inner => ({
  1541. tag2: inner.tag2,
  1542. tags2: inner.tags2,
  1543. tag3: inner.tag3,
  1544. tags3: inner.tags3,
  1545. symbol1: inner.symbol1,
  1546. logicSymbol: inner.logicSymbol
  1547. })),
  1548. tag4: condition.tag4,
  1549. tags4: condition.tags4,
  1550. tag5: condition.tag5,
  1551. tags5: condition.tags5,
  1552. formula1: condition.formula1,
  1553. formula2: condition.formula2
  1554. }));
  1555. } else if(this.symbol == 'getData'){
  1556. this.result='3'
  1557. // 数据获取情况已在setGetDataCondition中处理
  1558. }
  1559. },
  1560. // 多条件下设置条件
  1561. setConditionMulti(conditionIndex, innerIndex) {
  1562. this.setCondition();
  1563. },
  1564. //初始化输入框的真假值
  1565. initTFInput(args1,args2){
  1566. if((typeof args1) == 'object' && (args1.type == 'Element' || args1.type == 'ParamData')){
  1567. let ele = args1;
  1568. this.tags4 = [
  1569. Object.assign({
  1570. text:ele.name,
  1571. style:'background-color: #409EFF',
  1572. },ele)]
  1573. }else if((typeof args1) == 'string'){
  1574. this.tag4 = args1;
  1575. }
  1576. if((typeof args2) == 'object' && (args2.type == 'Element' || args2.type == 'ParamData')){
  1577. let ele = args2;
  1578. this.tags5 = [
  1579. Object.assign({
  1580. text:ele.name,
  1581. style:'background-color: #409EFF',
  1582. },ele)]
  1583. }else if((typeof args2) == 'string'){
  1584. this.tag5 = args2;
  1585. }
  1586. },
  1587. //初始化运算的真假值
  1588. initTFFormula(args1,args2){
  1589. if(Array.isArray(args1)){
  1590. args1.forEach((a,index)=>{
  1591. if(typeof a == 'string'){
  1592. this.$set(args1,index,{
  1593. type:'Text',
  1594. name:a,
  1595. selected:false,
  1596. })
  1597. }
  1598. })
  1599. this.selectEleFormula = args1;
  1600. }else if(typeof args1 == 'object' && (args1.type == 'Element' || args1.type == 'ParamData')){
  1601. this.selectEleFormula = [Object.assign({},args1)];
  1602. }else if(typeof args1 == 'string'){
  1603. this.selectEleFormula = [{
  1604. type:'Text',
  1605. name:args1,
  1606. selected:false,
  1607. }]
  1608. }
  1609. if(Array.isArray(args2)){
  1610. args2.forEach((a,index)=>{
  1611. if(typeof a == 'string'){
  1612. this.$set(args2,index,{
  1613. type:'Text',
  1614. name:a,
  1615. selected:false,
  1616. })
  1617. }
  1618. })
  1619. this.selectEleFormula2 = args2;
  1620. }else if(typeof args2 == 'object' && (args2.type == 'Element' || args2.type == 'ParamData')){
  1621. this.selectEleFormula2 = [Object.assign({},args2)];
  1622. }else if(typeof args2 == 'string'){
  1623. this.selectEleFormula2 = [{
  1624. type:'Text',
  1625. name:args2,
  1626. selected:false,
  1627. }]
  1628. }
  1629. },
  1630. //写入参数真假值
  1631. setTF(){
  1632. if(this.symbol !== 'more' && this.symbol !== 'getData') {
  1633. if(this.result == 1){
  1634. if(this.tags4.length == 0){
  1635. this.formulainfo.arguments[1] = this.tag4;
  1636. }else{
  1637. this.formulainfo.arguments[1] = this.tags4[0];
  1638. }
  1639. if(this.tags5.length == 0){
  1640. this.formulainfo.arguments[2] = this.tag5;
  1641. }else{
  1642. this.formulainfo.arguments[2] = this.tags5[0];
  1643. }
  1644. }else if(this.result == 2){
  1645. this.formulainfo.arguments[1] = this.selectEleFormula;
  1646. this.formulainfo.arguments[2] = this.selectEleFormula2;
  1647. }
  1648. }
  1649. if(this.symbol == 'more'){
  1650. console.log(this.result,'this.result');
  1651. this.remark=this.result
  1652. }
  1653. // 多条件情况在setCondition中处理
  1654. },
  1655. // 多条件下设置真假值
  1656. setTFMulti(conditionIndex) {
  1657. this.setCondition();
  1658. },
  1659. //添加条件
  1660. addCondition(index){
  1661. // 复制最后一个条件的结构作为新条件的基础
  1662. const newCondition = JSON.parse(JSON.stringify(this.conditionList[index]));
  1663. // 清空值但保留结构
  1664. newCondition.formulaIfElse = [
  1665. {
  1666. tag2: '',
  1667. tags2: [],
  1668. tag3: '',
  1669. tags3: [],
  1670. symbol1: '',
  1671. logicSymbol: ''
  1672. }
  1673. ];
  1674. newCondition.tag4 = '';
  1675. newCondition.tags4 = [];
  1676. newCondition.tag5 = '';
  1677. newCondition.tags5 = [];
  1678. newCondition.formula1 = [];
  1679. newCondition.formula2 = [];
  1680. this.conditionList.splice(index + 1, 0, newCondition);
  1681. this.setCondition();
  1682. },
  1683. //删除条件
  1684. removeCondition(index){
  1685. if (this.conditionList.length > 1) {
  1686. this.conditionList.splice(index,1);
  1687. this.setCondition();
  1688. } else {
  1689. this.$message({ type: "warning", message: "至少保留一个条件" });
  1690. }
  1691. },
  1692. // 添加内部条件项
  1693. addConditionItem(conditionIndex, innerIndex) {
  1694. const newInnerItem = {
  1695. tag2: '',
  1696. tags2: [],
  1697. tag3: '',
  1698. tags3: [],
  1699. symbol1: '',
  1700. logicSymbol: ''
  1701. };
  1702. this.conditionList[conditionIndex].formulaIfElse.splice(innerIndex + 1, 0, newInnerItem);
  1703. this.setCondition();
  1704. },
  1705. // 删除内部条件项
  1706. removeConditionItem(conditionIndex, innerIndex) {
  1707. if (this.conditionList[conditionIndex].formulaIfElse.length > 1) {
  1708. this.conditionList[conditionIndex].formulaIfElse.splice(innerIndex, 1);
  1709. this.setCondition();
  1710. } else {
  1711. this.$message({ type: "warning", message: "至少保留一个条件项" });
  1712. }
  1713. },
  1714. // 设置否则部分的焦点
  1715. setElseFocus(position) {
  1716. this.elseFocus = position;
  1717. },
  1718. // 否则部分输入框失焦处理
  1719. elseInputBlur(position) {
  1720. const tagField = `elseTag${position.charAt(0).toUpperCase() + position.slice(1)}`;
  1721. const tagsField = `elseTags${position.charAt(0).toUpperCase() + position.slice(1)}`;
  1722. if (this[tagField]) {
  1723. if (this[tagsField] && this[tagsField][0]) {
  1724. this.$emit('uncheck', this[tagsField][0].id);
  1725. }
  1726. this[tagsField] = [];
  1727. }
  1728. this.setGetDataCondition();
  1729. },
  1730. //返回数据获取相关的数据
  1731. getDataConditionData() {
  1732. const inputData = {
  1733. // 获取数据列表的函数
  1734. getDataList: this.getDataList,
  1735. // 左侧else标签
  1736. elseTagLeft: this.elseTagLeft,
  1737. elseTagsLeft: this.elseTagsLeft,
  1738. // 左侧else标签集合
  1739. elseTagRight:this.elseTagRight,
  1740. elseTagsRight:this.elseTagsRight,
  1741. }
  1742. console.log(inputData,'inputData');
  1743. const result = transformData(inputData);
  1744. const mapEle=generateElementMap(inputData)
  1745. return {
  1746. // 获取数据列表的函数
  1747. getDataList: this.getDataList,
  1748. elseTagsLeft: this.elseTagsLeft,
  1749. // 左侧else标签
  1750. elseTagLeft: this.elseTagLeft,
  1751. // 左侧else标签集合
  1752. elseTagRight:this.elseTagRight,
  1753. elseTagsRight:this.elseTagsRight,
  1754. result,
  1755. mapEle
  1756. };
  1757. },
  1758. //选择元素回显处理
  1759. handleTagClick(info,index) {
  1760. console.log(info,'info');
  1761. const {tag}=info;
  1762. this.curFocusIndex = index
  1763. const refName = `tagsInput${this.curFocusIndex}`;
  1764. this.$refs[refName].focus(); // 动态获取ref并调用focus方法
  1765. this.$emit('clickTag',tag)
  1766. },
  1767. // 处理多条件下的标签点击事件
  1768. handleMultiTagClick(info, conditionIndex, innerIndex, field) {
  1769. const { tag } = info;
  1770. // 设置当前焦点信息
  1771. this.setMultiFocus(conditionIndex, innerIndex, field);
  1772. // 获取对应的ref并聚焦
  1773. const refName = `multiTagsInput_${conditionIndex}_${innerIndex}_${field}`;
  1774. console.log(refName,'refName');
  1775. console.log(this.$refs,'this.$refs');
  1776. if (this.$refs[refName]) {
  1777. this.$refs[refName][0].focus();
  1778. }
  1779. // 向父组件传递点击的标签信息
  1780. this.$emit('clickTag', tag);
  1781. },
  1782. // 处理数据获取部分(循环项)的标签点击
  1783. handleDataTagClick(info, index, field) {
  1784. const { tag } = info;
  1785. // 1. 设置当前焦点
  1786. this.setDataFocus(index, field);
  1787. // 2. 聚焦到当前输入框
  1788. const refName = `dataTag_${index}_${field}`;
  1789. const tagInput = this.$refs[refName];
  1790. if (tagInput) {
  1791. const instance = Array.isArray(tagInput) ? tagInput[0] : tagInput;
  1792. if (instance && typeof instance.focus === 'function') {
  1793. instance.focus();
  1794. }
  1795. }
  1796. // 3. 向父组件传递选中的tag
  1797. this.$emit('clickTag', tag);
  1798. },
  1799. // 处理“否则”部分的标签点击
  1800. handleElseTagClick(info, position) {
  1801. const { tag } = info;
  1802. // 1. 设置当前焦点
  1803. this.setElseFocus(position);
  1804. // 2. 聚焦到当前输入框
  1805. const refName = `elseTag${position.charAt(0).toUpperCase() + position.slice(1)}`;
  1806. const instance = this.$refs[refName];
  1807. if (instance && typeof instance.focus === 'function') {
  1808. instance.focus();
  1809. }
  1810. // 3. 向父组件传递选中的tag
  1811. this.$emit('clickTag', tag);
  1812. },
  1813. }
  1814. }
  1815. </script>
  1816. <style scoped lang="scss">
  1817. .textblod{
  1818. font-weight: bold;
  1819. font-size: 18px;
  1820. }
  1821. .sele-ele-box{
  1822. height: 100px;
  1823. padding: 10px;
  1824. // margin-top: 10px;
  1825. }
  1826. .icon-box .el-link{
  1827. font-size: 20px;
  1828. margin-right: 10px;
  1829. }
  1830. .icon-btn{
  1831. color: #409EFF;
  1832. cursor: 409EFF;
  1833. }
  1834. .border-green {
  1835. border-color: green !important;
  1836. }
  1837. .border-grey {
  1838. border: 1px solid #ddd;
  1839. }
  1840. </style>