index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div class="home">
  3. <el-card class="head_card"
  4. shadow="always">
  5. <el-row class="head_card_row">
  6. <el-col :span="5"
  7. class="head_card_item">
  8. <span class="button_title">当前设备:</span>
  9. <el-select v-model="value"
  10. placeholder="请选择"
  11. @change="selectDevice">
  12. <el-option v-for="item in options"
  13. :key="item.value"
  14. :label="item.label"
  15. :value="item.value">
  16. </el-option>
  17. </el-select>
  18. </el-col>
  19. <el-col :span="4"
  20. class="head_card_item">
  21. <span class="button_title">当前设备状态:</span>
  22. <el-tag type="success"
  23. v-if="device.statue === 1">设备在线</el-tag>
  24. <el-tag type="danger"
  25. v-else-if="device.statue === 0">设备离线</el-tag>
  26. <el-tag v-else>无设备</el-tag>
  27. </el-col>
  28. <el-col :span="5"
  29. class="head_card_item">
  30. <span class="button_title">当前设备经度:</span>
  31. <span style="font-size: 17px;font-weight: bold;">{{ device.lon }}</span>
  32. </el-col>
  33. <el-col :span="5"
  34. class="head_card_item">
  35. <span class="button_title">当前设备纬度:</span>
  36. <span style="font-size: 17px;font-weight: bold;">{{ device.lat }}</span>
  37. </el-col>
  38. <el-col :span="5"
  39. class="head_card_item">
  40. <span class="button_title">当前设备解算状态:</span>
  41. <span style="font-size: 17px;font-weight: bold;">
  42. <!-- 只有当 f 为 0 时,显示 "无效" -->
  43. <span v-if="device.f === 0">无效</span>
  44. <!-- 当 f 为 1 时,显示 "单点定位" -->
  45. <span v-else-if="device.f === 1">单点定位</span>
  46. <!-- 当 f 为 2 时,显示 "差分定位" -->
  47. <span v-else-if="device.f === 2">差分定位</span>
  48. <!-- 当 f 为 3 时,显示 "GPS PPS 模式" -->
  49. <span v-else-if="device.f === 3">GPS PPS 模式</span>
  50. <!-- 当 f 为 4 时,显示 "RTK Int" -->
  51. <span v-else-if="device.f === 4">RTK Int</span>
  52. <!-- 当 f 为 5 时,显示 "RTK Float" -->
  53. <span v-else-if="device.f === 5">RTK Float</span>
  54. <!-- 当 f 为 6 时,显示 "惯导模式" -->
  55. <span v-else-if="device.f === 6">惯导模式</span>
  56. <!-- 当 f 为 7 时,显示 "手动输入模式" -->
  57. <span v-else-if="device.f === 7">手动输入模式</span>
  58. <!-- 当 f 为 8 时,显示 "模拟器模式" -->
  59. <span v-else-if="device.f === 8">模拟器模式</span>
  60. <!-- 其他情况都显示 "无" -->
  61. <span v-else>无</span>
  62. </span>
  63. </el-col>
  64. </el-row>
  65. </el-card>
  66. <el-card class="map_card"
  67. shadow="always">
  68. <div id="mapContainer"
  69. class="map"></div>
  70. </el-card>
  71. </div>
  72. </template>
  73. <script>
  74. import api from "@/api/item/device";
  75. import AMapLoader from '@amap/amap-jsapi-loader';
  76. export default {
  77. name: 'Home',
  78. data() {
  79. return {
  80. map: null, // 地图实例
  81. options: [], // 设备选项
  82. value: '', // 设备值
  83. device: [], // 设备数据
  84. marker: null, // 标记点
  85. };
  86. },
  87. mounted() {
  88. this.initMap();
  89. this.getOptions();
  90. },
  91. methods: {
  92. // 获取设备选项
  93. getOptions() {
  94. api.getDeviceOptions().then(res => {
  95. console.log(res.data);
  96. this.options = res.data;
  97. })
  98. },
  99. // 选择设备
  100. selectDevice(val) {
  101. console.log(val);
  102. api.getDeviceData(val).then(res => {
  103. console.log(res.data);
  104. this.device = res.data;
  105. this.drawMarkers(res.data);
  106. })
  107. },
  108. // 绘制点标记
  109. drawMarkers(device) {
  110. console.log(this.marker);
  111. let image = ''
  112. if (this.marker) {
  113. this.map.remove(this.marker);
  114. this.marker = null;
  115. }
  116. if (device.statue === 1) {
  117. image = 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png'
  118. } else {
  119. image = 'https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png'
  120. }
  121. this.marker = new AMap.Marker({
  122. map: this.map,
  123. position: [device.lon, device.lat],
  124. icon: new AMap.Icon({
  125. size: new AMap.Size(30, 30),
  126. image: image,
  127. imageOffset: new AMap.Pixel(0, 0)
  128. })
  129. });
  130. this.marker.on("click", () => {
  131. console.log(device);
  132. this.$router.push({ path: '/outdoor', query: { id: device.id, deviceId: device.deviceid } }) // 跳转到详情页
  133. })
  134. this.map.setCenter([device.lon, device.lat]);
  135. },
  136. // 初始化地图
  137. initMap() {
  138. AMapLoader.load({
  139. key: "577ee62b1059d73852c20c1f37638659",
  140. version: "2.0",
  141. plugins: ['AMap.Marker', 'AMap.InfoWindow', 'AMap.Polygon', 'AMap.Icon'], // 需要使用的插件列表
  142. }).then((AMap) => {
  143. /*初始化地图*/
  144. this.map = new AMap.Map("mapContainer", { //设置地图容器id
  145. layers: [
  146. // 路网
  147. // new AMap.TileLayer.RoadNet(),
  148. ],
  149. center: [116.3912, 39.9062],
  150. zoom: 12
  151. });
  152. }).catch(e => {
  153. console.log(e)
  154. })
  155. },
  156. }
  157. }
  158. </script>
  159. <style scoped lang="scss">
  160. .home {
  161. width: 100%;
  162. height: 100%;
  163. padding: 15px;
  164. background-color: #ffffff;
  165. }
  166. .button_title {
  167. font-family: '微软雅黑';
  168. font-size: 16px;
  169. margin-right: 10px;
  170. }
  171. .head_card {
  172. margin-bottom: 10px;
  173. height: 75px;
  174. &_row {
  175. display: flex;
  176. align-items: center;
  177. /* 垂直居中所有列 */
  178. }
  179. &_item {
  180. display: flex;
  181. align-items: center;
  182. /* 垂直居中 */
  183. justify-content: flex-start;
  184. /* 水平居中,视需要而定 */
  185. height: 100%;
  186. /* 确保有足够的高度 */
  187. }
  188. }
  189. .map_card {
  190. position: relative;
  191. height: calc(100% - 80px);
  192. width: 100%;
  193. }
  194. .map {
  195. position: absolute;
  196. width: 98%;
  197. height: 95%
  198. }
  199. </style>