uniapp update package js component

let server_url = '' //server_url server domain name or interface address
// Compare version numbers
function compare(v1, v2) {<!-- -->
    if (v1 === v2) {<!-- -->
        return 0
    }
    const arr1 = v1. split(/\D/)
    const arr2 = v2. split(/\D/)

    // The default version number is the same length
    for (let i = 0; i < arr1. length;) {<!-- -->
        // String subtraction implicitly converts strings to numbers
        if (arr1[i] - arr2[i] > 0){<!-- -->
            return 1
        }
        if (arr1[i] - arr2[i] < 0) {<!-- -->
            return -1
        }
        if (arr1[i] === arr2[i]) {<!-- -->
            i + +
        }
    }
}

// #ifdef APP-PLUS
const componentConfig = {<!-- -->
/**
* version app version information
* callback exists update callback
*/
getServerNo(version, isPrompt = false, callback) {<!-- -->
// if(process.env.NODE_ENV === 'development'){<!-- -->
// return false
// }
// Determine the version number used based on the domain name of the interface environment. The default development environment version number is not updated. The test production environment version number is manifest.json; the version number in
let versionName = server_url === 'Development Domain Name' ? '1.3.4' : version.versionName
let appId = process.env.NODE_ENV === 'development' ? 'Include body appId' : version.appId
// Query the version number of the package name, the interface needs to be replaced
selectPackage({<!-- -->
packageName: appId
}).then(res => {<!-- -->
console.log(res, '----------------------')
let data = res. data[0]
/* data description of res
| appId | y | String | app package name
| appIcon | y | String | app icon
| appName | y | String | application name
| versionName | y | String | version name |
| versionInfo | y | String | version information |
| updateType | y | String | forcibly = force update, solicit = pop-up confirmation update, silent = silent update |
| downloadApkUrl | y | String | Version download link (for IOS installation package updates, please put the jump store app store link, and for Android apk and wgt files, put the file download link) |
| downloadWgtUrl | N | String | The wgt file can be used for silent update and does not need to be uploaded. When wgt exists, the wgt update is used by default
*/
// Call the interface to upload the data below the appId callback
let newVersion = data. packageEdition. replace('v','')
let type = compare(newVersion,versionName)
//type ==0 means the version number is the same, update is not allowed
if (type != 0) {<!-- -->
callback({<!-- -->
versionName: versionName,
versionInfo: '',
updateType: '',
downloadApkUrl: '',
downloadWgtUrl: ''//type == -1 //The version number is smaller than the current version, it is not allowed to use wgt, the whole package must be returned, even if there is a wgt package, it will not be assigned
})
}
\t\t\t
})


},
appUpdateColor: "f00",
// pop-up window icon (the default icon is displayed without filling, link configuration example: '/static/demo/ic_attention.png')
appUpdateIcon: ''
}
const platform = uni.getSystemInfoSync().platform;
// main color
const $mainColor = componentConfig.appUpdateColor ? componentConfig.appUpdateColor : "FF5B78";
// Popup icon url
const $iconUrl = componentConfig.appUpdateIcon ? componentConfig.appUpdateIcon :
"/static/ic_ar.png";

