devicePosition.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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({
  174. method: 'get',
  175. url:`/api/position/history/${this.deviceId}`,
  176. params: {
  177. start: self.startTime,
  178. end: self.endTime,
  179. },
  180. }).then(function (res) {
  181. self.total = res.data.length;
  182. self.mobilePositionList = res.data;
  183. console.log(self.mobilePositionList);
  184. if (self.total == 0) {
  185. self.$message({
  186. showClose: true,
  187. message: '未找到符合条件的移动位置信息',
  188. type: 'error'
  189. });
  190. } else {
  191. self.$nextTick(() => {
  192. self.showMarkPoints(self);
  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({
  205. method: 'get',
  206. url:`/api/position/latest/${this.deviceId}`
  207. }).then(function (res) {
  208. console.log(res.data);
  209. self.total = res.data.length;
  210. self.mobilePositionList.push(res.data);
  211. console.log(self.mobilePositionList);
  212. if (self.total == 0) {
  213. self.$message({
  214. showClose: true,
  215. message: '未找到符合条件的移动位置信息',
  216. type: 'error'
  217. });
  218. } else {
  219. self.$nextTick(() => {
  220. self.showMarkPoints(self);
  221. });
  222. }
  223. }).catch(function (error) {
  224. console.log(error);
  225. });
  226. },
  227. subscribeMobilePosition: function() {
  228. let self = this;
  229. this.$axios({
  230. method: 'get',
  231. url:`/api/position/subscribe/${this.deviceId}`,
  232. params: {
  233. expires: self.expired,
  234. interval: self.interval,
  235. },
  236. }).then(function (res) {
  237. console.log(res.data);
  238. })
  239. .catch(function (error) {
  240. console.log(error);
  241. });
  242. },
  243. unSubscribeMobilePosition: function() {
  244. let self = this;
  245. this.$axios({
  246. method: 'get',
  247. url:`/api/position/subscribe/${this.deviceId}`,
  248. params: {
  249. expires: 0,
  250. interval: self.interval,
  251. },
  252. })
  253. .then(function (res) {
  254. console.log(res.data);
  255. }).catch(function (error) {
  256. console.log(error);
  257. });
  258. },
  259. toGBString: function (dateTime) {
  260. return (
  261. dateTime.getFullYear() +
  262. "-" + this.twoDigits(dateTime.getMonth() + 1) +
  263. "-" + this.twoDigits(dateTime.getDate()) +
  264. "T" + this.twoDigits(dateTime.getHours()) +
  265. ":" + this.twoDigits(dateTime.getMinutes()) +
  266. ":" + this.twoDigits(dateTime.getSeconds())
  267. );
  268. },
  269. twoDigits: function (num) {
  270. if (num < 10) {
  271. return "0" + num;
  272. } else {
  273. return "" + num;
  274. }
  275. },
  276. showMarkPoints: function(self) {
  277. let that = self;
  278. let npointJ = null;
  279. let npointW = null;
  280. let point = null;
  281. for (let i = 0; i < self.mobilePositionList.length; i++) {
  282. if (self.mobilePositionList[i].geodeticSystem == "BD-09") {
  283. npointJ = self.mobilePositionList[i].cnLng;
  284. npointW = self.mobilePositionList[i].cnLat;
  285. point = new BMap.Point(npointJ, npointW);
  286. } else {
  287. npointJ = self.mobilePositionList[i].longitude;
  288. npointW = self.mobilePositionList[i].latitude;
  289. let bd2 = geoTools.GPSToBaidu(npointJ, npointW);
  290. point = new BMap.Point(bd2.lat, bd2.lng);
  291. }
  292. self.mapPointList.push(point);
  293. let marker = new BMap.Marker(point); // 创建标注
  294. self.map.addOverlay(marker); // 将标注添加到地图中
  295. //提示信息 可以解析 HTML标签以及CSS
  296. let infoWindow = new BMap.InfoWindow(`<p style='text-align:left;font-weight:800'>设备: ${self.mobilePositionList[i].deviceId}</p>
  297. <p style='text-align:left;font-weight:0'>时间: ${self.mobilePositionList[i].time}</p>`);
  298. // 鼠标移上标注点要发生的事
  299. marker.addEventListener("mouseover", function () {
  300. this.openInfoWindow(infoWindow);
  301. });
  302. // 鼠标移开标注点要发生的事
  303. marker.addEventListener("mouseout", function () {
  304. this.closeInfoWindow(infoWindow);
  305. });
  306. // 鼠标点击标注点要发生的事情
  307. marker.addEventListener("click", function () {
  308. alert("点击");
  309. });
  310. }
  311. let view = that.map.getViewport(eval(self.mapPointList));
  312. that.map.centerAndZoom(view.center, view.zoom);
  313. },
  314. },
  315. };
  316. </script>
  317. <style>
  318. .videoList {
  319. display: flex;
  320. flex-wrap: wrap;
  321. align-content: flex-start;
  322. }
  323. .video-item {
  324. position: relative;
  325. width: 15rem;
  326. height: 10rem;
  327. margin-right: 1rem;
  328. background-color: #000000;
  329. }
  330. .video-item-img {
  331. position: absolute;
  332. top: 0;
  333. bottom: 0;
  334. left: 0;
  335. right: 0;
  336. margin: auto;
  337. width: 100%;
  338. height: 100%;
  339. }
  340. .video-item-img:after {
  341. content: "";
  342. display: inline-block;
  343. position: absolute;
  344. z-index: 2;
  345. top: 0;
  346. bottom: 0;
  347. left: 0;
  348. right: 0;
  349. margin: auto;
  350. width: 3rem;
  351. height: 3rem;
  352. background-image: url("../assets/loading.png");
  353. background-size: cover;
  354. background-color: #000000;
  355. }
  356. .video-item-title {
  357. position: absolute;
  358. bottom: 0;
  359. color: #000000;
  360. background-color: #ffffff;
  361. line-height: 1.5rem;
  362. padding: 0.3rem;
  363. width: 14.4rem;
  364. }
  365. .baidumap {
  366. width: 100%;
  367. height: 100%;
  368. border: none;
  369. position: absolute;
  370. left: 0;
  371. top: 0;
  372. right: 0;
  373. bottom: 0;
  374. margin: auto;
  375. }
  376. /* 去除百度地图版权那行字 和 百度logo */
  377. .baidumap > .BMap_cpyCtrl {
  378. display: none !important;
  379. }
  380. .baidumap > .anchorBL {
  381. display: none !important;
  382. }
  383. </style>