zhangyun пре 3 година
родитељ
комит
ab8cf6569d

+ 23 - 0
my_app1/.gitignore

@@ -0,0 +1,23 @@
+.DS_Store
+node_modules
+/dist
+
+
+# local env files
+.env.local
+.env.*.local
+
+# Log files
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+
+# Editor directories and files
+.idea
+.vscode
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?

+ 24 - 0
my_app1/README.md

@@ -0,0 +1,24 @@
+# my_app
+
+## Project setup
+```
+npm install
+```
+
+### Compiles and hot-reloads for development
+```
+npm run serve
+```
+
+### Compiles and minifies for production
+```
+npm run build
+```
+
+### Lints and fixes files
+```
+npm run lint
+```
+
+### Customize configuration
+See [Configuration Reference](https://cli.vuejs.org/config/).

+ 5 - 0
my_app1/babel.config.js

@@ -0,0 +1,5 @@
+module.exports = {
+  presets: [
+    '@vue/cli-plugin-babel/preset'
+  ]
+}

+ 19 - 0
my_app1/jsconfig.json

@@ -0,0 +1,19 @@
+{
+  "compilerOptions": {
+    "target": "es5",
+    "module": "esnext",
+    "baseUrl": "./",
+    "moduleResolution": "node",
+    "paths": {
+      "@/*": [
+        "src/*"
+      ]
+    },
+    "lib": [
+      "esnext",
+      "dom",
+      "dom.iterable",
+      "scripthost"
+    ]
+  }
+}

Разлика између датотеке није приказан због своје велике величине
+ 20066 - 0
my_app1/package-lock.json


+ 49 - 0
my_app1/package.json

@@ -0,0 +1,49 @@
+{
+  "name": "my_app",
+  "version": "0.1.0",
+  "private": true,
+  "scripts": {
+    "serve": "vue-cli-service serve",
+    "build": "vue-cli-service build",
+    "lint": "vue-cli-service lint"
+  },
+  "dependencies": {
+    "axios": "^0.26.1",
+    "core-js": "^3.8.3",
+    "echarts": "^5.3.1",
+    "element-ui": "^2.15.6",
+    "highcharts": "^10.0.0",
+    "vue": "^2.6.14"
+  },
+  "devDependencies": {
+    "@babel/core": "^7.12.16",
+    "@babel/eslint-parser": "^7.12.16",
+    "@vue/cli-plugin-babel": "~5.0.0",
+    "@vue/cli-plugin-eslint": "~5.0.0",
+    "@vue/cli-service": "~5.0.0",
+    "eslint": "^7.32.0",
+    "eslint-plugin-vue": "^8.0.3",
+    "sass": "^1.26.5",
+    "sass-loader": "^8.0.2",
+    "vue-template-compiler": "^2.6.14"
+  },
+  "eslintConfig": {
+    "root": true,
+    "env": {
+      "node": true
+    },
+    "extends": [
+      "plugin:vue/essential",
+      "eslint:recommended"
+    ],
+    "parserOptions": {
+      "parser": "@babel/eslint-parser"
+    },
+    "rules": {}
+  },
+  "browserslist": [
+    "> 1%",
+    "last 2 versions",
+    "not dead"
+  ]
+}

+ 1 - 0
my_app1/public/css/index.css

@@ -0,0 +1 @@
+

BIN
my_app1/public/favicon.ico


+ 17 - 0
my_app1/public/index.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="">
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width,initial-scale=1.0">
+    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
+    <title><%= htmlWebpackPlugin.options.title %></title>
+  </head>
+  <body>
+    <noscript>
+      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
+    </noscript>
+    <div id="app"></div>
+    <!-- built files will be auto injected -->
+  </body>
+</html>

+ 615 - 0
my_app1/src/App.vue

@@ -0,0 +1,615 @@
+<template>
+  <div id="app">
+    <!-- 导航栏部分 -->
+    <div class="nav">
+      <div class="div-watch">
+        <span class="watch">环境监测设备页面</span>
+      </div>
+
+      <!-- <div class="div-tabs">
+        <el-tabs v-model="activeName" class="tabs">
+          <el-tab-pane label="图表" name="chart"></el-tab-pane>
+        </el-tabs>
+      </div> -->
+
+      <div class="btn right">
+        <el-button>日期</el-button>
+        <el-button size="mini" :class="{ active: change == 1 }" @click="btn(1)"
+          >近一天</el-button
+        >
+        <el-button size="mini" :class="{ active: change == 2 }" @click="btn(2)"
+          >近七天</el-button
+        >
+        <el-button size="mini" :class="{ active: change == 3 }" @click="btn(3)"
+          >近一月</el-button
+        >
+        <el-button size="mini" :class="{ active: change == 4 }" @click="btn(4)"
+          >近三月</el-button
+        >
+      </div>
+
+      <div class="div-picker">
+        <el-date-picker
+          size="mini"
+          class="picker"
+          v-model="value1"
+          type="daterange"
+          range-separator="至"
+          start-placeholder="开始日期"
+          end-placeholder="结束日期"
+          value-format="timestamp"
+          @change="DateChange"
+        >
+        </el-date-picker>
+      </div>
+    </div>
+
+    <!-- 设备信息 -->
+
+    <div class="deviceInfo">
+      <el-card>
+        <div class="info">
+          <span>设备编号:{{ device_id }}</span>
+          <div class="lines"></div>
+          <span class="test">测试名称:{{ device_name }}</span>
+          <div class="lines"></div>
+          <span>安装位置:{{ device_addr }}</span>
+        </div>
+      </el-card>
+    </div>
+
+    <!-- 折线图 -->
+    <!-- style="width: 24.5%; height: 25rem" -->
+    <div class="container">
+      <el-row :gutter="10" style="width: 100%;">
+        <el-col
+          v-for="(item, index) in list"
+          :key="index"
+          :sm="12"
+          :md="8"
+          :lg="6"
+        >
+          <el-card class="main" style="width: 100%; height: 25rem">
+            <!-- <div></div> -->
+          </el-card>
+        </el-col>
+      </el-row>
+    </div>
+  </div>
+</template>
+
+<script>
+import { getChartData } from "./api/getData";
+export default {
+  name: "App",
+  data() {
+    return {
+      // activeName: "chart", //el-tags的
+      value1: "", //日期选择器
+      change: 1, //el-button的类
+      device_id: "", //设备id
+      device_name: "", //设备名字
+
+      device_addr: "", //设备地址
+      list: [], //折线图div里面的v-for
+      legends: [], //折线图下边的小图标
+      xData: [], //折线图x轴的数据
+      // arr: [], //存放转换后时间的数组\
+      titles: [], //图表的标题
+    };
+  },
+
+  mounted() {
+    let id = window.location.href; //获取url地址的设备id
+    id = id.split("=")[1];
+
+    let endTime = Date.parse(new Date()) / 1000;
+    let startTime = endTime - 86400;
+
+    this.device_id = id;
+    this.getData(this.device_id, startTime, endTime);
+  },
+
+  methods: {
+    // 日期选择器方法
+    DateChange() {
+      this.change = "";
+      var sTime = this.value1[0] / 1000;
+      var eTime = this.value1[1] / 1000;
+      this.getData(this.device_id, sTime, eTime);
+    },
+
+    // 近几天按钮的方法
+    btn(a) {
+      this.change = a;
+      let time = Date.now() / 1000;
+      // console.log(time); //1648178403467   1647847799
+      if (a == 1) {
+        //近一天
+        this.getData(
+          this.device_id,
+          Math.floor(time - 86400),
+          Math.floor(time)
+        );
+      }
+      if (a == 2) {
+        //近七天
+        this.getData(
+          this.device_id,
+          Math.floor(time - 86400 * 7),
+          Math.floor(time)
+        );
+      }
+
+      if (a == 3) {
+        //近一月
+        this.getData(
+          this.device_id,
+          Math.floor(time - 86400 * 30),
+          Math.floor(time)
+        );
+      }
+
+      if (a == 4) {
+        //近三月
+        this.getData(
+          this.device_id,
+          Math.floor(time - 86400 * 90),
+          Math.floor(time)
+        );
+      }
+    },
+
+    // 格式化时间yy-mm-dd  hh:mm:ss
+    formatTime(value) {
+      if (value) {
+        let date = new Date(value * 1000); // 时间戳为秒:10位数
+        //let date = new Date(value)	// 时间戳为毫秒:13位数
+        let year = date.getFullYear();
+        let month =
+          date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}`: date.getMonth() + 1;
+        let day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
+        let hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
+        let minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
+        let second = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds();
+        return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
+      } else {
+        return "";
+      }
+    },
+
+    myEcharts(list) {
+      // 基于准备好的dom,初始化echarts实例
+      var lists = document.getElementsByClassName("main");
+
+      setTimeout(() => {
+        var arr = [];
+        var arr2 = []; //存放时间戳
+        var arr3 = []; //存放格式化时间
+
+        for (var i = 0; i < lists.length; i++) {
+          // console.log(list[i]);
+          arr = [];
+          arr2 = [];
+          arr3 = [];
+
+          for (var j = 0; j < list[i].length; j++) {
+            
+            arr.push(list[i][j].data[0]);
+            arr2.push(list[i][j].data[1]);
+          }
+
+          for (let a = 0; a < list[i].length; a++) {
+            var obj1 = {};
+            var time = new Date(arr2[a] * 1000);
+            var date = time.getDate();
+            var month = time.getMonth() + 1;
+            var hours = time.getHours();
+            var min = time.getMinutes();
+            if ((hours >= 22 && hours < 24) || (hours >= 0 && hours < 2)) {
+              obj1 = [month + "/" + date];
+            } else {
+              obj1 = [hours + ":" + min];
+              obj1 = [(hours < 10 ? `0${hours}` : hours) + ":" + (min < 10 ? `0${min}` : min),];
+            }
+            arr3.push(obj1);
+          }
+
+          // console.log(arr3);
+
+          var myChart = this.$echarts.init(lists[i]);
+          // myChart = this.$echarts.init(lists[i]);
+
+          // console.log(arr3);
+          // 指定图表的配置项和数据
+
+          myChart.setOption({
+            title: {
+              text: this.titles[i].split("#")[0],
+              padding: [20, 20, 100, 30],
+              textStyle: {
+                fontWeight: "normal",
+              },
+            },
+            grid:{
+              left:"15%"
+            },
+            tooltip: {
+              trigger: "axis",
+              formatter: (params) => {
+                var str = `<div>
+                        ${this.formatTime(arr2[params[0].dataIndex])} <br/>
+                        ${this.titles[Number(params[0].seriesName.slice(1)) - 1].split("#")[0]}:${params[0].value} 
+                        ${this.titles[Number(params[0].seriesName.slice(1)) - 1].split("#")[1]}
+                        </div>`;
+                return str;
+              },
+            },
+            color: "#00DE94",
+            legend: {
+              orient: "vertical",
+              x: "center",
+              y: "bottom",
+            },
+            xAxis: {
+              type: "category",
+              boundaryGap: false,
+              data: arr3,
+            },
+            yAxis: {
+              type: "value",
+            },
+            series: [
+              {
+                lineStyle: {
+                  color: "#00DE94",
+                },
+                symbol: "none",
+                name: this.legends[i],
+                type: "line",
+                data: arr,
+              },
+            ],
+            // 暂无数据的设置
+            graphic: {
+              type: "text", // 类型:文本
+              left: "center",
+              top: "middle",
+              silent: true, // 不响应事件
+              invisible: arr.length > 0, // 有数据就隐藏
+              style: {
+                fill: "#9d9d9d",
+                fontWeight: "bold",
+                text: "暂无数据",
+                fontFamily: "Microsoft YaHei",
+                fontSize: "25px",
+              },
+            },
+          });
+        }
+        // console.log(arr);
+        // console.log(arr2);
+      }, 1000);
+    },
+
+    getData(device_id, start_time, end_time) {
+      getChartData(device_id, start_time, end_time).then((response) => {
+        // console.log(response);
+        if (response.status === 200) {
+          // 设备信息
+          this.device_id = response.data.data_info.device_id;
+          this.device_name = response.data.data_info.device_name;
+          this.device_addr = response.data.data_info.device_addr;
+
+          // 将对象转换为数组
+          var keys = Object.keys(response.data.conf); //图表的legends
+          // console.log(keys);
+          this.legends = keys;
+
+          // console.log(response.data.conf);
+          var title = Object.values(response.data.conf); //图表的标题
+
+          title = title.filter((str) => {
+            return !!str;
+          });
+          // console.log(title);
+          this.titles = title;
+          // console.log(this.titles);
+
+          var num = 0;
+          for (var key in response.data.conf) {
+            //遍历对象
+            if (response.data.conf[key]) {
+              num++;
+            }
+          }
+          this.list = num;
+
+          // console.log(num)
+          // console.log(response.data.data);
+          var list = [];
+          var obj = {};
+          for (var i = 0; i < num; i++) {
+            var arr = [];
+            for (var k = 0; k < response.data.data.length; k++) {
+              obj = {};
+              // console.log(response.data.data[k],i)
+              var str = response.data.data[k].dat["e" + (i + 1)].split("#")[0];
+              if (str == -99.99) {
+                // console.log(str);
+              } else {
+                obj["data"] = [Number(str), response.data.data[k].time];
+                arr.push(obj);
+              }
+            }
+            list.push(arr);
+
+            // list.reverse()
+          }
+          // console.log(list);
+          // console.log(list[0]);
+          for (let i = 0; i < list.length; i++) {
+            // console.log(list[i]);
+            list[i].reverse();
+          }
+
+          this.myEcharts(list);
+        }
+      });
+    },
+  },
+};
+</script>
+<style>
+/* pc页面样式 */
+@media screen and (min-width: 992px) {
+  body {
+    width: 100%;
+    background-color: #f6f6f6;
+  }
+  * {
+    margin: 0;
+    padding: 0;
+  }
+
+  /* 下划线 */
+  .lines {
+    display: none;
+  }
+
+  #app {
+    width: 95vw;
+    height: 100vh;
+    margin: 0 auto;
+  }
+
+  .nav {
+    width: 95vw;
+    margin: 0 auto;
+    display: flex;
+    flex-direction: row;
+    height: 50px;
+  }
+
+  .div-watch {
+    width: 20vw;
+  }
+
+  .watch {
+    margin-left: 5px;
+    line-height: 50px;
+
+    letter-spacing: 0.1rem;
+  }
+
+  /* .div-tabs {
+    width: 7vw;
+  } */
+
+  /* .tabs {
+    margin-left: 50px;
+    margin-top: 5px;
+  } */
+
+  .btn {
+    width: 40vw;
+
+    text-align: right;
+    line-height: 50px;
+  }
+
+  .right {
+    margin-left: auto;
+  }
+
+  .div-picker {
+    width: 19vw;
+  }
+
+  .picker {
+    padding: 0 !important;
+
+    margin: 12px 10px;
+    margin-right: 0;
+  }
+
+  .active {
+    background-color: #15a478 !important;
+    color: white !important;
+  }
+
+  /* 切换活动项的文字颜色 */
+  .el-tabs__item.is-active {
+    color: #000000 !important;
+  }
+
+  /* 切换活动项的长条颜色 */
+  .el-tabs__active-bar {
+    background-color: #15a478;
+  }
+
+  /*去掉tabs底部的下划线*/
+  .el-tabs__nav-wrap::after {
+    position: static !important;
+  }
+
+  .deviceInfo {
+    width: 95vw;
+    margin: 10px auto;
+  }
+
+  .el-card {
+    color: grey !important;
+  }
+
+  .el-card__body {
+    padding: 10px !important;
+  }
+
+  .test {
+    margin: 0 70px;
+  }
+
+  .container {
+    width: 95vw;
+    margin-top: -9px;
+    display: flex;
+    flex-wrap: wrap;
+    
+
+   
+  }
+  .main {
+    margin-top: 8px;
+    /* border: 1px solid red; */
+    border-radius: 10px;
+    /* margin-right: 11px; */
+    
+  }
+
+  .btn .el-button:nth-of-type(1) {
+    display: none;
+  }
+
+  /* 时间选择器的小图标 */
+  .el-icon-date:before {
+    margin-left: 10px;
+  }
+
+  /* 时间选择器的 "至" */
+  .el-range-editor--mini .el-range-separator {
+    line-height: 26px;
+  }
+}
+
+/* 手机页面样式 */
+@media screen and (min-width: 320px) and (max-width: 992px) {
+  * {
+    margin: 0;
+    padding: 0;
+  }
+
+  body {
+    width: 100%;
+    background-color: #f6f6f6;
+  }
+
+  #app {
+    width: 100vw;
+  }
+
+  .div-watch {
+    color: white;
+    width: 100vw;
+    height: 3rem;
+    background-color: #3eb983;
+    font-size: 20px;
+    line-height: 3rem;
+    text-align: center;
+  }
+
+ 
+
+  .btn {
+    /* border: 1px solid red; */
+    width: 100%;
+    display: flex;
+    flex-direction: row;
+    margin-left: 1rem;
+    background-color: #ffffff;
+    margin: 5px;
+    margin-left: -1px;
+  }
+
+  .btn .el-button {
+    /* margin: 10px; */
+    margin: 10px 0;
+    border-radius: 5px;
+    margin-left: 5px;
+  }
+  .btn .el-button:nth-of-type(1) {
+    border: 0px;
+    margin: 0;
+    padding: 0;
+    color: #6a6a6a;
+    background-color: #ffffff;
+    margin-left: 30px;
+  }
+
+  .div-picker {
+    display: none;
+  }
+  .deviceInfo {
+    width: 100%;
+  }
+
+  .el-card__body {
+    padding: 0;
+  }
+
+  .info {
+    display: flex;
+    flex-direction: column;
+    width: 100%;
+    color: gray;
+    margin-left: 20px;
+  }
+
+  .info span {
+    padding: 0.5rem;
+  }
+
+  .info span:nth-of-type(1) {
+    margin-top: 3px;
+  }
+
+  .info span:nth-of-type(3) {
+    margin-bottom: 3px;
+  }
+
+  .container {
+    width: 100%;
+    margin-top: 10px;
+  }
+
+  .main {
+    margin-bottom: 10px;
+
+    width: 100% !important;
+  }
+
+  .el-card {
+    border-radius: 0px;
+  }
+
+  .active {
+    background-color: #15a478 !important;
+    color: white !important;
+  }
+
+  .lines {
+    border-bottom: 1px solid gainsboro;
+    margin-left: 5px;
+  }
+}
+</style>

+ 4 - 0
my_app1/src/api/getData.js

@@ -0,0 +1,4 @@
+import ajax from './index'
+
+
+export const getChartData = (device_id,start_time,end_time) => ajax(`/api/qxz_data_chart?device_id=${device_id}&start_time=${start_time}&end_time=${end_time}`);

+ 49 - 0
my_app1/src/api/index.js

@@ -0,0 +1,49 @@
+// 对axios进行二次封装
+import axios from "axios"; // 引入axios模块
+
+
+
+// 配置ajax请求超时时间
+axios.defaults.timeout = 10000;
+
+
+// post的请求头
+axios.defaults.headers.post["Content-Type"] =
+  "application/x-www-form-urlencoded;charset=UTF-8";
+
+
+
+
+// 我们可以定义一个方法,ajax,当我们发送请求的时候,需要调用这个ajax
+// 发送ajax请求,其实就是调用ajax方法,返回promise
+export default function ajax(url = "", params = {}, type = "GET") {
+  let promise;
+  return new Promise((resolve, reject) => {
+    if (type.toUpperCase() === "GET") {
+      
+      promise = axios({
+        url,
+        params,
+      });
+    } else if (type.toUpperCase() === "POST") {
+      promise = axios({
+        method: "post",
+        url,
+        data: params,
+      });
+    }
+
+    promise
+      .then((response) => {
+        // 成功的时候
+        resolve(response);
+      })
+      .catch((error) => {
+        // 失败的时候
+        reject(error);
+      });
+  });
+}
+
+
+

BIN
my_app1/src/assets/logo.png


+ 21 - 0
my_app1/src/main.js

@@ -0,0 +1,21 @@
+import Vue from 'vue'
+
+import ElementUI from 'element-ui';
+import 'element-ui/lib/theme-chalk/index.css';
+
+import * as echarts from 'echarts';
+
+
+
+import App from './App.vue'
+
+Vue.use(ElementUI);
+
+
+Vue.config.productionTip = false
+Vue.prototype.$echarts = echarts //讲echaits注册成vue的全局属性
+
+new Vue({
+  render: h => h(App),
+}).$mount('#app')
+

+ 25 - 0
my_app1/vue.config.js

@@ -0,0 +1,25 @@
+// const { defineConfig } = require('@vue/cli-service')
+// module.exports = defineConfig({
+//   transpileDependencies: true,
+//   lintOnSave:false,//关闭代码检查
+ 
+  
+// })
+
+module.exports = {
+  lintOnSave:false, //关闭代码检查
+  devServer:{
+      host:"192.168.0.110",
+      // host:"192.168.0.195",
+      port:"8080",
+      proxy:{
+          '/api':{
+              target:'http://8.136.98.49:8002/',
+              
+          }
+         
+      }
+  }
+}
+
+