// Get the version number of the current application
export const getCurrentNo = function(callback) {<!-- -->
// Get the version number of the local application resource
try {<!-- -->
plus.runtime.getProperty(plus.runtime.appid, function(inf) {<!-- -->
callback & amp; & amp; callback({<!-- -->
versionCode: inf.versionCode,
versionName: inf.version,
appId: inf.appid
});
});
} catch (e) {<!-- -->
console. log(e)
}
}
// Download the application resource package (wgt file) from the server
const getDownload = function(data) {<!-- -->
let dtask;
if (data.updateType == 'forcibly' || data.updateType == 'solicit') {<!-- -->
let popupData = {<!-- -->
progress: true,
buttonNum: 2
};
if (data. updateType == 'forcibly') {<!-- -->
popupData. buttonNum = 0;
}
let lastProgressValue = 0;
let popupObj = downloadPopup(popupData);
dtask = plus.downloader.createDownload(data.downloadUrl, {<!-- -->}, function(download, status) {<!-- -->
console.log(download, status)
if (status == 200) {<!-- -->
popupObj.change({<!-- -->
progressValue: 100,
progressTip: "Installing files...",
progress: true,
buttonNum: 0
});
plus.runtime.install(download.filename, {<!-- -->}, function() {<!-- -->
popupObj.change({<!-- -->
contentText: "App resource update completed!",
buttonNum: 1,
progress: false
});
}, function(e) {<!-- -->
console. log(e)
popupObj. cancel();
plus.nativeUI.alert("Failed to install file [" + e.code + "]: " + e.message);
});
} else {<!-- -->
popupObj.change({<!-- -->
contentText: "File download failed...",
buttonNum: 1,
progress: false
});
}
});
//The following is to add parameters in the request header, which is applicable to the request file stream
//dtask.setRequestHeader("chlCode", "001");
//dtask.setRequestHeader("auth", getToken());
//dtask.setRequestHeader("content-type", 'application/octet-stream');
//dtask.setRequestHeader("isFile", '1');
dtask.start();
dtask.addEventListener("statechanged", function(task, status) {<!-- -->
console. log(task)
switch (task.state) {<!-- -->
case 1: // start
popupObj.change({<!-- -->
progressValue: 0,
progressTip: "Ready to download...",
progress: true
});
break;
case 2: // already connected to the server
popupObj.change({<!-- -->
progressValue: 0,
progressTip: "Start downloading...",
progress: true
});
break;
case 3:
const progress = parseInt(task.downloadedSize / task.totalSize * 100);
if (progress - lastProgressValue >= 2) {<!-- -->
lastProgressValue = progress;
popupObj.change({<!-- -->
progressValue: progress,
progressTip: "Downloaded" + progress + "%",
progress: true
});
}
break;
}
});
// cancel download
popupObj. cancelDownload = function() {<!-- -->
dtask & amp; & amp; dtask. abort();
uni.showToast({<!-- -->
title: "Download canceled",
icon: "none"
});
}
// Restart APP
popupObj. reboot = function() {<!-- -->
plus.runtime.restart();
}
} else if (data. updateType == "silent") {<!-- -->
dtask = plus.downloader.createDownload(data.downloadUrl, {<!-- -->
filename: "_doc/update/"
}, function(download, status) {<!-- -->
if (status == 200) {<!-- -->
plus.runtime.install(download.filename, {<!-- -->}, function() {<!-- -->
console.log("Application resource update completed");
}, function(e) {<!-- -->
plus.nativeUI.alert("Failed to install file [" + e.code + "]: " + e.message);
});
} else {<!-- -->
plus.nativeUI.alert("File download failed...");
}
});
//The following is to add parameters in the request header, which is applicable to the request file stream
//dtask.setRequestHeader("chlCode", "001");
//dtask.setRequestHeader("auth", getToken());
//dtask.setRequestHeader("content-type", 'application/octet-stream');
//dtask.setRequestHeader("isFile", '1');
dtask.start();
}
}
// wrap text
function drawtext(text, maxWidth) {<!-- -->
let textArr = text. split("");
let len = textArr. length;
// last node
let previousNode = 0;
// record node width
let nodeWidth = 0;
// text wrapping array
let rowText = [];
// If it is a letter, save the length on the side
let letterWidth = 0;
// Chinese character width
let chineseWidth = 14;
// otherFont width
let otherWidth = 7;
for (let i = 0; i < len; i ++ ) {<!-- -->
if (/[\一-\龥]|[\︰-\?]/g.test(textArr[i])) {<!-- -->
if (letterWidth > 0) {<!-- -->
if (nodeWidth + chineseWidth + letterWidth * otherWidth > maxWidth) {<!-- -->
rowText.push({<!-- -->
type: "text",
content: text.substring(previousNode, i)
});
previousNode = i;
nodeWidth = chineseWidth;
letterWidth = 0;
} else {<!-- -->
nodeWidth + = chineseWidth + letterWidth * otherWidth;
letterWidth = 0;
}
} else {<!-- -->
if (nodeWidth + chineseWidth > maxWidth) {<!-- -->
rowText.push({<!-- -->
type: "text",
content: text.substring(previousNode, i)
});
previousNode = i;
nodeWidth = chineseWidth;
} else {<!-- -->
nodeWidth += chineseWidth;
}
}
} else {<!-- -->
if (/\
/g.test(textArr[i])) {<!-- -->
rowText.push({<!-- -->
type: "break",
content: text.substring(previousNode, i)
});
previousNode = i + 1;
nodeWidth = 0;
letterWidth = 0;
} else if (textArr[i] == "" & amp; & amp; textArr[i + 1] == "n") {<!-- -->
rowText.push({<!-- -->
type: "break",
content: text.substring(previousNode, i)
});
previousNode = i + 2;
nodeWidth = 0;
letterWidth = 0;
} else if (/[a-zA-Z0-9]/g.test(textArr[i])) {<!-- -->
letterWidth += 1;
if (nodeWidth + letterWidth * otherWidth > maxWidth) {<!-- -->
rowText.push({<!-- -->
type: "text",
content: text.substring(previousNode, i + 1 - letterWidth)
});
previousNode = i + 1 - letterWidth;
nodeWidth = letterWidth * otherWidth;
letterWidth = 0;
}
} else {<!-- -->
if (nodeWidth + otherWidth > maxWidth) {<!-- -->
rowText.push({<!-- -->
type: "text",
content: text.substring(previousNode, i)
});
previousNode = i;
nodeWidth = otherWidth;
} else {<!-- -->
nodeWidth += otherWidth;
}
}
}
}
if (previousNode < len) {<!-- -->
rowText.push({<!-- -->
type: "text",
content: text.substring(previousNode, len)
});
}
return rowText;
}
// Whether to update the popup window
function updatePopup(data, callback) {<!-- -->
// Pop-up window mask layer
let maskLayer = new plus.nativeObj.View("maskLayer", {<!-- --> //Create the mask layer first
top: '0px',
left: '0px',
height: '100%',
width: '100%',
backgroundColor: 'rgba(0,0,0,0.5)'
});

// The following is the nview drawing layout of the calculation menu, which is a fixed algorithm, and the user has nothing to do
const screenWidth = plus. screen. resolutionWidth;
const screenHeight = plus. screen. resolutionHeight;
// popup window container width
const popupViewWidth = screenWidth * 0.7;
// Padding of the popup container
const viewContentPadding = 20;
// The width of the popup window container
const viewContentWidth = parseInt(popupViewWidth - (viewContentPadding * 2));
// list of descriptions
const descriptionList = drawtext(data.versionInfo, viewContentWidth);
// popup window container height
let popupViewHeight = 80 + 20 + 20 + 90 + 10;

let popupViewContentList = [{<!-- -->
src: $iconUrl,
id: "logo",
tag: "img",
position: {<!-- -->
top: "0px",
left: (popupViewWidth - 124) / 2 + "px",
width: "124px",
height: "80px",
}
},
{<!-- -->
tag: 'font',
id: 'title',
text: "New version found" + data.versionName,
textStyles: {<!-- -->
size: '18px',
color: "#333",
weight: "bold",
whiteSpace: "normal"
},
position: {<!-- -->
top: '90px',
left: viewContentPadding + "px",
width: viewContentWidth + "px",
height: "30px",
}
}
];
const textHeight = 18;
let contentTop = 130;
descriptionList.forEach((item, index) => {<!-- -->
if (index > 0) {<!-- -->
popupViewHeight += textHeight;
contentTop += textHeight;
}
popupViewContentList.push({<!-- -->
tag: 'font',
id: 'content' + index + 1,
text: item. content,
textStyles: {<!-- -->
size: '14px',
color: "#666",
lineSpacing: "50%",
align: "left"
},
position: {<!-- -->
top: contentTop + "px",
left: viewContentPadding + "px",
width: viewContentWidth + "px",
height: textHeight + "px",
}
});
if (item.type == "break") {<!-- -->
contentTop += 10;
popupViewHeight += 10;
}
});

if (data. updateType == "forcibly") {<!-- -->
popupViewContentList.push({<!-- -->
tag: 'rect', // draw bottom button
rectStyles: {<!-- -->
radius: "6px",
color: $mainColor
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: viewContentPadding + "px",
width: viewContentWidth + "px",
height: "30px"
}
});
popupViewContentList.push({<!-- -->
tag: 'font',
id: 'confirmText',
text: "Upgrade Now",
textStyles: {<!-- -->
size: '14px',
color: "#FFF",
lineSpacing: "0%",
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: viewContentPadding + "px",
width: viewContentWidth + "px",
height: "30px"
}
});
} else {<!-- -->
// draw bottom button
popupViewContentList.push({<!-- -->
tag: 'rect',
id: 'cancelBox',
rectStyles: {<!-- -->
radius: "3px",
borderColor: "#f1f1f1",
borderWidth: "1px",
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: viewContentPadding + "px",
width: (viewContentWidth - viewContentPadding) / 2 + "px",
height: "30px",
}
});
popupViewContentList.push({<!-- -->
tag: 'rect',
id: 'confirmBox',
rectStyles: {<!-- -->
radius: "3px",
color: $mainColor,
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
width: (viewContentWidth - viewContentPadding) / 2 + "px",
height: "30px",
}
});
popupViewContentList.push({<!-- -->
tag: 'font',
id: 'cancelText',
text: "No upgrade for now",
textStyles: {<!-- -->
size: '14px',
color: "#666",
lineSpacing: "0%",
whiteSpace: "normal"
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: viewContentPadding + "px",
width: (viewContentWidth - viewContentPadding) / 2 + "px",
height: "30px",
}
});
popupViewContentList.push({<!-- -->
tag: 'font',
id: 'confirmText',
text: "Upgrade Now",
textStyles: {<!-- -->
size: '14px',
color: "#FFF",
lineSpacing: "0%",
whiteSpace: "normal"
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
width: (viewContentWidth - viewContentPadding) / 2 + "px",
height: "30px",
}
});
}
// Popup content
let popupView = new plus.nativeObj.View("popupView", {<!-- --> //Create bottom icon menu
tag: "rect",
top: (screenHeight - popupViewHeight) / 2 + "px",
left: '15%',
height: popupViewHeight + "px",
width: "70%"
});
// draw white background
popupView.drawRect({<!-- -->
color: "#FFFFFF",
radius: "8px"
}, {<!-- -->
top: "40px",
height: popupViewHeight - 40 + "px",
});
console.log(popupViewContentList)
popupView.draw(popupViewContentList);
popupView. addEventListener("click", function(e) {<!-- -->
let maxTop = popupViewHeight - viewContentPadding;
let maxLeft = popupViewWidth - viewContentPadding;
let buttonWidth = (viewContentWidth - viewContentPadding) / 2;
if (e.clientY > maxTop - 30 & amp; & amp; e.clientY < maxTop) {<!-- -->
if (data. updateType == "forcibly") {<!-- -->
if (e.clientX > viewContentPadding & amp; & amp; e.clientX < maxLeft) {<!-- -->
\t\t\t\t\t// upgrade immediately
maskLayer.hide();
popupView.hide();
callback & amp; & amp; callback();
}
} else {<!-- -->
// don't upgrade yet
if (e.clientX > viewContentPadding & amp; & amp; e.clientX < maxLeft - buttonWidth - viewContentPadding) {<!-- -->
maskLayer.hide();
popupView.hide();
} else if (e.clientX > maxLeft - buttonWidth & amp; & amp; e.clientX < maxLeft) {<!-- -->
\t\t\t\t\t// upgrade immediately
maskLayer.hide();
popupView.hide();
callback & amp; & amp; callback();
}
}

}
});
if (data. updateType == "solicit") {<!-- -->
// Click on the mask layer
maskLayer.addEventListener("click", function() {<!-- --> //Process mask layer click
maskLayer.hide();
popupView.hide();
});
}
// show popup
maskLayer. show();
popupView. show();
}
// Pop-up drawing for file download
function downloadPopupDrawing(data) {<!-- -->
// The following is the nview drawing layout of the calculation menu, which is a fixed algorithm, and the user has nothing to do
const screenWidth = plus. screen. resolutionWidth;
const screenHeight = plus. screen. resolutionHeight;
// popup window container width
const popupViewWidth = screenWidth * 0.7;
// Padding of the popup container
const viewContentPadding = 20;
// The width of the popup window container
const viewContentWidth = popupViewWidth - (viewContentPadding * 2);
// popup window container height
let popupViewHeight = viewContentPadding * 3 + 60;
let progressTip = data.progressTip || "Ready to download...";
let contentText = data.contentText || "Updating for you, please be patient";
let elementList = [{<!-- -->
tag: 'rect', //background color
color: '#FFFFFF',
rectStyles: {<!-- -->
radius: "8px"
}
},
{<!-- -->
tag: 'font',
id: 'title',
text: "Upgrade APP",
textStyles: {<!-- -->
size: '16px',
color: "#333",
weight: "bold",
verticalAlign: "middle",
whiteSpace: "normal"
},
position: {<!-- -->
top: viewContentPadding + 'px',
height: "30px",
}
},
{<!-- -->
tag: 'font',
id: 'content',
text: contentText,
textStyles: {<!-- -->
size: '14px',
color: "#333",
verticalAlign: "middle",
whiteSpace: "normal"
},
position: {<!-- -->
top: viewContentPadding * 2 + 30 + 'px',
height: "20px",
}
}
];
// Whether there is a progress bar
if (data.progress) {<!-- -->
popupViewHeight += viewContentPadding + 40;
elementList = elementList.concat([{<!-- -->
tag: 'font',
id: 'progressValue',
text: progressTip,
textStyles: {<!-- -->
size: '14px',
color: $mainColor,
whiteSpace: "normal"
},
position: {<!-- -->
top: viewContentPadding * 4 + 20 + 'px',
height: "30px"
}
},
{<!-- -->
tag: 'rect', //draw progress bar background
id: 'progressBg',
rectStyles: {<!-- -->
radius: "4px",
borderColor: "#f1f1f1",
borderWidth: "1px",
},
position: {<!-- -->
top: viewContentPadding * 4 + 60 + 'px',
left: viewContentPadding + "px",
width: viewContentWidth + "px",
height: "8px"
}
},
]);
}
if (data. buttonNum == 2) {<!-- -->
popupViewHeight += viewContentPadding + 30;
elementList = elementList.concat([{<!-- -->
tag: 'rect', // draw bottom button
rectStyles: {<!-- -->
radius: "3px",
borderColor: "#f1f1f1",
borderWidth: "1px",
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: viewContentPadding + "px",
width: (viewContentWidth - viewContentPadding) / 2 + "px",
height: "30px"
}
},
{<!-- -->
tag: 'rect', // draw bottom button
rectStyles: {<!-- -->
radius: "3px",
color: $mainColor
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
width: (viewContentWidth - viewContentPadding) / 2 + "px",
height: "30px"
}
},
{<!-- -->
tag: 'font',
id: 'cancelText',
text: "Cancel Download",
textStyles: {<!-- -->
size: '14px',
color: "#666",
lineSpacing: "0%",
whiteSpace: "normal"
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: viewContentPadding + "px",
width: (viewContentWidth - viewContentPadding) / 2 + "px",
height: "30px",
}
},
{<!-- -->
tag: 'font',
id: 'confirmText',
text: "Background download",
textStyles: {<!-- -->
size: '14px',
color: "#FFF",
lineSpacing: "0%",
whiteSpace: "normal"
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
width: (viewContentWidth - viewContentPadding) / 2 + "px",
height: "30px",
}
}
]);
}
if (data. buttonNum == 1) {<!-- -->
popupViewHeight += viewContentPadding + 40;
elementList = elementList.concat([{<!-- -->
tag: 'rect', // draw bottom button
rectStyles: {<!-- -->
radius: "6px",
color: $mainColor
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: viewContentPadding + "px",
width: viewContentWidth + "px",
height: "40px"
}
},
{<!-- -->
tag: 'font',
id: 'confirmText',
text: "Close",
textStyles: {<!-- -->
size: '14px',
color: "#FFF",
lineSpacing: "0%",
},
position: {<!-- -->
bottom: viewContentPadding + 'px',
left: viewContentPadding + "px",
width: viewContentWidth + "px",
height: "40px"
}
}
]);
}
return {<!-- -->
popupViewHeight: popupViewHeight,
popupViewWidth: popupViewWidth,
screenHeight: screenHeight,
viewContentWidth: viewContentWidth,
viewContentPadding: viewContentPadding,
elementList: elementList
};
}
// popup window for file download
function downloadPopup(data) {<!-- -->
// Pop-up window mask layer
let maskLayer = new plus.nativeObj.View("maskLayer", {<!-- --> //Create the mask layer first
top: '0px',
left: '0px',
height: '100%',
width: '100%',
backgroundColor: 'rgba(0,0,0,0.5)'
});
let popupViewData = downloadPopupDrawing(data);
// Popup content
let popupView = new plus.nativeObj.View("popupView", {<!-- --> //Create bottom icon menu
tag: "rect",
top: (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px",
left: '15%',
height: popupViewData. popupViewHeight + "px",
width: "70%",
});
let progressValue = 0;
let progressTip = 0;
let contentText = 0;
let buttonNum = 2;
if (data. buttonNum >= 0) {<!-- -->
buttonNum = data. buttonNum;
}
popupView.draw(popupViewData.elementList);
let callbackData = {<!-- -->
change: function(res) {<!-- -->
let progressElement = [];
if (res. progressValue) {<!-- -->
progressValue = res.progressValue;
// draw the progress bar
progressElement. push({<!-- -->
tag: 'rect', //draw progress bar background
id: 'progressValueBg',
rectStyles: {<!-- -->
radius: "4px",
color: $mainColor
},
position: {<!-- -->
top: popupViewData.viewContentPadding * 4 + 60 + 'px',
left: popupViewData.viewContentPadding + "px",
width: popupViewData.viewContentWidth * (res.progressValue / 100) + "px",
height: "8px"
}
});
}
if (res.progressTip) {<!-- -->
progressTip = res.progressTip;
progressElement. push({<!-- -->
tag: 'font',
id: 'progressValue',
text: res.progressTip,
textStyles: {<!-- -->
size: '14px',
color: $mainColor,
whiteSpace: "normal"
},
position: {<!-- -->
top: popupViewData. viewContentPadding * 4 + 20 + 'px',
height: "30px"
}
});
}
if (res. contentText) {<!-- -->
contentText = res. contentText;
progressElement. push({<!-- -->
tag: 'font',
id: 'content',
text: res. contentText,
textStyles: {<!-- -->
size: '16px',
color: "#333",
whiteSpace: "normal"
},
position: {<!-- -->
top: popupViewData.viewContentPadding * 2 + 30 + 'px',
height: "30px",
}
});
}
if (res. buttonNum >= 0 & amp; & amp; buttonNum != res. buttonNum) {<!-- -->
buttonNum = res. buttonNum;
popupView. reset();
popupViewData = downloadPopupDrawing(Object.assign({<!-- -->
progressValue: progressValue,
progressTip: progressTip,
contentText: contentText,
}, res));
let newElement = [];
popupViewData.elementList.map((item, index) => {<!-- -->
let have = false;
progressElement.forEach((childItem, childIndex) => {<!-- -->
if (item.id == childItem.id) {<!-- -->
have = true;
}
});
if (!have) {<!-- -->
newElement. push(item);
}
});
progressElement = newElement. concat(progressElement);
popupView.setStyle({<!-- -->
tag: "rect",
top: (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px",
left: '15%',
height: popupViewData. popupViewHeight + "px",
width: "70%",
});
popupView. draw(progressElement);
} else {<!-- -->
popupView. draw(progressElement);
}
},
cancel: function() {<!-- -->
maskLayer.hide();
popupView.hide();
}
}
popupView. addEventListener("click", function(e) {<!-- -->
let maxTop = popupViewData.popupViewHeight - popupViewData.viewContentPadding;
let maxLeft = popupViewData.popupViewWidth - popupViewData.viewContentPadding;
if (e.clientY > maxTop - 40 & amp; & amp; e.clientY < maxTop) {<!-- -->
if (buttonNum == 1) {<!-- -->
// single button
if (e.clientX > popupViewData.viewContentPadding & amp; & amp; e.clientX < maxLeft) {<!-- -->
maskLayer.hide();
popupView.hide();
callbackData. reboot();
}
} else if (buttonNum == 2) {<!-- -->
// double button
let buttonWidth = (popupViewData.viewContentWidth - popupViewData.viewContentPadding) / 2;
if (e.clientX > popupViewData.viewContentPadding & amp; & amp; e.clientX < maxLeft - buttonWidth -
popupViewData.viewContentPadding) {<!-- -->
maskLayer.hide();
popupView.hide();
callbackData. cancelDownload();
} else if (e.clientX > maxLeft - buttonWidth & amp; & amp; e.clientX < maxLeft) {<!-- -->
maskLayer.hide();
popupView.hide();
}
}
}
});
// show popup
maskLayer. show();
popupView. show();
// change the progress bar
return callbackData;
}
export default function(isPrompt = false) {<!-- -->
getCurrentNo(versionInfo => {<!-- -->
console.log(versionInfo, '------------')
componentConfig.getServerNo(versionInfo, isPrompt, res => {<!-- -->
console. log(res)
//There is a wgt download address, the default is to use wgt
res.downloadUrl = res.downloadWgtUrl ? res.downloadWgtUrl : res.downloadApkUrl
//Judge whether it is a download address or a file id
if (res.downloadUrl.indexOf('http') == -1) {<!-- -->
res.downloadUrl = server_url + 'interface name'
}
console.log('Download address==================', res.downloadUrl)
if (res. updateType == "forcibly" || res. updateType == "silent") {<!-- -->
if (/\.wgt$/i.test(res.downloadUrl)) {<!-- -->
getDownload(res);
} else if (/\.html$/i.test(res.downloadUrl)) {<!-- -->
plus.runtime.openURL(res.downloadUrl);
} else {<!-- -->
if (platform == "android") {<!-- -->
getDownload(res);
} else {<!-- -->
plus.runtime.openURL(res.downloadUrl);
}
}
\t\t\t\t

} else if (res. updateType == "solicit") {<!-- -->
updatePopup(res, function() {<!-- -->
if (/\.wgt$/i.test(res.downloadUrl)) {<!-- -->
getDownload(res);
} else if (/\.html$/i.test(res.downloadUrl)) {<!-- -->
plus.runtime.openURL(res.downloadUrl);
} else {<!-- -->
if (platform == "android") {<!-- -->
getDownload(res);
} else {<!-- -->
plus.runtime.openURL(res.downloadUrl);
}
}
\t\t\t\t\t
});
}
});
});
}

// #endif