解决app升级bug

master
lemon橪 2021-06-10 10:13:21 +08:00
parent 305f05bade
commit a2a949be8f
1 changed files with 863 additions and 809 deletions

View File

@ -2,55 +2,51 @@
/**** 此文件说明请看注释 *****/ /**** 此文件说明请看注释 *****/
// 可以用自己项目的请求方法 // 可以用自己项目的请求方法
// 请求配置说明https://ext.dcloud.net.cn/plugin?id=822 // 请求配置说明https://ext.dcloud.net.cn/plugin?id=822
import { import { getAppVersionList } from "@/api/message.js";
getAppVersionList
} from '@/api/message.js'
const platform = uni.getSystemInfoSync().platform; const platform = uni.getSystemInfoSync().platform;
// 主颜色 // 主颜色
const $mainColor = "#1ABC9C"; const $mainColor = "#1ABC9C";
// 弹窗图标url // 弹窗图标url
const $iconUrl = "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/app/upgrade.png"; const $iconUrl =
"https://lilishop-oss.oss-cn-beijing.aliyuncs.com/app/upgrade.png";
// 获取当前应用的版本号 // 获取当前应用的版本号
export const getCurrentNo = function (callback) { export const getCurrentNo = function (callback) {
// 获取本地应用资源版本号 // 获取本地应用资源版本号
plus.runtime.getProperty(plus.runtime.appid, function (inf) { plus.runtime.getProperty(plus.runtime.appid, function (inf) {
callback &&
callback && callback({ callback({
versionCode: inf.version.replace(/\./g, ""), versionCode: inf.version.replace(/\./g, ""),
version: inf.version version: inf.version,
}); });
}); });
} };
// 发起ajax请求获取服务端版本号 // 发起ajax请求获取服务端版本号
export const getServerNo = function (callback) { export const getServerNo = function (callback) {
let type; let type;
platform == "android" ? type = "ANDROID" : type = "IOS" platform == "android" ? (type = "ANDROID") : (type = "IOS");
getAppVersionList(type).then(res => { getAppVersionList(type).then((res) => {
console.log(res) if (res.data.success && res.data.result.downloadUrl) {
if(res.data.success && res.data.result.downloadUrl){ let response = res.data.result;
let response = res.data.result let result = {};
let result ={}
result.versionCode = response.version; result.versionCode = response.version;
result.versionName = response.versionName; result.versionName = response.versionName;
result.versionInfo = response.content || '暂无'; result.versionInfo = response.content || "暂无";
result.forceUpdate = response.forceUpdate; result.forceUpdate = response.forceUpdate;
result.downloadUrl = response.downloadUrl; result.downloadUrl = response.downloadUrl;
console.log(result,response)
callback && callback(result); callback && callback(result);
} }
}) });
};
}
// 从服务器下载应用资源包wgt文件 // 从服务器下载应用资源包wgt文件
export const getDownload = function (data) { export const getDownload = function (data) {
let popupData = { let popupData = {
progress: true, progress: true,
buttonNum: 2 buttonNum: 2,
}; };
if (data.forceUpdate) { if (data.forceUpdate) {
popupData.buttonNum = 0; popupData.buttonNum = 0;
@ -58,35 +54,48 @@ export const getDownload = function (data) {
} }
let dtask; let dtask;
let lastProgressValue = 0; let lastProgressValue = 0;
downloadPopup(popupData, function (res) { downloadPopup(
dtask = plus.downloader.createDownload(data.downloadUrl, { popupData,
filename: "_doc/update/" function (res) {
}, function (download, status) { dtask = plus.downloader.createDownload(
data.downloadUrl,
{
filename: "_doc/update/",
},
function (download, status) {
if (status == 200) { if (status == 200) {
res.change({ res.change({
progressValue: 100, progressValue: 100,
progressTip: "正在安装文件...", progressTip: "正在安装文件...",
progress: true, progress: true,
buttonNum: 0 buttonNum: 0,
}); });
plus.runtime.install(download.filename, {}, function () { plus.runtime.install(
download.filename,
{},
function () {
res.change({ res.change({
contentText: "应用资源更新完成!", contentText: "应用资源更新完成!",
buttonNum: 1, buttonNum: 1,
progress: false progress: false,
}); });
}, function (e) { },
function (e) {
res.cancel(); res.cancel();
plus.nativeUI.alert("安装文件失败[" + e.code + "]" + e.message); plus.nativeUI.alert(
}); "安装文件失败[" + e.code + "]" + e.message
);
}
);
} else { } else {
res.change({ res.change({
contentText: "文件下载失败...", contentText: "文件下载失败...",
buttonNum: 1, buttonNum: 1,
progress: false progress: false,
}); });
} }
}); }
);
dtask.start(); dtask.start();
dtask.addEventListener("statechanged", function (task, status) { dtask.addEventListener("statechanged", function (task, status) {
switch (task.state) { switch (task.state) {
@ -94,42 +103,46 @@ export const getDownload = function (data) {
res.change({ res.change({
progressValue: 0, progressValue: 0,
progressTip: "准备下载...", progressTip: "准备下载...",
progress: true progress: true,
}); });
break; break;
case 2: // 已连接到服务器 case 2: // 已连接到服务器
res.change({ res.change({
progressValue: 0, progressValue: 0,
progressTip: "开始下载...", progressTip: "开始下载...",
progress: true progress: true,
}); });
break; break;
case 3: case 3:
const progress = parseInt(task.downloadedSize / task.totalSize * 100); const progress = parseInt(
(task.downloadedSize / task.totalSize) * 100
);
if (progress - lastProgressValue >= 2) { if (progress - lastProgressValue >= 2) {
lastProgressValue = progress; lastProgressValue = progress;
res.change({ res.change({
progressValue: progress, progressValue: progress,
progressTip: "已下载" + progress + "%", progressTip: "已下载" + progress + "%",
progress: true progress: true,
}); });
} }
break; break;
} }
}); });
}, function () { },
function () {
// 取消下载 // 取消下载
dtask && dtask.abort(); dtask && dtask.abort();
uni.showToast({ uni.showToast({
title: "已取消下载", title: "已取消下载",
icon: "none" icon: "none",
}); });
}, },
function () { function () {
// 重启APP // 重启APP
plus.runtime.restart(); plus.runtime.restart();
}); }
} );
};
// 文字换行 // 文字换行
function drawtext(text, maxWidth) { function drawtext(text, maxWidth) {
let textArr = text.split(""); let textArr = text.split("");
@ -142,8 +155,6 @@ function drawtext(text, maxWidth) {
// 文本换行数组 // 文本换行数组
let rowText = []; let rowText = [];
// 如果是字母,侧保存长度 // 如果是字母,侧保存长度
let letterWidth = 0; let letterWidth = 0;
// 汉字宽度 // 汉字宽度
@ -156,7 +167,7 @@ function drawtext(text, maxWidth) {
if (nodeWidth + chineseWidth + letterWidth * otherWidth > maxWidth) { if (nodeWidth + chineseWidth + letterWidth * otherWidth > maxWidth) {
rowText.push({ rowText.push({
type: "text", type: "text",
content: text.substring(previousNode, i) content: text.substring(previousNode, i),
}); });
previousNode = i; previousNode = i;
nodeWidth = chineseWidth; nodeWidth = chineseWidth;
@ -169,7 +180,7 @@ function drawtext(text, maxWidth) {
if (nodeWidth + chineseWidth > maxWidth) { if (nodeWidth + chineseWidth > maxWidth) {
rowText.push({ rowText.push({
type: "text", type: "text",
content: text.substring(previousNode, i) content: text.substring(previousNode, i),
}); });
previousNode = i; previousNode = i;
nodeWidth = chineseWidth; nodeWidth = chineseWidth;
@ -181,7 +192,7 @@ function drawtext(text, maxWidth) {
if (/\n/g.test(textArr[i])) { if (/\n/g.test(textArr[i])) {
rowText.push({ rowText.push({
type: "break", type: "break",
content: text.substring(previousNode, i) content: text.substring(previousNode, i),
}); });
previousNode = i + 1; previousNode = i + 1;
nodeWidth = 0; nodeWidth = 0;
@ -189,7 +200,7 @@ function drawtext(text, maxWidth) {
} else if (textArr[i] == "\\" && textArr[i + 1] == "n") { } else if (textArr[i] == "\\" && textArr[i + 1] == "n") {
rowText.push({ rowText.push({
type: "break", type: "break",
content: text.substring(previousNode, i) content: text.substring(previousNode, i),
}); });
previousNode = i + 2; previousNode = i + 2;
nodeWidth = 0; nodeWidth = 0;
@ -199,7 +210,7 @@ function drawtext(text, maxWidth) {
if (nodeWidth + letterWidth * otherWidth > maxWidth) { if (nodeWidth + letterWidth * otherWidth > maxWidth) {
rowText.push({ rowText.push({
type: "text", type: "text",
content: text.substring(previousNode, i + 1 - letterWidth) content: text.substring(previousNode, i + 1 - letterWidth),
}); });
previousNode = i + 1 - letterWidth; previousNode = i + 1 - letterWidth;
nodeWidth = letterWidth * otherWidth; nodeWidth = letterWidth * otherWidth;
@ -209,7 +220,7 @@ function drawtext(text, maxWidth) {
if (nodeWidth + otherWidth > maxWidth) { if (nodeWidth + otherWidth > maxWidth) {
rowText.push({ rowText.push({
type: "text", type: "text",
content: text.substring(previousNode, i) content: text.substring(previousNode, i),
}); });
previousNode = i; previousNode = i;
nodeWidth = otherWidth; nodeWidth = otherWidth;
@ -222,7 +233,7 @@ function drawtext(text, maxWidth) {
if (previousNode < len) { if (previousNode < len) {
rowText.push({ rowText.push({
type: "text", type: "text",
content: text.substring(previousNode, len) content: text.substring(previousNode, len),
}); });
} }
@ -231,12 +242,13 @@ function drawtext(text, maxWidth) {
// 是否更新弹窗 // 是否更新弹窗
function updatePopup(data, callback) { function updatePopup(data, callback) {
// 弹窗遮罩层 // 弹窗遮罩层
let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层 let maskLayer = new plus.nativeObj.View("maskLayer", {
top: '0px', //先创建遮罩层
left: '0px', top: "0px",
height: '100%', left: "0px",
width: '100%', height: "100%",
backgroundColor: 'rgba(0,0,0,0.5)' width: "100%",
backgroundColor: "rgba(0,0,0,0.5)",
}); });
let downloadUrl = data.downloadUrl; let downloadUrl = data.downloadUrl;
// 以下为计算菜单的nview绘制布局为固定算法使用者无关关心 // 以下为计算菜单的nview绘制布局为固定算法使用者无关关心
@ -247,87 +259,90 @@ function updatePopup(data, callback) {
// 弹窗容器的Padding // 弹窗容器的Padding
const viewContentPadding = 20; const viewContentPadding = 20;
// 弹窗容器的宽度 // 弹窗容器的宽度
const viewContentWidth = parseInt(popupViewWidth - (viewContentPadding * 5)); const viewContentWidth = parseInt(popupViewWidth - viewContentPadding * 5);
// 描述的列表 // 描述的列表
const descriptionList = drawtext(data.versionInfo, viewContentWidth); const descriptionList = drawtext(data.versionInfo, viewContentWidth);
// 弹窗容器高度 // 弹窗容器高度
let popupViewHeight = 400; let popupViewHeight = 400;
let popupViewContentList = [{ let popupViewContentList = [
{
src: $iconUrl, src: $iconUrl,
id: "logo", id: "logo",
tag: "img" tag: "img",
}, },
{ {
tag: 'font', tag: "font",
id: 'title', id: "title",
text: 'V' + data.versionCode, text: "V" + data.versionCode,
textStyles: { textStyles: {
size: '26px', size: "26px",
color: "#fff", color: "#fff",
weight: "700" weight: "700",
}, },
position: { position: {
top: '60px', top: "60px",
left: "64px", left: "64px",
height: "20px", height: "20px",
} },
}, },
{ {
tag: 'font', tag: "font",
id: 'welcome', id: "welcome",
text: '欢迎体验', text: "欢迎体验",
textStyles: { textStyles: {
size: '16px', size: "16px",
color: "#fff", color: "#fff",
weight: "400" weight: "400",
}, },
position: { position: {
top: '85px', top: "85px",
left: "64px", left: "64px",
height: "20px", height: "20px",
} },
} },
]; ];
const textHeight = 18; const textHeight = 18;
let contentTop = popupViewHeight / 2 + 8; let contentTop = popupViewHeight / 2 + 8;
popupViewContentList.push({ popupViewContentList.push({
tag: 'font', tag: "font",
id: 'content-title', id: "content-title",
text: '新版本特性:', text: "新版本特性:",
textStyles: { textStyles: {
size: '20px', size: "20px",
lineSpacing: "50%", lineSpacing: "50%",
align: "left" align: "left",
}, },
position: { position: {
top: (popupViewHeight / 2) - 24 + "px", top: popupViewHeight / 2 - 24 + "px",
left: viewContentPadding + "px", left: viewContentPadding + "px",
width: viewContentWidth + "px", width: viewContentWidth + "px",
height: textHeight + "px", height: textHeight + "px",
} },
}); });
descriptionList.forEach((item, index) => { descriptionList.forEach((item, index) => {
if (index > 0) { if (index > 0) {
popupViewHeight += textHeight; popupViewHeight += textHeight;
contentTop += textHeight; contentTop += textHeight;
} }
let content = item.content.replace('<p>', '<font>'); let content = item.content.replace("<p>", "<font>");
content = content.replace('</p>', '</font>'); content = content.replace("</p>", "</font>");
popupViewContentList.push({ popupViewContentList.push({
tag: 'richtext', tag: "richtext",
id: 'content' + index + 1, id: "content" + index + 1,
text: content, text: content,
richTextStyles: { richTextStyles: {
align: "left" align: "left",
color: "#333",
}, },
position: { position: {
top: contentTop + "px", top: contentTop + "px",
left: viewContentPadding + "px", left: viewContentPadding + "px",
width: viewContentWidth + "px", width: viewContentWidth + "px",
height: textHeight + "px", height: textHeight + "px",
} },
}); });
if (item.type == "break") { if (item.type == "break") {
contentTop += 10; contentTop += 10;
@ -335,73 +350,86 @@ function updatePopup(data, callback) {
} }
}); });
// 弹窗内容 // 弹窗内容
let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单 let popupView = new plus.nativeObj.View("popupView", {
//创建底部图标菜单
tag: "rect", tag: "rect",
top: (screenHeight - popupViewHeight) / 2 + "px", top: (screenHeight - popupViewHeight) / 2 + "px",
left: '10%', left: "10%",
height: popupViewHeight + "px", height: popupViewHeight + "px",
width: "80%" width: "80%",
}); });
// 绘制白色背景 // 绘制白色背景
popupView.drawRect({ popupView.drawRect(
{
color: "#FFFFFF", color: "#FFFFFF",
radius: "8px" radius: "8px",
}, { },
{
top: "40px", top: "40px",
height: popupViewHeight - 40 + "px", height: popupViewHeight - 40 + "px",
}); }
);
// 绘制底边按钮 // 绘制底边按钮
popupView.drawRect({ popupView.drawRect(
{
radius: "3px", radius: "3px",
borderColor: "#f1f1f1", borderColor: "#f1f1f1",
borderWidth: "1px", borderWidth: "1px",
}, { },
bottom: viewContentPadding + 'px', {
bottom: viewContentPadding + "px",
left: viewContentPadding + "px", left: viewContentPadding + "px",
width: (viewContentWidth - viewContentPadding) / 2 + "px", width: (viewContentWidth - viewContentPadding) / 2 + "px",
height: "30px", height: "30px",
}); }
);
// 绘制底边按钮 // 绘制底边按钮
popupView.drawRect({ popupView.drawRect(
{
radius: "3px", radius: "3px",
color: $mainColor, color: $mainColor,
borderColor: $mainColor borderColor: $mainColor,
}, { },
bottom: viewContentPadding + 'px', {
left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", bottom: viewContentPadding + "px",
left:
(viewContentWidth - viewContentPadding) / 2 +
viewContentPadding * 2 +
"px",
width: (viewContentWidth - viewContentPadding) / 2 + "px", width: (viewContentWidth - viewContentPadding) / 2 + "px",
height: "30px" height: "30px",
}); }
);
popupViewContentList.push({ popupViewContentList.push({
tag: 'rect', tag: "rect",
id: 'confimBtn', id: "confimBtn",
rectStyles: { rectStyles: {
color: $mainColor, color: $mainColor,
radius: "3px" radius: "3px",
}, },
position: { position: {
bottom: viewContentPadding + 'px', bottom: viewContentPadding + "px",
left: (viewContentWidth - viewContentPadding) / 3 + "px", left: (viewContentWidth - viewContentPadding) / 3 + "px",
width: (viewContentWidth - viewContentPadding) + "px", width: viewContentWidth - viewContentPadding + "px",
height: "40px", height: "40px",
} },
}); });
popupViewContentList.push({ popupViewContentList.push({
tag: 'font', tag: "font",
id: 'confirmText', id: "confirmText",
text: "立即更新", text: "立即更新",
textStyles: { textStyles: {
size: '18px', size: "18px",
color: '#fff', color: "#fff",
lineSpacing: "0%", lineSpacing: "0%",
whiteSpace: "normal" whiteSpace: "normal",
}, },
position: { position: {
bottom: viewContentPadding + 'px', bottom: viewContentPadding + "px",
left: (viewContentWidth - viewContentPadding) / 3 + "px", left: (viewContentWidth - viewContentPadding) / 3 + "px",
width: (viewContentWidth - viewContentPadding) + "px", width: viewContentWidth - viewContentPadding + "px",
height: "40px", height: "40px",
} },
}); });
popupView.draw(popupViewContentList); popupView.draw(popupViewContentList);
popupView.addEventListener("click", function (e) { popupView.addEventListener("click", function (e) {
@ -410,7 +438,10 @@ function updatePopup(data, callback) {
let buttonWidth = (viewContentWidth - viewContentPadding) / 2; let buttonWidth = (viewContentWidth - viewContentPadding) / 2;
if (e.clientY > maxTop - 30 && e.clientY < maxTop) { if (e.clientY > maxTop - 30 && e.clientY < maxTop) {
// 暂不升级 // 暂不升级
if (e.clientX > viewContentPadding && e.clientX < maxLeft - buttonWidth - viewContentPadding) { if (
e.clientX > viewContentPadding &&
e.clientX < maxLeft - buttonWidth - viewContentPadding
) {
// 立即升级 // 立即升级
if (platform == "android") { if (platform == "android") {
maskLayer.hide(); maskLayer.hide();
@ -436,12 +467,12 @@ function updatePopup(data, callback) {
} }
plus.runtime.openURL(downloadUrl); plus.runtime.openURL(downloadUrl);
} }
} }
} }
}); });
// 点击遮罩层 // 点击遮罩层
maskLayer.addEventListener("click", function () { //处理遮罩层点击 maskLayer.addEventListener("click", function () {
//处理遮罩层点击
if (!data.forceUpdate) { if (!data.forceUpdate) {
maskLayer.hide(); maskLayer.hide();
popupView.hide(); popupView.hide();
@ -461,81 +492,83 @@ function downloadPopupDrawing(data) {
// 弹窗容器的Padding // 弹窗容器的Padding
const viewContentPadding = 20; const viewContentPadding = 20;
// 弹窗容器的宽度 // 弹窗容器的宽度
const viewContentWidth = popupViewWidth - (viewContentPadding * 2); const viewContentWidth = popupViewWidth - viewContentPadding * 2;
// 弹窗容器高度 // 弹窗容器高度
let popupViewHeight = viewContentPadding * 3 + 60; let popupViewHeight = viewContentPadding * 3 + 60;
let progressTip = data.progressTip || "准备下载..."; let progressTip = data.progressTip || "准备下载...";
let contentText = data.contentText || "正在为您更新,请耐心等待"; let contentText = data.contentText || "正在为您更新,请耐心等待";
let elementList = [{ let elementList = [
tag: 'rect', //背景色 {
color: '#FFFFFF', tag: "rect", //背景色
color: "#FFFFFF",
rectStyles: { rectStyles: {
radius: "8px" radius: "8px",
} },
}, },
{ {
tag: 'font', tag: "font",
id: 'title', id: "title",
text: "升级APP", text: "升级APP",
textStyles: { textStyles: {
size: '16px', size: "16px",
color: "#333", color: "#333",
weight: "bold", weight: "bold",
verticalAlign: "middle", verticalAlign: "middle",
whiteSpace: "normal" whiteSpace: "normal",
}, },
position: { position: {
top: viewContentPadding + 'px', top: viewContentPadding + "px",
height: "30px", height: "30px",
} },
}, },
{ {
tag: 'font', tag: "font",
id: 'content', id: "content",
text: contentText, text: contentText,
textStyles: { textStyles: {
size: '14px', size: "14px",
color: "#333", color: "#333",
verticalAlign: "middle", verticalAlign: "middle",
whiteSpace: "normal" whiteSpace: "normal",
}, },
position: { position: {
top: viewContentPadding * 2 + 30 + 'px', top: viewContentPadding * 2 + 30 + "px",
height: "20px", height: "20px",
} },
} },
]; ];
// 是否有进度条 // 是否有进度条
if (data.progress) { if (data.progress) {
popupViewHeight += viewContentPadding + 40; popupViewHeight += viewContentPadding + 40;
elementList = elementList.concat([{ elementList = elementList.concat([
tag: 'font', {
id: 'progressValue', tag: "font",
id: "progressValue",
text: progressTip, text: progressTip,
textStyles: { textStyles: {
size: '14px', size: "14px",
color: $mainColor, color: $mainColor,
whiteSpace: "normal" whiteSpace: "normal",
}, },
position: { position: {
top: viewContentPadding * 4 + 20 + 'px', top: viewContentPadding * 4 + 20 + "px",
height: "30px" height: "30px",
} },
}, },
{ {
tag: 'rect', //绘制进度条背景 tag: "rect", //绘制进度条背景
id: 'progressBg', id: "progressBg",
rectStyles: { rectStyles: {
radius: "4px", radius: "4px",
borderColor: "#f1f1f1", borderColor: "#f1f1f1",
borderWidth: "1px", borderWidth: "1px",
}, },
position: { position: {
top: viewContentPadding * 4 + 60 + 'px', top: viewContentPadding * 4 + 60 + "px",
left: viewContentPadding + "px", left: viewContentPadding + "px",
width: viewContentWidth + "px", width: viewContentWidth + "px",
height: "8px" height: "8px",
} },
}, },
]); ]);
} }
@ -603,39 +636,39 @@ function downloadPopupDrawing(data) {
// } // }
// } // }
// ]); // ]);
} }
if (data.buttonNum == 1) { if (data.buttonNum == 1) {
popupViewHeight += viewContentPadding + 40; popupViewHeight += viewContentPadding + 40;
elementList = elementList.concat([{ elementList = elementList.concat([
tag: 'rect', //绘制底边按钮 {
tag: "rect", //绘制底边按钮
rectStyles: { rectStyles: {
radius: "6px", radius: "6px",
color: $mainColor color: $mainColor,
}, },
position: { position: {
bottom: viewContentPadding + 'px', bottom: viewContentPadding + "px",
left: viewContentPadding + "px", left: viewContentPadding + "px",
width: viewContentWidth + "px", width: viewContentWidth + "px",
height: "40px" height: "40px",
} },
}, },
{ {
tag: 'font', tag: "font",
id: 'confirmText', id: "confirmText",
text: "关闭", text: "关闭",
textStyles: { textStyles: {
size: '14px', size: "14px",
color: "#FFF", color: "#FFF",
lineSpacing: "0%", lineSpacing: "0%",
}, },
position: { position: {
bottom: viewContentPadding + 'px', bottom: viewContentPadding + "px",
left: viewContentPadding + "px", left: viewContentPadding + "px",
width: viewContentWidth + "px", width: viewContentWidth + "px",
height: "40px" height: "40px",
} },
} },
]); ]);
} }
return { return {
@ -644,25 +677,28 @@ function downloadPopupDrawing(data) {
screenHeight: screenHeight, screenHeight: screenHeight,
viewContentWidth: viewContentWidth, viewContentWidth: viewContentWidth,
viewContentPadding: viewContentPadding, viewContentPadding: viewContentPadding,
elementList: elementList elementList: elementList,
}; };
} }
// 文件下载的弹窗 // 文件下载的弹窗
function downloadPopup(data, callback, cancelCallback, rebootCallback) { function downloadPopup(data, callback, cancelCallback, rebootCallback) {
// 弹窗遮罩层 // 弹窗遮罩层
let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层 let maskLayer = new plus.nativeObj.View("maskLayer", {
top: '0px', //先创建遮罩层
left: '0px', top: "0px",
height: '100%', left: "0px",
width: '100%', height: "100%",
backgroundColor: 'rgba(0,0,0,0.5)' width: "100%",
backgroundColor: "rgba(0,0,0,0.5)",
}); });
let popupViewData = downloadPopupDrawing(data); let popupViewData = downloadPopupDrawing(data);
// 弹窗内容 // 弹窗内容
let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单 let popupView = new plus.nativeObj.View("popupView", {
//创建底部图标菜单
tag: "rect", tag: "rect",
top: (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px", top:
left: '15%', (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px",
left: "15%",
height: popupViewData.popupViewHeight + "px", height: popupViewData.popupViewHeight + "px",
width: "70%", width: "70%",
}); });
@ -676,26 +712,35 @@ function downloadPopup(data, callback, cancelCallback, rebootCallback) {
} }
popupView.draw(popupViewData.elementList); popupView.draw(popupViewData.elementList);
popupView.addEventListener("click", function (e) { popupView.addEventListener("click", function (e) {
let maxTop = popupViewData.popupViewHeight - popupViewData.viewContentPadding; let maxTop =
let maxLeft = popupViewData.popupViewWidth - popupViewData.viewContentPadding; popupViewData.popupViewHeight - popupViewData.viewContentPadding;
let maxLeft =
popupViewData.popupViewWidth - popupViewData.viewContentPadding;
if (e.clientY > maxTop - 40 && e.clientY < maxTop) { if (e.clientY > maxTop - 40 && e.clientY < maxTop) {
if (buttonNum == 1) { if (buttonNum == 1) {
// 单按钮 // 单按钮
if (e.clientX > popupViewData.viewContentPadding && e.clientX < maxLeft) { if (
e.clientX > popupViewData.viewContentPadding &&
e.clientX < maxLeft
) {
maskLayer.hide(); maskLayer.hide();
popupView.hide(); popupView.hide();
} }
} else if (buttonNum == 2) { } else if (buttonNum == 2) {
// 双按钮 // 双按钮
let buttonWidth = (popupViewData.viewContentWidth - popupViewData.viewContentPadding) / 2; let buttonWidth =
if (e.clientX > popupViewData.viewContentPadding && e.clientX < maxLeft - buttonWidth - popupViewData.viewContentPadding) { (popupViewData.viewContentWidth - popupViewData.viewContentPadding) /
2;
if (
e.clientX > popupViewData.viewContentPadding &&
e.clientX < maxLeft - buttonWidth - popupViewData.viewContentPadding
) {
maskLayer.hide(); maskLayer.hide();
popupView.hide(); popupView.hide();
//cancelCallback && cancelCallback(); //cancelCallback && cancelCallback();
} else if (e.clientX > maxLeft - buttonWidth && e.clientX < maxLeft) { } else if (e.clientX > maxLeft - buttonWidth && e.clientX < maxLeft) {
maskLayer.hide(); maskLayer.hide();
popupView.hide(); popupView.hide();
} }
} }
} }
@ -711,62 +756,68 @@ function downloadPopup(data, callback, cancelCallback, rebootCallback) {
progressValue = res.progressValue; progressValue = res.progressValue;
// 绘制进度条 // 绘制进度条
progressElement.push({ progressElement.push({
tag: 'rect', //绘制进度条背景 tag: "rect", //绘制进度条背景
id: 'progressValueBg', id: "progressValueBg",
rectStyles: { rectStyles: {
radius: "4px", radius: "4px",
color: $mainColor color: $mainColor,
}, },
position: { position: {
top: popupViewData.viewContentPadding * 4 + 60 + 'px', top: popupViewData.viewContentPadding * 4 + 60 + "px",
left: popupViewData.viewContentPadding + "px", left: popupViewData.viewContentPadding + "px",
width: popupViewData.viewContentWidth * (res.progressValue / 100) + "px", width:
height: "8px" popupViewData.viewContentWidth * (res.progressValue / 100) + "px",
} height: "8px",
},
}); });
} }
if (res.progressTip) { if (res.progressTip) {
progressTip = res.progressTip; progressTip = res.progressTip;
progressElement.push({ progressElement.push({
tag: 'font', tag: "font",
id: 'progressValue', id: "progressValue",
text: res.progressTip, text: res.progressTip,
textStyles: { textStyles: {
size: '14px', size: "14px",
color: $mainColor, color: $mainColor,
whiteSpace: "normal" whiteSpace: "normal",
}, },
position: { position: {
top: popupViewData.viewContentPadding * 4 + 20 + 'px', top: popupViewData.viewContentPadding * 4 + 20 + "px",
height: "30px" height: "30px",
} },
}); });
} }
if (res.contentText) { if (res.contentText) {
contentText = res.contentText; contentText = res.contentText;
progressElement.push({ progressElement.push({
tag: 'font', tag: "font",
id: 'content', id: "content",
text: res.contentText, text: res.contentText,
textStyles: { textStyles: {
size: '16px', size: "16px",
color: "#333", color: "#333",
whiteSpace: "normal" whiteSpace: "normal",
}, },
position: { position: {
top: popupViewData.viewContentPadding * 2 + 30 + 'px', top: popupViewData.viewContentPadding * 2 + 30 + "px",
height: "30px", height: "30px",
} },
}); });
} }
if (res.buttonNum >= 0 && buttonNum != res.buttonNum) { if (res.buttonNum >= 0 && buttonNum != res.buttonNum) {
buttonNum = res.buttonNum; buttonNum = res.buttonNum;
popupView.reset(); popupView.reset();
popupViewData = downloadPopupDrawing(Object.assign({ popupViewData = downloadPopupDrawing(
Object.assign(
{
progressValue: progressValue, progressValue: progressValue,
progressTip: progressTip, progressTip: progressTip,
contentText: contentText, contentText: contentText,
}, res)); },
res
)
);
let newElement = []; let newElement = [];
popupViewData.elementList.map((item, index) => { popupViewData.elementList.map((item, index) => {
let have = false; let have = false;
@ -782,8 +833,10 @@ function downloadPopup(data, callback, cancelCallback, rebootCallback) {
progressElement = newElement.concat(progressElement); progressElement = newElement.concat(progressElement);
popupView.setStyle({ popupView.setStyle({
tag: "rect", tag: "rect",
top: (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px", top:
left: '15%', (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 +
"px",
left: "15%",
height: popupViewData.popupViewHeight + "px", height: popupViewData.popupViewHeight + "px",
width: "70%", width: "70%",
}); });
@ -795,14 +848,15 @@ function downloadPopup(data, callback, cancelCallback, rebootCallback) {
cancel: function () { cancel: function () {
maskLayer.hide(); maskLayer.hide();
popupView.hide(); popupView.hide();
} },
}); });
} }
export default function (isPrompt = false) { export default function (isPrompt = false) {
getCurrentNo(version => { getCurrentNo((version) => {
getServerNo( res => { getServerNo((res) => {
if (res.versionCode.replace(/\./g, "") < version.versionCode) {
if( res.version.replace(/\./g, "") > version.versionCode){return false} return false;
}
if (res.forceUpdate) { if (res.forceUpdate) {
if (/\.wgt$/i.test(res.downloadUrl)) { if (/\.wgt$/i.test(res.downloadUrl)) {
@ -815,7 +869,7 @@ export default function (isPrompt = false) {
} else { } else {
updatePopup(res, function () { updatePopup(res, function () {
plus.runtime.openURL(res.downloadUrl); plus.runtime.openURL(res.downloadUrl);
}) });
// uni.showLoading({ // uni.showLoading({
// title: "升级中......", // title: "升级中......",
// mask: true // mask: true