conditionAssistance.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <template>
  2. <BasicModal
  3. @register="register"
  4. title="风机运行工况辅助决策"
  5. :maskStyle="{ backgroundColor: '#000000aa' }"
  6. width="1200px"
  7. v-bind="$attrs"
  8. @ok="onSubmit"
  9. @cancel="onSubmit"
  10. :canFullscreen="false"
  11. :destroyOnClose="true"
  12. :footer="null"
  13. >
  14. <div class="modal-box">
  15. <div class="right-box">
  16. <!-- <div class="box-title">风机信息</div> -->
  17. <dv-decoration7 style="height: 20px">
  18. <div class="box-title">风机信息</div>
  19. </dv-decoration7>
  20. <div class="info-container">
  21. <template v-if="isMock">
  22. <div v-for="(item, index) in fanInfo" class="info-item" :key="index">
  23. <div class="title">{{ item.title }}:</div>
  24. <div class="value">{{ fanInfoData && fanInfoData[item.code] ? fanInfoData[item.code] : '-' }}</div>
  25. </div>
  26. </template>
  27. <template v-else>
  28. <div v-for="(item, index) in columns" class="info-item" :key="index">
  29. <div class="title">{{ item['title'] }}:</div>
  30. <div class="value">{{ selectData && selectData[item['dataIndex']] ? selectData[item['dataIndex']] : '-' }}</div>
  31. </div>
  32. </template>
  33. </div>
  34. </div>
  35. <div class="center-box">
  36. <a-spin :spinning="loadding" tip="正在计算,请稍等。。。">
  37. <div ref="chartRef" class="info-echarts" style="width: 450px; height: 375px"></div>
  38. <div v-if="resultObj" class="result-tip">
  39. 工况点为
  40. <span style="color: #9a60b4; padding: 0 10px; font-weight: 600">{{ parseInt(resultObj.Hz) }}Hz</span>
  41. <span style="color: #c60000; padding: 0 10px; font-weight: 600">{{ formatNum(resultObj.x) }} m³/s</span>
  42. <span style="color: #c60000; padding: 0 10px; font-weight: 600">{{ formatNum(resultObj.y) }} Pa</span></div
  43. >
  44. </a-spin>
  45. </div>
  46. <div class="left-box">
  47. <!-- <div class="box-title">曲线方程</div> -->
  48. <dv-decoration7 style="height: 20px">
  49. <div class="box-title">曲线方程</div>
  50. </dv-decoration7>
  51. <div class="info-lines">
  52. <div v-for="(item, index) in lineEquation" class="info-item" :key="index">
  53. <div class="title">{{ item }}</div>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. <div class="setting-box">
  59. <div class="left-buttons">
  60. <!-- <div class="btn btn1" @click="edit('info')">编辑风机信息</div> -->
  61. <!-- <div class="btn btn1" @click="edit('line')">编辑特性曲线</div> -->
  62. 风机当前角度:<span>{{ selectData.bladeAngle }} &nbsp;°</span>
  63. </div>
  64. <!-- <div class="border-clip"></div> -->
  65. <div class="right-inputs">
  66. <div class="vent-flex-row">
  67. <div class="input-title">风量(m³/s):</div>
  68. <Input class="input-box" size="large" v-model:value="uQ" />
  69. <div class="input-title">风压(Pa):</div>
  70. <Input class="input-box" size="large" v-model:value="uH" />
  71. </div>
  72. <div class="btn btn1" @click="makeLine">决策工况</div>
  73. </div>
  74. </div>
  75. <!-- <div v-if="formShow" class="is-close" :class="{ 'is-open': formShow }">
  76. <a-divider orientation="left" style="border-color: #00d8ff22">{{ formType }}</a-divider>
  77. <BasicForm @register="registerForm" @submit="handleSubmit" :schemas="columns" />
  78. </div> -->
  79. </BasicModal>
  80. </template>
  81. <script lang="ts" setup>
  82. //ts语法
  83. import { ref, onMounted, reactive, nextTick, defineProps, defineEmits, watch } from 'vue';
  84. import echarts from '/@/utils/lib/echarts';
  85. import { option, initData, fanInfoData, fanInfo, getSchamas, getSchamas1, lineFormData } from '../main.data.ts';
  86. import { BasicModal, useModalInner } from '/@/components/Modal';
  87. import { BasicForm, useForm } from '/@/components/Form/index';
  88. import { Input } from 'ant-design-vue';
  89. import { Decoration7 as DvDecoration7 } from '@kjgl77/datav-vue3';
  90. import { message } from 'ant-design-vue';
  91. import { formatNum } from '/@/utils/ventutil';
  92. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  93. import { list } from '../main.api';
  94. const props = defineProps({
  95. deviceType: {
  96. type: String,
  97. },
  98. selectData: {
  99. type: Object,
  100. default: () => {},
  101. },
  102. });
  103. const emit = defineEmits(['close', 'register', 'openModal']);
  104. type AssistanceItemType = {
  105. angle: number;
  106. Hz: number;
  107. a: number;
  108. b: number;
  109. c: number;
  110. min: number;
  111. max: number;
  112. };
  113. const columns = ref([]);
  114. const isMock = true;
  115. // 注册 modal
  116. const [register, { closeModal }] = useModalInner(() => {
  117. nextTick(() => {
  118. computeAssistance();
  119. if (option['xAxis']) option['xAxis']['data'] = xData;
  120. option['series'] = yDataList;
  121. initEcharts();
  122. });
  123. });
  124. const loadding = ref<boolean>(false);
  125. const formShow = ref(false);
  126. const formType = ref('');
  127. const chartRef = ref();
  128. const myChart = ref();
  129. const refresh = ref(true);
  130. const xData: any[] = [];
  131. const yDataList: [] = [];
  132. let lineNum = 0;
  133. const lineEquation = ref<string[]>([]);
  134. const deviceData = ref({});
  135. const uQ = ref<string | undefined>(undefined); // 100 - 400
  136. const uH = ref<number | undefined>(undefined); // - 1000
  137. const resultObj = ref<{ x: number; y: number; Hz: number } | null>(null);
  138. const [registerForm, {}] = useForm({
  139. labelWidth: 120,
  140. actionColOptions: {
  141. span: 24,
  142. },
  143. compact: true,
  144. showSubmitButton: true,
  145. submitButtonOptions: {
  146. text: '提交',
  147. preIcon: '',
  148. },
  149. showResetButton: true,
  150. resetButtonOptions: {
  151. text: '关闭',
  152. preIcon: '',
  153. },
  154. resetFunc: async () => {
  155. formShow.value = false;
  156. },
  157. });
  158. function computeAssistance() {
  159. const assistanceData = initData();
  160. lineNum = 0;
  161. const assistanceDataList = [];
  162. const lineEquationList: string[] = [];
  163. for (const key in assistanceData) {
  164. const item = assistanceData[key];
  165. assistanceDataList.push(item);
  166. lineEquationList.push(
  167. `H${parseInt(item['Hz'])} = ${item['a']}Q² ${Number(item['b']) > 0 ? '+' : '-'} ${Math.abs(Number(item['b'])).toFixed(5)}Q ${
  168. Number(item['c']) > 0 ? '+' : '-'
  169. } ${Math.abs(Number(item['c'])).toFixed(5)}`
  170. );
  171. }
  172. lineEquation.value = lineEquationList;
  173. lineNum = assistanceDataList.length;
  174. const xDataMin =
  175. Math.min.apply(
  176. Math,
  177. assistanceDataList.map((item) => {
  178. return item.min;
  179. })
  180. ) - 10;
  181. // const xDataMax = Math.max.apply(Math, assistanceDataList.map(item => { return item.max }))
  182. const xDataMax = 230;
  183. fanInfoData.flfw = `${xDataMin}~${xDataMax}`;
  184. const computeItem = (item: AssistanceItemType) => {
  185. const min = item.min;
  186. const max = item.max;
  187. const HList: number[] = [];
  188. for (let i = xDataMin; i <= xDataMax; i++) {
  189. if (i < min) {
  190. HList.push(null);
  191. } else if (i > max) {
  192. HList.push(null);
  193. } else {
  194. HList.push(item.a * i * i + item.b * i + item.c);
  195. }
  196. }
  197. return HList;
  198. };
  199. for (const key in assistanceData) {
  200. const element: AssistanceItemType = assistanceData[key];
  201. const yData: number[] = computeItem(element);
  202. const series = {
  203. name: `${element['Hz']}Hz`,
  204. type: 'line',
  205. smooth: true,
  206. showSymbol: false,
  207. emphasis: {
  208. focus: 'series',
  209. },
  210. itemStyle: { normal: { label: { show: true } } },
  211. lineStyle: {
  212. width: 1,
  213. color: '#ffffff88',
  214. },
  215. zlevel: 0,
  216. z: 1,
  217. endLabel: {
  218. show: true,
  219. formatter: '{a}',
  220. distance: 0,
  221. color: '#39E9FE99',
  222. backgroundColor: 'transparent',
  223. padding: [3, 3, 2, 3],
  224. },
  225. data: yData,
  226. };
  227. yDataList.push(series);
  228. }
  229. for (let i = xDataMin; i <= xDataMax; i++) {
  230. xData.push(i);
  231. }
  232. }
  233. function computeRLine() {
  234. if (uH.value && uQ.value) {
  235. const R = uH.value / Number(uQ.value) / Number(uQ.value);
  236. const yAxis: number[] = [];
  237. for (let i = 0; i < xData.length; i++) {
  238. const x = xData[i];
  239. const y = R * x * x;
  240. if (x == uQ.value) {
  241. uH.value = y;
  242. }
  243. yAxis.push(y);
  244. }
  245. const series = {
  246. name: 'R',
  247. type: 'line',
  248. smooth: true,
  249. showSymbol: false,
  250. zlevel: 0,
  251. emphasis: {
  252. focus: 'series',
  253. },
  254. itemStyle: { normal: { label: { show: true } } },
  255. lineStyle: {
  256. width: 2,
  257. color: '#D0A343',
  258. },
  259. endLabel: {
  260. show: true,
  261. formatter: '{a}',
  262. distance: 0,
  263. color: '#D0A343',
  264. },
  265. data: yAxis,
  266. };
  267. yDataList[lineNum] = series;
  268. }
  269. }
  270. function reSetLine() {
  271. let minIndex = -1;
  272. for (let i = 0; i < yDataList.length; i++) {
  273. if (i !== lineNum && i != lineNum + 1) {
  274. if (yDataList[i]['lineStyle']) yDataList[i]['lineStyle']['color'] = '#ffffff88';
  275. if (yDataList[i]['lineStyle']) yDataList[i]['lineStyle']['width'] = 1;
  276. if (yDataList[i]['endLabel'] && yDataList[i]['endLabel']['color']) yDataList[i]['endLabel']['color'] = '#39E9FE99';
  277. if (yDataList[i]['endLabel'] && yDataList[i]['endLabel']['backgroundColor']) yDataList[i]['endLabel']['backgroundColor'] = 'transparent';
  278. if (yDataList[i]['z']) yDataList[i]['z'] = 1;
  279. }
  280. if (`${resultObj.value.Hz}Hz` == yDataList[i]['name']) {
  281. minIndex = i;
  282. }
  283. }
  284. if (minIndex != -1) {
  285. yDataList[minIndex]['lineStyle']['color'] = '#9A60B4';
  286. yDataList[minIndex]['lineStyle']['width'] = 2;
  287. yDataList[minIndex]['endLabel']['color'] = '#9A60B4';
  288. yDataList[minIndex]['endLabel']['backgroundColor'] = '#111';
  289. yDataList[minIndex]['z'] = 999;
  290. }
  291. }
  292. // 根据风量计算压差
  293. function computePa() {
  294. const R = uH.value / Number(uQ.value) / Number(uQ.value);
  295. const pointX = Number(uQ.value);
  296. const pointY = Number(uH.value);
  297. type ItemType = {
  298. x: number;
  299. y: number;
  300. Hz: number;
  301. };
  302. const assistanceData = initData();
  303. const paList = new Map<number, ItemType>(); // key 是最近距离
  304. const getIntersectionPoint = (a, b, c, R, min, max) => {
  305. const obj: { x: undefined | number; y: undefined | number } = { x: undefined, y: undefined };
  306. // 计算二次方程的判别式
  307. const discriminant = b * b - 4 * (a - R) * c;
  308. if (discriminant > 0) {
  309. // 有两个实根
  310. const x1 = (-b + Math.sqrt(discriminant)) / (2 * (a - R));
  311. const x2 = (-b - Math.sqrt(discriminant)) / (2 * (a - R));
  312. const y1 = R * x1 * x1;
  313. const y2 = R * x2 * x2;
  314. if (x1 >= min && x1 <= max) {
  315. obj.x = x1;
  316. obj.y = y1;
  317. } else {
  318. obj.x = x2;
  319. obj.y = y2;
  320. }
  321. } else if (discriminant === 0) {
  322. // 有一个实根
  323. const x = -b / (2 * (a - R));
  324. const y = R * x * x;
  325. if (x >= min && x <= max) {
  326. obj.x = x;
  327. obj.y = y;
  328. }
  329. // console.log(`唯一交点: (${x}, ${y})`);
  330. } else {
  331. // 没有实根,交点在虚数域
  332. console.log('没有实数交点');
  333. }
  334. return obj;
  335. };
  336. for (let key in assistanceData) {
  337. const item: AssistanceItemType = assistanceData[key];
  338. paList.set(item.Hz, getIntersectionPoint(item.a, item.b, item.c, R, item.min, item.max));
  339. }
  340. const min = (points: Map<number, ItemType>) => {
  341. const targetX = uQ.value;
  342. const targetY = uH.value;
  343. let minDistance = Number.POSITIVE_INFINITY;
  344. let closestPoint = null;
  345. let keyVal = '';
  346. // 遍历已知点数组,计算距离并更新最小距离和对应的点
  347. for (const [key, point] of points) {
  348. const distance = Math.sqrt((targetX - point.x) ** 2 + (targetY - point.y) ** 2);
  349. if (distance < minDistance) {
  350. minDistance = distance;
  351. closestPoint = point;
  352. keyVal = key;
  353. }
  354. }
  355. if (closestPoint !== null) {
  356. console.log(`距离最小的点是 (${closestPoint.x}, ${closestPoint.y}), 距离为 ${minDistance}`);
  357. resultObj.value = { x: closestPoint.x, y: closestPoint.y, Hz: keyVal };
  358. } else {
  359. console.log('没有找到最小距离的点');
  360. }
  361. };
  362. min(paList);
  363. reSetLine();
  364. }
  365. function computeR() {
  366. if (uQ.value && uH.value) {
  367. computeRLine();
  368. computePa();
  369. if (resultObj.value && resultObj.value.x && resultObj.value.y) {
  370. const series = {
  371. type: 'effectScatter',
  372. symbolSize: 5,
  373. // symbolOffset:[1, 1],
  374. showEffectOn: 'render',
  375. // 涟漪特效相关配置。
  376. rippleEffect: {
  377. // 波纹的绘制方式,可选 'stroke' 和 'fill'。
  378. brushType: 'stroke',
  379. },
  380. zlevel: 1,
  381. z: 999,
  382. itemStyle: {
  383. color: '#C60000',
  384. },
  385. data: [[resultObj.value.x.toFixed(0), Number(resultObj.value.y.toFixed(0))]],
  386. };
  387. yDataList[lineNum + 1] = series;
  388. }
  389. }
  390. }
  391. function edit(flag) {
  392. if (flag == 'info') {
  393. formType.value = '编辑风机信息';
  394. }
  395. if (flag == 'line') {
  396. formType.value = '编辑特性曲线';
  397. }
  398. if (formShow.value == true) {
  399. formShow.value = false;
  400. nextTick(() => {
  401. formShow.value = true;
  402. });
  403. } else {
  404. formShow.value = true;
  405. }
  406. }
  407. async function onSubmit() {
  408. emit('close');
  409. closeModal();
  410. chartRef.value = null;
  411. uQ.value = undefined;
  412. uH.value = undefined;
  413. formType.value = '';
  414. myChart.value = undefined;
  415. refresh.value = true;
  416. xData.length = 0;
  417. yDataList.length = 0;
  418. lineNum = 0;
  419. lineEquation.value = [];
  420. resultObj.value = null;
  421. }
  422. function initEcharts() {
  423. if (chartRef.value) {
  424. computeR();
  425. myChart.value = echarts.init(chartRef.value);
  426. option && myChart.value.setOption(option);
  427. refresh.value = false;
  428. nextTick(() => {
  429. setTimeout(() => {
  430. refresh.value = true;
  431. }, 0);
  432. });
  433. }
  434. }
  435. function makeLine() {
  436. if (uQ.value && uH.value) {
  437. loadding.value = true;
  438. setTimeout(() => {
  439. initEcharts();
  440. loadding.value = false;
  441. }, 1200);
  442. }
  443. }
  444. function handleSubmit() {
  445. message.success('提交成功');
  446. setTimeout(() => {
  447. formShow.value = false;
  448. }, 800);
  449. }
  450. function getColumn() {
  451. let lineColumns = [];
  452. if (props.deviceType) {
  453. lineColumns = getTableHeaderColumns(props.deviceType + '_input') as [];
  454. if (lineColumns && lineColumns.length < 1) {
  455. lineColumns = getTableHeaderColumns(props.deviceType.split('_')[0] + '_input') as [];
  456. }
  457. if (lineColumns.length > 0) {
  458. lineColumns = lineColumns.filter((item) => item['dataIndex'] && item['dataIndex'].includes('_line_'));
  459. columns.value = lineColumns;
  460. }
  461. }
  462. }
  463. watch(
  464. () => props.deviceType,
  465. async () => {
  466. getColumn();
  467. // deviceData.value = await list({ devicetype: 'fanmain', pagetype: 'normal' });
  468. }
  469. );
  470. watch(
  471. () => props.selectData,
  472. async (selectData) => {
  473. debugger;
  474. deviceData.value = selectData;
  475. }
  476. );
  477. onMounted(() => {});
  478. </script>
  479. <style scoped lang="less">
  480. .modal-box {
  481. display: flex;
  482. flex-direction: row;
  483. background-color: #ffffff05;
  484. padding: 20px 8px;
  485. border: 1px solid #00d8ff22;
  486. // min-height: 600px;
  487. .box-title {
  488. width: calc(100% - 40px);
  489. text-align: center;
  490. background-color: #1dc1f522;
  491. }
  492. .info-item {
  493. display: flex;
  494. justify-content: space-between;
  495. align-items: center;
  496. padding: 2px 0px;
  497. margin: 4px 0;
  498. background-image: linear-gradient(to right, #39deff15, #3977e500);
  499. &:first-child {
  500. margin-top: 0;
  501. }
  502. .title {
  503. width: 200px;
  504. text-align: left;
  505. padding-left: 20px;
  506. color: #f1f1f1cc;
  507. }
  508. .value {
  509. width: 150px;
  510. color: #00d8ff;
  511. padding-right: 20px;
  512. text-align: right;
  513. }
  514. }
  515. .right-box {
  516. width: 350px;
  517. .info-container {
  518. width: calc(100% - 2px);
  519. margin-top: 5px;
  520. box-shadow: 0px 0px 50px #86baff08 inset;
  521. }
  522. }
  523. .left-box {
  524. width: 350px;
  525. .info-lines {
  526. width: calc(100% - 2px);
  527. height: 390px;
  528. box-shadow: 0px 0px 50px #86baff08 inset;
  529. overflow-y: auto;
  530. margin-top: 5px;
  531. .title {
  532. width: 100%;
  533. color: #f1f1f1cc;
  534. }
  535. }
  536. }
  537. .center-box {
  538. margin: 0 10px;
  539. .info-echarts {
  540. // background-color: #ffffff11;
  541. }
  542. .result-tip {
  543. text-align: center;
  544. background-color: #00000011;
  545. line-height: 28px;
  546. margin: 10px 50px 0 50px;
  547. border: 1px solid #00d8ff22;
  548. border-radius: 2px;
  549. }
  550. }
  551. }
  552. .setting-box {
  553. width: 1170px;
  554. height: 70px;
  555. margin: 10px 0;
  556. background-color: #ffffff05;
  557. border: 1px solid #00d8ff22;
  558. display: flex;
  559. align-items: center;
  560. justify-content: space-between;
  561. .right-inputs {
  562. display: flex;
  563. height: 40px;
  564. margin-right: 10px;
  565. }
  566. .left-buttons {
  567. display: flex;
  568. height: 40px;
  569. margin-left: 15px;
  570. .btn {
  571. margin: 0 10px;
  572. }
  573. span {
  574. color: #00d8ff;
  575. }
  576. }
  577. .border-clip {
  578. width: 1px;
  579. height: 25px;
  580. border-right: 1px solid #8b8b8b77;
  581. }
  582. .input-title {
  583. width: 80px;
  584. }
  585. .input-box {
  586. width: 200px !important;
  587. background: transparent !important;
  588. border-color: #00d8ff44 !important;
  589. margin-right: 20px;
  590. color: #fff !important;
  591. }
  592. .btn {
  593. padding: 8px 20px;
  594. position: relative;
  595. border-radius: 2px;
  596. color: #fff;
  597. width: fit-content;
  598. cursor: pointer;
  599. &::before {
  600. position: absolute;
  601. display: block;
  602. content: '';
  603. width: calc(100% - 4px);
  604. height: calc(100% - 4px);
  605. top: 2px;
  606. left: 2px;
  607. border-radius: 2px;
  608. z-index: -1;
  609. }
  610. }
  611. .btn1 {
  612. border: 1px solid #5cfaff;
  613. &::before {
  614. background-image: linear-gradient(#2effee92, #0cb1d592);
  615. }
  616. &:hover {
  617. border: 1px solid #5cfaffaa;
  618. &::before {
  619. background-image: linear-gradient(#2effee72, #0cb1d572);
  620. }
  621. }
  622. }
  623. }
  624. .is-open {
  625. animation: open 0.5s;
  626. animation-iteration-count: 1;
  627. animation-fill-mode: forwards;
  628. animation-timing-function: ease-in;
  629. }
  630. .is-close {
  631. height: 0px;
  632. }
  633. @keyframes open {
  634. 0% {
  635. height: 0px;
  636. }
  637. 100% {
  638. height: fit-content;
  639. }
  640. }
  641. @keyframes close {
  642. 0% {
  643. height: fit-content;
  644. }
  645. 100% {
  646. height: 0px;
  647. }
  648. }
  649. :deep(.zxm-divider-inner-text) {
  650. color: #cacaca88 !important;
  651. }
  652. :deep(.zxm-form-item) {
  653. margin-bottom: 10px;
  654. }
  655. </style>