index.js 21 KB

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