This commit is contained in:
xianfuxing 2018-08-27 21:48:47 +08:00
parent 6d69ca3948
commit 08d1712ad0
4 changed files with 100 additions and 7 deletions

View File

@ -56,6 +56,7 @@
"simplemde": "1.11.2", "simplemde": "1.11.2",
"sortablejs": "1.7.0", "sortablejs": "1.7.0",
"vue": "2.5.10", "vue": "2.5.10",
"vue-amap": "^0.5.8",
"vue-count-to": "1.0.13", "vue-count-to": "1.0.13",
"vue-i18n": "7.3.2", "vue-i18n": "7.3.2",
"vue-multiselect": "2.0.8", "vue-multiselect": "2.0.8",

View File

@ -23,7 +23,18 @@ Vue.use(VueAMap)
VueAMap.initAMapApiLoader({ VueAMap.initAMapApiLoader({
key: '29fc9d79996d548cb00726229752cd1f', key: '29fc9d79996d548cb00726229752cd1f',
plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'], plugin: [
'AMap.Geolocation',
'AMap.Driving',
'AMap.Autocomplete',
'AMap.PlaceSearch',
'AMap.Scale',
'AMap.OverView',
'AMap.ToolBar',
'AMap.MapType',
'AMap.PolyEditor',
'AMap.CircleEditor'
],
// 默认高德 sdk 版本为 1.4.4 // 默认高德 sdk 版本为 1.4.4
v: '1.4.4' v: '1.4.4'
}) })

View File

@ -80,9 +80,11 @@
min-width="100"> min-width="100">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="text" <el-button type="text"
@click="handleDeviceClick(scope.row.device_id)" size="small">详情 @click="handleDetailClick(scope.row.device_id)" size="small">详情
</el-button>
<el-button type="text"
@click="handleMapClick(scope.row.device_id)" size="small">地图
</el-button> </el-button>
<el-button type="text" size="small">地图</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -138,13 +140,21 @@ export default {
this.listLoading = true this.listLoading = true
this.getDevices({ page }) this.getDevices({ page })
}, },
handleDeviceClick(deviceID) { handleDetailClick(deviceID) {
// console.log(deviceID) // console.log(deviceID)
this.$store.dispatch('chnageDeviceID', deviceID).then(() => { this.$store.dispatch('chnageDeviceID', deviceID).then(() => {
this.$router.push('/counter/detail') this.$router.push('/counter/detail')
}).catch(() => { }).catch(() => {
console.log('Err: get device_id failed in device page') console.log('Err: get device_id failed in device page')
}) })
},
handleMapClick(deviceID) {
// console.log(deviceID)
this.$store.dispatch('chnageDeviceID', deviceID).then(() => {
this.$router.push('/counter/map')
}).catch(() => {
console.log('Err: get device_id failed in device page')
})
} }
}, },
created() { created() {

View File

@ -1,21 +1,92 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<div class="amap-wrapper"> <div class="amap-wrapper">
<el-amap class="amap-box" :vid="'amap-vue'"></el-amap> <el-amap v-if="flag" :zoom="zoom" :center="center" :plugin="plugin" class="amap-box" :vid="'amap-vue'">
<el-amap-marker
v-for="(marker, index) in markers"
:key="index"
:position="marker.position"
:visible="marker.visible" :draggable="marker.draggable" :vid="index"
>
</el-amap-marker>
</el-amap>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { fetchDeviceList } from '@/api/counter'
const defaultEvents = {
click: () => {
alert('click marker')
},
dragend: (e) => {
console.log('---event---: dragend')
this.markers[0].position = [e.lnglat.lng, e.lnglat.lat]
}
}
export default { export default {
name: 'map' name: 'amap',
data() {
return {
flag: false,
defaultPositions: [
{
name: '上海',
position: [121.59996, 31.197646]
},
{
name: '古镇',
position: [113.203698459202, 22.649173177084]
}
],
zoom: 16,
center: [113.203698459202, 22.649173177084],
markers: [],
plugin: ['ToolBar', {
pName: 'MapType',
defaultType: 0,
events: {
init(o) {
console.log(o)
}
}
}]
}
},
methods: {
getDevices(params) {
fetchDeviceList(params).then(response => {
this.deviceList = response.data.results
// console.log(this.deviceList)
this.coordinate = this.deviceList[0].coordinate
if (this.coordinate === null) {
this.coordinate = [113.203460828994, 22.64902452257]
}
// console.log(this.coordinate)
this.flag = true
})
}
},
created() {
const device_id = this.$store.getters.deviceID
this.getDevices({ device_id })
this.defaultPositions.forEach((item, index) => {
const entry = {}
entry.position = item.position
entry.events = defaultEvents
entry.visible = true
entry.draggable = false
this.markers.push(entry)
})
}
} }
</script> </script>
<style lang="scss"> <style lang="scss">
.amap-wrapper { .amap-wrapper {
width: 100%; width: 100%;
height: 100%; height: 80%;
overflow: hidden; overflow: hidden;
position: absolute; position: absolute;
} }