history-search.vue 16 KB

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