index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <!-- 页面 -->
  3. <div class="block">
  4. <br>
  5. <el-timeline>
  6. <h1>数据表单</h1>
  7. <el-table
  8. :data="tableData"
  9. height="250"
  10. border
  11. style="width: 97%">
  12. <el-table-column
  13. prop="billCode"
  14. label="单据号"
  15. width="90">
  16. </el-table-column>
  17. <el-table-column
  18. prop="measuringPointName"
  19. label="车牌号"
  20. width="110">
  21. </el-table-column>
  22. <el-table-column
  23. prop="temperature"
  24. label="温度"
  25. width="90">
  26. </el-table-column>
  27. <el-table-column
  28. prop="humidity"
  29. label="湿度"
  30. width="90">
  31. </el-table-column>
  32. <el-table-column
  33. prop="hisDate"
  34. label="时间点"
  35. width="180">
  36. </el-table-column>
  37. <el-table-column
  38. prop="gpsLongitude"
  39. label="经度"
  40. width="180">
  41. </el-table-column>
  42. <el-table-column
  43. prop="gpsLatitude"
  44. label="纬度"
  45. width="180">
  46. </el-table-column>
  47. <el-table-column
  48. prop="address"
  49. label="地址">
  50. </el-table-column>
  51. </el-table>
  52. </el-timeline>
  53. <el-timeline>
  54. <br><br><br>
  55. <h1>温湿度折线图</h1>
  56. <div class="echart" id="mychart" :style="myChartStyle"></div>
  57. <br><br><br>
  58. <h1>历史轨迹</h1>
  59. </el-timeline>
  60. <!-- <el-timeline>
  61. <input type="button" value="查询" @click="aaa" />
  62. </el-timeline> -->
  63. <div id="container"></div>
  64. <!-- <iframe :src = url width="100%" height="1000"> </iframe> -->
  65. </div>
  66. </template>
  67. <script>
  68. import AMapLoader from '@amap/amap-jsapi-loader'
  69. window._AMapSecurityConfig = {
  70. securityJsCode: '8e23904a0cf421675353f31fd1fc213c'
  71. }
  72. import historyApi from '@/api/WMS/historical-route'
  73. import * as echarts from "echarts";
  74. // import {queryAddress,} from '@/api/WMS/historical-route'
  75. export default {
  76. data() {
  77. return {
  78. //地图对象
  79. map: null,
  80. myChart: {},
  81. xData: [], //横坐标
  82. temperatureData: [], //温度数据
  83. humidityData: [], //湿度数据
  84. myChartStyle: { float: "left", width: "100%", height: "400px" }, //图表样式
  85. position: [],
  86. // url: '',
  87. tableData:[],
  88. resData:[],
  89. resX:[],
  90. resYTemperature:[],
  91. resYHumidity:[],
  92. carMessage:{
  93. billCode: "",
  94. plateNumber: "",
  95. startTime: "",
  96. endTime: ""
  97. }
  98. };
  99. },
  100. mounted() {
  101. //渲染图表
  102. this.initEcharts();
  103. //DOM初始化完成进行地图初始化
  104. this.initMap()
  105. },
  106. methods: {
  107. initMap() {
  108. AMapLoader.load({
  109. key: 'f953210b2d5276ffbf5a2bc01ef80f55', // 申请好的Web端开发者Key,首次调用 load 时必填
  110. version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  111. plugins: [''] // 需要使用的的插件列表,如比例尺'AMap.Scale'等
  112. })
  113. .then(AMap => {
  114. this.map = new AMap.Map('container', {
  115. //设置地图容器id
  116. viewMode: '3D', //是否为3D地图模式
  117. zoom: 13, //初始化地图级别
  118. center: [112.976376,28.195318] //初始化地图中心点位置
  119. })
  120. })
  121. .catch(e => {
  122. console.log(e)
  123. })
  124. },
  125. //渲染图表
  126. initEcharts() {
  127. const option = {
  128. xAxis: {
  129. data: this.xData
  130. },
  131. legend: { // 图例
  132. data: ["温度", "湿度/100"],
  133. bottom: "0%"
  134. },
  135. yAxis: {},
  136. series: [
  137. {
  138. name: "温度",
  139. data: this.temperatureData,
  140. type: "line", // 类型设置为折线图
  141. label: {
  142. show: true,
  143. position: "top",
  144. textStyle: {
  145. fontSize: 16
  146. }
  147. }
  148. },
  149. {
  150. name: "湿度/100",
  151. data: this.humidityData,
  152. type: "line", // 类型设置为折线图
  153. label: {
  154. show: true,
  155. position: "bottom",
  156. textStyle: {
  157. fontSize: 16
  158. }
  159. }
  160. }
  161. ]
  162. };
  163. this.myChart = echarts.init(document.getElementById("mychart"));
  164. this.myChart.setOption(option);
  165. //随着屏幕大小调节图表
  166. window.addEventListener("resize", () => {
  167. this.myChart.resize();
  168. });
  169. },
  170. //查询按钮
  171. handleQuery() {
  172. // window.location.href = ''
  173. this.handleGeocodeRepo(this.carMessage);
  174. },
  175. handleGeocodeRepo(data) {
  176. // let data = {
  177. // billCode: "CS01",
  178. // plateNumber: "湘A79D2R",
  179. // startTime: "2023-02-01",
  180. // endTime: "2023-02-02"
  181. // }
  182. console.log(data, 'data');
  183. historyApi.queryAddress(data).then(res => {
  184. console.log(res, 'res-----------------');
  185. // //X轴时间数据
  186. // this.xData = res.data.map(item => {return item.hisDate});
  187. // //温度数据转换
  188. // this.temperatureData = res.data.map(item => {return item.temperature});
  189. // //湿度数据转换
  190. // this.humidityData = res.data.map(item => {return item.humidity});
  191. let { code, data } = res;
  192. // let text;
  193. let count = 0;
  194. if (code == 200) {
  195. //定义经纬度不为0的数组[i]为起点
  196. for (let i = 0; i < data.length; i++) {
  197. if (data[i].gpsLatitude != 0 && data[i].gpsLongitude != 0) {
  198. //定义经纬度不为0的数组[j]为终点
  199. for (let j = data.length - 1; j > i; j--) {
  200. if (data[j].gpsLatitude != 0 && data[j].gpsLongitude != 0) {
  201. var map, route;
  202. //基本地图加载
  203. map = new AMap.Map("container", {
  204. resizeEnable: true
  205. });
  206. //绘制初始路径
  207. var path = [];
  208. path.push([data[i].gpsLongitude, data[i].gpsLatitude]);
  209. //起点数据
  210. this.resData[0] = res.data[i];
  211. this.resX[0] = res.data[i].hisDate;
  212. this.resYTemperature[0] = res.data[i].temperature;
  213. this.resYHumidity[0] = res.data[i].humidity / 100;
  214. //定义递增值
  215. let increment = Math.trunc((j - i) / 15);
  216. for (let z = i + increment; z < j; z = z + increment) {
  217. // for (let z = i; z < j; z++) {
  218. // console.log("i",i)
  219. // text += `&via[${count}][id][${z}]&via[${count}][lnglat]=${data[z].gpsLongitude},${data[z].gpsLatitude}` ;
  220. if(data[z].gpsLongitude != 0 && data[z].gpsLatitude != 0) {
  221. path.push([data[z].gpsLongitude, data[z].gpsLatitude]);
  222. this.resData[count + 1] = res.data[z];
  223. this.resX[count + 1] = res.data[z].hisDate;
  224. this.resYTemperature[count + 1] = res.data[z].temperature;
  225. this.resYHumidity[count + 1] = res.data[z].humidity / 100;
  226. count++;
  227. }
  228. }
  229. path.push([data[j].gpsLongitude, data[j].gpsLatitude]);
  230. //终点数据
  231. this.resData[count] = res.data[j];
  232. this.resX[count] = res.data[j].hisDate;
  233. this.resYTemperature[count] = res.data[j].temperature;
  234. this.resYHumidity[count] = res.data[j].humidity / 100;
  235. map.plugin("AMap.DragRoute", function() {
  236. route = new AMap.DragRoute(map, path, AMap.DrivingPolicy.LEAST_FEE); //构造拖拽导航类
  237. route.search(); //查询导航路径并开启拖拽导航
  238. });
  239. // this.position = data;
  240. // let url = `//uri.amap.com/navigation?from=${data[0].gpsLongitude},${data[0].gpsLatitude},startpoint&to=${data[data.length-1].gpsLongitude},${data[data.length-1].gpsLatitude},endpoint&via=${data[260].gpsLongitude},${data[260].gpsLatitude},midwaypoint&mode=car&policy=0&src=mypage&coordinate=gaode&callnative=0`
  241. // let url = `https://ditu.amap.com/dir?type=car&policy=1&from[lnglat]=${data[i].gpsLongitude},${data[i].gpsLatitude}&from[name]=startpoint&from[id]=${i}-from&to[lnglat]=${data[j].gpsLongitude},${data[j].gpsLatitude}&to[name]=endpoint&to[id]=${i}-to${text}&src=mypage&callnative=0&platform=pc&innersrc=uriapi`
  242. // console.log(url, 'url---------------------');
  243. // this.url = url;
  244. this.xData = res.data.temperature;
  245. this.tableData = this.resData;
  246. // window.location.href = url;
  247. // window.open(url, "newWindow", "width=1000,height=1000");
  248. // window.location.reload();
  249. this.xData = this.resX;
  250. this.temperatureData = this.resYTemperature;
  251. this.humidityData = this.resYHumidity;
  252. // console.log('this.xData',this.xData);
  253. // console.log('this.temperatureData',this.temperatureData);
  254. // console.log('this.humidityData',this.humidityData);
  255. this.initEcharts();
  256. // console.log(text,'text')
  257. return;
  258. }
  259. }
  260. }
  261. }
  262. }
  263. })
  264. // queryAddress({})
  265. }
  266. },
  267. created() {
  268. console.log(this.$route.query,'this.$route')
  269. this.carMessage = this.$route.query;
  270. this.handleQuery();
  271. }
  272. };
  273. </script>
  274. <style scoped>
  275. #container {
  276. padding: 100px;
  277. margin: 10px;
  278. width: 1000;
  279. height: 800px;
  280. }
  281. </style>