This commit is contained in:
杨鹏
2025-09-29 11:22:27 +08:00
parent c4d508bb4f
commit e7d3fa8855
+37 -6
View File
@@ -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>