APPUpdate.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. /**** 此文件说明请看注释 *****/
  2. // 可以用自己项目的请求方法
  3. // 请求配置说明:https://ext.dcloud.net.cn/plugin?id=822
  4. import { getAppVersion } from '@/api/common';
  5. /**** 结束 *****/
  6. const platform = uni.getSystemInfoSync().platform;
  7. // 主颜色
  8. const $mainColor = "FF5C03";
  9. // 弹窗图标url
  10. const $iconUrl = "./static/images/ic_ar.png";
  11. // 获取当前应用的版本号
  12. export const getCurrentNo = function(callback) {
  13. // 获取本地应用资源版本号
  14. plus.runtime.getProperty(plus.runtime.appid, function(inf) {
  15. callback && callback({
  16. versionCode: inf.versionCode,
  17. versionName: inf.version
  18. });
  19. });
  20. }
  21. // 发起ajax请求获取服务端版本号
  22. export const getServerNo = function(version, isPrompt = false, callback) {
  23. let isAndroid = platform == "android";
  24. let type = isAndroid ? 1 : 2;
  25. getAppVersion(type).then(res => {
  26. if (res.code == 200) {
  27. let cVersion = version.versionCode; //用户当前版本
  28. let appVersion = res.data.versionCode; //升级包版本
  29. if (cVersion < appVersion) {
  30. callback && callback(res.data);
  31. } else if (isPrompt) {
  32. uni.showToast({
  33. title: "当前已是最新版本",
  34. icon: "none"
  35. });
  36. }
  37. } else if (isPrompt) {
  38. uni.showToast({
  39. title: "检查更新失败",
  40. icon: "none"
  41. });
  42. }
  43. }).catch(err => {
  44. if (isPrompt) {
  45. uni.showToast({
  46. title: "检查更新失败",
  47. icon: "none"
  48. });
  49. }
  50. })
  51. }
  52. // 从服务器下载应用资源包(wgt文件)
  53. const getDownload = function(data) {
  54. let downloadUrl = data.url;
  55. if(data.isHotForce && !!data.wgtUrl){
  56. downloadUrl = data.wgtUrl;
  57. }
  58. if(plus.runtime.channel == "baidu" && data.baiduUrl){
  59. downloadUrl = data.baiduUrl;
  60. }
  61. console.log("qxj downloadUrl",downloadUrl);
  62. let popupData = {
  63. progress: true,
  64. buttonNum: 2
  65. };
  66. if(data.isForce || data.isHotForce){
  67. popupData.buttonNum = 0;
  68. }
  69. // 判断是否为 WGT 文件,如果是则隐藏按钮
  70. const isWGT = downloadUrl && String(downloadUrl).match(/\.wgt$/i);
  71. if (isWGT) {
  72. popupData.buttonNum = 0;
  73. } else if (popupData.buttonNum !== 0) {
  74. // 非强制且非WGT,默认显示关闭按钮
  75. popupData.buttonNum = 1;
  76. }
  77. let dtask;
  78. let lastProgressValue = 0;
  79. let popupObj = downloadPopup(popupData);
  80. // 使用 plus.downloader 创建下载任务,参考官方逻辑,虽然官方使用的是 uni.downloadFile,但 plus.downloader 提供更细粒度的控制,且此处已有进度条 UI 适配
  81. dtask = plus.downloader.createDownload(downloadUrl, {
  82. filename: "_doc/update/"
  83. }, function(download, status) {
  84. if (status == 200) {
  85. // 下载完成,如果是 WGT 热更新,立即提示正在安装
  86. const isWGT = download.filename.match(/\.wgt$/i);
  87. if (isWGT) {
  88. popupObj.change({
  89. contentText: "资源更新完成,正在安装...",
  90. buttonNum: 0,
  91. progress: false
  92. });
  93. }
  94. // 安装应用资源包
  95. // force: true 强制安装,忽略版本号校验,解决 -1205 错误(WGT安装包中manifest.json文件的version版本不匹配)
  96. // 因为前置逻辑已经校验过服务端版本号,此处强制安装以确保更新成功
  97. plus.runtime.install(download.filename, {
  98. force: isWGT
  99. }, function() {
  100. // 安装成功
  101. if (isWGT) {
  102. // WGT热更新:提示重启并自动重启
  103. popupObj.change({
  104. contentText: "安装成功,即将重启...",
  105. buttonNum: 0, // 不显示按钮
  106. progress: false
  107. });
  108. setTimeout(() => {
  109. plus.runtime.restart();
  110. }, 500); // 缩短重启等待时间以提升体验
  111. } else {
  112. // APK更新:系统安装界面已调起,直接关闭弹窗即可
  113. // 用户在系统安装界面操作,不需要应用内重启
  114. popupObj.cancel();
  115. }
  116. }, function(e) {
  117. popupObj.cancel();
  118. plus.nativeUI.alert("安装更新失败[" + e.code + "]:" + e.message);
  119. });
  120. } else {
  121. popupObj.change({
  122. contentText: "文件下载失败",
  123. buttonNum: 1,
  124. progress: false
  125. });
  126. }
  127. });
  128. dtask.start();
  129. // 监听下载进度
  130. dtask.addEventListener("statechanged", function(task, status) {
  131. switch (task.state) {
  132. case 1: // 开始
  133. popupObj.change({
  134. progressValue: 0,
  135. progressTip: "准备下载...",
  136. progress: true
  137. });
  138. break;
  139. case 2: // 已连接到服务器
  140. popupObj.change({
  141. progressValue: 0,
  142. progressTip: "开始下载...",
  143. progress: true
  144. });
  145. break;
  146. case 3: // 下载中
  147. if (task.totalSize > 0) {
  148. const progress = parseInt(task.downloadedSize / task.totalSize * 100);
  149. if (progress - lastProgressValue >= 2 || progress === 100) {
  150. lastProgressValue = progress;
  151. popupObj.change({
  152. progressValue: progress,
  153. progressTip: "已下载 " + progress + "%",
  154. progress: true
  155. });
  156. }
  157. }
  158. break;
  159. case 4: // 下载完成
  160. // 已经在 createDownload 回调中处理
  161. break;
  162. }
  163. });
  164. // 取消下载
  165. popupObj.cancelDownload = function(){
  166. dtask && dtask.abort();
  167. uni.showToast({
  168. title: "已取消下载",
  169. icon: "none"
  170. });
  171. }
  172. // 关闭/重启 (虽然此处命名为 reboot,但在失败或完成时可能是关闭弹窗)
  173. popupObj.reboot = function(){
  174. // 这里的逻辑取决于 popupObj.change 后的状态
  175. // 如果是下载失败,点击关闭只是关闭弹窗
  176. // 如果是安装成功,通常会自动重启,或者点击后重启
  177. // 目前 buttonNum=1 时绑定的是 reboot
  178. popupObj.cancel();
  179. }
  180. }
  181. // 文字换行
  182. function drawtext(text, maxWidth) {
  183. let textArr = text.split("");
  184. let len = textArr.length;
  185. // 上个节点
  186. let previousNode = 0;
  187. // 记录节点宽度
  188. let nodeWidth = 0;
  189. // 文本换行数组
  190. let rowText = [];
  191. // 如果是字母,侧保存长度
  192. let letterWidth = 0;
  193. // 汉字宽度
  194. let chineseWidth = 14;
  195. // otherFont宽度
  196. let otherWidth = 7;
  197. for (let i = 0; i < len; i++) {
  198. if (/[\u4e00-\u9fa5]|[\uFE30-\uFFA0]/g.test(textArr[i])) {
  199. if(letterWidth > 0){
  200. if(nodeWidth + chineseWidth + letterWidth * otherWidth > maxWidth){
  201. rowText.push({
  202. type: "text",
  203. content: text.substring(previousNode, i)
  204. });
  205. previousNode = i;
  206. nodeWidth = chineseWidth;
  207. letterWidth = 0;
  208. } else {
  209. nodeWidth += chineseWidth + letterWidth * otherWidth;
  210. letterWidth = 0;
  211. }
  212. }
  213. else {
  214. if(nodeWidth + chineseWidth > maxWidth){
  215. rowText.push({
  216. type: "text",
  217. content: text.substring(previousNode, i)
  218. });
  219. previousNode = i;
  220. nodeWidth = chineseWidth;
  221. }else{
  222. nodeWidth += chineseWidth;
  223. }
  224. }
  225. }
  226. else {
  227. if(/\n/g.test(textArr[i])){
  228. rowText.push({
  229. type: "break",
  230. content: text.substring(previousNode, i)
  231. });
  232. previousNode = i + 1;
  233. nodeWidth = 0;
  234. letterWidth = 0;
  235. }else if(textArr[i] == "\\" && textArr[i + 1] == "n"){
  236. rowText.push({
  237. type: "break",
  238. content: text.substring(previousNode, i)
  239. });
  240. previousNode = i + 2;
  241. nodeWidth = 0;
  242. letterWidth = 0;
  243. }else if(/[a-zA-Z0-9]/g.test(textArr[i])){
  244. letterWidth += 1;
  245. if(nodeWidth + letterWidth * otherWidth > maxWidth){
  246. rowText.push({
  247. type: "text",
  248. content: text.substring(previousNode, i + 1 - letterWidth)
  249. });
  250. previousNode = i + 1 - letterWidth;
  251. nodeWidth = letterWidth * otherWidth;
  252. letterWidth = 0;
  253. }
  254. } else{
  255. if(nodeWidth + otherWidth > maxWidth){
  256. rowText.push({
  257. type: "text",
  258. content: text.substring(previousNode, i)
  259. });
  260. previousNode = i;
  261. nodeWidth = otherWidth;
  262. }else{
  263. nodeWidth += otherWidth;
  264. }
  265. }
  266. }
  267. }
  268. if (previousNode < len) {
  269. rowText.push({
  270. type: "text",
  271. content: text.substring(previousNode, len)
  272. });
  273. }
  274. return rowText;
  275. }
  276. // 是否更新弹窗
  277. function updatePopup(data, callback) {
  278. // 弹窗遮罩层
  279. let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层
  280. top: '0px',
  281. left: '0px',
  282. height: '100%',
  283. width: '100%',
  284. backgroundColor: 'rgba(0,0,0,0.5)'
  285. });
  286. // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心
  287. const screenWidth = plus.screen.resolutionWidth;
  288. const screenHeight = plus.screen.resolutionHeight;
  289. //弹窗容器宽度
  290. const popupViewWidth = screenWidth * 0.7;
  291. // 弹窗容器的Padding
  292. const viewContentPadding = 20;
  293. // 弹窗容器的宽度
  294. const viewContentWidth = parseInt(popupViewWidth - (viewContentPadding * 2));
  295. // 描述的列表
  296. const descriptionList = drawtext(data.note, viewContentWidth);
  297. // 弹窗容器高度
  298. let popupViewHeight = 80 + 20 + 20 + 90 + 10;
  299. let popupViewContentList = [{
  300. src: $iconUrl,
  301. id: "logo",
  302. tag: "img",
  303. position: {
  304. top: "0px",
  305. left: (popupViewWidth - 124) / 2 + "px",
  306. width: "124px",
  307. height: "80px",
  308. }
  309. },
  310. {
  311. tag: 'font',
  312. id: 'title',
  313. text: "发现新版本" + data.versionName,
  314. textStyles: {
  315. size: '18px',
  316. color: "#333",
  317. weight: "bold",
  318. whiteSpace: "normal"
  319. },
  320. position: {
  321. top: '90px',
  322. left: viewContentPadding + "px",
  323. width: viewContentWidth + "px",
  324. height: "30px",
  325. }
  326. }];
  327. const textHeight = 18;
  328. let contentTop = 130;
  329. descriptionList.forEach((item,index) => {
  330. if(index > 0){
  331. popupViewHeight += textHeight;
  332. contentTop += textHeight;
  333. }
  334. popupViewContentList.push({
  335. tag: 'font',
  336. id: 'content' + index + 1,
  337. text: item.content,
  338. textStyles: {
  339. size: '14px',
  340. color: "#666",
  341. lineSpacing: "50%",
  342. align: "left"
  343. },
  344. position: {
  345. top: contentTop + "px",
  346. left: viewContentPadding + "px",
  347. width: viewContentWidth + "px",
  348. height: textHeight + "px",
  349. }
  350. });
  351. if(item.type == "break"){
  352. contentTop += 10;
  353. popupViewHeight += 10;
  354. }
  355. });
  356. // 弹窗内容
  357. let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单
  358. tag: "rect",
  359. top: (screenHeight - popupViewHeight) / 2 + "px",
  360. left: '15%',
  361. height: popupViewHeight + "px",
  362. width: "70%"
  363. });
  364. // 绘制白色背景
  365. popupView.drawRect({
  366. color: "#FFFFFF",
  367. radius: "8px"
  368. }, {
  369. top: "40px",
  370. height: popupViewHeight - 40 + "px",
  371. });
  372. // 绘制底边按钮
  373. popupView.drawRect({
  374. radius: "3px",
  375. borderColor: "#f1f1f1",
  376. borderWidth: "1px",
  377. }, {
  378. bottom: viewContentPadding + 'px',
  379. left: viewContentPadding + "px",
  380. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  381. height: "30px",
  382. });
  383. // 绘制底边按钮
  384. popupView.drawRect({
  385. radius: "3px",
  386. color: $mainColor,
  387. }, {
  388. bottom: viewContentPadding + 'px',
  389. left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
  390. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  391. height: "30px",
  392. });
  393. popupViewContentList.push({
  394. tag: 'font',
  395. id: 'cancelText',
  396. text: "暂不升级",
  397. textStyles: {
  398. size: '14px',
  399. color: "#666",
  400. lineSpacing: "0%",
  401. whiteSpace: "normal"
  402. },
  403. position: {
  404. bottom: viewContentPadding + 'px',
  405. left: viewContentPadding + "px",
  406. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  407. height: "30px",
  408. }
  409. });
  410. popupViewContentList.push({
  411. tag: 'font',
  412. id: 'confirmText',
  413. text: "立即升级",
  414. textStyles: {
  415. size: '14px',
  416. color: "#FFF",
  417. lineSpacing: "0%",
  418. whiteSpace: "normal"
  419. },
  420. position: {
  421. bottom: viewContentPadding + 'px',
  422. left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
  423. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  424. height: "30px",
  425. }
  426. });
  427. popupView.draw(popupViewContentList);
  428. popupView.addEventListener("click", function(e) {
  429. let maxTop = popupViewHeight - viewContentPadding;
  430. let maxLeft = popupViewWidth - viewContentPadding;
  431. let buttonWidth = (viewContentWidth - viewContentPadding) / 2;
  432. if (e.clientY > maxTop - 30 && e.clientY < maxTop) {
  433. // 暂不升级
  434. if (e.clientX > viewContentPadding && e.clientX < maxLeft - buttonWidth - viewContentPadding) {
  435. maskLayer.hide();
  436. popupView.hide();
  437. } else if (e.clientX > maxLeft - buttonWidth && e.clientX < maxLeft) {
  438. // 立即升级
  439. maskLayer.hide();
  440. popupView.hide();
  441. callback && callback();
  442. }
  443. }
  444. });
  445. // 点击遮罩层
  446. maskLayer.addEventListener("click", function() { //处理遮罩层点击
  447. maskLayer.hide();
  448. popupView.hide();
  449. });
  450. // 显示弹窗
  451. maskLayer.show();
  452. popupView.show();
  453. }
  454. // 文件下载的弹窗
  455. function downloadPopup(data) {
  456. // 弹窗遮罩层
  457. let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层
  458. top: '0px',
  459. left: '0px',
  460. height: '100%',
  461. width: '100%',
  462. backgroundColor: 'rgba(0,0,0,0.5)'
  463. });
  464. let popupViewData = downloadPopupDrawing(data);
  465. // 弹窗内容
  466. let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单
  467. tag: "rect",
  468. top: (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px",
  469. left: '15%',
  470. height: popupViewData.popupViewHeight + "px",
  471. width: "70%",
  472. });
  473. let progressValue = 0;
  474. let progressTip = 0;
  475. let contentText = 0;
  476. let buttonNum = 2;
  477. if(data.buttonNum >= 0){
  478. buttonNum = data.buttonNum;
  479. }
  480. popupView.draw(popupViewData.elementList);
  481. let callbackData = {
  482. change: function(res) {
  483. let progressElement = [];
  484. if(res.progressValue){
  485. progressValue = res.progressValue;
  486. // 绘制进度条
  487. progressElement.push({
  488. tag: 'rect', //绘制进度条背景
  489. id: 'progressValueBg',
  490. rectStyles:{
  491. radius: "4px",
  492. color: $mainColor
  493. },
  494. position:{
  495. top: popupViewData.viewContentPadding * 4 + 60 + 'px',
  496. left: popupViewData.viewContentPadding + "px",
  497. width: popupViewData.viewContentWidth * (res.progressValue / 100) + "px",
  498. height: "8px"
  499. }
  500. });
  501. }
  502. if(res.progressTip){
  503. progressTip = res.progressTip;
  504. progressElement.push({
  505. tag: 'font',
  506. id: 'progressValue',
  507. text: res.progressTip,
  508. textStyles: {
  509. size: '14px',
  510. color: $mainColor,
  511. whiteSpace: "normal"
  512. },
  513. position: {
  514. top: popupViewData.viewContentPadding * 4 + 20 + 'px',
  515. height: "30px"
  516. }
  517. });
  518. }
  519. if(res.contentText){
  520. contentText = res.contentText;
  521. progressElement.push({
  522. tag: 'font',
  523. id: 'content',
  524. text: res.contentText,
  525. textStyles: {
  526. size: '16px',
  527. color: "#333",
  528. whiteSpace: "normal"
  529. },
  530. position: {
  531. top: popupViewData.viewContentPadding * 2 + 30 + 'px',
  532. height: "30px",
  533. }
  534. });
  535. }
  536. if(res.buttonNum >= 0 && buttonNum != res.buttonNum){
  537. buttonNum = res.buttonNum;
  538. popupView.reset();
  539. popupViewData = downloadPopupDrawing(Object.assign({
  540. progressValue:progressValue,
  541. progressTip:progressTip,
  542. contentText:contentText,
  543. },res));
  544. let newElement = [];
  545. popupViewData.elementList.map((item,index) => {
  546. let have = false;
  547. progressElement.forEach((childItem,childIndex) => {
  548. if(item.id == childItem.id){
  549. have = true;
  550. }
  551. });
  552. if(!have){
  553. newElement.push(item);
  554. }
  555. });
  556. progressElement = newElement.concat(progressElement);
  557. popupView.setStyle({
  558. tag: "rect",
  559. top: (popupViewData.screenHeight - popupViewData.popupViewHeight) / 2 + "px",
  560. left: '15%',
  561. height: popupViewData.popupViewHeight + "px",
  562. width: "70%",
  563. });
  564. popupView.draw(progressElement);
  565. }else{
  566. popupView.draw(progressElement);
  567. }
  568. },
  569. cancel: function() {
  570. maskLayer.hide();
  571. popupView.hide();
  572. }
  573. }
  574. popupView.addEventListener("click", function(e) {
  575. let maxTop = popupViewData.popupViewHeight - popupViewData.viewContentPadding;
  576. let maxLeft = popupViewData.popupViewWidth - popupViewData.viewContentPadding;
  577. if (e.clientY > maxTop - 40 && e.clientY < maxTop) {
  578. if(buttonNum == 1){
  579. // 单按钮
  580. if (e.clientX > popupViewData.viewContentPadding && e.clientX < maxLeft) {
  581. // maskLayer.hide();
  582. // popupView.hide();
  583. callbackData.reboot();
  584. }
  585. }else if(buttonNum == 2){
  586. // 双按钮
  587. let buttonWidth = (popupViewData.viewContentWidth - popupViewData.viewContentPadding) / 2;
  588. if (e.clientX > popupViewData.viewContentPadding && e.clientX < maxLeft - buttonWidth - popupViewData.viewContentPadding) {
  589. maskLayer.hide();
  590. popupView.hide();
  591. callbackData.cancelDownload();
  592. } else if (e.clientX > maxLeft - buttonWidth && e.clientX < maxLeft) {
  593. maskLayer.hide();
  594. popupView.hide();
  595. }
  596. }
  597. }
  598. });
  599. // 显示弹窗
  600. maskLayer.show();
  601. popupView.show();
  602. // 改变进度条
  603. return callbackData;
  604. }
  605. // 文件下载的弹窗绘图
  606. function downloadPopupDrawing(data){
  607. // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心
  608. const screenWidth = plus.screen.resolutionWidth;
  609. const screenHeight = plus.screen.resolutionHeight;
  610. //弹窗容器宽度
  611. const popupViewWidth = screenWidth * 0.7;
  612. // 弹窗容器的Padding
  613. const viewContentPadding = 20;
  614. // 弹窗容器的宽度
  615. const viewContentWidth = popupViewWidth - (viewContentPadding * 2);
  616. // 弹窗容器高度
  617. let popupViewHeight = viewContentPadding * 3 + 60;
  618. let progressTip = data.progressTip || "准备下载...";
  619. let contentText = data.contentText || "健康守护系统更新中~~请稍候";
  620. let elementList = [
  621. {
  622. tag: 'rect', //背景色
  623. color: '#FFFFFF',
  624. rectStyles:{
  625. radius: "8px"
  626. }
  627. },
  628. {
  629. tag: 'font',
  630. id: 'title',
  631. text: "升级APP",
  632. textStyles: {
  633. size: '16px',
  634. color: "#333",
  635. weight: "bold",
  636. verticalAlign: "middle",
  637. whiteSpace: "normal"
  638. },
  639. position: {
  640. top: viewContentPadding + 'px',
  641. height: "30px",
  642. }
  643. },
  644. {
  645. tag: 'font',
  646. id: 'content',
  647. text: contentText,
  648. textStyles: {
  649. size: '14px',
  650. color: "#333",
  651. verticalAlign: "middle",
  652. whiteSpace: "normal"
  653. },
  654. position: {
  655. top: viewContentPadding * 2 + 30 + 'px',
  656. height: "20px",
  657. }
  658. }
  659. ];
  660. // 是否有进度条
  661. if(data.progress){
  662. popupViewHeight += viewContentPadding + 40;
  663. elementList = elementList.concat([
  664. {
  665. tag: 'font',
  666. id: 'progressValue',
  667. text: progressTip,
  668. textStyles: {
  669. size: '14px',
  670. color: $mainColor,
  671. whiteSpace: "normal"
  672. },
  673. position: {
  674. top: viewContentPadding * 4 + 20 + 'px',
  675. height: "30px"
  676. }
  677. },
  678. {
  679. tag: 'rect', //绘制进度条背景
  680. id: 'progressBg',
  681. rectStyles:{
  682. radius: "4px",
  683. borderColor: "#f1f1f1",
  684. borderWidth: "1px",
  685. },
  686. position:{
  687. top: viewContentPadding * 4 + 60 + 'px',
  688. left: viewContentPadding + "px",
  689. width: viewContentWidth + "px",
  690. height: "8px"
  691. }
  692. },
  693. ]);
  694. }
  695. if (data.buttonNum == 2) {
  696. popupViewHeight += viewContentPadding + 30;
  697. elementList = elementList.concat([
  698. {
  699. tag: 'rect', //绘制底边按钮
  700. rectStyles:{
  701. radius: "3px",
  702. borderColor: "#f1f1f1",
  703. borderWidth: "1px",
  704. },
  705. position:{
  706. bottom: viewContentPadding + 'px',
  707. left: viewContentPadding + "px",
  708. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  709. height: "30px"
  710. }
  711. },
  712. {
  713. tag: 'rect', //绘制底边按钮
  714. rectStyles:{
  715. radius: "3px",
  716. color: $mainColor
  717. },
  718. position:{
  719. bottom: viewContentPadding + 'px',
  720. left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
  721. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  722. height: "30px"
  723. }
  724. },
  725. {
  726. tag: 'font',
  727. id: 'cancelText',
  728. text: "取消下载",
  729. textStyles: {
  730. size: '14px',
  731. color: "#666",
  732. lineSpacing: "0%",
  733. whiteSpace: "normal"
  734. },
  735. position: {
  736. bottom: viewContentPadding + 'px',
  737. left: viewContentPadding + "px",
  738. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  739. height: "30px"
  740. }
  741. },
  742. {
  743. tag: 'font',
  744. id: 'confirmText',
  745. text: "后台下载",
  746. textStyles: {
  747. size: '14px',
  748. color: "#FFF",
  749. lineSpacing: "0%",
  750. whiteSpace: "normal"
  751. },
  752. position: {
  753. bottom: viewContentPadding + 'px',
  754. left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
  755. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  756. height: "30px"
  757. }
  758. }
  759. ]);
  760. }
  761. if (data.buttonNum == 1) {
  762. popupViewHeight += viewContentPadding + 40;
  763. elementList = elementList.concat([
  764. {
  765. tag: 'rect', //绘制底边按钮
  766. rectStyles:{
  767. radius: "6px",
  768. color: $mainColor
  769. },
  770. position:{
  771. bottom: viewContentPadding + 'px',
  772. left: viewContentPadding + "px",
  773. width: viewContentWidth + "px",
  774. height: "40px"
  775. }
  776. },
  777. {
  778. tag: 'font',
  779. id: 'confirmText',
  780. text: "关闭",
  781. textStyles: {
  782. size: '14px',
  783. color: "#FFF",
  784. lineSpacing: "0%",
  785. },
  786. position: {
  787. bottom: viewContentPadding + 'px',
  788. left: viewContentPadding + "px",
  789. width: viewContentWidth + "px",
  790. height: "40px"
  791. }
  792. }
  793. ]);
  794. }
  795. return {
  796. popupViewHeight:popupViewHeight,
  797. popupViewWidth:popupViewWidth,
  798. screenHeight:screenHeight,
  799. viewContentWidth:viewContentWidth,
  800. viewContentPadding:viewContentPadding,
  801. elementList: elementList
  802. };
  803. }
  804. export function openDownload(data) {
  805. getDownload(data);
  806. }
  807. export function appCheckUdate(isPrompt = false) {
  808. getCurrentNo(versionInfo => {
  809. getServerNo(versionInfo, isPrompt, res => {
  810. updatePopup(res, function() {
  811. if (/\.wgt$/i.test(res.url)) {
  812. getDownload(res);
  813. } else if(/\.html$/i.test(res.url)){
  814. plus.runtime.openURL(res.url);
  815. } else {
  816. if (platform == "android") {
  817. getDownload(res);
  818. } else {
  819. plus.runtime.openURL(res.url);
  820. }
  821. }
  822. });
  823. });
  824. });
  825. }