datasearch.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <div class="datasearch">
  3. <el-card class="box-card cardleft">
  4. <div class="cardleft_top">
  5. <el-select
  6. v-if="!isStation"
  7. v-model="state.stationId"
  8. clearable
  9. style="width: 140px; margin-right: 20px"
  10. size="mini"
  11. placeholder="全部场站"
  12. popper-class="select"
  13. @change="getWindturbineList()"
  14. >
  15. <el-option
  16. v-for="item in stationList"
  17. :key="item.id"
  18. :value="item.id"
  19. :label="item.name"
  20. ></el-option>
  21. </el-select>
  22. <el-select
  23. v-model="state.modeId"
  24. clearable
  25. style="flex: 1"
  26. size="mini"
  27. placeholder="全部机型"
  28. popper-class="select"
  29. >
  30. <el-option
  31. v-for="item in modelList"
  32. :key="item.id"
  33. :value="item.id"
  34. :label="item.aname"
  35. ></el-option>
  36. </el-select>
  37. </div>
  38. <el-input
  39. v-model="state.input"
  40. size="mini"
  41. placeholder="检索"
  42. clearable
  43. />
  44. <div style="height: calc(100% - 54px)">
  45. <el-scrollbar height="100%">
  46. <div
  47. v-for="item in filterWTList"
  48. :key="item"
  49. :class="[
  50. 'scrollbar-demo-item',
  51. item.id == state.activeWT ? 'active' : '',
  52. ]"
  53. @click="clickWT(item)"
  54. >
  55. {{ item.aname }}
  56. </div>
  57. </el-scrollbar>
  58. </div>
  59. </el-card>
  60. <el-card class="box-card cardmid">
  61. <el-input
  62. v-model="state.inputAI"
  63. style="margin-bottom: 10px"
  64. size="mini"
  65. placeholder="点名检索"
  66. clearable
  67. />
  68. <el-tree
  69. :data="state.treedata"
  70. :props="state.defaultProps"
  71. node-key="id"
  72. highlight-current
  73. default-expand-all
  74. @node-click="handleNodeClick"
  75. />
  76. </el-card>
  77. <el-card class="box-card cardright">
  78. <el-table :data="filterAIList" style="width: 100%" height="77vh">
  79. <el-table-column prop="uniformCode" label="点名" width="120" />
  80. <el-table-column prop="name" label="名称" align="center" />
  81. <el-table-column prop="value" label="值" width="80">
  82. <template #default="scope">
  83. <el-tag type="success">{{ scope.row.value }}</el-tag>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="时间" width="180" align="center">
  87. <template #default="scope">
  88. <el-tag>{{
  89. dayjs(scope.row.time).format("YYYY-MM-DD HH:mm:ss")
  90. }}</el-tag>
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="单位" width="180" align="center">
  94. <template #default="scope">
  95. {{ scope.row.unitName }}
  96. {{ scope.row.unitNameCn ? `(${scope.row.unitNameCn})` : "" }}
  97. </template>
  98. </el-table-column>
  99. <el-table-column width="100">
  100. <template #default="scope">
  101. <el-button size="small" @click="handleSearch(scope.row)"
  102. >历史数据</el-button
  103. >
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. <div class="pagination">
  108. <el-pagination
  109. background
  110. layout="total, prev, pager, next"
  111. hide-on-single-page
  112. :current-page="query.page"
  113. :page-size="query.limit"
  114. :total="query.pageTotal"
  115. @current-change="handlePageChange"
  116. ></el-pagination>
  117. </div>
  118. </el-card>
  119. <el-dialog
  120. v-model="dialogVisible"
  121. width="80%"
  122. :before-close="dialogClose"
  123. :title="`${state.activeWT}_${state.activeAI}_${
  124. state.handleSearch?.name || ''
  125. }历史数据`"
  126. >
  127. <div class="pickerFifter">
  128. <el-date-picker
  129. v-model="state.pickerVal"
  130. type="datetimerange"
  131. range-separator="-"
  132. start-placeholder="开始时间"
  133. end-placeholder="结束时间"
  134. >
  135. </el-date-picker>
  136. <el-select
  137. v-model="state.selectDataVal"
  138. placeholder="数据源"
  139. style="margin: 0 10px"
  140. >
  141. <el-option
  142. v-for="item in state.selectData"
  143. :key="item.value"
  144. :label="item.label"
  145. :value="item.value"
  146. >
  147. </el-option>
  148. </el-select>
  149. <!-- <el-select
  150. v-model="state.selectTimeVal"
  151. v-show="state.selectDataVal !== 1"
  152. placeholder="时间间隔"
  153. >
  154. <el-option
  155. v-for="item in state.selectTime"
  156. :key="item.value"
  157. :label="item.label"
  158. :value="item.value"
  159. >
  160. </el-option>
  161. </el-select> -->
  162. <el-input
  163. v-model="state.selectTimeVal"
  164. style="width: 200px"
  165. v-show="state.selectDataVal !== 1"
  166. placeholder="时间间隔"
  167. >
  168. <template #append>分钟</template>
  169. </el-input>
  170. <el-button
  171. size="small"
  172. type="primary"
  173. style="margin: 0 10px"
  174. @click="pickerSearch"
  175. >查询</el-button
  176. >
  177. <el-button size="small" type="primary" @click="export2Excel"
  178. >导出</el-button
  179. >
  180. </div>
  181. <div class="dChart" style="height: 500px; width: 100%" :id="eChart"></div>
  182. </el-dialog>
  183. </div>
  184. </template>
  185. <script setup>
  186. import {
  187. ref,
  188. onMounted,
  189. watch,
  190. reactive,
  191. computed,
  192. onUnmounted,
  193. nextTick,
  194. } from "vue";
  195. import {
  196. fetchWindturbineList,
  197. tree,
  198. fetchAIDIPointList,
  199. getAdapterLatest,
  200. getAdapterHistory,
  201. getAdapterHistorysnap,
  202. AdapterHistoryExport,
  203. getStationinfo,
  204. fetchModel,
  205. } from "/@/api/api.js";
  206. import dayjs from "dayjs";
  207. import * as echarts from "echarts";
  208. import { useStore } from "vuex";
  209. import axios from "axios";
  210. import { ElMessage } from "element-plus";
  211. import { outExportExcel } from "/@/utils/exportExcel"; //引入文件
  212. const store = useStore();
  213. const isStation = computed(() => store.getters.isStation);
  214. const stationList = computed(() => store.state.stationListAll);
  215. const eChart = ref("eChart" + Date.now() + Math.random());
  216. watch(
  217. () => stationList,
  218. (val, old) => {
  219. val.value[0] &&
  220. nextTick(async () => {
  221. state.stationId = stationList.value[0]?.id;
  222. await getWindturbineList();
  223. getTreeData();
  224. });
  225. },
  226. {
  227. deep: true,
  228. immediate: true,
  229. }
  230. );
  231. onMounted(async () => {
  232. getequipmentmodel_list();
  233. });
  234. onUnmounted(() => {
  235. state.echarts?.clear(); //销毁
  236. clearInterval(state.Interval);
  237. state.Interval = null;
  238. });
  239. const dialogClose = (done) => {
  240. state.echarts?.clear(); //销毁
  241. done();
  242. };
  243. const query = reactive({
  244. page: 1,
  245. limit: 14,
  246. pageTotal: null,
  247. });
  248. const dialogVisible = ref(null);
  249. const state = reactive({
  250. handleSearch: null,
  251. input: "",
  252. inputAI: "",
  253. stationId: "",
  254. windturbineList: [],
  255. modelListAll: [],
  256. modeId: "",
  257. AIList: [],
  258. activeWT: "",
  259. activeAI: "",
  260. Interval: null,
  261. pickerVal: [new Date(new Date() - 1 * 60 * 60 * 1000), new Date()],
  262. echarts: null,
  263. treedata: [],
  264. defaultProps: {
  265. children: "children",
  266. label: (a) => {
  267. return a.node.name;
  268. },
  269. },
  270. structcode: "",
  271. selectDataVal: 1,
  272. selectData: [
  273. {
  274. label: "原始数据",
  275. value: 1,
  276. },
  277. {
  278. label: "数据快照",
  279. value: 2,
  280. },
  281. ],
  282. selectTimeVal: 1,
  283. downData: null,
  284. });
  285. // 机型
  286. const getequipmentmodel_list = async () => {
  287. const { data } = await fetchModel();
  288. state.modelListAll = data;
  289. };
  290. const modelList = computed(() => {
  291. if (state.stationId == "") {
  292. return [];
  293. } else {
  294. return state.modelListAll[state.stationId];
  295. }
  296. });
  297. //get 风机机组
  298. const getWindturbineList = async () => {
  299. const { data } = await fetchWindturbineList(state.stationId);
  300. state.windturbineList = data;
  301. state.activeWT = state.windturbineList[0]?.id;
  302. state.modeId = "";
  303. // await getequipmentmodel_list();
  304. await getFetchAIPointListt();
  305. };
  306. // 风机搜索
  307. const filterWTList = computed(() =>
  308. state.windturbineList?.filter(
  309. (data) =>
  310. data.aname.includes(state.input) && data.modelId.includes(state.modeId)
  311. )
  312. );
  313. //AI点检索
  314. const filterAIList = computed(() =>
  315. state.AIList?.filter(
  316. (data) => !state.inputAI || data.name.includes(state.inputAI)
  317. // !state.inputAI ||
  318. // (data.uniformCode.toUpperCase().includes(state.inputAI.toUpperCase()) ||
  319. // data.name.indexOf(state.inputAI))
  320. )
  321. );
  322. // get 实时data
  323. const getLatest = async (stationId, AIlist) => {
  324. const data = await getAdapterLatest(stationId, AIlist, state.stationId);
  325. state.AIList?.forEach((e) => {
  326. if (e.uniformCode.indexOf("AI") !== -1) {
  327. e.value = Number(data[e.uniformCode]?.doubleValue).toFixed(2);
  328. }
  329. // else {
  330. // e.value = data[e.uniformCode]?.booleanValue - 0;
  331. // }
  332. e["time"] = data[e.uniformCode]?.ts;
  333. });
  334. };
  335. // get 历史数据
  336. const getHistory = async (stationId, AIpoint) => {
  337. let startTs = dayjs(state.pickerVal[0]).valueOf();
  338. let endTs = dayjs(state.pickerVal[1]).valueOf();
  339. const baseUrl = `http://10.81.3.162:801${
  340. /FDC/.test(state.stationId) ? "1" : "2"
  341. }/`;
  342. const data = await getAdapterHistory(
  343. stationId,
  344. AIpoint,
  345. startTs,
  346. endTs,
  347. baseUrl
  348. );
  349. state.downData = data;
  350. option.xAxis.data = [];
  351. option.series[0].data = [];
  352. let timeArr = [];
  353. data.forEach((e) => {
  354. option.series[0].data.push(e.doubleValue.toFixed(2));
  355. option.xAxis.data.push(dayjs(e.ts).format("YYYY-MM-DD HH:mm:ss"));
  356. });
  357. let chat = echarts.init(document.getElementById(eChart.value));
  358. state.echarts = await chat.setOption(option);
  359. };
  360. // get 数据快照
  361. const getHistorysnap = async (stationId, AIpoint, interval) => {
  362. let startTs = dayjs(state.pickerVal[0]).valueOf();
  363. let endTs = dayjs(state.pickerVal[1]).valueOf();
  364. const baseUrl = `http://10.81.3.162:801${
  365. /FDC/.test(state.stationId) ? "1" : "2"
  366. }/`;
  367. const data = await getAdapterHistorysnap(
  368. stationId,
  369. AIpoint,
  370. startTs,
  371. endTs,
  372. interval,
  373. baseUrl
  374. );
  375. state.downData = data;
  376. option.xAxis.data = [];
  377. option.series[0].data = [];
  378. let timeArr = [];
  379. data.forEach((e) => {
  380. option.series[0].data.push(e.doubleValue.toFixed(2));
  381. option.xAxis.data.push(dayjs(e.ts).format("YYYY-MM-DD HH:mm:ss"));
  382. });
  383. let chat = echarts.init(document.getElementById(eChart.value));
  384. state.echarts = await chat.setOption(option);
  385. };
  386. const option = {
  387. tooltip: {
  388. trigger: "axis",
  389. position: function (pt) {
  390. return [pt[0], "10%"];
  391. },
  392. },
  393. xAxis: {
  394. type: "category",
  395. boundaryGap: false,
  396. data: [],
  397. },
  398. yAxis: {
  399. type: "value",
  400. boundaryGap: [0, "100%"],
  401. },
  402. dataZoom: [
  403. {
  404. type: "inside",
  405. start: 0,
  406. end: 10,
  407. },
  408. {
  409. start: 0,
  410. end: 10,
  411. },
  412. ],
  413. series: [
  414. {
  415. data: [],
  416. type: "line",
  417. smooth: true,
  418. },
  419. ],
  420. };
  421. //get AI
  422. const getFetchAIPointListt = async () => {
  423. const res = await fetchAIDIPointList(
  424. "windturbine",
  425. state.structcode,
  426. state.stationId,
  427. state.activeWT,
  428. query.page,
  429. query.limit
  430. );
  431. state.AIList = res?.records;
  432. query.pageTotal = res?.total;
  433. let AIlist = [];
  434. res.records?.forEach((e) => {
  435. AIlist.push(e.uniformCode);
  436. });
  437. if (state.Interval) {
  438. clearInterval(state.Interval);
  439. }
  440. state.Interval = setInterval(getLatest, 1000, state.activeWT, AIlist);
  441. };
  442. // TREE
  443. // tree click
  444. const handleNodeClick = (data) => {
  445. state.structcode = data.node.code;
  446. getFetchAIPointListt();
  447. };
  448. // gettreeData
  449. const getTreeData = async () => {
  450. // const res = await tree();
  451. // let data = res.children[1].children;
  452. let data = [];
  453. data.unshift({ node: { code: "", name: "全部" } });
  454. // data.unshift({ node: { code: "1010102", name: "全部" } });
  455. // data.forEach((e) => {
  456. // delete e.children;
  457. // });
  458. state.treedata = data;
  459. };
  460. //
  461. const handleSearch = (item) => {
  462. dialogVisible.value = true;
  463. state.handleSearch = item;
  464. state.activeAI = item.uniformCode;
  465. getHistory(state.activeWT, state.activeAI);
  466. };
  467. const clickWT = (item) => {
  468. state.activeWT = item.id;
  469. if (state.Interval) {
  470. clearInterval(state.Interval);
  471. }
  472. getFetchAIPointListt();
  473. };
  474. const pickerSearch = () => {
  475. if (state.selectDataVal == 1) {
  476. getHistory(state.activeWT, state.activeAI);
  477. } else {
  478. getHistorysnap(state.activeWT, state.activeAI, state.selectTimeVal * 60);
  479. }
  480. };
  481. // 分页导航
  482. const handlePageChange = (val) => {
  483. query.page = val;
  484. getFetchAIPointListt();
  485. };
  486. // 批量导出
  487. const export2Excel = async () => {
  488. let data = state.downData;
  489. data.forEach((e) => {
  490. e.doubleValue = e.doubleValue.toFixed(2);
  491. e.ts = dayjs(e.ts).format("YYYY-MM-DD HH:mm:ss");
  492. });
  493. ElMessage.success(`导出成功!`);
  494. const tableHeader = ["时间", "值"];
  495. const tableKey = ["ts", "doubleValue"];
  496. outExportExcel(
  497. tableHeader,
  498. tableKey,
  499. data,
  500. `${state.activeWT}_${state.activeAI}_${dayjs(state.pickerVal[0]).format(
  501. "YYYY-MM-DD HH:mm"
  502. )}-${dayjs(state.pickerVal[1]).format("YYYY-MM-DD HH:mm")}历史数据excel`
  503. );
  504. };
  505. </script>
  506. <style lang="scss" scoped>
  507. .datasearch {
  508. width: 100%;
  509. height: 100%;
  510. display: flex;
  511. justify-content: space-between;
  512. .el-card__body {
  513. height: calc(100% - 40px);
  514. }
  515. .cardleft {
  516. width: 18vw;
  517. .cardleft_top {
  518. display: flex;
  519. justify-content: space-between;
  520. margin-bottom: 5px;
  521. }
  522. .active {
  523. background: #afd5ff;
  524. }
  525. }
  526. .cardmid {
  527. width: 10vw;
  528. margin: 0 10px;
  529. .active {
  530. background: #afd5ff;
  531. }
  532. }
  533. .cardright {
  534. flex: 1;
  535. }
  536. }
  537. .pickerFifter {
  538. width: 80%;
  539. margin: 0 auto;
  540. display: flex;
  541. align-items: center;
  542. margin-bottom: 10px;
  543. }
  544. .scrollbar-demo-item {
  545. display: flex;
  546. align-items: center;
  547. justify-content: center;
  548. cursor: pointer;
  549. height: 30px;
  550. margin: 8px 0;
  551. text-align: center;
  552. border-radius: 4px;
  553. color: var(--el-color-primary);
  554. background: var(--el-color-primary-light-9);
  555. }
  556. </style>
  557. <style lang="scss">
  558. .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
  559. background-color: #bbdbff !important;
  560. }
  561. .deviceModelClass {
  562. .el-table__header tr,
  563. .el-table__header th {
  564. padding: 0;
  565. height: 40px;
  566. }
  567. .el-table__body tr,
  568. .el-table__body td {
  569. padding: 0;
  570. height: 40px;
  571. }
  572. }
  573. </style>