请官方回答-小程序内嵌h5,调用openLocation提示permission, denied?
微信版本号:8.0.24 jssdk: 1.6.0 手机型号:华为荣耀FRD-AL10 Android版本:8.0.0 问题描述: 小程序内嵌h5页面,首页没有路由redirect时,调用openLocation正常。当首页有路由redirect时,调用openLocation提示permission, denied。checkApiJs返回true。 [图片] 代码片段: weixin config: export function getSign(url) {
console.log('sign url:', url)
return new Promise((resolve, reject) => {
axios
.get(`${SIGN_URL}?url=${url}`)
.then((res) => {
if (res.status === 200) {
console.log("sign success");
resolve(res.data);
} else {
console.log("sign failed");
reject();
}
})
.catch((e) => {
console.log("get sign error", JSON.stringify(e));
reject();
});
});
}
export function wxconfig(params) {
console.log('params:', params)
return new Promise(async (resolve, reject) => {
await window.__wx_jssdk_promise__;
wx.config({
debug: true, // 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来,若要查看传入的参数,可以在 pc 端打开,参数信息会通过 log 打出,仅在 pc 端时才会打印。
appId: params.appid, // 必填,公众号的唯一标识
timestamp: params.timestamp, // 必填,生成签名的时间戳
nonceStr: params.nonceStr, // 必填,生成签名的随机串
signature: params.signature, // 必填,签名
jsApiList: params.jsApiList,
});
wx.ready(function () {
console.log("success");
resolve();
});
wx.error(function (err) {
console.log("error");
reject();
});
});
}
export async function signAndConfig(url, jsApiList) {
const signParams = await getSign(url)
console.log('=> sign params: ', JSON.stringify(signParams))
await wxconfig({
...JSON.parse(signParams),
jsApiList,
})
}
vue router: const routes = [
{
path: "/",
redirect: () => {
return { path: "/home" };
},
},
{
path: "/home",
name: "home",
component: HomeView,
}
];
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
router.afterEach(async (from, to, next) => {
await signAndConfig(location.href, ['openLocation'])
wx.checkJsApi({
jsApiList: ["openLocation"], // 需要检测的 JS 接口列表,所有 JS 接口列表见附录2,
success: function (res) {
console.log('checkJsApi:', JSON.stringify(res))
},
});
wx.openLocation({
latitude: 0,
longitude: 0,
success(res) {
console.warn(`小程序导航成功${res}`);
},
fail(e) {
console.warn(`小程序导航失败${JSON.stringify(e)}`);
},
});
})