初始化黄果短剧 H5 客户端
对接后端 hgmjapi.mfcg.me: - 接口解密 key 更新为 resKey360 - 登录 sysType 使用原生 getDevType(后端已放开 pc/android) - 修正榜单接口路径 /vid/rangking → /vid/ranking,方法改为 GET Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,333 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="loadingBox" v-if="state.dataloading">
|
||||
<van-loading class="loading" color="#fff" vertical>加载中...</van-loading>
|
||||
</div>
|
||||
<div v-else>
|
||||
<mobile v-if="isMobile" />
|
||||
<pc v-else />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, onUnmounted, reactive } from 'vue';
|
||||
import { useAppStore } from '@/stores/app';
|
||||
import { useConfigStore } from '@/stores/config';
|
||||
import { useUserStore } from '@/stores/user';
|
||||
import { useGlobalStore } from '@/stores/global';
|
||||
import { getDevType } from '@/utils';
|
||||
import { getAdItem } from '@/utils/getConfig';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { AdType, SourceType } from '@/enums/app';
|
||||
import { useHomeStore } from '@/stores/home';
|
||||
import axios from 'axios';
|
||||
import AppApi from '@/service/app';
|
||||
import mobile from './../mobile/index.vue';
|
||||
import pc from './../pc/index.vue';
|
||||
|
||||
const isMobile = ref(false);
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const appStore = useAppStore();
|
||||
const userStore = useUserStore();
|
||||
const configStore = useConfigStore();
|
||||
const globalStore = useGlobalStore();
|
||||
const homeStore = useHomeStore();
|
||||
const state = reactive({
|
||||
isCheckError: false, //是否选线失败
|
||||
checkLineErrorNum: 0, //选线失败次数
|
||||
isResLock: false, // 请求结果锁
|
||||
resResult: <any>[], // 响应结果
|
||||
pingCheckCount: 0, // 请求的ping失败次数
|
||||
loading: true, // 选线loading
|
||||
videoPlayer: true,
|
||||
dataloading: true,
|
||||
});
|
||||
|
||||
const setDeviceType = () => {
|
||||
isMobile.value = window.innerWidth <= 768;
|
||||
// if (isMobile.value) {
|
||||
// router.push('/home')
|
||||
// } else {
|
||||
// router.push('/welfare')
|
||||
// }
|
||||
};
|
||||
|
||||
setDeviceType();
|
||||
// 监听屏幕大小变化
|
||||
window.addEventListener('resize', () => {
|
||||
setDeviceType();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', setDeviceType);
|
||||
});
|
||||
|
||||
/**
|
||||
* @description 如果没有用户ID就生成一个
|
||||
*/
|
||||
const generateUid = () => {
|
||||
if (!appStore.uid) {
|
||||
appStore.generateUid();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description 登陆
|
||||
* @returns 是否登陆成功
|
||||
*/
|
||||
const login = async (): Promise<boolean> => {
|
||||
try {
|
||||
const uid = appStore.uid;
|
||||
const sysType = getDevType();
|
||||
const cutInfos = Object.keys(route.query).length > 0 ? JSON.stringify(route.query) : undefined;
|
||||
let userInfo = await AppApi.login(uid, sysType, cutInfos);
|
||||
userStore.saveUserInfo(userInfo);
|
||||
userStore.saveToken(userInfo.token);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description 初始化资源域名配置
|
||||
* @param list 资源列表
|
||||
*/
|
||||
const initSourceInfo = (list: Array<Types.App.SourceListItem>): void => {
|
||||
let sourceInfo: Types.App.SourceInfo = {
|
||||
GROUP: '',
|
||||
GUIDE: '',
|
||||
QRCODE: '',
|
||||
IMAGE: '',
|
||||
VID: [],
|
||||
LAND: '',
|
||||
PROXYRULE: '',
|
||||
FAQ: '',
|
||||
WELFARE: '',
|
||||
ACT: '',
|
||||
AppStore: '',
|
||||
UP: '',
|
||||
TELEGRAM: '',
|
||||
EMAIL: '',
|
||||
AUDIO: '',
|
||||
Download: '',
|
||||
};
|
||||
for (let item of list) {
|
||||
switch (item.type) {
|
||||
case SourceType.GROUP:
|
||||
sourceInfo.GROUP = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.TELEGRAM:
|
||||
sourceInfo.TELEGRAM = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.GUIDE:
|
||||
sourceInfo.GUIDE = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.IMAGE:
|
||||
sourceInfo.IMAGE = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.VID:
|
||||
sourceInfo.VID = item.domain;
|
||||
break;
|
||||
case SourceType.LAND:
|
||||
sourceInfo.LAND = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.PROXYRULE:
|
||||
sourceInfo.PROXYRULE = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.FAQ:
|
||||
sourceInfo.FAQ = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.QRCODE:
|
||||
sourceInfo.QRCODE = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.WELFARE:
|
||||
sourceInfo.WELFARE = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.AppStore:
|
||||
sourceInfo.AppStore = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.ACT:
|
||||
sourceInfo.ACT = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.UP:
|
||||
sourceInfo.UP = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.EMAIL:
|
||||
sourceInfo.EMAIL = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.AUDIO:
|
||||
sourceInfo.AUDIO = item.domain[0]?.url;
|
||||
break;
|
||||
case SourceType.Download:
|
||||
sourceInfo.Download = item.domain;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
configStore.saveSourceInfo(sourceInfo);
|
||||
};
|
||||
/**
|
||||
* @description 获取配置信息
|
||||
* @returns 获取配置信息是否成功
|
||||
*/
|
||||
const getConfig = async (): Promise<boolean> => {
|
||||
try {
|
||||
const configList = await AppApi.queryDomain();
|
||||
state.dataloading = false;
|
||||
configStore.saveAppConfig(configList);
|
||||
initSourceInfo(configList.sourceList);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const pingErrorPop = (hosts: any) => {
|
||||
// 只有最后一条域名出错时,判断响应结果不存在true的时候,说明全部不通,即弹出选线失败
|
||||
state.pingCheckCount++;
|
||||
if (state.pingCheckCount == hosts.length) {
|
||||
state.pingCheckCount = 0;
|
||||
let index = state.resResult.indexOf(true);
|
||||
if (index == -1) {
|
||||
if (state.checkLineErrorNum == 1) {
|
||||
state.isCheckError = true;
|
||||
return;
|
||||
}
|
||||
// showDialog({
|
||||
// title: '温馨提示',
|
||||
// message: '选线失败',
|
||||
// confirmButtonText: '重试',
|
||||
// theme: 'round-button',
|
||||
// }).then(() => {
|
||||
// state.checkLineErrorNum++;
|
||||
// appStore.$reset();
|
||||
// userStore.$reset();
|
||||
// configStore.$reset();
|
||||
// init();
|
||||
// });
|
||||
}
|
||||
}
|
||||
};
|
||||
const queryContactInfo = async () => {
|
||||
try {
|
||||
let req = {
|
||||
type: 2,
|
||||
};
|
||||
const res: any = await AppApi.getBusiness(req);
|
||||
useConfigStore().setContactInfo(res || []);
|
||||
// console.log(res);
|
||||
// contactInfo
|
||||
// configStore.saveAppConfig(configList);
|
||||
// initSourceInfo(configList.sourceList);
|
||||
// return true;
|
||||
} catch (error) {
|
||||
// return false;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
const init = async () => {
|
||||
generateUid();
|
||||
const baseUrls: string = process.env.VITE_BASE_URL || '[]';
|
||||
const hosts = JSON.parse(baseUrls);
|
||||
state.resResult = new Array(hosts.length);
|
||||
hosts.forEach((url: any, index: number) => {
|
||||
axios({
|
||||
method: 'GET',
|
||||
url: url + '/api/app/ping/check',
|
||||
timeout: 1000 * 10, // 10秒超时
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res.data.code == 200) {
|
||||
if (!state.isResLock) {
|
||||
state.isResLock = true;
|
||||
state.resResult[index] = true;
|
||||
//选线成功
|
||||
useConfigStore().saveBaseUrl(url);
|
||||
console.log(configStore.sourceInfo.VID[0]);
|
||||
state.loading = false;
|
||||
//登陆
|
||||
if (!(userStore.userInfo && userStore.token)) {
|
||||
let userInfo: any = localStorage.getItem('userInfo');
|
||||
let token = localStorage.getItem('token');
|
||||
if (userInfo && token) {
|
||||
userStore.saveUserInfo(JSON.parse(userInfo));
|
||||
userStore.saveToken(JSON.parse(token));
|
||||
} else {
|
||||
const loginOk = await login();
|
||||
if (!loginOk) {
|
||||
// showDialog({
|
||||
// title: '温馨提示',
|
||||
// message: '用户登陆失败',
|
||||
// confirmButtonText: '重试',
|
||||
// theme: 'round-button',
|
||||
// }).then(() => {
|
||||
// appStore.$reset();
|
||||
// userStore.$reset();
|
||||
// configStore.$reset();
|
||||
// init();
|
||||
// });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
homeStore.getHomeData();
|
||||
queryContactInfo();
|
||||
//获取配置信息
|
||||
const configOk = await getConfig();
|
||||
globalStore.setVideoRoadLine(configStore.sourceInfo.VID[0]); // 默认选择第一个线路
|
||||
if (!configOk) {
|
||||
// showDialog({
|
||||
// title: '温馨提示',
|
||||
// message: '获取配置信息失败',
|
||||
// confirmButtonText: '重试',
|
||||
// theme: 'round-button',
|
||||
// }).then(() => {
|
||||
// appStore.$reset();
|
||||
// userStore.$reset();
|
||||
// configStore.$reset();
|
||||
// init();
|
||||
// userStore.saveToken('');
|
||||
// localStorage.removeItem('userInfo');
|
||||
// localStorage.removeItem('token');
|
||||
// });
|
||||
return;
|
||||
}
|
||||
// const launchList = getAdItem(AdType.START);
|
||||
// if (launchList.length > 0) {
|
||||
// state.launchInfo = launchList[0];
|
||||
// state.advsList = launchList || [];
|
||||
// }
|
||||
//开机广告
|
||||
// adControl();
|
||||
}
|
||||
} else {
|
||||
pingErrorPop(hosts);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
pingErrorPop(hosts);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* created
|
||||
*/
|
||||
init();
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
.loadingBox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
// .loading {
|
||||
// width: 40px;
|
||||
// }
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user