8
0

edit-formula.vue 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  1. <template>
  2. <hc-drawer v-model="isShow" ui="hc-project-list-edit-formula-drawer" to-id="hc-layout-box" is-close @close="drawerClose">
  3. <hc-card is-action-btn :scrollbar="isScrollBar">
  4. <div class="hc-project-list-edit-formula-card" :class="isScrollBar ? '' : 'is-no-scroll'">
  5. <!-- 顶部操作 -->
  6. <div class="hc-formula-card-box border-dashed-card hc-flex mb-14px h-58px">
  7. <div class="retain hc-flex h-full w-174px">
  8. <el-checkbox v-model="isRetain" size="large" />
  9. <span class="ml-5px text-14px">保留</span>
  10. <div class="relative ml-5px w-90px">
  11. <el-input-number v-model="retainNum" block :step="1" :min="0" :max="5" :disabled="!isRetain" controls-position="right" />
  12. </div>
  13. <span class="ml-5px text-14px">位</span>
  14. </div>
  15. <div class="range hc-flex h-full w-155px">
  16. <el-button :type="deviationRangeShow ? 'primary' : ''" @click="setDeviationRange">允许偏差值范围</el-button>
  17. </div>
  18. <div class="menu h-full flex-1">
  19. <hc-body padding="0">
  20. <el-menu :default-active="formulaMenuIndex" mode="horizontal" @select="handleFormulaMenu">
  21. <el-sub-menu v-for="(arr, key, index) in formulaMenuList" :key="key" :index="key">
  22. <template #title>{{ key }}</template>
  23. <el-menu-item v-for="(item, i) in arr" :key="i" :index="`${index + 1}-${i + 1}`">{{ item?.name }}</el-menu-item>
  24. </el-sub-menu>
  25. </el-menu>
  26. </hc-body>
  27. </div>
  28. <div class="hand hc-flex h-full w-100px">
  29. <el-button @click="handWritClick">手写模式</el-button>
  30. </div>
  31. </div>
  32. <!-- 函数公式 -->
  33. <div class="border-dashed-card hc-formula-card-math mb-14px">
  34. <div class="header hc-flex">
  35. <div class="name flex-1 text-14px">函数公式.</div>
  36. <div class="extra relative ml-24px">
  37. <el-button size="small" @click="clearResetFunClick">清除选择</el-button>
  38. <el-button :type="isResetFun ? 'primary' : 'info'" size="small" @click="resetFunClick">重置函数</el-button>
  39. </div>
  40. </div>
  41. <div class="body relative">
  42. <template v-for="(item, index) in resultFormula" :key="index">
  43. <span class="element-class text-22px" :class="item.selected ? 'is-cur' : ''" @click="resultFormulaItem(item, index)">{{ item.name }}</span>
  44. </template>
  45. <span class="ml-10px mr-10px text-24px">=</span>
  46. <template v-for="(item, index) in processFormula" :key="index">
  47. <el-tooltip :content="item.tableName" placement="top-start" :disabled="item.type !== 'Element' || isNullES(item.tableName)">
  48. <span class="element-class text-22px" :class="item.selected ? 'is-cur' : ''" :data-name="getItemTableName(item)" @click="processFormulaItem(item, index)">{{ item.name }}</span>
  49. </el-tooltip>
  50. </template>
  51. </div>
  52. </div>
  53. <!-- 重置函数 -->
  54. <div v-if="isResetFun" class="hc-formula-reset-fun mb-14px">
  55. <hc-body split padding="0">
  56. <template #left>
  57. <hc-card class="reset-fun-left-card" scrollbar :loading="treeResetFunLoading">
  58. <template #header>
  59. <hc-search-input v-model="resetFunTree" @search="resetFunTreeSearch" />
  60. </template>
  61. <el-tree
  62. v-if="isResetFunTreeLazy" ref="treeResetFunLazyRef" :default-expanded-keys="treeResetFunLazyExpanded" node-key="id"
  63. :props="defaultProps" :expand-on-click-node="false" lazy highlight-current :load="treeResetFunLazyLoad"
  64. @node-click="treeResetFunLazyClick"
  65. />
  66. <el-tree
  67. v-else ref="treeResetFunAllRef" :data="resetFunTreeAll" :props="defaultProps" node-key="id"
  68. :expand-on-click-node="false" @node-click="treeResetFunLazyClick"
  69. />
  70. </hc-card>
  71. </template>
  72. <hc-card class="reset-fun-right-card">
  73. <template #header>
  74. <hc-search-input v-model="resetFunEle" placeholder="请输入你想搜索的元素字段" @search="resetFunEleSearch" />
  75. </template>
  76. <div class="body h-full">
  77. <div v-loading="isResetFunEleLoading" class="tag-box">
  78. <template v-for="(item, index) in resetFunEleData" :key="index">
  79. <el-button v-if="item.k" type="primary" plain size="small" @click="resetFunEleTagClick(item)">{{ item.name }}</el-button>
  80. <el-button v-else type="primary" plain size="small" @click="resetFunEleTagClick(item)">{{ item.eName }}</el-button>
  81. </template>
  82. </div>
  83. <div class="action-box hc-flex">
  84. <div class="left hc-flex flex-1">
  85. <div class="btn hc-flex-center" @click="resetFunText">
  86. <span class="text">输入值</span>
  87. </div>
  88. <div class="btn hc-flex-center" @click="resetFunBrackets('(')">
  89. <span class="symbol">(</span>
  90. </div>
  91. <div class="btn hc-flex-center" @click="resetFunBrackets(')')">
  92. <span class="symbol">)</span>
  93. </div>
  94. <div class="btn hc-flex-center" @click="resetFunOperator('+')">
  95. <i class="i-ri-add-line" />
  96. </div>
  97. <div class="btn hc-flex-center" @click="resetFunOperator('-')">
  98. <i class="i-ri-subtract-line" />
  99. </div>
  100. <div class="btn hc-flex-center" @click="resetFunOperator('*')">
  101. <i class="i-ri-close-line" />
  102. </div>
  103. <div class="btn hc-flex-center" @click="resetFunOperator('%')">
  104. <hc-icon name="divide" />
  105. </div>
  106. </div>
  107. <div class="right hc-flex">
  108. <el-tooltip content="删除元素" placement="top-end">
  109. <div class="btn hc-flex-center" @click="resetFunDel">
  110. <i class="i-ri-delete-back-2-line" />
  111. </div>
  112. </el-tooltip>
  113. <el-tooltip content="清空所有" placement="top-end">
  114. <div class="btn hc-flex-center" @click="resetFunClear">
  115. <i class="i-ri-delete-bin-3-line" />
  116. </div>
  117. </el-tooltip>
  118. </div>
  119. </div>
  120. <div class="input-box">
  121. <draggable v-model="selectEleFormula" item-key="index">
  122. <template #item="{ element }">
  123. <span class="element-class" :class="[`is-${element.type}`, element.selected ? 'is-cur' : '']" @click="selectEleFormulaItem(element)">{{ element.name }}</span>
  124. </template>
  125. </draggable>
  126. </div>
  127. </div>
  128. </hc-card>
  129. </hc-body>
  130. </div>
  131. <!-- 函数公式运算执行溯源 -->
  132. <div v-if="!isResetFun && !deviationRangeShow" class="border-dashed-card hc-formula-card-project mb-14px">
  133. <div class="header mb-14px text-14px">函数公式运算执行溯源</div>
  134. <div class="body relative">
  135. <el-select v-model="projectId" filterable clearable class="mr-14px w-380px" placeholder="选择项目" @change="projectChange">
  136. <el-option v-for="item in projectList" :key="item.id" :label="item.projectName" :value="item.id" />
  137. </el-select>
  138. <el-select v-model="contractId" filterable clearable class="mr-14px w-200px" placeholder="请选择合同段">
  139. <el-option v-for="item in contractList" :key="item.id" :label="item.contractName" :value="item.id" />
  140. </el-select>
  141. <el-button type="info" @click="projectQueryClick">查询</el-button>
  142. </div>
  143. </div>
  144. <!-- 允许偏差值范围 -->
  145. <div v-if="deviationRangeShow && !isResetFun" class="border-dashed-card hc-formula-card-range mb-14px" :class="isRangeSelectEle ? 'is-h' : ''">
  146. <div class="hc-formula-card-range-form hc-flex mb-12px text-14px">
  147. <div>允许偏差值范围:</div>
  148. <div class="w-130px">
  149. <el-select v-model="deviationRangeSymbol" filterable clearable placeholder="请选择允许偏差值范围">
  150. <el-option label="【min,max】" value="【min,max】" />
  151. <el-option label=">" value=">" />
  152. <el-option label="<" value="<" />
  153. <el-option label="≥" value="≥" />
  154. <el-option label="≤" value="≤" />
  155. </el-select>
  156. </div>
  157. <div class="ml-50px">模式:</div>
  158. <div class="mr-50px w-100px">
  159. <el-select v-model="deviationRangeResult" filterable clearable placeholder="请选择模式" @change="deviationRangeResultChange">
  160. <el-option label="普通" value="1" />
  161. <el-option label="自定义" value="2" />
  162. </el-select>
  163. </div>
  164. <div v-if="deviationRangeResult === '1'" class="hc-flex mr-50px">
  165. <VueTagsInput
  166. v-if="!(deviationRangeSymbol === '<' || deviationRangeSymbol === '≤')" v-model="deviationRangeTag1" :tags="deviationRangeTags1"
  167. placeholder="输入/参数" class="mr-12px" :class="curRangeFocusIndex === 1 ? 'cur' : ''" @focus="curRangeFocusIndex = 1"
  168. @blur="deviationRangeBlur1" @before-adding-tag="rangeAddingTag"
  169. />
  170. <VueTagsInput
  171. v-if="!(deviationRangeSymbol === '>' || deviationRangeSymbol === '≥')" v-model="deviationRangeTag2" :tags="deviationRangeTags2"
  172. placeholder="输入/参数" :class="curRangeFocusIndex === 2 ? 'cur' : ''" @focus="curRangeFocusIndex = 2" @blur="deviationRangeBlur2"
  173. @before-adding-tag="rangeAddingTag"
  174. />
  175. </div>
  176. <el-button :type="isRangeSelectEle ? 'primary' : 'info'" @click="deviationRangeSelectEle">选择参数</el-button>
  177. </div>
  178. <div v-if="deviationRangeResult === '2'" class="hc-formula-card-range-param relative mb-12px">
  179. <el-row :gutter="20">
  180. <el-col v-if="!(deviationRangeSymbol === '<' || deviationRangeSymbol === '≤')" :span="12">
  181. <div class="deviation-range-param-card" :class="curRangeFocusIndex === 3 ? 'cur' : ''" @click.capture="curRangeFocusIndex = 3">
  182. <div class="title-box">参数1</div>
  183. <div class="action-box hc-flex">
  184. <div class="left hc-flex flex-1">
  185. <div class="btn hc-flex-center" @click="resetFunText">
  186. <span class="text">输入值</span>
  187. </div>
  188. <div class="btn hc-flex-center" @click="resetFunBrackets('(')">
  189. <span class="symbol">(</span>
  190. </div>
  191. <div class="btn hc-flex-center" @click="resetFunBrackets(')')">
  192. <span class="symbol">)</span>
  193. </div>
  194. <div class="btn hc-flex-center" @click="resetFunOperator('+')">
  195. <i class="i-ri-add-line" />
  196. </div>
  197. <div class="btn hc-flex-center" @click="resetFunOperator('-')">
  198. <i class="i-ri-subtract-line" />
  199. </div>
  200. <div class="btn hc-flex-center" @click="resetFunOperator('*')">
  201. <i class="i-ri-close-line" />
  202. </div>
  203. <div class="btn hc-flex-center" @click="resetFunOperator('%')">
  204. <hc-icon name="divide" />
  205. </div>
  206. </div>
  207. <div class="right hc-flex">
  208. <el-tooltip content="删除元素" placement="top-end">
  209. <div class="btn hc-flex-center" @click="resetFunDel">
  210. <i class="i-ri-delete-back-2-line" />
  211. </div>
  212. </el-tooltip>
  213. <el-tooltip content="清空所有" placement="top-end">
  214. <div class="btn hc-flex-center" @click="resetFunClear">
  215. <i class="i-ri-delete-bin-3-line" />
  216. </div>
  217. </el-tooltip>
  218. </div>
  219. </div>
  220. <div class="input-box">
  221. <draggable v-if="selectEleFormula3.length > 0" v-model="selectEleFormula3" item-key="index">
  222. <template #item="{ element }">
  223. <span class="element-class" :class="[`is-${element.type}`, element.selected ? 'is-cur' : '']" @click="selectEleFormulaItem(element)">{{ element.name }}</span>
  224. </template>
  225. </draggable>
  226. <div v-else class="text-gray-5">请选择元素</div>
  227. </div>
  228. </div>
  229. </el-col>
  230. <el-col v-if="!(deviationRangeSymbol === '>' || deviationRangeSymbol === '≥')" :span="12">
  231. <div class="deviation-range-param-card" :class="curRangeFocusIndex === 4 ? 'cur' : ''" @click.capture="curRangeFocusIndex = 4">
  232. <div class="title-box">参数2</div>
  233. <div class="action-box hc-flex">
  234. <div class="left hc-flex flex-1">
  235. <div class="btn hc-flex-center" @click="resetFunText">
  236. <span class="text">输入值</span>
  237. </div>
  238. <div class="btn hc-flex-center" @click="resetFunBrackets('(')">
  239. <span class="symbol">(</span>
  240. </div>
  241. <div class="btn hc-flex-center" @click="resetFunBrackets(')')">
  242. <span class="symbol">)</span>
  243. </div>
  244. <div class="btn hc-flex-center" @click="resetFunOperator('+')">
  245. <i class="i-ri-add-line" />
  246. </div>
  247. <div class="btn hc-flex-center" @click="resetFunOperator('-')">
  248. <i class="i-ri-subtract-line" />
  249. </div>
  250. <div class="btn hc-flex-center" @click="resetFunOperator('*')">
  251. <i class="i-ri-close-line" />
  252. </div>
  253. <div class="btn hc-flex-center" @click="resetFunOperator('%')">
  254. <hc-icon name="divide" />
  255. </div>
  256. </div>
  257. <div class="right hc-flex">
  258. <el-tooltip content="删除元素" placement="top-end">
  259. <div class="btn hc-flex-center" @click="resetFunDel">
  260. <i class="i-ri-delete-back-2-line" />
  261. </div>
  262. </el-tooltip>
  263. <el-tooltip content="清空所有" placement="top-end">
  264. <div class="btn hc-flex-center" @click="resetFunClear">
  265. <i class="i-ri-delete-bin-3-line" />
  266. </div>
  267. </el-tooltip>
  268. </div>
  269. </div>
  270. <div class="input-box">
  271. <draggable v-if="selectEleFormula4.length > 0" v-model="selectEleFormula4" item-key="index">
  272. <template #item="{ element }">
  273. <span class="element-class" :class="[`is-${element.type}`, element.selected ? 'is-cur' : '']" @click="selectEleFormulaItem(element)">{{ element.name }}</span>
  274. </template>
  275. </draggable>
  276. <div v-else class="text-gray-5">请选择元素</div>
  277. </div>
  278. </div>
  279. </el-col>
  280. </el-row>
  281. </div>
  282. <div v-if="isRangeSelectEle" class="hc-formula-card-range-select relative">
  283. <hc-body split padding="0">
  284. <template #left>
  285. <hc-card class="hc-formula-card-range-select-left-card" scrollbar :loading="treeResetFunLoading">
  286. <template #header>
  287. <hc-search-input v-model="resetFunTree" @search="resetFunTreeSearch" />
  288. </template>
  289. <el-tree
  290. v-if="isResetFunTreeLazy" ref="treeRangeSelectLazyRef" :default-expanded-keys="treeResetFunLazyExpanded" node-key="id"
  291. :props="defaultProps" :expand-on-click-node="false" lazy highlight-current :load="treeResetFunLazyLoad"
  292. @node-click="treeResetFunLazyClick"
  293. />
  294. <el-tree
  295. v-else ref="treeRangeSelectAllRef" :data="resetFunTreeAll" :props="defaultProps" node-key="id"
  296. :expand-on-click-node="false" @node-click="treeResetFunLazyClick"
  297. />
  298. </hc-card>
  299. </template>
  300. <hc-card scrollbar class="hc-formula-card-range-select-right-card">
  301. <template #header>
  302. <hc-search-input v-model="resetFunEle" placeholder="请输入你想搜索的元素字段" @search="resetFunEleSearch" />
  303. </template>
  304. <div v-loading="isResetFunEleLoading" class="body h-full">
  305. <template v-for="(item, index) in resetFunEleData" :key="index">
  306. <el-button v-if="item.k" type="primary" plain size="small" @click="resetFunEleTagClick(item)">{{ item.name }}</el-button>
  307. <el-button v-else type="primary" plain size="small" @click="resetFunEleTagClick(item)">{{ item.eName }}</el-button>
  308. </template>
  309. </div>
  310. </hc-card>
  311. </hc-body>
  312. </div>
  313. </div>
  314. </div>
  315. <template #action>
  316. <el-button @click="drawerClose">取消</el-button>
  317. <el-button type="primary" :loading="submitLoading" @click="submitClick">保存</el-button>
  318. </template>
  319. </hc-card>
  320. <!-- 手写模式 -->
  321. <hc-dialog v-model="isHandWritEle" is-table widths="900px" title="手写模式" @close="handWritEleClose">
  322. <template #search>
  323. <div class="relative">
  324. <div class="mb-6px text-orange-6">tips:手写模式不保证能转换成配置模式!!即使能转换也不保证正确!!!</div>
  325. <div class="text-orange-6">无法在手写模式手写加入新的元素!新的节点参数!</div>
  326. </div>
  327. </template>
  328. <el-input v-model="handWritText" type="textarea" class="hc-formula-hand-writ-text" placeholder="请输入内容" />
  329. <template #footer>
  330. <el-button hc-btn @click="handWritEleClose">取消</el-button>
  331. <el-button hc-btn type="primary" @click="handWritTransform">转换</el-button>
  332. </template>
  333. </hc-dialog>
  334. </hc-drawer>
  335. </template>
  336. <script setup>
  337. import { nextTick, ref, watch } from 'vue'
  338. import { useClick } from 'hc-vue3-ui'
  339. import {
  340. arrIndex, deepClone, getArrValue, getObjValue,
  341. getRandom, isArray, isNullES, isString,
  342. } from 'js-fast-way'
  343. import { ElMessageBox } from 'element-plus'
  344. import { VueTagsInput } from '@vojtechlanka/vue-tags-input'
  345. import draggable from 'vuedraggable'
  346. //辅助解析文件
  347. import { rangeToString } from './formula/rangeToString'
  348. import { formulaArrayToString } from './formula/formulaArrayToString'
  349. import { formulaStringToArray } from './formula/formulaStringToArray'
  350. //接口文件
  351. import projectApi from '~api/project/project'
  352. import contractApi from '~api/project/contract'
  353. import formulaApi from '~api/project/formula'
  354. import elementApi from '~api/project/element'
  355. import privateApi from '~api/wbs/private'
  356. import treeApi from '~api/wbs/tree'
  357. const props = defineProps({
  358. data: {
  359. type: Object,
  360. default: () => ({}),
  361. },
  362. })
  363. //事件
  364. const emit = defineEmits(['close', 'finish', 'uncheck'])
  365. //双向绑定
  366. const isShow = defineModel('modelValue', {
  367. default: false,
  368. })
  369. //监听数据
  370. const dataInfo = ref(props.data)
  371. watch(() => props.data, (data) => {
  372. dataInfo.value = getObjValue(data)
  373. }, { immediate: true, deep: true })
  374. //监听显示
  375. watch(isShow, (val) => {
  376. if (val) getDataApi()
  377. })
  378. //基础变量
  379. const symbolReg = /(\+|-|\*|\/)(.+)/ //加减乘除
  380. const operatorReg = /^\+|-|\*|%/ //加减乘除
  381. const startFCRegExp = /^FC\.([a-zA-Z\d]+)\(/ //匹配开始的FC.xxx(
  382. const isScrollBar = ref(true)
  383. //获取数据
  384. const getDataApi = async () => {
  385. console.log(dataInfo.value)
  386. await getTypeMapApi()
  387. await getWbsFormElementData()
  388. await getFormulaStringToArrayApi()
  389. getProjectDataApi().then()
  390. }
  391. //保留位数
  392. const isRetain = ref(false)
  393. const retainNum = ref(2)
  394. //把公式文本还原数组
  395. const rightDict = ref([])
  396. const formulaId = ref('')
  397. const deviationRangeObj = ref({})
  398. const getFormulaStringToArrayApi = async () => {
  399. const { eleId, globalType, nodeId, pid } = getObjValue(dataInfo.value)
  400. const { code, data } = await formulaApi.detail({
  401. projectId: pid,
  402. elementId: eleId,
  403. nodeId: nodeId,
  404. scope: globalType,
  405. })
  406. if (code !== 200) return
  407. const res = getObjValue(data)
  408. console.log(res)
  409. if (!isNullES(res.id)) {
  410. //获取右边元素的字典
  411. let dictMap = getObjValue(res.dict), dictArr = []
  412. //遍历
  413. for (let i in dictMap) {
  414. dictArr.push(dictMap[i])
  415. }
  416. rightDict.value = dictArr
  417. formulaId.value = res.id
  418. //把公式字符串还原成数组
  419. let formula = formulaStringToArray(res.formula, res.map, formulaMenuMap.value)
  420. processFormula.value = getArrValue(formula?.processFormula)
  421. const results = resultFormula.value
  422. formula.resultFormula[0].id = results[0].id
  423. formula.resultFormula[0].name = results[0].name
  424. formula.resultFormula[0].tableElementKey = results[0].tableElementKey
  425. resultFormula.value[0].children = formula.resultFormula[0].children
  426. //允许偏差值范围
  427. let mapObj = JSON.parse(res.map)
  428. if (mapObj.deviationRangeJson) {
  429. deviationRangeObj.value = JSON.parse(mapObj.deviationRangeJson)
  430. }
  431. }
  432. if (res.scale >= 0) {
  433. isRetain.value = true
  434. retainNum.value = res.scale
  435. } else {
  436. isRetain.value = false
  437. retainNum.value = 2
  438. }
  439. }
  440. //获取当前元素的表名
  441. const getItemTableName = (item) => {
  442. if (item.type !== 'Element') {
  443. return
  444. }
  445. rightDict.value.forEach((ele) => {
  446. if (ele.ekey === item.tableElementKey) {
  447. item.tableName = ele.tableName
  448. }
  449. })
  450. }
  451. //允许偏差值范围
  452. const deviationRangeShow = ref(false)
  453. const setDeviationRange = () => {
  454. if (isResetFun.value) {
  455. window?.$message.warning('请先关闭重置函数')
  456. return
  457. }
  458. const val = !deviationRangeShow.value
  459. deviationRangeShow.value = val
  460. if (val) {
  461. const { symbol, model, arguments1, arguments2 } = deviationRangeObj.value
  462. deviationRangeSymbol.value = symbol
  463. deviationRangeResult.value = model
  464. curRangeFocusIndex.value = 1
  465. //公式
  466. if (isArray(arguments1) && arguments1.length > 1 || isArray(arguments2) && arguments2.length > 1) {
  467. //selectEleFormula.value = arguments1
  468. selectEleFormula3.value = arguments1
  469. selectEleFormula4.value = arguments2
  470. return
  471. }
  472. //参数1
  473. if (isString(arguments1)) {
  474. deviationRangeTag1.value = arguments1
  475. } else {
  476. deviationRangeTags1.value = arguments1
  477. }
  478. //参数2
  479. if (isString(arguments2)) {
  480. deviationRangeTag2.value = arguments2
  481. } else {
  482. deviationRangeTags2.value = arguments2
  483. }
  484. } else {
  485. curRangeFocusIndex.value = 0
  486. }
  487. }
  488. //获取顶部菜单数据
  489. const formulaMenuMap = ref({})
  490. const formulaMenuIndex = ref(null)
  491. const formulaMenuList = ref({})
  492. const getTypeMapApi = async () => {
  493. const { data } = await formulaApi.getTypeMap()
  494. const res = getObjValue(data)
  495. formulaMenuList.value = deepClone(res)
  496. //生成map,方便查找
  497. for (let key in res) {
  498. if (typeof(res[key]) === 'object') {
  499. res[key].forEach((formula)=>{
  500. formula.template = JSON.parse(formula.template)
  501. if (operatorReg.test(formula.template.ft)) {
  502. formulaMenuMap.value[formula.template.ft] = formula
  503. } else if (startFCRegExp.test(formula.template.ft)) {
  504. let regRes = formula.template.ft.match(startFCRegExp)
  505. formulaMenuMap.value[regRes[0]] = formula
  506. }
  507. })
  508. }
  509. }
  510. }
  511. //菜单被选择
  512. const handleFormulaMenu = (index, path) => {
  513. if (isResetFun.value) {
  514. //重置函数
  515. if (path[0] !== '基础运算') {
  516. window?.$message.warning('当前只能使用基础运算')
  517. return
  518. }
  519. try {
  520. let index = Number(path[1].split('-')[1]) - 1
  521. const item = formulaMenuList.value[path[0]][index]
  522. const val = symbolReg.exec(item.name)[1]
  523. resetFunOperator(val)
  524. } catch (e) {
  525. console.error(e)
  526. }
  527. } else {
  528. equationSelect(index, path)
  529. }
  530. }
  531. //在等式模式下点选计算式
  532. const equationSelectEle = ref({})
  533. const equationSelect = (index, path) => {
  534. console.log(index, path)
  535. const selectEle = equationSelectEle.value
  536. const isValidElement = element => element?.type === 'Element' || element?.type === 'ParamData'
  537. if (!selectEle || !isValidElement(selectEle)) {
  538. window?.$message.warning('请先选中元素')
  539. return
  540. }
  541. console.log(selectEle)
  542. }
  543. //获取数据
  544. const resultFormula = ref([])
  545. const getWbsFormElementData = async () => {
  546. const { eleId } = getObjValue(dataInfo.value)
  547. resultFormula.value = []
  548. if (isNullES(eleId)) return
  549. const { data } = await elementApi.detail(eleId)
  550. const obj = getObjValue(data)
  551. resultFormula.value = [{
  552. type: 'Element',
  553. name: obj.eName,
  554. id: obj.id,
  555. selected: false,
  556. tableElementKey: obj.tableElementKey,
  557. children: [],
  558. }]
  559. }
  560. //左边被点击
  561. const processIndex = ref(-1)
  562. const processType = ref('')
  563. const resultFormulaItem = (item, index) => {
  564. clearResetFunClick()
  565. //设置当前选中
  566. processIndex.value = index
  567. processType.value = 'resultFormula'
  568. item.selected = true
  569. }
  570. //右边被点击
  571. const processFormulaItem = (item, index) => {
  572. clearResetFunClick()
  573. //设置当前选中
  574. processIndex.value = index
  575. processType.value = 'processFormula'
  576. item.selected = true
  577. }
  578. //清除选择
  579. const clearResetFunClick = () => {
  580. //清除左边的选中
  581. resultFormula.value.forEach((obj) => {
  582. obj.selected = false
  583. })
  584. //清除右边的选中
  585. processFormula.value.forEach((obj) => {
  586. obj.selected = false
  587. })
  588. //设置当前选中
  589. processIndex.value = -1
  590. processType.value = ''
  591. }
  592. //是否重置函数
  593. const isResetFun = ref(false)
  594. const resetFunClick = () => {
  595. if (deviationRangeShow.value) {
  596. window?.$message.warning('请先关闭允许偏差值范围')
  597. return
  598. }
  599. const val = !isResetFun.value
  600. if (val) {
  601. curRangeFocusIndex.value = 99
  602. } else {
  603. curRangeFocusIndex.value = 0
  604. }
  605. isResetFun.value = val
  606. isScrollBar.value = !val
  607. }
  608. //tree树配置
  609. const defaultProps = {
  610. label: 'title',
  611. children: 'children',
  612. isLeaf: (data) => {
  613. return !data.hasChildren
  614. },
  615. }
  616. //重置函数懒加载树
  617. const treeResetFunLazyRef = ref(null)
  618. const treeRangeSelectLazyRef = ref(null)
  619. const treeResetFunAllRef = ref(null)
  620. const treeRangeSelectAllRef = ref(null)
  621. const treeResetFunLazyExpanded = ref([])
  622. //获取重置函数懒加载树的数据
  623. const treeResetFunLoading = ref(false)
  624. const treeResetFunLazyLoad = async (node, resolve) => {
  625. const { level, data } = node
  626. treeResetFunItemData.value = data
  627. let parentId = level !== 0 ? data.id : 12345678910
  628. const { eleType, node: dataNode, tableType } = getObjValue(dataInfo.value)
  629. const treeNode = getObjValue(dataNode)
  630. if (level === 0) treeResetFunLoading.value = true
  631. if (!eleType) {
  632. //获取接口数据
  633. const { data } = await privateApi.tabTypeLazyTreeAll({
  634. parentId,
  635. current: 1,
  636. size: 99999,
  637. hasPartFormula: treeNode.hasPartFormula,
  638. })
  639. const res = getArrValue(data.records)
  640. treeResetFunLoading.value = false
  641. resolve(res)
  642. //处理返回的数据
  643. await nextTick()
  644. //处理展开
  645. try {
  646. const expandId = tableType ? Number(treeNode.tableType) - 1 : Number(treeNode.parentId) - 1
  647. if (!isNullES(expandId) && expandId >= 0) node.childNodes[expandId].expand()
  648. } catch { /* empty */ }
  649. //处理选中
  650. try {
  651. const paramsId = treeNode.initTableId
  652. if (!isNullES(paramsId)) {
  653. treeResetFunLazyRef.value?.setCurrentKey(paramsId)
  654. treeRangeSelectLazyRef.value?.setCurrentKey(paramsId)
  655. }
  656. } catch { /* empty */ }
  657. //获取节点详情
  658. await getNodeDetailApi(treeNode)
  659. } else if (eleType) {
  660. resolve([])
  661. }
  662. }
  663. //重置函数懒加载树点击
  664. const treeResetFunItemData = ref({})
  665. const treeResetFunNodeData = ref({})
  666. const treeResetFunLazyClick = async (data, node) => {
  667. treeResetFunItemData.value = data
  668. treeResetFunNodeData.value = node
  669. await getNodeDetailApi(data)
  670. }
  671. //重置函数树搜索
  672. const resetFunTree = ref('')
  673. const resetFunTreeAll = ref([])
  674. const isResetFunTreeLazy = ref(true)
  675. const resetFunTreeSearch = async () => {
  676. if (isNullES(resetFunTree.value)) {
  677. isResetFunTreeLazy.value = true
  678. return
  679. }
  680. isResetFunTreeLazy.value = false
  681. treeResetFunLoading.value = true
  682. const obj = treeResetFunItemData.value
  683. const parentId = obj.hasChildren ? obj.id : ''
  684. const { data, code } = await privateApi.tabTypeLazyTreeAll({
  685. parentId: parentId,
  686. current:1,
  687. size:1000,
  688. titleName: resetFunTree.value,
  689. })
  690. if (code !== 200) {
  691. resetFunTreeAll.value = []
  692. treeResetFunLoading.value = false
  693. return
  694. }
  695. resetFunTreeAll.value = getArrValue(data?.records)
  696. treeResetFunLoading.value = false
  697. }
  698. //重置函数元素搜索
  699. const resetFunEle = ref('')
  700. const isResetFunEleLoading = ref(false)
  701. const resetFunEleSearch = async () => {
  702. const { initTableId } = treeResetFunItemData.value
  703. if (isNullES(initTableId)) {
  704. resetFunEleData.value = []
  705. isResetFunEleLoading.value = false
  706. return
  707. }
  708. isResetFunEleLoading.value = true
  709. if (isNullES(resetFunEle.value)) {
  710. const { data } = await treeApi.getTableElments({
  711. id: initTableId,
  712. })
  713. resetFunEleData.value = getArrValue(data)
  714. } else {
  715. const { data } = await treeApi.getTableElments({
  716. id: initTableId,
  717. search: resetFunEle.value,
  718. })
  719. resetFunEleData.value = getArrValue(data)
  720. }
  721. isResetFunEleLoading.value = false
  722. }
  723. //获取节点详情
  724. const resetFunEleData = ref([])
  725. const getNodeDetailApi = async (item) => {
  726. await useClick(300)
  727. if (isNullES(item.initTableId)) {
  728. resetFunEleData.value = []
  729. isResetFunEleLoading.value = false
  730. return
  731. }
  732. if (item.hasChildren === false || item.isLinkTable === 2) {
  733. isResetFunEleLoading.value = true
  734. const { data } = await treeApi.getTableElments({
  735. id: item.initTableId,
  736. })
  737. resetFunEleData.value = getArrValue(data)
  738. } else {
  739. resetFunEleData.value = []
  740. }
  741. isResetFunEleLoading.value = false
  742. }
  743. //元素字段被点击
  744. const selectEleFormula = ref([])
  745. const selectEleFormula3 = ref([])
  746. const selectEleFormula4 = ref([])
  747. const resetFunEleTagClick = (item) => {
  748. const index = curRangeFocusIndex.value
  749. if (index <= 0) {
  750. window?.$message.warning('非正常操作')
  751. return
  752. }
  753. let arr = []
  754. if (index === 99) {
  755. //重置函数
  756. arr = selectEleFormula.value
  757. } else if (index === 3) {
  758. //参数1
  759. arr = selectEleFormula3.value
  760. } else if (index === 4) {
  761. //参数2
  762. arr = selectEleFormula4.value
  763. }
  764. let { type, name } = getObjValue(arr[arr.length - 1])
  765. if (type === 'Text') {
  766. window?.$message.warning('元素无法连续出现在输入值后面')
  767. return
  768. }
  769. if (type === 'Brackets' && name === ')') {
  770. window?.$message.warning('元素无法连续出现在右括号后面')
  771. return
  772. }
  773. if (arr.length === 0 || ['Operator', 'Brackets'].includes(type) || name === '(') {
  774. if (!isNullES(item.tableElementKey)) {
  775. const obj = {
  776. type: 'Element',
  777. name: item.eName,
  778. id: item.id,
  779. selected: false,
  780. tableElementKey: item.tableElementKey,
  781. index: getRandom(5),
  782. children: [],
  783. }
  784. if (index === 99) {
  785. selectEleFormula.value.push(obj)
  786. } else if (index === 3) {
  787. selectEleFormula3.value.push(obj)
  788. } else if (index === 4) {
  789. selectEleFormula4.value.push(obj)
  790. }
  791. }
  792. } else {
  793. window?.$message.warning('当前操作不符合要求')
  794. }
  795. }
  796. //输入弹窗
  797. const promptMessageBox = async () => {
  798. return new Promise(resolve => {
  799. ElMessageBox.prompt('', '请输入值', {
  800. confirmButtonText: '确定',
  801. cancelButtonText: '取消',
  802. inputErrorMessage: '请输入内容',
  803. inputValidator: (value) => {
  804. return !isNullES(value)
  805. },
  806. }).then(({ value }) => {
  807. resolve(value)
  808. }).catch(() => {
  809. resolve()
  810. })
  811. })
  812. }
  813. //输入值
  814. const resetFunText = async () => {
  815. const val = await promptMessageBox()
  816. if (isNullES(val)) return
  817. const index = curRangeFocusIndex.value
  818. if (index <= 0) {
  819. window?.$message.warning('非正常操作')
  820. return
  821. }
  822. //获取数组
  823. let arr = []
  824. if (index === 99) {
  825. //重置函数
  826. arr = selectEleFormula.value
  827. } else if (index === 3) {
  828. //参数1
  829. arr = selectEleFormula3.value
  830. } else if (index === 4) {
  831. //参数2
  832. arr = selectEleFormula4.value
  833. }
  834. if (arr.length > 0) {
  835. let { type, name } = getObjValue(arr[arr.length - 1])
  836. if (type === 'Element') {
  837. window?.$message.warning('输入值无法连续出现在元素后面')
  838. return
  839. }
  840. if (type === 'Text') {
  841. window?.$message.warning('输入值无法连续出现在输入值后面')
  842. return
  843. }
  844. if (type === 'Brackets' && name === ')') {
  845. window?.$message.warning('输入值无法连续出现在右括号后面')
  846. return
  847. }
  848. }
  849. //公共对象
  850. const obj = {
  851. type: 'Text',
  852. name: val,
  853. selected: false,
  854. index: getRandom(5),
  855. }
  856. if (index === 99) {
  857. selectEleFormula.value.push(obj)
  858. } else if (index === 3) {
  859. selectEleFormula3.value.push(obj)
  860. } else if (index === 4) {
  861. selectEleFormula4.value.push(obj)
  862. }
  863. }
  864. //括号
  865. const resetFunBrackets = (val) => {
  866. const index = curRangeFocusIndex.value
  867. if (index <= 0) {
  868. window?.$message.warning('非正常操作')
  869. return
  870. }
  871. //公共对象
  872. const obj = {
  873. type: 'Brackets',
  874. name: val,
  875. selected: false,
  876. index: getRandom(5),
  877. }
  878. if (index === 99) {
  879. //重置函数
  880. selectEleFormula.value.push(obj)
  881. } else if (index === 3) {
  882. //参数1
  883. selectEleFormula3.value.push(obj)
  884. } else if (index === 4) {
  885. //参数2
  886. selectEleFormula4.value.push(obj)
  887. }
  888. }
  889. //运算符
  890. const resetFunOperator = (val) => {
  891. const index = curRangeFocusIndex.value
  892. if (index <= 0) {
  893. window?.$message.warning('非正常操作')
  894. return
  895. }
  896. //获取数组
  897. let arr = []
  898. if (index === 99) {
  899. //重置函数
  900. arr = selectEleFormula.value
  901. } else if (index === 3) {
  902. //参数1
  903. arr = selectEleFormula3.value
  904. } else if (index === 4) {
  905. //参数2
  906. arr = selectEleFormula4.value
  907. }
  908. const map = formulaMenuMap.value
  909. if (arr.length <= 0) {
  910. window?.$message.warning('公式开头不能是运算符号')
  911. return
  912. }
  913. let { type, name } = getObjValue(arr[arr.length - 1])
  914. if (type === 'Operator') {
  915. window?.$message.warning('运算符号无法连续出现在运算符号后面')
  916. return
  917. }
  918. if (type === 'Brackets' && name === '(') {
  919. window?.$message.warning('运算符号无法连续出现在左括号后面')
  920. return
  921. }
  922. const obj = getObjValue(map[val])
  923. //公共对象
  924. const data = {
  925. type: 'Operator',
  926. name: symbolReg.exec(obj.name)[1],
  927. selected: false,
  928. template: obj.template,
  929. index: getRandom(5),
  930. }
  931. if (index === 99) {
  932. selectEleFormula.value.push(data)
  933. } else if (index === 3) {
  934. selectEleFormula3.value.push(data)
  935. } else if (index === 4) {
  936. selectEleFormula4.value.push(data)
  937. }
  938. }
  939. //删除
  940. const resetFunDel = () => {
  941. const index = curRangeFocusIndex.value
  942. if (index <= 0) {
  943. window?.$message.warning('非正常操作')
  944. return
  945. }
  946. //获取数组
  947. let arr = []
  948. if (index === 99) {
  949. //重置函数
  950. arr = selectEleFormula.value
  951. } else if (index === 3) {
  952. //参数1
  953. arr = selectEleFormula3.value
  954. } else if (index === 4) {
  955. //参数2
  956. arr = selectEleFormula4.value
  957. }
  958. const newArr = deepClone(arr)
  959. if (newArr.length <= 0) {
  960. window?.$message.warning('请先添加相关元素')
  961. return
  962. }
  963. const indexs = arrIndex(newArr, 'selected', true)
  964. if (indexs !== -1) {
  965. newArr.splice(indexs, 1)
  966. if (index === 99) {
  967. selectEleFormula.value = newArr
  968. } else if (index === 3) {
  969. selectEleFormula3.value = newArr
  970. } else if (index === 4) {
  971. selectEleFormula4.value = newArr
  972. }
  973. } else {
  974. newArr.splice(newArr.length - 1, 1)
  975. if (index === 99) {
  976. selectEleFormula.value = newArr
  977. } else if (index === 3) {
  978. selectEleFormula3.value = newArr
  979. } else if (index === 4) {
  980. selectEleFormula4.value = newArr
  981. }
  982. }
  983. }
  984. //清空
  985. const resetFunClear = () => {
  986. const index = curRangeFocusIndex.value
  987. if (index <= 0) {
  988. window?.$message.warning('非正常操作')
  989. return
  990. }
  991. if (index === 99) {
  992. //重置函数
  993. selectEleFormula.value = []
  994. } else if (index === 3) {
  995. //参数1
  996. selectEleFormula3.value = []
  997. } else if (index === 4) {
  998. //参数2
  999. selectEleFormula4.value = []
  1000. }
  1001. }
  1002. //被点击
  1003. const selectEleFormulaItem = (item) => {
  1004. const index = curRangeFocusIndex.value
  1005. if (index <= 0) {
  1006. window?.$message.warning('非正常操作')
  1007. return
  1008. }
  1009. //获取数组
  1010. let arr = []
  1011. if (index === 99) {
  1012. //重置函数
  1013. arr = selectEleFormula.value
  1014. } else if (index === 3) {
  1015. //参数1
  1016. arr = selectEleFormula3.value
  1017. } else if (index === 4) {
  1018. //参数2
  1019. arr = selectEleFormula4.value
  1020. }
  1021. for (let i = 0; i < arr.length; i++) {
  1022. if (item.index === arr[i].index) {
  1023. arr[i].selected = !arr[i].selected
  1024. } else {
  1025. arr[i].selected = false
  1026. }
  1027. }
  1028. if (index === 99) {
  1029. selectEleFormula.value = arr
  1030. } else if (index === 3) {
  1031. selectEleFormula3.value = arr
  1032. } else if (index === 4) {
  1033. selectEleFormula4.value = arr
  1034. }
  1035. }
  1036. //赋值给等号右边的数组
  1037. const processFormula = ref([])
  1038. const setProcessFormula = () => {
  1039. const arr = selectEleFormula.value
  1040. let leftNum = 0, rightNum = 0
  1041. arr.forEach(({ type, name }) => {
  1042. if (type === 'Brackets') {
  1043. if (name === '(') {
  1044. leftNum++
  1045. } else if (name === ')') {
  1046. rightNum++
  1047. }
  1048. }
  1049. })
  1050. if (leftNum !== rightNum) {
  1051. window?.$message.warning('左右括号数量不相等,请先检查是否正确')
  1052. return
  1053. }
  1054. processFormula.value = deepClone(arr)
  1055. isResetFun.value = false
  1056. isScrollBar.value = true
  1057. }
  1058. //获取项目数据
  1059. const projectId = ref('')
  1060. const projectList = ref([])
  1061. const getProjectDataApi = async () => {
  1062. const { data } = await projectApi.page({
  1063. current: 1,
  1064. size: 99999,
  1065. })
  1066. projectList.value = getArrValue(data?.records)
  1067. }
  1068. //项目被选择
  1069. const contractId = ref('')
  1070. const contractList = ref([])
  1071. const projectChange = async () => {
  1072. contractId.value = ''
  1073. const { data } = await contractApi.getList(projectId.value)
  1074. contractList.value = getArrValue(data)
  1075. }
  1076. //项目查询
  1077. const projectQueryClick = () => {
  1078. console.log('原来就没做这个功能')
  1079. }
  1080. //允许偏差值范围
  1081. const deviationRangeSymbol = ref('【min,max】')
  1082. //模式切换
  1083. const deviationRangeResult = ref('1')
  1084. const deviationRangeResultChange = () => {
  1085. if (deviationRangeResult.value === '1') {
  1086. if (!['<', '≤'].includes(deviationRangeSymbol.value)) {
  1087. curRangeFocusIndex.value = 1
  1088. } else if (!['>', '≥'].includes(deviationRangeSymbol.value)) {
  1089. curRangeFocusIndex.value = 2
  1090. }
  1091. } else if (deviationRangeResult.value === '2') {
  1092. if (!['<', '≤'].includes(deviationRangeSymbol.value)) {
  1093. curRangeFocusIndex.value = 3
  1094. } else if (!['>', '≥'].includes(deviationRangeSymbol.value)) {
  1095. curRangeFocusIndex.value = 4
  1096. }
  1097. }
  1098. }
  1099. //允许偏差值范围1
  1100. const deviationRangeTag1 = ref('')
  1101. const deviationRangeTags1 = ref([])
  1102. const deviationRangeBlur1 = () => {
  1103. if (deviationRangeTag1.value) {
  1104. if (deviationRangeTag1.value && deviationRangeTags1.value[0]) {
  1105. emit('uncheck', deviationRangeTags1.value[0].id)
  1106. }
  1107. deviationRangeTags1.value = []
  1108. }
  1109. }
  1110. //允许偏差值范围2
  1111. const deviationRangeTag2 = ref('')
  1112. const deviationRangeTags2 = ref([])
  1113. const deviationRangeBlur2 = () => {
  1114. if (deviationRangeTag2.value) {
  1115. if (deviationRangeTag2.value && deviationRangeTags2.value[0]) {
  1116. emit('uncheck', deviationRangeTags2.value[0].id)
  1117. }
  1118. deviationRangeTags2.value = []
  1119. }
  1120. }
  1121. //当前在哪个输入框
  1122. const curRangeFocusIndex = ref(0)
  1123. const rangeAddingTag = () => {
  1124. console.log('原来的版本就啥也没做')
  1125. }
  1126. //选择参数
  1127. const isRangeSelectEle = ref(false)
  1128. const deviationRangeSelectEle = () => {
  1129. const val = !isRangeSelectEle.value
  1130. isRangeSelectEle.value = val
  1131. isScrollBar.value = !val
  1132. }
  1133. //手写模式
  1134. const handWritText = ref('')
  1135. const handWritEleMap = ref({})
  1136. const isHandWritEle = ref(false)
  1137. const handWritClick = () => {
  1138. try {
  1139. let { text, eleMap } = formulaArrayToString(processFormula.value, resultFormula.value)
  1140. handWritText.value = text
  1141. handWritEleMap.value = JSON.stringify(eleMap)
  1142. isHandWritEle.value = true
  1143. } catch (error) {
  1144. console.log(error)
  1145. window?.$message.error('生成公式文本失败')
  1146. }
  1147. }
  1148. //手写模式转换
  1149. const handWritTransform = () => {
  1150. try {
  1151. let formula = formulaStringToArray(handWritText.value, handWritEleMap.value, formulaMenuMap.value)
  1152. processFormula.value = getArrValue(formula.processFormula)
  1153. const results = resultFormula.value
  1154. formula.resultFormula[0].id = results[0].id
  1155. formula.resultFormula[0].name = results[0].name
  1156. formula.resultFormula[0].tableElementKey = results[0].tableElementKey
  1157. resultFormula.value[0].children = formula.resultFormula[0].children
  1158. handWritEleClose()
  1159. } catch (error) {
  1160. console.log(error)
  1161. window?.$message.error('转成配置用的数组失败')
  1162. }
  1163. }
  1164. //手写模式关闭
  1165. const handWritEleClose = () => {
  1166. isHandWritEle.value = false
  1167. handWritText.value = ''
  1168. handWritEleMap.value = {}
  1169. }
  1170. const findNumber = (array) => {
  1171. for (const item of array) {
  1172. if (!item.children) continue
  1173. const child = item.children.find(child => child.number)
  1174. if (child) return child.number
  1175. }
  1176. return ''
  1177. }
  1178. //保存
  1179. const submitLoading = ref(false)
  1180. const submitClick = async () => {
  1181. if (isResetFun.value) {
  1182. //重置函数
  1183. setProcessFormula()
  1184. } else {
  1185. //允许偏差值范围
  1186. submitLoading.value = true
  1187. const result = deviationRangeResult.value
  1188. deviationRangeObj.value = {
  1189. symbol: deviationRangeSymbol.value,
  1190. model: result,
  1191. arguments1: result === '2' ? selectEleFormula3.value : deviationRangeTag1.value,
  1192. arguments2: result === '2' ? selectEleFormula4.value : deviationRangeTag2.value,
  1193. }
  1194. //处理数据
  1195. const process = processFormula.value, results = resultFormula.value
  1196. let obj = formulaArrayToString(process, results)
  1197. let deviationRangeText = rangeToString(deviationRangeObj.value, obj.eleMap)
  1198. obj.eleMap.deviationRangeJson = JSON.stringify(deviationRangeObj.value)
  1199. //特殊公式会有number
  1200. let number = findNumber(process) || findNumber(results)
  1201. //发起请求
  1202. const { eleId, globalType, nodeId, pid } = getObjValue(dataInfo.value)
  1203. const formData = {
  1204. formula: obj.text,
  1205. remark: '',
  1206. nodeId: nodeId,
  1207. elementId: eleId,
  1208. scale: isRetain.value ? retainNum.value : '',
  1209. number: number,
  1210. map: JSON.stringify(obj.eleMap),
  1211. scope: globalType,
  1212. projectId: projectId.value || pid,
  1213. dev: deviationRangeText,
  1214. }
  1215. let res = {}
  1216. if (isNullES(formulaId.value)) {
  1217. //新增
  1218. res = await formulaApi.save({ ...formData, ver:1 })
  1219. } else {
  1220. //更新
  1221. res = await formulaApi.update({ id: formulaId.value, ...formData })
  1222. }
  1223. const { code, msg, data } = getObjValue(res)
  1224. if (code !== 200) {
  1225. submitLoading.value = false
  1226. return
  1227. }
  1228. let msgStr = '保存成功'
  1229. if (msg === '公式已删除') {
  1230. formulaId.value = ''
  1231. msgStr = msg
  1232. } else if (!isNullES(data)) {
  1233. formulaId.value = data
  1234. }
  1235. window?.$message.success(msgStr)
  1236. getFormulaStringToArrayApi()
  1237. submitLoading.value = false
  1238. }
  1239. }
  1240. //关闭抽屉
  1241. const drawerClose = () => {
  1242. if (isResetFun.value) {
  1243. //重置函数
  1244. isResetFun.value = false
  1245. isScrollBar.value = true
  1246. curRangeFocusIndex.value = 0
  1247. } else if (deviationRangeShow.value) {
  1248. //允许偏差值范围
  1249. deviationRangeShow.value = false
  1250. isRangeSelectEle.value = false
  1251. curRangeFocusIndex.value = 0
  1252. } else {
  1253. isShow.value = false
  1254. //重置元素
  1255. isResetFun.value = false
  1256. isScrollBar.value = true
  1257. //允许偏差值范围
  1258. deviationRangeShow.value = false
  1259. curRangeFocusIndex.value = 0
  1260. //选择的元素
  1261. selectEleFormula.value = []
  1262. selectEleFormula3.value = []
  1263. selectEleFormula4.value = []
  1264. //手写模式
  1265. isHandWritEle.value = false
  1266. handWritText.value = ''
  1267. handWritEleMap.value = {}
  1268. emit('close')
  1269. }
  1270. }
  1271. </script>
  1272. <style lang="scss">
  1273. @import '~src/styles/view/project/edit-formula';
  1274. </style>