index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div style="width: 100%;height: 100%;">
  3. <div class="content">
  4. <el-container style="height: 100%;">
  5. <el-aside class="leftaside">
  6. <div class="left-1">
  7. <ex-design ref="exRef" :type="type" :exDatajson="oneData"/>
  8. </div>
  9. <div class="left-2">
  10. <agent-model ref="amRef" :type="type" :amDatajson="twoData" :isfileup="isButtonEnabled"/>
  11. </div>
  12. <div class="left-3">
  13. <op-algorithm ref="oaRef" :type="type" :oaDatajson="thirdData"/>
  14. </div>
  15. <div class="left-4">
  16. <op-run :type="type" @saveAllData="projectinfochange"/>
  17. </div>
  18. </el-aside>
  19. <el-main></el-main>
  20. <el-aside class="rightaside">
  21. <div class="right-1">
  22. <op-problem ref="opRef" :type="type" :opDatajson="fourData" :runtype="type"/>
  23. </div>
  24. <div class="right-2">
  25. <analyze-work @changetype="handleTypeChange"/>
  26. </div>
  27. </el-aside>
  28. </el-container>
  29. </div>
  30. <div class="footer">
  31. <info-log />
  32. </div>
  33. </div>
  34. </template>
  35. <script setup>
  36. import { request, enPassword } from "@/utils/request";
  37. import { ElMessage, ElMessageBox } from 'element-plus'
  38. import infoLog from './footer/infoLog.vue';
  39. import exDesign from './leftaside/exDesign.vue';
  40. import agentModel from './leftaside/agentModel.vue';
  41. import opAlgorithm from './leftaside/opAlgorithm.vue';
  42. import opRun from './leftaside/opRun.vue';
  43. import analyzeWork from './rightaside/analyzeWork.vue';
  44. import opProblem from './rightaside/opProblem.vue';
  45. import { useProjectStore } from '@/store/project'
  46. import { useValOptionsStore } from '@/store/valoptions'
  47. const projectStore = useProjectStore()
  48. const valOptionsStore = useValOptionsStore()
  49. const pid = computed(() => projectStore.pid)
  50. const type = ref(0)
  51. const projectInitJson = ref()
  52. const oneData = ref()
  53. const twoData = ref()
  54. const thirdData = ref()
  55. const fourData = ref()
  56. const exRef = ref()
  57. const amRef = ref()
  58. const oaRef = ref()
  59. const opRef = ref()
  60. const valType1Items = ref()
  61. const getProjectInit = () => {
  62. const params = {
  63. transCode: 'AC00009',
  64. pid: pid.value,
  65. type: type.value,
  66. };
  67. request(params)
  68. .then((res) => {
  69. projectInitJson.value = JSON.parse(res.pattJson); // 转换为 JSON 对象
  70. console.log(projectInitJson.value); // 输出解析后的对象
  71. oneData.value = projectInitJson.value[0];
  72. twoData.value = projectInitJson.value[1];
  73. thirdData.value = projectInitJson.value[2];
  74. fourData.value = projectInitJson.value[3];
  75. // 初始化选项
  76. valType1Items.value = findValType1Items(projectInitJson.value);
  77. // 去重
  78. const valCodeTypes = [
  79. ...new Set(
  80. valType1Items.value
  81. .filter(item => item?.valCodeType)
  82. .map(item => item.valCodeType)
  83. )
  84. ];
  85. console.log('valCodeTypes:', valCodeTypes);
  86. Promise.all(
  87. valCodeTypes.map(async (valCodeType) => {
  88. const rows = await getValTypeOptions(valCodeType);
  89. return { valCodeType, rows };
  90. })
  91. )
  92. .then(results => {
  93. const dataMap = Object.fromEntries(results.map(item => [item.valCodeType, item.rows]));
  94. console.log("映射结果 dataMap:", dataMap);
  95. valOptionsStore.setValOptionsMap(dataMap);
  96. })
  97. .catch(err => {
  98. ElMessage.error(err.returnMsg || "选项初始化失败");
  99. console.log(err);
  100. });
  101. console.log('选项',valType1Items);
  102. // console.log(oneData.value);
  103. })
  104. .catch((err) => {
  105. ElMessage.error(err.returnMsg || "初始化失败");
  106. console.error(err);
  107. });
  108. }
  109. const getValTypeOptions = async (valCodeType) => {
  110. const params = {
  111. transCode: 'BES001',
  112. type: valCodeType,
  113. };
  114. const res = await request(params);
  115. return res.rows;
  116. };
  117. function findValType1Items(nodes) {
  118. let result = [];
  119. function traverse(nodeList) {
  120. nodeList.forEach(node => {
  121. // 判断当前节点
  122. if (node.vo?.valType === 1 && node.vo?.valCodeType !== "swithType") {
  123. result.push(node.vo);
  124. }
  125. // 递归遍历子节点
  126. if (Array.isArray(node.svo) && node.svo.length > 0) {
  127. traverse(node.svo);
  128. }
  129. });
  130. }
  131. traverse(nodes);
  132. return result;
  133. }
  134. // 项目属性添加修改
  135. const projectinfochange = async () => {
  136. try {
  137. const exdata = exRef.value.saveData();
  138. const amdata = amRef.value.saveData();
  139. const oadata = oaRef.value.saveData();
  140. const opdata = opRef.value.gatherData();
  141. // 合并数据
  142. const allData = [...exdata, ...amdata, ...oadata, ...opdata];
  143. console.log('alldata', allData);
  144. // 格式化 rows
  145. const rows = allData.map(item => ({
  146. pid: pid.value,
  147. attId: item.attId,
  148. pattId: item.pattId,
  149. val: item.val
  150. }));
  151. // 发请求
  152. const params = {
  153. transCode: 'AC00005',
  154. rows
  155. };
  156. const res = await request(params);
  157. // ElMessage.success('保存成功');
  158. } catch (err) {
  159. console.error(err);
  160. ElMessage.error(err.returnMsg || '保存失败');
  161. }
  162. };
  163. // 分析工况类型切换
  164. const handleTypeChange = async (val) => {
  165. console.log('type', val);
  166. await projectinfochange();
  167. type.value = val;
  168. };
  169. // 代理模型文件上传是否可用
  170. const isButtonEnabled = computed(() => {
  171. const DOE = exRef.value?.exDataObj?.switch?.val;
  172. const SMT = amRef.value?.amDataObj?.switch?.val;
  173. const OPT = oaRef.value?.oaDataObj?.switch?.val;
  174. // console.log('[调试] DOE:', DOE, 'SMT:', SMT, 'OPT:', OPT );
  175. // 情况 3: DOE关, SMT开, OPT关
  176. const case3 = DOE === '0' && SMT === '1' && OPT === '0';
  177. // 情况 6: DOE关, SMT开, OPT开
  178. const case6 = DOE === '0' && SMT === '1' && OPT === '1';
  179. // console.log('[调试] case3:', case3, 'case6:', case6, '最终可用:', case3 || case6);
  180. return case3 || case6;
  181. });
  182. // 监听 type 的变化
  183. watch(
  184. () => type.value,
  185. (newVal) => {
  186. getProjectInit();
  187. }
  188. )
  189. onMounted(() => {
  190. getProjectInit();
  191. });
  192. </script>
  193. <style scoped>
  194. .content {
  195. width: 100%;
  196. height: 80%;
  197. .leftaside {
  198. width: 25%;
  199. height: 100%;
  200. padding-left: 10px;
  201. display: flex;
  202. flex-direction: column;
  203. gap: 5px;
  204. overflow: auto;
  205. }
  206. .rightaside {
  207. width: 25%;
  208. height: 100%;
  209. padding-right: 10px;
  210. display: flex;
  211. flex-direction: column;
  212. gap: 5px;
  213. overflow: auto;
  214. }
  215. }
  216. .leftaside {
  217. .left-1 {
  218. width: 100%;
  219. height: 23%;
  220. }
  221. .left-2 {
  222. width: 100%;
  223. height: 23%;
  224. }
  225. .left-3 {
  226. width: 100%;
  227. height: 29%;
  228. }
  229. .left-4 {
  230. width: 100%;
  231. height: 22%;
  232. }
  233. }
  234. .rightaside {
  235. .right-1 {
  236. width: 100%;
  237. height: 67%;
  238. }
  239. .right-2 {
  240. width: 100%;
  241. height: 30%;
  242. }
  243. }
  244. .footer {
  245. width: 100%;
  246. height: 20%;
  247. padding: 20px 10px;
  248. font-size: 12px;
  249. }
  250. </style>