APPUpdate.js 21 KB

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