edit-formula.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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>手写模式</el-button>
  30. </div>
  31. </div>
  32. <!-- 函数公式 -->
  33. <div class="hc-formula-card-math border-dashed-card 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 :type="isResetFun ? 'primary' : 'info'" size="small" @click="resetFunClick">重置函数</el-button>
  38. </div>
  39. </div>
  40. <div class="body relative">
  41. <template v-for="(item, index) in resultFormula" :key="index">
  42. <span class="element-class text-26px" :class="item.selected ? 'is-cur' : ''" @click="resultFormulaItem(item, index)">{{ item.name }}</span>
  43. </template>
  44. <span class="ml-10px mr-10px text-26px">=</span>
  45. </div>
  46. </div>
  47. <!-- 重置函数 -->
  48. <div class="hc-formula-reset-fun border-dashed-card mb-14px">
  49. 1111
  50. </div>
  51. </div>
  52. <template #action>
  53. <el-button @click="drawerClose">取消</el-button>
  54. <el-button type="primary" :loading="submitLoading" @click="submitClick">保存</el-button>
  55. </template>
  56. </hc-card>
  57. </hc-drawer>
  58. </template>
  59. <script setup>
  60. import { ref, watch } from 'vue'
  61. import { deepClone, getObjValue, isNullES } from 'js-fast-way'
  62. import mainApi from '~api/project/formula'
  63. import eleApi from '~api/project/element'
  64. const props = defineProps({
  65. data: {
  66. type: Object,
  67. default: () => ({}),
  68. },
  69. })
  70. //事件
  71. const emit = defineEmits(['close', 'finish'])
  72. //双向绑定
  73. const isShow = defineModel('modelValue', {
  74. default: false,
  75. })
  76. //监听数据
  77. const dataInfo = ref(props.data)
  78. watch(() => props.data, (data) => {
  79. dataInfo.value = getObjValue(data)
  80. }, { immediate: true, deep: true })
  81. //监听显示
  82. watch(isShow, (val) => {
  83. if (val) getDataApi()
  84. })
  85. //基础变量
  86. const operatorReg = /^\+|-|\*|%/ //加减乘除
  87. const startFCRegExp = /^FC\.([a-zA-Z\d]+)\(/ //匹配开始的FC.xxx(
  88. const isScrollBar = ref(false)
  89. //获取数据
  90. const getDataApi = async () => {
  91. console.log(dataInfo.value)
  92. getTypeMapApi().then()
  93. getWbsFormElementData().then()
  94. }
  95. //保留位数
  96. const isRetain = ref(false)
  97. const retainNum = ref(2)
  98. //允许偏差值范围
  99. const deviationRangeShow = ref(false)
  100. const setDeviationRange = () => {
  101. deviationRangeShow.value = !deviationRangeShow.value
  102. }
  103. //获取顶部菜单数据
  104. const formulaMenuIndex = ref(null)
  105. const formulaMenuList = ref({})
  106. const formulaMenuMap = ref({})
  107. const getTypeMapApi = async () => {
  108. const { data } = await mainApi.getTypeMap()
  109. const res = getObjValue(data)
  110. formulaMenuList.value = deepClone(res)
  111. //生成map,方便查找
  112. for (let key in res) {
  113. if (typeof(res[key]) === 'object') {
  114. res[key].forEach((formula)=>{
  115. formula.template = JSON.parse(formula.template)
  116. if (operatorReg.test(formula.template.ft)) {
  117. formulaMenuMap.value[formula.template.ft] = formula
  118. } else if (startFCRegExp.test(formula.template.ft)) {
  119. let regRes = formula.template.ft.match(startFCRegExp)
  120. formulaMenuMap.value[regRes[0]] = formula
  121. }
  122. })
  123. }
  124. }
  125. }
  126. //菜单被选择
  127. const handleFormulaMenu = (index, path) => {
  128. console.log(index, path)
  129. }
  130. //获取数据
  131. const resultFormula = ref([])
  132. const getWbsFormElementData = async () => {
  133. const { eleId } = getObjValue(dataInfo.value)
  134. resultFormula.value = []
  135. if (isNullES(eleId)) return
  136. const { data } = await eleApi.detail(eleId)
  137. const obj = getObjValue(data)
  138. resultFormula.value = [{
  139. type: 'Element',
  140. name: obj.eName,
  141. id: obj.id,
  142. selected: false,
  143. tableElementKey: obj.tableElementKey,
  144. children: [],
  145. }]
  146. }
  147. //被点击
  148. const resultFormulaItem = (item, index) => {
  149. item.selected = !item.selected
  150. console.log(item, index)
  151. }
  152. //是否重置函数
  153. const isResetFun = ref(false)
  154. const resetFunClick = () => {
  155. isResetFun.value = !isResetFun.value
  156. isScrollBar.value = !isResetFun.value
  157. }
  158. //保存
  159. const submitLoading = ref(false)
  160. const submitClick = async () => {
  161. }
  162. //关闭抽屉
  163. const drawerClose = () => {
  164. isShow.value = false
  165. emit('close')
  166. }
  167. </script>
  168. <style lang="scss">
  169. @import '~src/styles/view/project/edit-formula';
  170. </style>