html
<template>
<view class="box">
<!-- <view class="inputDevice">
</view> -->
<view class="container">
<u-sticky>
<!-- 只能有一个根元素 -->
<view class="sticky" style="background: #fff;">
<u-search placeholder="搜索设备名称" v-model="describeName" @custom='searchClick'></u-search>
</view>
</u-sticky>
</view>
<view class="page-body">
<view class="page-section page-section-gap">
<map style="width: 100%; height: 650px;" :latitude="latitude" :longitude="longitude" :markers="covers"
@markertap="markertap" @tap="tap">
</map>
</view>
</view>
</view>
</template>
js
<script>
export default {
data() {
return {
id: 0, // 使用 marker点击事件 需要填写id
title: 'map',
// 地图中心点
latitude: 39.909,
longitude: 116.39742,
// 地图信息
covers: [],
// 搜索设备名称
describeName: "",
windowHeight:""
}
},
onShow() {
this.getDataList()
uni.getSystemInfo({
success: function (res) {
this.windowHeight = res.windowHeight + "px"
console.log(res.windowHeight)
}
})
},
methods: {
// 搜索click
searchClick(e) {
const parameter = {
pageNum: 1,
pageSize: 10,
name: e
}
this.$api.listInstance(parameter).then(res => {
this.latitude = res.rows.locationLatitudes,
this.longitude = res.rows.locationLongitudes
})
},
// list数据
getDataList() {
this.$api.listInstances().then(res => {
// this.dataList = res.data
console.log(res.rows)
const dataList = res.rows
const covers = []
dataList.forEach((e) => {
console.log(e.id)
this.covers.push({
value: e.id,
latitude: e.locationLatitudes - 0.006,
longitude: e.locationLongitudes - 0.0065
})
})
})
},
// 标记点的点击事件
markertap(e) {
console.log("===你点击了标记点===")
console.log(e.detail)
},
//点击地图时触发; 事件
tap(e) {
// console.log("===你点击了地图点===")
console.log(e.detail)
},
}
}
</script>