425 lines
9.4 KiB
Vue
425 lines
9.4 KiB
Vue
<template>
|
||
<div class="container" @click="doCopy()">
|
||
<template v-if="version == 'A'">
|
||
<mobile1
|
||
v-if="!isPC"
|
||
class="mobile"
|
||
:os="os"
|
||
@getApkInfo="handleGetApkInfo"
|
||
:ip="ip"
|
||
:switchData="switchData"
|
||
:version="version"
|
||
style="height:100%"
|
||
></mobile1>
|
||
|
||
<tips
|
||
v-else-if="isPC && page_pc_url === 'https://sisqd.com/?dc=THD2'"
|
||
></tips>
|
||
<pc
|
||
v-else
|
||
class="pc"
|
||
:qr-img="QRImg"
|
||
:os="os"
|
||
@getApkInfo="handleGetApkInfo"
|
||
></pc>
|
||
</template>
|
||
<template v-else>
|
||
<mobile2
|
||
v-if="!isPC"
|
||
class="mobile"
|
||
:os="os"
|
||
@getApkInfo="handleGetApkInfo"
|
||
:ip="ip"
|
||
:switchData="switchData"
|
||
style="height:100%"
|
||
ref="mobileRef"
|
||
/>
|
||
<tips
|
||
v-else-if="isPC && page_pc_url === 'https://sisqd.com/?dc=THD2'"
|
||
></tips>
|
||
<pc2
|
||
v-else
|
||
class="pc"
|
||
:qr-img="QRImg"
|
||
:os="os"
|
||
@getApkInfo="handleGetApkInfo"
|
||
></pc2>
|
||
</template>
|
||
<!-- loading-->
|
||
<div class="loading_box" v-if="loading && !isPC">
|
||
<div style="height: 5px"></div>
|
||
<div class="lds-roller">
|
||
<div></div>
|
||
<div></div>
|
||
<div></div>
|
||
<div></div>
|
||
<div></div>
|
||
<div></div>
|
||
<div></div>
|
||
<div></div>
|
||
</div>
|
||
<h3>加载中...</h3>
|
||
</div>
|
||
<selectLinePopup
|
||
:apiUrls="apiUrls"
|
||
:showOverlay="showOverlay"
|
||
@selectLine="selectLine"
|
||
></selectLinePopup>
|
||
</div>
|
||
</template>
|
||
<script>
|
||
import { getButtonList, bottonclick, downloadH5 } from "@/api/btn";
|
||
import userAgent from "@/utils/userAgent";
|
||
import QRCode from "qrcode";
|
||
import axios from "@/utils/request.js";
|
||
import mobile1 from "./components/mobile1";
|
||
import mobile2 from "./components/mobile2";
|
||
import pc from "./components/pc";
|
||
import pc2 from "./components/pc2";
|
||
import tips from "./components/tips";
|
||
import selectLinePopup from "./components/selectLinePopup";
|
||
import { getTraceId } from "@/utils/traceId";
|
||
export default {
|
||
components: {
|
||
mobile1,
|
||
mobile2,
|
||
pc,
|
||
pc2,
|
||
tips,
|
||
selectLinePopup
|
||
},
|
||
data() {
|
||
return {
|
||
QRImg: "",
|
||
os: "",
|
||
ip: "",
|
||
switchData: {},
|
||
page_pc_url: "",
|
||
loading: true,
|
||
currUrl: window.location.href,
|
||
apiUrls: JSON.parse(process.env.VUE_APP_BASE_HOSTS), // api数组
|
||
showOverlay: false, // 显示选线弹窗
|
||
version: "A",
|
||
trace_id: getTraceId()
|
||
};
|
||
},
|
||
|
||
computed: {
|
||
isPC() {
|
||
return this.os.isPc;
|
||
}
|
||
},
|
||
created() {
|
||
this.version = "A";
|
||
this.getPcUrl();
|
||
this.os = userAgent();
|
||
this.init();
|
||
const referrer = document.referrer;
|
||
if (referrer) {
|
||
sessionStorage.setItem("referrer", referrer);
|
||
}
|
||
if (this.$route.query.dc) {
|
||
sessionStorage.setItem("dc", this.$route.query.dc);
|
||
}
|
||
},
|
||
mounted() {
|
||
this.getQRImg();
|
||
},
|
||
methods: {
|
||
getPcUrl() {
|
||
this.page_pc_url = window.location.href;
|
||
},
|
||
async init() {
|
||
await this.getIp();
|
||
await this.getButtonlist();
|
||
},
|
||
// 去掉空值后序列化渠道参数
|
||
filterChannel() {
|
||
const result = {};
|
||
Object.entries(this.$route.query).forEach(([key, value]) => {
|
||
if (value) result[key] = value;
|
||
});
|
||
return JSON.stringify(result);
|
||
},
|
||
//1.获取按钮开关(iosDown / iosStore / iosTF / iosH5 / androidButton)
|
||
async getButtonlist() {
|
||
try {
|
||
const res = await getButtonList({
|
||
ip: this.ip,
|
||
channel: JSON.stringify(this.$route.query)
|
||
});
|
||
this.loading = false;
|
||
if (res.data.code === 200) {
|
||
this.switchData = res.data.data || {};
|
||
}
|
||
} catch (err) {
|
||
this.loading = false;
|
||
this.showOverlay = true;
|
||
console.log(err);
|
||
}
|
||
},
|
||
//2. 获取外网IP地址
|
||
async getIp() {
|
||
try {
|
||
const res = await fetch("https://api.ipify.org?format=json");
|
||
const data = await res.json();
|
||
this.ip = data.ip || "";
|
||
} catch (err) {
|
||
console.log("获取外部IP失败" + err);
|
||
}
|
||
},
|
||
jumpToLink(link) {
|
||
// 微信内加时间戳,避免命中缓存
|
||
window.location.href = this.os.isWx ? link + "?time=" + Date.now() : link;
|
||
},
|
||
// bottonclick 返回的下载地址数组
|
||
async fetchLinks(terminal, extra = {}) {
|
||
const res = await bottonclick({
|
||
ip: this.ip,
|
||
channel: this.filterChannel(),
|
||
domain: window.location.host || "",
|
||
type: "iosH5",
|
||
terminal,
|
||
...extra
|
||
});
|
||
const link = res && res.data && res.data.data && res.data.data.link;
|
||
return Array.isArray(link) ? link.filter(Boolean) : [];
|
||
},
|
||
// iOS 轻量版:直接调 h5/config 下载描述文件
|
||
async downloadMobileConfig() {
|
||
const paramData = {};
|
||
if (this.$route.query.dc) paramData.dc = String(this.$route.query.dc);
|
||
if (this.$route.query.pc) paramData.pc = String(this.$route.query.pc);
|
||
const content = await downloadH5(paramData);
|
||
const file = new File([content], "descriptionFile.mobileconfig", {
|
||
type: "application/x-apple-aspen-config"
|
||
});
|
||
const objectUrl = URL.createObjectURL(file);
|
||
const link = document.createElement("a");
|
||
link.href = objectUrl;
|
||
link.download = "descriptionFile.mobileconfig";
|
||
link.click();
|
||
setTimeout(() => URL.revokeObjectURL(objectUrl), 10000);
|
||
},
|
||
//3. 点击下载按钮获取下载地址并下载
|
||
async handleGetApkInfo(type) {
|
||
await this.doCopy();
|
||
try {
|
||
if (type === "ios") {
|
||
await this.downloadMobileConfig();
|
||
} else if (type === "shopIos") {
|
||
if (!this.switchData.iosStore) return;
|
||
const links = await this.fetchLinks("ios", {
|
||
type: "iosStore",
|
||
packageType: 2
|
||
});
|
||
if (links.length) this.jumpToLink(links[0]);
|
||
} else {
|
||
const links = await this.fetchLinks("android");
|
||
const target = (type === "androidSpare" && links[1]) || links[0];
|
||
if (target) this.jumpToLink(target);
|
||
}
|
||
} catch (err) {
|
||
console.log("下载失败" + err);
|
||
}
|
||
},
|
||
//4.生成二维码
|
||
getQRImg() {
|
||
QRCode.toDataURL(this.currUrl, {
|
||
width: 170,
|
||
margin: 1,
|
||
maskPattern: 1,
|
||
scale: 1,
|
||
color: {
|
||
dark: "#000",
|
||
light: "rgba()"
|
||
}
|
||
}).then(url => {
|
||
const regex = /code=/gi;
|
||
if (url.indexOf("code=") != -1) {
|
||
this.QRImg = url.replace(regex, "pc=");
|
||
} else {
|
||
this.QRImg = url;
|
||
}
|
||
});
|
||
},
|
||
// 5.剪贴板
|
||
doCopy() {
|
||
let req = JSON.stringify({
|
||
...this.$route.query,
|
||
tid: this.trace_id
|
||
});
|
||
return this.$copyText(req).then(
|
||
() => {
|
||
console.log("复制成功");
|
||
},
|
||
() => {
|
||
console.log("复制失败");
|
||
}
|
||
);
|
||
},
|
||
// 选线
|
||
selectLine(item) {
|
||
axios.defaults.baseURL = item; // 更改apiURL
|
||
setTimeout(() => {
|
||
this.showOverlay = false;
|
||
this.loading = true;
|
||
this.getButtonlist(); // 重新请求接口
|
||
}, 300);
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.container {
|
||
overflow: hidden;
|
||
height: 100%;
|
||
.mobile {
|
||
height: 100%;
|
||
}
|
||
}
|
||
// @media screen and (min-width: 750px) {
|
||
// .mobile {
|
||
// display: none;
|
||
// }
|
||
// .pc {
|
||
// overflow: hidden;
|
||
// }
|
||
// }
|
||
// @media screen and (max-width: 750px) {
|
||
// .pc {
|
||
// display: none;
|
||
// }
|
||
// }
|
||
/* loading */
|
||
.loading_box {
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
bottom: 0;
|
||
right: 0;
|
||
background: rgba(0, 0, 0, 0.7);
|
||
z-index: 10;
|
||
border-radius: 20px;
|
||
display: flex;
|
||
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
|
||
h3 {
|
||
padding-top: 10px;
|
||
font-size: 20px;
|
||
color: #fff;
|
||
}
|
||
}
|
||
|
||
.lds-roller {
|
||
display: inline-block;
|
||
position: relative;
|
||
width: 80px;
|
||
height: 80px;
|
||
}
|
||
|
||
.lds-roller div {
|
||
animation: lds-roller 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
|
||
transform-origin: 40px 40px;
|
||
}
|
||
|
||
.lds-roller div:after {
|
||
content: " ";
|
||
display: block;
|
||
position: absolute;
|
||
width: 7px;
|
||
height: 7px;
|
||
border-radius: 50%;
|
||
background: #fff;
|
||
margin: -4px 0 0 -4px;
|
||
}
|
||
|
||
.lds-roller div:nth-child(1) {
|
||
animation-delay: -0.036s;
|
||
}
|
||
|
||
.lds-roller div:nth-child(1):after {
|
||
top: 63px;
|
||
left: 63px;
|
||
}
|
||
|
||
.lds-roller div:nth-child(2) {
|
||
animation-delay: -0.072s;
|
||
}
|
||
|
||
.lds-roller div:nth-child(2):after {
|
||
top: 68px;
|
||
left: 56px;
|
||
}
|
||
|
||
.lds-roller div:nth-child(3) {
|
||
animation-delay: -0.108s;
|
||
}
|
||
|
||
.lds-roller div:nth-child(3):after {
|
||
top: 71px;
|
||
left: 48px;
|
||
}
|
||
|
||
.lds-roller div:nth-child(4) {
|
||
animation-delay: -0.144s;
|
||
}
|
||
|
||
.lds-roller div:nth-child(4):after {
|
||
top: 72px;
|
||
left: 40px;
|
||
}
|
||
|
||
.lds-roller div:nth-child(5) {
|
||
animation-delay: -0.18s;
|
||
}
|
||
|
||
.lds-roller div:nth-child(5):after {
|
||
top: 71px;
|
||
left: 32px;
|
||
}
|
||
|
||
.lds-roller div:nth-child(6) {
|
||
animation-delay: -0.216s;
|
||
}
|
||
|
||
.lds-roller div:nth-child(6):after {
|
||
top: 68px;
|
||
left: 24px;
|
||
}
|
||
|
||
.lds-roller div:nth-child(7) {
|
||
animation-delay: -0.252s;
|
||
}
|
||
|
||
.lds-roller div:nth-child(7):after {
|
||
top: 63px;
|
||
left: 17px;
|
||
}
|
||
|
||
.lds-roller div:nth-child(8) {
|
||
animation-delay: -0.288s;
|
||
}
|
||
|
||
.lds-roller div:nth-child(8):after {
|
||
top: 56px;
|
||
left: 12px;
|
||
}
|
||
|
||
@keyframes lds-roller {
|
||
0% {
|
||
transform: rotate(0deg);
|
||
}
|
||
|
||
100% {
|
||
transform: rotate(360deg);
|
||
}
|
||
}
|
||
|
||
//loading
|
||
</style>
|