视频改为接口获取

This commit is contained in:
17792275749
2025-12-29 15:03:11 +08:00
parent bb0536c7e4
commit 4f9d79461c
3 changed files with 86 additions and 4 deletions
+42 -3
View File
@@ -34,7 +34,7 @@
</div>
</div>
<VideoComponent :src="videoUrl" />
<VideoComponent v-if="videoUrl" :src="videoUrl" />
</div>
</template>
<script setup lang="ts">
@@ -64,6 +64,13 @@
const loading = ref<boolean>(false);
const imgList = [itemOnePng, itemTwoPng, itemThreePng];
import { getVideo } from '/@/api/user';
import { getAppEnvConfig } from '/@/utils/env.ts';
const videoUrlLocal = window.localStorage.getItem('videoUrl') || null;
// 1. 本次进来,直接取 Pinia/缓存中的老地址,保证视频组件能立即渲染
const videoUrl = ref(videoUrlLocal);
// const itemList = [
// {
// label: '健康监测平台',
@@ -87,10 +94,42 @@
rightDate.value = '累计运行时间:' + (dayjs().diff(dayjs(initDate.value), 'days') + 1) + ' 天';
const centerInfo = getAuthCache('centerInfo');
document.title = centerInfo.screenTitle || '健康服务中心';
asyncUpdateVideoCache();
});
// 定义网络视频地址
const videoUrl = 'https://api-xj.tri.icdat.cn/file/show/temp/20251229/20251229_1766980290812.mp4';
/**
* 异步校验并预热下次使用的视频
*/
async function asyncUpdateVideoCache() {
try {
const res: any = await getVideo();
if (res && res.success) {
const serverUrl = getAppEnvConfig().VITE_GLOB_API_URL + '/file/show/' + res.result.videoUrl;
// 2. 比对地址:如果服务器地址变了,说明下次需要换视频
if (serverUrl !== videoUrl.value) {
console.log('检测到新资源,后台开始异步预缓存...');
// 3. 立即更新 Pinia 和持久化缓存(这样下次进来 getSrc 就是新的了)
window.localStorage.setItem('videoUrl', serverUrl);
// 4. 动态插入 link 标签,让浏览器在后台静默下载新视频
// 浏览器会自动处理,不会影响当前正在播放的老视频
const link = document.createElement('link');
link.rel = 'preload';
link.as = 'video';
link.href = serverUrl;
link.type = 'video/mp4';
document.head.appendChild(link);
} else {
console.log('视频地址一致,不需要做任何操作...');
}
}
} catch (e) {
console.warn('后台异步更新视频缓存失败', e);
}
}
const getTime = () => {
dateInfo.value = {