Newer
Older
KaiFengPC / src / views / dataAnalysis / syntheticData / stationDialog.vue
@zhangdeliang zhangdeliang on 23 May 8 KB 初始化项目
  1. <template>
  2. <!-- 站点对比分析-选择 -->
  3. <div class="stationDialogPage">
  4. <div class="searchBox">
  5. <el-date-picker
  6. v-model="dateRange"
  7. value-format="YYYY-MM-DD"
  8. type="daterange"
  9. range-separator="-"
  10. start-placeholder="开始日期"
  11. end-placeholder="结束日期"
  12. @change="constrastData"
  13. >
  14. </el-date-picker>
  15. <el-button type="warning" @click="exportData">
  16. <el-icon><Download /></el-icon> 导出
  17. </el-button>
  18. <el-button type="primary" @click="clearData">
  19. <el-icon><DeleteFilled /></el-icon> 清除全部
  20. </el-button>
  21. </div>
  22. <div class="stationDialog">
  23. <div class="stationLeft">
  24. <el-input v-model="filterText" class="searchInput" placeholder="请输入名称" clearable />
  25. <el-tree
  26. ref="treeRef"
  27. :data="stationList"
  28. show-checkbox
  29. node-key="id"
  30. default-expand-all
  31. :default-checked-keys="defaultCheckedKeys"
  32. :props="{ label: 'name', children: 'children' }"
  33. @check="checkNode"
  34. v-loading="treeLoading"
  35. :filter-node-method="filterNode"
  36. />
  37. </div>
  38. <div class="stationRight">
  39. <!-- 具体echarts分析 -->
  40. <div id="stationEchartDB" v-if="chartOptionYs.xAxis.data.length > 0" v-loading="echartLoading"></div>
  41. <!-- 暂无数据 -->
  42. <el-empty
  43. v-loading="echartLoading"
  44. :image-size="200"
  45. v-if="chartOptionYs.xAxis.data.length == 0"
  46. style="flex: 1; margin-top: 200px"
  47. />
  48. </div>
  49. </div>
  50. </div>
  51. </template>
  52. <script setup>
  53. import { monitorPropertyList, monitorPropertyGraphicCompare } from '@/api/dataAnalysis/syntherticData';
  54. import chartOptionYs from './chartYs';
  55. import bus from '@/utils/mitt';
  56.  
  57. const props = defineProps({
  58. stationDBInfo: Object,
  59. });
  60. const { proxy } = getCurrentInstance();
  61. const myChart = shallowRef(null);
  62. const dateRange = ref([proxy.moment().subtract(7, 'days').format('YYYY-MM-DD'), proxy.moment().format('YYYY-MM-DD')]);
  63. const stationList = ref([]);
  64. const defaultCheckedKeys = ref([]);
  65. const treeLoading = ref(true);
  66. const monitorCode = ref([]);
  67. const echartLoading = ref(false);
  68. const filterText = ref('');
  69.  
  70. const propsColor = proxy.fixDict['propsColorYs']; // 根据因子的单位来匹配
  71.  
  72. // 选择树节点
  73. function checkNode(data, checkedData) {
  74. monitorCode.value = [];
  75. monitorCode.value = checkedData.checkedNodes; //选择的id值
  76. constrastData();
  77. }
  78. // 对树节点进行筛选时执行的方法
  79. function filterNode(value, data, node) {
  80. let parentNode = node.parent; // 父级node
  81. let labels = [node.label]; // 当前node的名字
  82. let level = 1; // 层级
  83. while (level < node.level) {
  84. labels = [...labels, parentNode.label]; // 当前node名字,父级node的名字
  85. parentNode = parentNode.parent;
  86. level++;
  87. }
  88. return labels.some(d => d.indexOf(value) !== -1);
  89. }
  90. /** 根据名称筛选站点 */
  91. watch(filterText, val => {
  92. // console.log(val, proxy.$refs['treeRef'].filter(val));
  93. proxy.$refs['treeRef'].filter(val);
  94. });
  95. // 清除所有选中的
  96. function clearData() {
  97. monitorCode.value = [];
  98. proxy.$refs['treeRef'].setCheckedKeys([]);
  99. constrastData();
  100. }
  101.  
  102. // echarts
  103. function intChart() {
  104. if (!!myChart.value) {
  105. myChart.value.dispose();
  106. }
  107. myChart.value = proxy.echarts.init(document.getElementById('stationEchartDB'));
  108. // 绘制图表
  109. myChart.value.clear();
  110. myChart.value.setOption(chartOptionYs);
  111. }
  112. // 获取监测项
  113. function getPropertyList() {
  114. treeLoading.value = true;
  115. monitorPropertyList().then(res => {
  116. stationList.value = res.data.filter(item => item.children.length > 0);
  117. defaultCheckedKeys.value.push(stationList.value[0].children[0].children[0].id); //默认选中第一个
  118. monitorCode.value.push(stationList.value[0].children[0].children[0]);
  119. constrastData();
  120. treeLoading.value = false;
  121. });
  122. }
  123.  
  124. // 导出数据
  125. async function exportData() {
  126. let monitorArr = [];
  127. monitorCode.value.map(item => {
  128. monitorArr.push({
  129. monitorCode: item.code,
  130. stCode: item.assistField1,
  131. });
  132. });
  133. let params = {
  134. startTime: dateRange.value ? dateRange.value[0] + ' 00:00:00' : '',
  135. endTime: dateRange.value ? dateRange.value[1] + ' 23:59:59' : '',
  136. itemListString: JSON.stringify(monitorArr),
  137. };
  138. proxy.download(
  139. 'business/siteHistoryMonitor/monitorPropertyGraphicCompareExport',
  140. {
  141. ...params,
  142. },
  143. `对比分析_${new Date().getTime()}.xlsx`
  144. );
  145. }
  146.  
  147. // 对比分析搜索
  148. function constrastData() {
  149. chartOptionYs.series = [];
  150. chartOptionYs.legend.data = [];
  151. chartOptionYs.xAxis.data = [];
  152. chartOptionYs.yAxis = [];
  153. chartOptionYs.color = [];
  154. echartLoading.value = true;
  155. let monitorArr = [];
  156. monitorCode.value.map(item => {
  157. monitorArr.push({
  158. monitorCode: item.code,
  159. stCode: item.assistField1,
  160. });
  161. });
  162. let params = {
  163. startTime: dateRange.value ? dateRange.value[0] + ' 00:00:00' : '',
  164. endTime: dateRange.value ? dateRange.value[1] + ' 23:59:59' : '',
  165. itemList: monitorArr,
  166. };
  167. monitorPropertyGraphicCompare(params).then(res => {
  168. let datas = res.data;
  169. if (JSON.stringify(datas) == '{}' || datas.propertyMonitorXList.length == 0) {
  170. chartOptionYs.xAxis.data = [];
  171. echartLoading.value = false;
  172. return false;
  173. } else {
  174. chartOptionYs.xAxis.data = datas.propertyMonitorXList;
  175. datas.propertyMonitorList.map(item => {
  176. setEchartY(item); //设置多y轴
  177. // console.log(chartOptionYs.yAxis, '--', chartOptionYs.color);
  178. chartOptionYs.series.push({
  179. name: item.stName + '--' + item.monitorPropertyName + item.propertyUnit,
  180. type: 'line',
  181. lineStyle: { color: chartOptionYs.color[chartOptionYs.yAxis.length - 1] },
  182. smooth: true,
  183. data: item.ylist,
  184. yAxisIndex: chartOptionYs.yAxis.length - 1,
  185. });
  186. chartOptionYs.legend.data.push(item.stName + '--' + item.monitorPropertyName + item.propertyUnit);
  187. });
  188. chartOptionYs.grid.left = 50 * (chartOptionYs.yAxis.length - 1); //left值设置
  189. setTimeout(() => {
  190. intChart();
  191. });
  192. echartLoading.value = false;
  193. }
  194. });
  195. }
  196. // 设置多y轴
  197. function setEchartY(row) {
  198. propsColor.map((item, index) => {
  199. if (row.propertyUnit == item.label) {
  200. chartOptionYs.color.push(item.color);
  201. chartOptionYs.yAxis.push({
  202. name: item.value, //value是英文单位,label是中文单位
  203. position: 'left',
  204. offset: 50 * chartOptionYs.yAxis.length,
  205. axisLine: { show: true, lineStyle: { color: item.color } },
  206. axisTick: { show: true },
  207. splitLine: {
  208. show: true, // 显示网格线
  209. lineStyle: { type: 'dashed' },
  210. },
  211. });
  212. }
  213. });
  214. chartOptionYs.color = [...new Set(chartOptionYs.color)]; //颜色和值对应
  215. chartOptionYs.yAxis = unique(chartOptionYs.yAxis); //去重
  216. }
  217. // 数组内对象去重
  218. function unique(arr) {
  219. let allArr = [];
  220. for (let i = 0; i < arr.length; i++) {
  221. let flag = true;
  222. for (let j = 0; j < allArr.length; j++) {
  223. if (arr[i].name == allArr[j].name) {
  224. flag = false;
  225. }
  226. }
  227. if (flag) {
  228. allArr.push(arr[i]);
  229. }
  230. }
  231. return allArr;
  232. }
  233.  
  234. //自适应
  235. function resizeTheChart() {
  236. if (myChart.value) {
  237. myChart.value.resize();
  238. }
  239. }
  240.  
  241. // 初始化
  242. onMounted(() => {
  243. getPropertyList(); //获取监测项
  244. window.addEventListener('resize', resizeTheChart);
  245. bus.on('toggleSideBarClick', e => {
  246. // console.log(e, document.querySelector('.stationRight').clientWidth);
  247. // myChart.value.resize({ width: width });
  248. });
  249. });
  250. onUnmounted(() => {
  251. window.removeEventListener('resize', resizeTheChart);
  252. bus.off('toggleSideBarClick');
  253. });
  254. </script>
  255. <style lang="scss">
  256. .stationDialogPage {
  257. padding-bottom: 10px;
  258. .searchBox {
  259. margin-bottom: 10px;
  260. .el-button {
  261. margin-left: 10px;
  262. margin-top: -5px;
  263. }
  264. }
  265. .stationDialog {
  266. width: 100%;
  267. margin-bottom: 30px;
  268. display: flex;
  269. .stationLeft {
  270. width: 400px;
  271. height: 600px;
  272. padding: 15px;
  273. .searchInput {
  274. margin-bottom: 10px;
  275. }
  276. .el-tree {
  277. height: calc(100vh - 200px) !important;
  278. overflow: auto;
  279. }
  280. .el-tree-node__expand-icon.is-leaf {
  281. visibility: hidden;
  282. }
  283. }
  284. .stationRight {
  285. width: 100%;
  286. flex: 1;
  287. margin-left: 10px;
  288. #stationEchartDB {
  289. height: 600px;
  290. width: 100%;
  291. }
  292. }
  293. }
  294. }
  295. </style>