视频改为接口获取
This commit is contained in:
@@ -2,6 +2,7 @@ import { get, post } from '/@/api/request.ts';
|
||||
|
||||
enum Api {
|
||||
getInputCode = '/sys/randomImage',
|
||||
videoApi = '/health-emergency/api/anon/screen-animation/query',
|
||||
Login = '/sys/login',
|
||||
Logout = '/sys/logout',
|
||||
GetUserInfo = '/sys/user/getUserInfo',
|
||||
@@ -9,8 +10,12 @@ enum Api {
|
||||
emergencyCenter = '/health-emergency/emergency/center/getCenterDetail',
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const getCodeInfo = (params: any) => get(Api.getInputCode + `/${params}`);
|
||||
|
||||
export const getVideo = () => get(Api.videoApi);
|
||||
|
||||
export function loginApi(params: any) {
|
||||
return post(Api.Login, params);
|
||||
}
|
||||
|
||||
+42
-3
@@ -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 = {
|
||||
|
||||
+39
-1
@@ -91,7 +91,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" name="login-mini" setup>
|
||||
import { getAuth, getCodeInfo, getEmergencyCenterApi, getUserInfo } from '/@/api/user';
|
||||
import { getAuth, getVideo, getCodeInfo, getEmergencyCenterApi, getUserInfo } from '/@/api/user';
|
||||
import { onMounted, reactive, ref, toRaw, watch } from 'vue';
|
||||
import codeImg from '/@/assets/images/checkcode.png';
|
||||
import { useUserStore } from '/@/store/modules/user';
|
||||
@@ -102,6 +102,7 @@
|
||||
import { getAuthCache } from '/@/utils/auth.ts';
|
||||
import { TOKEN_KEY } from '/@/enum/cacheEnum.ts';
|
||||
import { getCurrentPath, PageEnum, setBaseLogin, toHomeByLogoutPath } from '/@/enum/pageEnum.ts';
|
||||
import { getAppEnvConfig } from '/@/utils/env.ts';
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
const router = useRouter();
|
||||
@@ -144,6 +145,40 @@
|
||||
.catch((e) => {});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取视频播放地址
|
||||
*/
|
||||
async function asyncUpdateVideoCache() {
|
||||
try {
|
||||
const videoUrlLocal = window.localStorage.getItem('videoUrl') || null;
|
||||
const res: any = await getVideo();
|
||||
if (res && res.success) {
|
||||
const serverUrl = getAppEnvConfig().VITE_GLOB_API_URL + '/file/show/' + res.result.videoUrl;
|
||||
|
||||
// 2. 比对地址:如果服务器地址变了,说明下次需要换视频
|
||||
if (serverUrl !== videoUrlLocal) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号或者手机登录
|
||||
*/
|
||||
@@ -264,6 +299,9 @@
|
||||
onMounted(() => {
|
||||
checkToken();
|
||||
|
||||
//获取视频播放地址
|
||||
asyncUpdateVideoCache();
|
||||
|
||||
//加载验证码
|
||||
handleChangeCheckCode();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user