.
This commit is contained in:
+37
-6
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<view>
|
||||
<s-layout title="试衣间" navbar="custom" tabbar="" :bgStyle="{ color: '#fff' }">
|
||||
<web-view :src="url">
|
||||
<web-view :src="webviewUrl" ref="webviewRef">
|
||||
<cover-view-tabbar activeUrl="/pages/index/room" />
|
||||
</web-view>
|
||||
</s-layout>
|
||||
@@ -21,19 +21,50 @@
|
||||
fail: () => {},
|
||||
});
|
||||
|
||||
const tokenCheckTimer = ref(null);
|
||||
const token = ref('');
|
||||
const webviewRef = ref();
|
||||
const webviewUrl = ref(
|
||||
`https://fitting-room.huimeimeta.com/pages/fittingRoom/index?token=${getAccessToken()}&t=${Date.now()}`,
|
||||
);
|
||||
|
||||
onShow(async () => {
|
||||
if (!sheep.$store('user').isLogin) {
|
||||
uni.redirectTo({ url: '/pages/login/index' });
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {});
|
||||
onLoad(() => {
|
||||
token.value = getAccessToken();
|
||||
startTokenListener();
|
||||
});
|
||||
|
||||
onUnload(() => {});
|
||||
onUnload(() => {
|
||||
stopTokenListener();
|
||||
});
|
||||
|
||||
const url = ref(
|
||||
`https://fitting-room.huimeimeta.com/pages/fittingRoom/index?token=${getAccessToken()}`,
|
||||
);
|
||||
function startTokenListener() {
|
||||
tokenCheckTimer.value = setInterval(() => {
|
||||
checkTokenUpdate();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function checkTokenUpdate() {
|
||||
const currentToken = getAccessToken() || '';
|
||||
|
||||
if (currentToken !== token.value) {
|
||||
console.log('检测到token变化,更新H5页面');
|
||||
token.value = currentToken;
|
||||
webviewUrl.value = `https://fitting-room.huimeimeta.com/pages/fittingRoom/index?token=${currentToken}&t=${Date.now()}`;
|
||||
}
|
||||
}
|
||||
|
||||
function stopTokenListener() {
|
||||
if (tokenCheckTimer.value) {
|
||||
clearInterval(tokenCheckTimer.value);
|
||||
tokenCheckTimer.value = null;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
|
||||
Reference in New Issue
Block a user