opProblem.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <!-- 优化问题 -->
  3. <div style="height: 100%;">
  4. <el-card class="custom-card">
  5. <template #header>
  6. <span>{{ opDatajson?.vo.name }}</span>
  7. </template>
  8. <div class="opProblem-container" :class="currentClass">
  9. <div class="first-container">
  10. <div class="content-container">
  11. <div class="content-aside">
  12. <el-row justify="center">
  13. <img src="@/assets/img/yhwt.png" class="content-aside-img" alt="Experiment Icon" />
  14. </el-row>
  15. <el-row justify="center" align="middle">
  16. <span style="font-size: 10px;line-height: 32px;">{{ opDatajson?.svo[0]?.vo.name }}</span>
  17. <el-switch v-if="ophasSwitch1.switch" v-model="ophasSwitch1.switch.val" active-value="1" inactive-value="0" class="custom-switch custom-switch-colors" />
  18. </el-row>
  19. </div>
  20. <div class="content-form content-form-right">
  21. <template v-for="(form, formIndex) in opDataObj1" :key="formIndex">
  22. <el-form class="custom-form" :label-width="Labelwidth" label-position="left">
  23. <el-form-item v-if="form.header.code !== 'is_cons'" :label="form.header.name"></el-form-item>
  24. <template v-for="(item, index) in form.body" :key="index">
  25. <!-- 下拉框和输入框(带 label) -->
  26. <el-form-item
  27. v-if="item.vo.valCodeType !== 'swithType'"
  28. :label="item.vo.name"
  29. >
  30. <el-select
  31. v-if="item.vo.valType === 1"
  32. v-model="item.vo.val"
  33. size="small"
  34. >
  35. <el-option
  36. v-for="option in valoption[item.vo.valCodeType]"
  37. :key="option.val"
  38. :label="option.tag"
  39. :value="option.val"
  40. />
  41. </el-select>
  42. <el-input
  43. v-else-if="item.vo.valType === 2"
  44. v-model="item.vo.val"
  45. size="small"
  46. />
  47. </el-form-item>
  48. <!-- 复选框(无 label、不占位) -->
  49. <el-checkbox
  50. v-else-if="item.vo.valType === 1 && item.vo.valCodeType === 'swithType'"
  51. v-model="item.vo.val"
  52. class="custom-checkbox"
  53. true-value = 1
  54. false-value = 0
  55. >
  56. {{ item.vo.name }}
  57. </el-checkbox>
  58. </template>
  59. </el-form>
  60. </template>
  61. </div>
  62. </div>
  63. </div>
  64. <el-divider />
  65. <div class="second-container">
  66. <div class="content-container">
  67. <div class="content-aside">
  68. <el-row justify="center">
  69. <img src="@/assets/img/yhwt.png" class="content-aside-img" alt="Experiment Icon" />
  70. </el-row>
  71. <el-row justify="center" align="middle" >
  72. <span style="font-size: 10px;line-height: 32px;">{{ opDatajson?.svo[1]?.vo.name }}</span>
  73. <el-switch v-if="ophasSwitch2.switch" v-model="ophasSwitch2.switch.val" active-value="1" inactive-value="0" class="custom-switch custom-switch-colors" />
  74. </el-row>
  75. </div>
  76. <div class="content-form content-form-right">
  77. <template v-for="(form, formIndex) in opDataObj2" :key="formIndex">
  78. <el-form v-show="form.body.length>0" class="custom-form" :label-width="Labelwidth" label-position="left">
  79. <el-form-item v-if="form.header.code !== 'is_cons'" :label="form.header.name"></el-form-item>
  80. <template v-for="(item, index) in form.body" :key="index">
  81. <!-- 下拉框和输入框(带 label) -->
  82. <el-form-item
  83. v-if="item.vo.valCodeType !== 'swithType'"
  84. :label="item.vo.name"
  85. >
  86. <el-select
  87. v-if="item.vo.valType === 1"
  88. v-model="item.vo.val"
  89. size="small"
  90. >
  91. <el-option
  92. v-for="option in valoption[item.vo.valCodeType]"
  93. :key="option.val"
  94. :label="option.tag"
  95. :value="option.val"
  96. />
  97. </el-select>
  98. <el-input
  99. v-else-if="item.vo.valType === 2"
  100. v-model="item.vo.val"
  101. size="small"
  102. />
  103. </el-form-item>
  104. <!-- 复选框(无 label、不占位) -->
  105. <el-checkbox
  106. v-else-if="item.vo.valType === 1 && item.vo.valCodeType === 'swithType'"
  107. v-model="item.vo.val"
  108. class="custom-checkbox"
  109. true-value = 1
  110. false-value = 0
  111. >
  112. {{ item.vo.name }}
  113. </el-checkbox>
  114. </template>
  115. </el-form>
  116. </template>
  117. </div>
  118. </div>
  119. </div>
  120. <el-divider />
  121. <div class="third-container">
  122. <div class="content-container">
  123. <div class="content-aside">
  124. <el-row justify="center">
  125. <img src="@/assets/img/yhwt.png" class="content-aside-img" alt="Experiment Icon" />
  126. </el-row>
  127. <el-row justify="center" align="middle">
  128. <span style="font-size: 10px;line-height: 32px;">{{ opDatajson?.svo[2]?.vo.name }}</span>
  129. <el-switch v-if="ophasSwitch3.switch" v-model="ophasSwitch3.switch.val" active-value="1" inactive-value="0" class="custom-switch custom-switch-colors" />
  130. </el-row>
  131. </div>
  132. <div class="content-form content-form-right">
  133. <template v-for="(form, formIndex) in opDataObj3" :key="formIndex">
  134. <el-form class="custom-form" :label-width="Labelwidth" label-position="left">
  135. <el-form-item v-if="form.header.code !== 'is_cons'" :label="form.header.name"></el-form-item>
  136. <template v-for="(item, index) in form.body" :key="index">
  137. <!-- 下拉框和输入框(带 label) -->
  138. <el-form-item
  139. v-if="item.vo.valCodeType !== 'swithType'"
  140. :label="item.vo.name"
  141. >
  142. <el-select
  143. v-if="item.vo.valType === 1"
  144. v-model="item.vo.val"
  145. size="small"
  146. >
  147. <el-option
  148. v-for="option in valoption[item.vo.valCodeType]"
  149. :key="option.val"
  150. :label="option.tag"
  151. :value="option.val"
  152. />
  153. </el-select>
  154. <el-input
  155. v-else-if="item.vo.valType === 2"
  156. v-model="item.vo.val"
  157. size="small"
  158. />
  159. </el-form-item>
  160. <!-- 复选框(无 label、不占位) -->
  161. <el-checkbox
  162. v-else-if="item.vo.valType === 1 && item.vo.valCodeType === 'swithType'"
  163. v-model="item.vo.val"
  164. class="custom-checkbox"
  165. true-value = 1
  166. false-value = 0
  167. >
  168. {{ item.vo.name }}
  169. </el-checkbox>
  170. </template>
  171. </el-form>
  172. </template>
  173. </div>
  174. </div>
  175. </div>
  176. </div>
  177. </el-card>
  178. </div>
  179. </template>
  180. <script setup>
  181. import { analysisJson } from '../js/analysisData.js'
  182. import { useValOptionsStore } from '@/store/valoptions'
  183. const valOptionsStore = useValOptionsStore()
  184. const props = defineProps({
  185. opDatajson: {
  186. type: Object
  187. },
  188. runtype: {
  189. type: Number,
  190. default: 0
  191. }
  192. })
  193. const currentClass = computed(() => {
  194. if (props.runtype === 0) return 'class-qidong'
  195. if (props.runtype === 1) return 'class-jiegou'
  196. return 'class-qitan'
  197. })
  198. const Labelwidth = '70px';
  199. const valoption = computed(() => valOptionsStore.valOptionsMap)
  200. const opDataObj = ref({})
  201. const opDataObj1 = ref([])
  202. const opDataObj2 = ref([])
  203. const opDataObj3 = ref([])
  204. const ophasSwitch1 = ref({})
  205. const ophasSwitch2 = ref({})
  206. const ophasSwitch3 = ref({})
  207. // 监听 opDatajson 变化
  208. watch(
  209. () => props.opDatajson,
  210. (newVal) => {
  211. getdatainit()
  212. },
  213. { deep: true } // 深度监听
  214. );
  215. const getdatainit = () => {
  216. // 整体数据
  217. opDataObj.value = analysisJson(props.opDatajson);
  218. ophasSwitch1.value = analysisJson(props.opDatajson.svo[0])
  219. ophasSwitch2.value = analysisJson(props.opDatajson.svo[1])
  220. ophasSwitch3.value = analysisJson(props.opDatajson.svo[2])
  221. // 生成各个子组的数组
  222. const groups = [opDataObj1, opDataObj2, opDataObj3];
  223. groups.forEach((targetRef, index) => {
  224. const subGroup = props.opDatajson?.svo?.[index]?.svo;
  225. targetRef.value = Array.isArray(subGroup)
  226. ? subGroup.map(group => analysisJson(group))
  227. : [];
  228. });
  229. console.log('props.opDatajson', props.opDatajson);
  230. console.log('opDataObj', opDataObj.value);
  231. console.log('opDataObj1', opDataObj1.value);
  232. console.log('opDataObj2', opDataObj2.value);
  233. console.log('opDataObj3', opDataObj3.value);
  234. };
  235. const gatherData = () => {
  236. let opdata1 = saveData(ophasSwitch1)
  237. let opdata2 = saveData(ophasSwitch2)
  238. let opdata3 = saveData(ophasSwitch3)
  239. let opdata = [...opdata1,...opdata2,...opdata3]
  240. console.log("op保存数据:", opdata)
  241. return opdata
  242. }
  243. // 保存前过滤
  244. const saveData = (obj) => {
  245. // 过滤 body
  246. const filteredBody = obj.value.body
  247. .map(item => item.vo);
  248. const switchObj = obj.value.switch
  249. const saveArr = switchObj ? [...filteredBody, switchObj] : filteredBody;
  250. // 这里执行你的上传或保存逻辑
  251. return saveArr;
  252. };
  253. defineExpose({gatherData})
  254. </script>
  255. <style scoped>
  256. .opProblem-container {
  257. width: 100%;
  258. height: 100%;
  259. display: flex;
  260. flex-direction: column;
  261. }
  262. .class-qidong {
  263. .first-container {
  264. width: 100%;
  265. height: 33%;
  266. }
  267. .second-container {
  268. width: 100%;
  269. height: 33%;
  270. }
  271. .third-container {
  272. width: 100%;
  273. height: 33%;
  274. }
  275. }
  276. .class-jiegou {
  277. .first-container {
  278. width: 100%;
  279. height: 33%;
  280. }
  281. .second-container {
  282. width: 100%;
  283. height: 33%;
  284. }
  285. .third-container {
  286. width: 100%;
  287. height: 33%;
  288. }
  289. }
  290. .class-qitan {
  291. .first-container {
  292. width: 100%;
  293. height: 44%;
  294. }
  295. .second-container {
  296. width: 100%;
  297. height: 34%;
  298. }
  299. .third-container {
  300. width: 100%;
  301. height: 20%;
  302. }
  303. }
  304. .content-form-top {
  305. width: 100%;
  306. height: 45%;
  307. }
  308. .content-form-bottom {
  309. width: 100%;
  310. height: 45%;
  311. }
  312. </style>