devicePosition.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <div id="devicePosition" style="height: 100%">
  3. <el-container style="height: 100%">
  4. <el-header>
  5. <uiHeader></uiHeader>
  6. </el-header>
  7. <el-main>
  8. <div style="background-color: #ffffff; position: relative; padding: 1rem 0.5rem 0.5rem 0.5rem; text-align: center;">
  9. <span style="font-size: 1rem; font-weight: 500">设备定位 ({{ parentChannelId == 0 ? deviceId : parentChannelId }})</span>
  10. </div>
  11. <div style="background-color: #ffffff; margin-bottom: 1rem; position: relative; padding: 0.5rem; text-align: left; font-size: 14px;">
  12. <el-button icon="el-icon-arrow-left" size="mini" style="margin-right: 1rem" type="primary" @click="showDevice">返回</el-button>
  13. <!-- <span class="demonstration">从</span> -->
  14. <el-date-picker v-model="searchFrom" type="datetime" placeholder="选择开始日期时间" default-time="00:00:00" size="mini" style="width: 11rem;" align="right" :picker-options="pickerOptions"></el-date-picker>
  15. <el-date-picker v-model="searchTo" type="datetime" placeholder="选择结束日期时间" default-time="00:00:00" size="mini" style="width: 11rem;" align="right" :picker-options="pickerOptions"></el-date-picker>
  16. <el-button-group>
  17. <el-button icon="el-icon-search" size="mini" type="primary" @click="showHistoryPath">历史轨迹</el-button>
  18. <el-button icon="el-icon-search" size="mini" style="margin-right: 1rem" type="primary" @click="showLatestPosition">最新位置</el-button>
  19. </el-button-group>
  20. <el-tag style="width: 5rem; text-align: center" size="medium">过期时间</el-tag>
  21. <el-input-number size="mini" v-model="expired" :min="300" :controls="false" style="width: 4rem;"></el-input-number>
  22. <el-tag style="width: 5rem; text-align: center" size="medium">上报周期</el-tag>
  23. <el-input-number size="mini" v-model="interval" :min="1" :controls="false" style="width: 4rem;"></el-input-number>
  24. <el-button-group>
  25. <el-button icon="el-icon-search" size="mini" type="primary" @click="subscribeMobilePosition">位置订阅</el-button>
  26. <el-button icon="el-icon-search" size="mini" type="primary" @click="unSubscribeMobilePosition">取消订阅</el-button>
  27. </el-button-group>
  28. <el-checkbox size="mini" style="margin-right: 1rem; float: right" v-model="autoList" @change="autoListChange" >自动刷新</el-checkbox>
  29. </div>
  30. <div class="mapContainer" style="background-color: #ffffff; position: relative; padding: 1rem 0.5rem 0.5rem 0.5rem; text-align: center; height: calc(100% - 10rem);">
  31. <div class="baidumap" id="allmap"></div>
  32. </div>
  33. </el-main>
  34. </el-container>
  35. </div>
  36. </template>
  37. <script>
  38. import uiHeader from "./UiHeader.vue";
  39. import moment from "moment";
  40. import geoTools from "./GeoConvertTools.js";
  41. export default {
  42. name: "devicePosition",
  43. components: {
  44. uiHeader,
  45. },
  46. data() {
  47. return {
  48. pickerOptions: {
  49. shortcuts: [{
  50. text: '今天',
  51. onClick(picker) {
  52. picker.$emit('pick', new Date());
  53. }
  54. }, {
  55. text: '昨天',
  56. onClick(picker) {
  57. const date = new Date();
  58. date.setTime(date.getTime() - 3600 * 1000 * 24);
  59. picker.$emit('pick', date);
  60. }
  61. }, {
  62. text: '一周前',
  63. onClick(picker) {
  64. const date = new Date();
  65. date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
  66. picker.$emit('pick', date);
  67. }
  68. }]
  69. },
  70. deviceId: this.$route.params.deviceId,
  71. showHistoryPosition: false, //显示历史轨迹
  72. startTime: null,
  73. endTime: null,
  74. searchFrom: null,
  75. searchTo: null,
  76. expired: 600,
  77. interval: 5,
  78. mobilePositionList: [],
  79. mapPointList: [],
  80. parentChannelId: this.$route.params.parentChannelId,
  81. updateLooper: 0, //数据刷新轮训标志
  82. total: 0,
  83. beforeUrl: "/deviceList",
  84. isLoging: false,
  85. autoList: false,
  86. };
  87. },
  88. mounted() {
  89. this.initData();
  90. this.initBaiduMap();
  91. if (this.autoList) {
  92. this.updateLooper = setInterval(this.initData, 5000);
  93. }
  94. },
  95. destroyed() {
  96. // this.$destroy("videojs");
  97. clearTimeout(this.updateLooper);
  98. },
  99. methods: {
  100. initData: function () {
  101. // if (this.parentChannelId == "" || this.parentChannelId == 0) {
  102. // this.getDeviceChannelList();
  103. // } else {
  104. // this.showSubchannels();
  105. // }
  106. },
  107. initParam: function () {
  108. // this.deviceId = this.$route.params.deviceId;
  109. // this.parentChannelId = this.$route.params.parentChannelId;
  110. // this.currentPage = parseInt(this.$route.params.page);
  111. // this.count = parseInt(this.$route.params.count);
  112. // if (this.parentChannelId == "" || this.parentChannelId == 0) {
  113. // this.beforeUrl = "/deviceList";
  114. // }
  115. },
  116. initBaiduMap() {
  117. this.map = new BMap.Map("allmap"); // 创建地图实例
  118. let points = [];
  119. let point = new BMap.Point(116.231398, 39.567445); // 创建点坐标
  120. this.map.centerAndZoom(point, 5); // 初始化地图,设置中心点坐标和地图级别
  121. this.map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
  122. this.map.addControl(new BMap.NavigationControl());
  123. this.map.addControl(new BMap.ScaleControl());
  124. this.map.addControl(new BMap.OverviewMapControl());
  125. this.map.addControl(new BMap.MapTypeControl());
  126. //map.setMapStyle({ style: 'midnight' }) //地图风格
  127. },
  128. currentChange: function (val) {
  129. // var url = `/${this.$router.currentRoute.name}/${this.deviceId}/${this.parentChannelId}/${this.count}/${val}`;
  130. // console.log(url);
  131. // this.$router.push(url).then(() => {
  132. // this.initParam();
  133. // this.initData();
  134. // });
  135. },
  136. handleSizeChange: function (val) {
  137. // var url = `/${this.$router.currentRoute.name}/${this.$router.params.deviceId}/${this.$router.params.parentChannelId}/${val}/1`;
  138. // this.$router.push(url).then(() => {
  139. // this.initParam();
  140. // this.initData();
  141. // });
  142. },
  143. showDevice: function () {
  144. this.$router.push(this.beforeUrl).then(() => {
  145. this.initParam();
  146. this.initData();
  147. });
  148. },
  149. autoListChange: function () {
  150. if (this.autoList) {
  151. this.updateLooper = setInterval(this.initData, 1500);
  152. } else {
  153. window.clearInterval(this.updateLooper);
  154. }
  155. },
  156. showHistoryPath: function () {
  157. this.map.clearOverlays();
  158. this.mapPointList = [];
  159. this.mobilePositionList = [];
  160. if (!!this.searchFrom) {
  161. this.startTime = this.toGBString(this.searchFrom);
  162. console.log(this.startTime);
  163. } else{
  164. this.startTime = null;
  165. }
  166. if (!!this.searchTo) {
  167. this.endTime = this.toGBString(this.searchTo);
  168. console.log(this.endTime);
  169. } else {
  170. this.endTime = null;
  171. }
  172. let self = this;
  173. this.$axios.get(`/api/position/history/${this.deviceId}`, {
  174. params: {
  175. start: self.startTime,
  176. end: self.endTime,
  177. },
  178. })
  179. .then(function (res) {
  180. self.total = res.data.length;
  181. self.mobilePositionList = res.data;
  182. console.log(self.mobilePositionList);
  183. if (self.total == 0) {
  184. self.$message({
  185. showClose: true,
  186. message: '未找到符合条件的移动位置信息',
  187. type: 'error'
  188. });
  189. } else {
  190. self.$nextTick(() => {
  191. self.showMarkPoints(self);
  192. });
  193. }
  194. })
  195. .catch(function (error) {
  196. console.log(error);
  197. });
  198. },
  199. showLatestPosition: function() {
  200. this.map.clearOverlays();
  201. this.mapPointList = [];
  202. this.mobilePositionList = [];
  203. let self = this;
  204. this.$axios.get(`/api/position/latest/${this.deviceId}`)
  205. .then(function (res) {
  206. console.log(res.data);
  207. self.total = res.data.length;
  208. self.mobilePositionList.push(res.data);
  209. console.log(self.mobilePositionList);
  210. if (self.total == 0) {
  211. self.$message({
  212. showClose: true,
  213. message: '未找到符合条件的移动位置信息',
  214. type: 'error'
  215. });
  216. } else {
  217. self.$nextTick(() => {
  218. self.showMarkPoints(self);
  219. });
  220. }
  221. })
  222. .catch(function (error) {
  223. console.log(error);
  224. });
  225. },
  226. subscribeMobilePosition: function() {
  227. let self = this;
  228. this.$axios.get(`/api/position/subscribe/${this.deviceId}`, {
  229. params: {
  230. expires: self.expired,
  231. interval: self.interval,
  232. },
  233. })
  234. .then(function (res) {
  235. console.log(res.data);
  236. })
  237. .catch(function (error) {
  238. console.log(error);
  239. });
  240. },
  241. unSubscribeMobilePosition: function() {
  242. let self = this;
  243. this.$axios.get(`/api/position/subscribe/${this.deviceId}`, {
  244. params: {
  245. expires: 0,
  246. interval: self.interval,
  247. },
  248. })
  249. .then(function (res) {
  250. console.log(res.data);
  251. })
  252. .catch(function (error) {
  253. console.log(error);
  254. });
  255. },
  256. toGBString: function (dateTime) {
  257. return (
  258. dateTime.getFullYear() +
  259. "-" + this.twoDigits(dateTime.getMonth() + 1) +
  260. "-" + this.twoDigits(dateTime.getDate()) +
  261. "T" + this.twoDigits(dateTime.getHours()) +
  262. ":" + this.twoDigits(dateTime.getMinutes()) +
  263. ":" + this.twoDigits(dateTime.getSeconds())
  264. );
  265. },
  266. twoDigits: function (num) {
  267. if (num < 10) {
  268. return "0" + num;
  269. } else {
  270. return "" + num;
  271. }
  272. },
  273. showMarkPoints: function(self) {
  274. let that = self;
  275. let npointJ = null;
  276. let npointW = null;
  277. let point = null;
  278. for (let i = 0; i < self.mobilePositionList.length; i++) {
  279. if (self.mobilePositionList[i].geodeticSystem == "BD-09") {
  280. npointJ = self.mobilePositionList[i].cnLng;
  281. npointW = self.mobilePositionList[i].cnLat;
  282. point = new BMap.Point(npointJ, npointW);
  283. } else {
  284. npointJ = self.mobilePositionList[i].longitude;
  285. npointW = self.mobilePositionList[i].latitude;
  286. let bd2 = geoTools.GPSToBaidu(npointJ, npointW);
  287. point = new BMap.Point(bd2.lat, bd2.lng);
  288. }
  289. self.mapPointList.push(point);
  290. let marker = new BMap.Marker(point); // 创建标注
  291. self.map.addOverlay(marker); // 将标注添加到地图中
  292. //提示信息 可以解析 HTML标签以及CSS
  293. let infoWindow = new BMap.InfoWindow(`<p style='text-align:left;font-weight:800'>设备: ${self.mobilePositionList[i].deviceId}</p>
  294. <p style='text-align:left;font-weight:0'>时间: ${self.mobilePositionList[i].time}</p>`);
  295. // 鼠标移上标注点要发生的事
  296. marker.addEventListener("mouseover", function () {
  297. this.openInfoWindow(infoWindow);
  298. });
  299. // 鼠标移开标注点要发生的事
  300. marker.addEventListener("mouseout", function () {
  301. this.closeInfoWindow(infoWindow);
  302. });
  303. // 鼠标点击标注点要发生的事情
  304. marker.addEventListener("click", function () {
  305. alert("点击");
  306. });
  307. }
  308. let view = that.map.getViewport(eval(self.mapPointList));
  309. that.map.centerAndZoom(view.center, view.zoom);
  310. },
  311. },
  312. };
  313. </script>
  314. <style>
  315. .videoList {
  316. display: flex;
  317. flex-wrap: wrap;
  318. align-content: flex-start;
  319. }
  320. .video-item {
  321. position: relative;
  322. width: 15rem;
  323. height: 10rem;
  324. margin-right: 1rem;
  325. background-color: #000000;
  326. }
  327. .video-item-img {
  328. position: absolute;
  329. top: 0;
  330. bottom: 0;
  331. left: 0;
  332. right: 0;
  333. margin: auto;
  334. width: 100%;
  335. height: 100%;
  336. }
  337. .video-item-img:after {
  338. content: "";
  339. display: inline-block;
  340. position: absolute;
  341. z-index: 2;
  342. top: 0;
  343. bottom: 0;
  344. left: 0;
  345. right: 0;
  346. margin: auto;
  347. width: 3rem;
  348. height: 3rem;
  349. background-image: url("../assets/loading.png");
  350. background-size: cover;
  351. background-color: #000000;
  352. }
  353. .video-item-title {
  354. position: absolute;
  355. bottom: 0;
  356. color: #000000;
  357. background-color: #ffffff;
  358. line-height: 1.5rem;
  359. padding: 0.3rem;
  360. width: 14.4rem;
  361. }
  362. .baidumap {
  363. width: 100%;
  364. height: 100%;
  365. border: none;
  366. position: absolute;
  367. left: 0;
  368. top: 0;
  369. right: 0;
  370. bottom: 0;
  371. margin: auto;
  372. }
  373. /* 去除百度地图版权那行字 和 百度logo */
  374. .baidumap > .BMap_cpyCtrl {
  375. display: none !important;
  376. }
  377. .baidumap > .anchorBL {
  378. display: none !important;
  379. }
  380. </style>