|
项目是基于react框架的,使用了aMap高德导航模块。在第一次进入此compnent时,useEffect中执行的openFrame能正常打开一个frame。在退出此compnent后再次进入,useEffect代码能正常执行,但openFrame却不能打开相应的frame。奇怪的是,下一次此操作又能正常。即:奇数次进入compnent的useEffect能正常打开frame,偶数次无法正常打开。附代码:
compnent -------->
const Inspection = () => {
const [aMap, setAMap] = useState();
useEffect(() => {
const _aMap = window.api.require('aMap');
setAMap(aMap);
// 调用隐私授权 TODO: 第一次需要有授权弹窗
_aMap.updateMapViewPrivacy({
privacyAgree:'didAgree',
privacyShow:'didShow',
containStatus:'didContain'
});
_aMap.open({
rect: {
x: 0,
y: 0,
w: window.api.frameWidth,
h: window.api.frameHeight - 84, // 屏幕高度减去下面菜单栏高度
showUserLocation: true,
zoomLevel: 11
}
}, (ret, err) => {
if (!ret.status) {
alert(`加载地图失败:${JSON.stringify(err)}`);
}
});
window.api.openFrame({
name: 'wrap',
url: 'widget://html/inspection_map_wrap.html',
rect: {
x: window.api.frameWidth / 2 - 142 / 2,
y: window.api.frameHeight * 0.8,
w: 142,
h: 47
},
fixedOn: 'ui_widget',
pageParam: {
status: 'stop'
}
});
return () => {
window.api.closeFrame({
name: 'wrap'
});
_aMap.close();
};
}, []);
return (
<div/>
);
};
html --------->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MapWrap</title>
<style type="text/css">
body {
margin: 0;
}
#wrap {
display: flex;
justify-content: center;
align-items: flex-start;
}
.button {
margin: 0 2px 4px 2px;
width: 138px;
height: 43px;
color: white;
border-radius: 10px;
outline: none;
filter: drop-shadow(0px 2px 2px rgba(0, 0, 0, 0.25));
}
#start {
background-color: #49CC9D;
border: 1px solid #49CC9D;
}
#end {
background-color: #D2743F;
border: 1px solid #D2743F;
}
.hide {
display: none;
}
</style>
</head>
<body>
<div id="wrap">
<button id="start" class="button">开始巡检</button>
<button id="end" class="button hide">结束巡检</button>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script>
window.apiready = () => {
const pageParam = window.api.pageParam;
alert(JSON.stringify(pageParam));
// if (pageParam.status === 'stop') {
// window.document.getElementById('start').classList.remove('hide')
// }
};
</script>
</html>
|
|