conditionAssistance.vue 17 KB

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