history-search.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <div class="searchPage1">
  3. <div class="query mg-b-8">
  4. <div class="query-items">
  5. <div class="query-item">
  6. <div class="lable">日期:</div>
  7. <div class="search-input">
  8. <el-date-picker size="medium" v-model="form.dateArea" type="datetimerange" :picker-options="pickerOptions" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right"> </el-date-picker>
  9. </div>
  10. </div>
  11. <div class="query-item">
  12. <div class="lable">间隔:</div>
  13. <div class="search-input">
  14. <el-input-number v-model="form.interval" controls-position="right"></el-input-number>
  15. </div>
  16. </div>
  17. <div class="query-item">
  18. <div class="lable"></div>
  19. <div class="search-input">
  20. <transition name="el-zoom-in-center">
  21. <el-radio-group v-model="form.type" size="small" v-show="form.interval">
  22. <el-radio label="0" @click.prevent="getRadio('0')">最大</el-radio>
  23. <el-radio label="1" @click.prevent="getRadio('1')">最小</el-radio>
  24. <el-radio label="2" @click.prevent="getRadio('2')">平均</el-radio>
  25. </el-radio-group>
  26. </transition>
  27. </div>
  28. </div>
  29. </div>
  30. <div class="query-actions">
  31. <button class="btn green" @click="renderCharts">生成曲线</button>
  32. </div>
  33. </div>
  34. <div class="cardBox">
  35. <el-card class="box-card">
  36. <template v-slot:header class="clearfix">
  37. <span>类型</span>
  38. <!-- <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button> -->
  39. </template>
  40. <div>
  41. <el-radio-group
  42. v-model="form.fjType"
  43. size="small"
  44. @change="
  45. (fjType) => {
  46. resetForm();
  47. }
  48. "
  49. >
  50. <el-form ref="form" :model="form">
  51. <el-form-item style="margin-bottom:5px;">
  52. <el-radio border size="medium" label="1">单风机多参数对比</el-radio>
  53. </el-form-item>
  54. <el-form-item style="margin-bottom:5px;">
  55. <el-radio border size="medium" label="2">多风机单参数对比</el-radio>
  56. </el-form-item>
  57. </el-form>
  58. </el-radio-group>
  59. </div>
  60. </el-card>
  61. <el-card class="box-card">
  62. <template v-slot:header class="clearfix">
  63. <span>设备结构</span>
  64. </template>
  65. <div>
  66. <div class="treeBox">
  67. <el-input size="small" placeholder="输入以检索" :disabled="!treeData.length" v-model="filterText"></el-input>
  68. <el-tree ref="treeRef" node-key="id" :data="treeData" :props="treeProps" :show-checkbox="true" :highlight-current="true" :filter-node-method="filterNode" @check-change="getTreeChecked"></el-tree>
  69. </div>
  70. </div>
  71. </el-card>
  72. <el-card class="box-card">
  73. <template v-slot:header class="clearfix">
  74. <span>关键参数</span>
  75. </template>
  76. <div class="selectBox treeBox">
  77. <el-input size="small" placeholder="输入以检索" :disabled="!gjcsOptions.length" v-model="filterText1"></el-input>
  78. <el-tree ref="treeRef1" node-key="code" :data="gjcsOptions" :props="{ children: null, label: 'description' }" :show-checkbox="true" :highlight-current="true" :filter-node-method="filterNode1" @check-change="getTreeChecked1"></el-tree>
  79. <!-- <el-select style="width:100%;" v-model="form.gjcs" filterable clearable :multiple="!treeIsMultiple"
  80. placeholder="输入以检索" @change="(res) => { this.$forceUpdate(); }">
  81. <el-option v-for="item in gjcsOptions" :key="item.id" :label="item.description" :value="item.code">
  82. </el-option>
  83. </el-select> -->
  84. </div>
  85. </el-card>
  86. </div>
  87. <div class="chartsBox">
  88. <div id="lineChart" style="width:100%;height:100%;"></div>
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. import * as echarts from "echarts";
  94. export default {
  95. data() {
  96. return {
  97. form: {
  98. pointId: "",
  99. pointName: "",
  100. autoReq: false,
  101. dateArea: [this.fmtDate(new Date(new Date().setTime(new Date().getTime() - 3600 * 1000 * 24))), this.fmtDate(new Date())],
  102. interval: "",
  103. type: "",
  104. fjType: "1",
  105. gjcs: "",
  106. },
  107. treeIsMultiple: false,
  108. filterText: "",
  109. filterText1: "",
  110. treeData: [
  111. {
  112. id: 1,
  113. label: "一级 2",
  114. children: [
  115. {
  116. id: 3,
  117. label: "二级 2-1",
  118. children: [
  119. {
  120. id: 4,
  121. label: "三级 3-1-1",
  122. },
  123. {
  124. id: 5,
  125. label: "三级 3-1-2",
  126. disabled: true,
  127. },
  128. ],
  129. },
  130. {
  131. id: 2,
  132. label: "二级 2-2",
  133. disabled: true,
  134. children: [
  135. {
  136. id: 6,
  137. label: "三级 3-2-1",
  138. },
  139. {
  140. id: 7,
  141. label: "三级 3-2-2",
  142. disabled: true,
  143. },
  144. ],
  145. },
  146. ],
  147. },
  148. ],
  149. gjcsOptions: [],
  150. treeProps: {
  151. children: "children",
  152. label: "label",
  153. },
  154. pickerOptions: {
  155. shortcuts: [
  156. {
  157. text: "最近一天",
  158. onClick(picker) {
  159. const end = new Date();
  160. const start = new Date();
  161. start.setTime(start.getTime() - 3600 * 1000 * 24);
  162. picker.$emit("pick", [start, end]);
  163. },
  164. },
  165. {
  166. text: "最近一周",
  167. onClick(picker) {
  168. const end = new Date();
  169. const start = new Date();
  170. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  171. picker.$emit("pick", [start, end]);
  172. },
  173. },
  174. {
  175. text: "最近一个月",
  176. onClick(picker) {
  177. const end = new Date();
  178. const start = new Date();
  179. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  180. picker.$emit("pick", [start, end]);
  181. },
  182. },
  183. {
  184. text: "最近三个月",
  185. onClick(picker) {
  186. const end = new Date();
  187. const start = new Date();
  188. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  189. picker.$emit("pick", [start, end]);
  190. },
  191. },
  192. ],
  193. },
  194. };
  195. },
  196. mounted() {
  197. let that = this;
  198. that.$nextTick(() => {
  199. that.getEquipmentStructure();
  200. that.getEquipmentParams();
  201. });
  202. },
  203. methods: {
  204. // 获取设备结构
  205. getEquipmentStructure() {
  206. let that = this;
  207. that.API.requestData({
  208. baseURL: "http://10.155.32.4:8031/",
  209. subUrl: "paramComparison/equipmentStructure",
  210. timeout: 30000,
  211. success(res) {
  212. // 请求成功的回调
  213. let treeData = [];
  214. res.data.forEach((ele) => {
  215. let findRes = treeData.find((findEle) => {
  216. return ele.windpowerstationid === findEle.label;
  217. });
  218. if (!findRes) {
  219. let treeTemp = {
  220. label: ele.windpowerstationid,
  221. children: [],
  222. };
  223. treeTemp.children.push({
  224. label: ele.name,
  225. id: ele.id,
  226. });
  227. treeData.push(treeTemp);
  228. } else {
  229. findRes.children.push({
  230. label: ele.name,
  231. id: ele.id,
  232. });
  233. }
  234. });
  235. that.treeData = treeData;
  236. },
  237. });
  238. },
  239. // 获取关键节点
  240. getEquipmentParams() {
  241. let that = this;
  242. that.API.requestData({
  243. baseURL: "http://10.155.32.4:8031/",
  244. subUrl: "paramComparison/equipmentParams",
  245. success(res) {
  246. that.gjcsOptions = res.data;
  247. },
  248. });
  249. },
  250. // 获取单选结果
  251. getRadio(type) {
  252. if (type === this.form.type && this.form.type !== "") {
  253. this.form.type = "";
  254. } else {
  255. this.form.type = type;
  256. }
  257. },
  258. // 渲染图表
  259. renderCharts() {
  260. let that = this;
  261. that.$nextTick(() => {
  262. let begin = that.form.dateArea.length ? new Date(that.form.dateArea[0]).formatDate("yyyy-MM-dd hh:mm:ss") : "";
  263. let end = that.form.dateArea.length ? new Date(that.form.dateArea[1]).formatDate("yyyy-MM-dd hh:mm:ss") : "";
  264. let interval = that.form.interval;
  265. let type = that.form.type;
  266. let paramtype = that.form.fjType;
  267. let wts = [];
  268. let wtsArray = that.$refs.treeRef.getCheckedNodes();
  269. let params = [];
  270. let paramsArray = that.$refs.treeRef1.getCheckedNodes();
  271. // let params = that.form.gjcs;
  272. wtsArray.forEach((pEle) => {
  273. if (pEle.id) {
  274. wts.push(pEle.id);
  275. } else {
  276. pEle.children.forEach((cEle) => {
  277. wts.push(cEle.id);
  278. });
  279. }
  280. });
  281. paramsArray.forEach((pEle) => {
  282. params.push(pEle.code);
  283. });
  284. let data = {};
  285. data.begin = begin;
  286. data.end = end;
  287. interval && (data.interval = interval);
  288. type && (data.type = type);
  289. data.paramtype = paramtype;
  290. data.wts = wts.toString();
  291. data.params = params.toString();
  292. if (begin && end && paramtype && wts.length && params.length) {
  293. that.API.requestData({
  294. baseURL: "http://10.155.32.4:8031/",
  295. subUrl: "paramComparison/generatingCurve",
  296. timeout: 10000,
  297. data,
  298. success(res) {
  299. if (res.data.length) {
  300. let xAxisData = []; // x轴标题
  301. let seriesData = []; // 折线图数据
  302. let keyArray = [];
  303. if (that.form.fjType === "1") {
  304. params.forEach((ele) => {
  305. let findRes = that.gjcsOptions.find((findEle) => {
  306. return ele === findEle.code;
  307. });
  308. keyArray.push(findRes.description);
  309. });
  310. } else {
  311. wtsArray.forEach((pEle) => {
  312. if (pEle.id) {
  313. keyArray.push(pEle.label);
  314. } else {
  315. pEle.children.forEach((cEle) => {
  316. keyArray.push(cEle.label);
  317. });
  318. }
  319. });
  320. }
  321. keyArray.forEach((ele) => {
  322. seriesData.push({
  323. data: [],
  324. type: "line",
  325. smooth: true,
  326. name: ele,
  327. });
  328. });
  329. res.data.forEach((pEle) => {
  330. xAxisData.push(that.fmtDate(new Date(pEle.time)));
  331. keyArray.forEach((cEle, cIndex) => {
  332. seriesData[cIndex].data.push(pEle[cEle] || null);
  333. });
  334. });
  335. document.getElementById("lineChart").removeAttribute("_echarts_instance_");
  336. let chartDom = document.getElementById("lineChart");
  337. let myChart = echarts.init(chartDom);
  338. let option = {
  339. xAxis: {
  340. type: "category",
  341. data: xAxisData,
  342. },
  343. yAxis: {
  344. type: "value",
  345. },
  346. series: seriesData,
  347. tooltip: {
  348. trigger: "axis",
  349. axisPointer: {
  350. type: "cross",
  351. label: {
  352. backgroundColor: "#6a7985",
  353. },
  354. },
  355. },
  356. };
  357. option && myChart.setOption(option);
  358. } else {
  359. that.BASE.showMsg({
  360. type: "warning",
  361. msg: "所选参数暂无数据,请切换参数后再次尝试",
  362. });
  363. }
  364. },
  365. });
  366. } else {
  367. that.BASE.showMsg({
  368. msg: "无法生成,请检查 日期、设备结构与关键参数是否已选择",
  369. });
  370. }
  371. });
  372. },
  373. // 过滤树形节点
  374. filterNode(value, data) {
  375. if (!value) return true;
  376. return data.label.indexOf(value) !== -1;
  377. },
  378. // 过滤树形节点
  379. filterNode1(value, data) {
  380. if (!value) return true;
  381. return data.description.indexOf(value) !== -1;
  382. },
  383. // 获取树形选中
  384. getTreeChecked(data, checked, node) {
  385. if (!this.treeIsMultiple) {
  386. if (checked === true) {
  387. this.checkedId = data.id;
  388. this.$refs.treeRef.setCheckedKeys([data.id]);
  389. } else {
  390. if (this.checkedId == data.id) {
  391. this.$refs.treeRef.setCheckedKeys([]);
  392. }
  393. }
  394. }
  395. },
  396. // 获取树形选中
  397. getTreeChecked1(data, checked, node) {
  398. if (this.treeIsMultiple) {
  399. if (checked === true) {
  400. this.checkedId = data.code;
  401. this.$refs.treeRef1.setCheckedKeys([data.code]);
  402. } else {
  403. if (this.checkedId == data.code) {
  404. this.$refs.treeRef1.setCheckedKeys([]);
  405. }
  406. }
  407. }
  408. },
  409. // 重置表单
  410. resetForm() {
  411. this.form.fjType === "1" ? (this.treeIsMultiple = false) : (this.treeIsMultiple = true);
  412. this.$refs.treeRef.setCheckedKeys([]);
  413. this.$refs.treeRef1.setCheckedKeys([]);
  414. this.form.gjcs = "";
  415. this.$forceUpdate();
  416. document.getElementById("lineChart").removeAttribute("_echarts_instance_");
  417. echarts.init(document.getElementById("lineChart"));
  418. },
  419. // 格式化日期
  420. fmtDate(date) {
  421. let curDate = date || new Date();
  422. let year = curDate.getFullYear();
  423. let mouth = curDate.getUTCMonth() + 1;
  424. let day = curDate.getDate();
  425. let hour = curDate.getHours();
  426. let minutes = curDate.getMinutes();
  427. let seconds = curDate.getSeconds();
  428. return year + "-" + (mouth < 10 ? "0" + mouth : mouth) + "-" + (day < 10 ? "0" + day : day) + " " + (hour < 10 ? "0" + hour : hour) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
  429. },
  430. },
  431. watch: {
  432. filterText(val) {
  433. this.$refs.treeRef.filter(val);
  434. },
  435. filterText1(val) {
  436. this.$refs.treeRef1.filter(val);
  437. },
  438. },
  439. };
  440. </script>
  441. <style lang="less" scoped>
  442. .searchBox1 {
  443. width: 80%;
  444. display: flex;
  445. justify-content: start;
  446. align-items: center;
  447. position: relative;
  448. .btnBox {
  449. position: absolute;
  450. left: calc(100% + 60px);
  451. top: 0;
  452. display: flex;
  453. justify-content: start;
  454. align-items: center;
  455. }
  456. .el-input {
  457. width: 150px;
  458. }
  459. }
  460. .cardBox {
  461. width: 100%;
  462. display: flex;
  463. justify-content: space-between;
  464. align-items: center;
  465. margin-top: 20px;
  466. .el-card {
  467. width: 32%;
  468. height: 255px;
  469. .treeBox {
  470. width: 100%;
  471. .el-tree {
  472. width: 100%;
  473. height: 160px;
  474. margin-top: 10px;
  475. overflow-y: scroll;
  476. }
  477. }
  478. }
  479. }
  480. .selectBox {
  481. .el-select {
  482. max-height: 150px;
  483. overflow-y: scroll;
  484. }
  485. }
  486. .chartsBox {
  487. width: 100%;
  488. height: 400px;
  489. }
  490. </style>
  491. <style lang="less">
  492. .cardBox {
  493. .el-card__header {
  494. padding: 5px 20px;
  495. }
  496. .el-card__body {
  497. padding: 10px 20px;
  498. }
  499. }
  500. </style>