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