小程序
小游戏
企业微信
微信支付
扫描小程序码分享
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
需要看下具体代码
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
需要看下具体代码
import { onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue';
import api from '../../api';
// 确认删除这里的 markers 引用
// console.log('markers', markers);
const longitude = ref(0);
const latitude = ref(0);
const currentMarker = ref(null);
const isScan = ref(true);
const markers = ref([]); // 保留这一行
const app = getApp();
onLoad(() => {
uni.getLocation({
success(res) {
console.log('res', res);
longitude.value = res.longitude;
latitude.value = res.latitude;
},
fail(err) {
console.log('err', err);
}
});
api.getStadiumList().then(res => {
if (res.code === 0) {
console.log('res', res);
app.globalData.markers = markers.value = res.data.map(i => {
return {
...i,
width: 40,
iconPath: '/static/profile.png',
latitude: +i.latitude,
longitude: +i.longitude,
title: i.name
};
});
} else {
uni.showToast({
title: res.message,
icon: 'none'
});
}
});
});
const handleMarkerTap = (e) => {
console.log(e.detail.markerId);
const current = markers.value.find((i) => i.id === e.detail.markerId);
console.log('current', current);
currentMarker.value = current;
isScan.value = false;
};
const handleScan = () => {
uni.scanCode({
success(res) {
console.log('res', res.result.split('=')[1]);
}
});
};
const handleMapTap = () => {
// isScan.value = true;
};
const handleNavTap = () => {
console.log('跳转到详情');
uni.navigateTo({
url: `/pages/ground/ground?id=${currentMarker.value.id}`
});
};
const actionList = [
{ id: 1, src: '/static/search.png', name: '地图搜索' },
{ id: 2, src: '/static/support.png', name: '客服中心' },
{ id: 3, src: '/static/origin.png', name: '回到原点' },
{ id: 4, src: '/static/profile.png', name: '个人中心' }
];
const handlemageTap = (item) => {
switch (item.id) {
case 1:
uni.chooseLocation({
success(res) {
console.log('res', res);
longitude.value = res.longitude;
latitude.value = res.latitude;
}
});
break;
case 2:
console.log('客服中心');
uni.navigateTo({
url: '/pages/contact/contact'
});
break;
case 3:
const mapContext = uni.createMapContext('map');
mapContext.moveToLocation();
break;
case 4:
console.log('个人中心');
console.log('token',token)
if(!app.globalData.token){
uni.showModal({
title:'尚未登陆',
content:'点击确认进行登陆',
success(res) {
if(res.confirm){
uni.navigateTo({
url:'/pages/login/login'
})
}
}
})
return
}
uni.navigateTo({
url: '/pages/profire/profire'
});
break;
default:
break;
}
};
</script>
<template>
<view class="map-box">
<map
class="map"
id="map"
:longitude="longitude"
:latitude="latitude"
show-location
:markers="markers"
:scale="10"
@markertap="handleMarkerTap"
@tap="handleMapTap"
></map>
<view v-show="isScan" class="scan-box scan-title" @tap="handleScan">扫码借还</view>
<view v-show="!isScan" class="scan-box marker-sunmmary">
<!-- left -->
<view class="scan-box-left">
<image src="/static/logo.png" mode="widthFix"></image>
</view>
<view class="scan-box-center">
<view class="top scan-box-center-item">
{{ currentMarker?.title || '-' }}
</view>
<view class="bottom scan-box-center-item">
{{ currentMarker?.address || '-' }}
</view>
</view>
<view class="scan-box-right" @tap="handleNavTap">
<img src="../../static/nav.png" mode="widthFix" />
</view>
</view>
<view class="action-box">
<image
v-for="item in actionList"
:key="item.id"
:src="item.src"
mode="widthFix"
@tap="handlemageTap(item)"
></image>
</view>
</view>
</template>
<style>
.map-box {
position: relative;
}
.map {
width: 100vw;
height: 100vh;
}
.scan-box {
position: absolute;
width: 80%;
height: 120rpx;
left: 10%;
bottom: 100rpx;
background-color: #1296db;
box-shadow: 0 0 20rpx #1296db;
border-radius: 20rpx;
padding: 20rpx 0;
display: flex;
}
.scan-title {
font-size: 50rpx;
font-weight: bold;
justify-content: center;
align-items: center;
color: white;
letter-spacing: 4rpx;
}
.marker-sunmmary {
background-color: white;
}
.scan-box-left,
.scan-box-right {
width: 120rpx;
/* background-color: #1296db; */
margin: 0 20rpx;
}
.scan-box-left image,
.scan-box-right image {
width: 100%;
border-radius: 50%;
}
.scan-box-right image {
width: 80%;
margin: 10% 0 0 10%;
}
.scan-box-center {
flex: 1;
}
.scan-box-center-item {
height: 60rpx;
line-height: 60rpx;
width: 280rpx;
overflow: hidden;
text-overflow: ellipsis;
word-spacing: normal;
}
.top {
font-weight: bold;
}
.bottom {
font-size: 28rpx;
}
.action-box {
position: absolute;
right: 10%;
bottom: 300rpx;
width: 90rpx;
/* background-color: white; */
}
.action-box image {
width: 50rpx;
padding: 20rpx;
border-radius: 50%;
box-shadow: 0 0 20rpx #1296db;
background-color: white;
margin-bottom: 40rpx;
}
<style>