index.js 23 KB

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