.
This commit is contained in:
+37
-6
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view>
|
<view>
|
||||||
<s-layout title="试衣间" navbar="custom" tabbar="" :bgStyle="{ color: '#fff' }">
|
<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" />
|
<cover-view-tabbar activeUrl="/pages/index/room" />
|
||||||
</web-view>
|
</web-view>
|
||||||
</s-layout>
|
</s-layout>
|
||||||
@@ -21,19 +21,50 @@
|
|||||||
fail: () => {},
|
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 () => {
|
onShow(async () => {
|
||||||
if (!sheep.$store('user').isLogin) {
|
if (!sheep.$store('user').isLogin) {
|
||||||
uni.redirectTo({ url: '/pages/login/index' });
|
uni.redirectTo({ url: '/pages/login/index' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onLoad(() => {});
|
onLoad(() => {
|
||||||
|
token.value = getAccessToken();
|
||||||
|
startTokenListener();
|
||||||
|
});
|
||||||
|
|
||||||
onUnload(() => {});
|
onUnload(() => {
|
||||||
|
stopTokenListener();
|
||||||
|
});
|
||||||
|
|
||||||
const url = ref(
|
function startTokenListener() {
|
||||||
`https://fitting-room.huimeimeta.com/pages/fittingRoom/index?token=${getAccessToken()}`,
|
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>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped></style>
|
<style lang="scss" scoped></style>
|
||||||
|
|||||||
Reference in New Issue
Block a user