first commit
This commit is contained in:
112
share/js/index.js
Normal file
112
share/js/index.js
Normal file
@@ -0,0 +1,112 @@
|
||||
class index {
|
||||
constructor() {
|
||||
this.appUpdateInfo = {};
|
||||
this.iosDownApkUrl = "http://47.114.153.249/page/home.html";
|
||||
this.checkUpdateUrl = "http://47.114.153.249:3000/api/json/updateVersion";
|
||||
this.goToReg();
|
||||
this.getVersion();
|
||||
}
|
||||
|
||||
goToReg() {
|
||||
// 如果地址栏有 objectId,表示代理分享出来的链接,先删除下载区域
|
||||
if (this.GetQueryString("objectId") != null) {
|
||||
$(".app_download").remove()
|
||||
}
|
||||
|
||||
if (this.GetQueryString("objectId") == null) {
|
||||
$(".h5_version").remove()
|
||||
} else {
|
||||
$(".h5_version_r").click(() => {
|
||||
if (this.GetQueryString("objectId") == null) {
|
||||
location.href = "../page/reg.html"
|
||||
} else {
|
||||
location.href = `../page/reg.html?objectId=${this.GetQueryString("objectId")}`
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
getVersion() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: this.checkUpdateUrl,
|
||||
success: (res) => {
|
||||
this.appUpdateInfo = res;
|
||||
// 设置app版本
|
||||
$(".version_num").text(this.appUpdateInfo.version);
|
||||
|
||||
// 设置按钮文字
|
||||
this.downloadApp() == "ios"
|
||||
? $(".down_button").append(`
|
||||
<i class="iconfont icon-ios"></i>
|
||||
<span>H5 访问</span>
|
||||
`)
|
||||
: $(".down_button").append(`
|
||||
<i class="iconfont icon-android"></i>
|
||||
<span>下载并安装</span>
|
||||
`);
|
||||
|
||||
// 点击安装事件
|
||||
this.downloadApp() == "ios"
|
||||
? $(".down_button").click(() => location.href = this.iosDownApkUrl)
|
||||
: $(".down_button").click(() => location.href = this.appUpdateInfo.downUrl);
|
||||
|
||||
// 生成二维码
|
||||
$(".app_download").length != 0 ? this.CreatedQrcode() : ''
|
||||
// 新版本特性
|
||||
this.appUpdateInfo.updateMsg.forEach((v,i) => {
|
||||
$(".update").append(`<li>${v}</li>`)
|
||||
});
|
||||
// 详细信息
|
||||
$(".detailed .update_time").text(`更新时间:${this.appUpdateInfo.updatedAt}`)
|
||||
},
|
||||
error: (err) => {
|
||||
throw new Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
CreatedQrcode() {
|
||||
let url = this.downloadApp() == "ios"
|
||||
? this.iosDownApkUrl
|
||||
: this.appUpdateInfo.downUrl;
|
||||
|
||||
new QRCode("QRCodeNone", {
|
||||
text: url,
|
||||
width: 128,
|
||||
height: 128,
|
||||
colorDark : "#000000",
|
||||
colorLight : "#ffffff",
|
||||
correctLevel : QRCode.CorrectLevel.H
|
||||
});
|
||||
$("#down_code").append(
|
||||
this.convertCanvasToImage($("canvas")[0])
|
||||
);
|
||||
}
|
||||
|
||||
convertCanvasToImage(canvas){
|
||||
var image = new Image();
|
||||
image.src = canvas.toDataURL("image/png");
|
||||
return image;
|
||||
}
|
||||
|
||||
downloadApp() {
|
||||
var u = navigator.userAgent;
|
||||
var ua = navigator.userAgent.toLowerCase();
|
||||
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
|
||||
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
|
||||
if (isiOS) {
|
||||
return 'ios';
|
||||
} else if (isAndroid) {
|
||||
return "android"
|
||||
}
|
||||
}
|
||||
|
||||
GetQueryString(name) {
|
||||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
||||
var r = window.location.search.substr(1).match(reg);
|
||||
if (r != null) return decodeURIComponent(r[2]); return null;
|
||||
}
|
||||
}
|
||||
|
||||
new index()
|
||||
Reference in New Issue
Block a user