ForceUpdate.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import Util from "../../../before/util/Util";
  2. import JsbSystem from "../../../mk/system/JsbSystem";
  3. import { UpdateState } from "../../data/AppData";
  4. import { AUDIO_TYPE } from "../../data/GameData";
  5. /** 最新版本下载 */
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class ForceUpdate extends cc.Component {
  9. @property(cc.Label)
  10. labUpdate: cc.Label = null
  11. @property(cc.Label)
  12. labFix: cc.Label = null
  13. @property(cc.Node)
  14. btnSure: cc.Node = null
  15. @property(cc.Node)
  16. btnCancel: cc.Node = null
  17. @property(cc.Sprite)
  18. fileProgress: cc.Sprite = null
  19. @property(cc.Label)
  20. labPro: cc.Label = null
  21. start() {
  22. this.setText()
  23. }
  24. clickDownLoad() {
  25. mk.audio.playEffect("ef_button_click")
  26. this.btnSure.active = false
  27. this.btnCancel.active = false
  28. this.fileProgress.node.parent.active = true
  29. let apkUrl = gData.appData.installUrl
  30. let arr = apkUrl.split('/')
  31. let apkName = arr[arr.length - 1]
  32. let installUrl = Util.checkHasApk(apkName)
  33. //已下载过
  34. if (installUrl != '') {
  35. JsbSystem.installApk(installUrl)
  36. }
  37. else {
  38. //未下载过
  39. JsbSystem.downFile2Local(apkUrl, apkName,
  40. (locaPath) => {
  41. JsbSystem.installApk(locaPath)
  42. },
  43. (locaPath) => {
  44. let str = '下载失败,请检查网络后重试'
  45. mk.tip.pop(str);
  46. this.fileProgress.node.parent.active = false
  47. this.fileProgress.fillRange = 0
  48. this.labPro.string = '0%'
  49. this.btnSure.active = true
  50. this.btnCancel.active = true
  51. },
  52. (bytesReceived, totalBytesReceived, totalBytesExpected) => {
  53. let pro = totalBytesReceived / totalBytesExpected
  54. this.setPro(pro)
  55. })
  56. }
  57. }
  58. //更新进度
  59. setPro(pro) {
  60. this.labPro.string = `${Math.floor(pro * 100)}%`
  61. this.fileProgress.fillRange = pro
  62. }
  63. clickSkip() {
  64. mk.audio.playEffect(AUDIO_TYPE.button)
  65. mk.ui.closePanel('module/forceUpdate/forceUpdate');
  66. gData.appData.updateState = UpdateState.ForceUpdateFinish;
  67. }
  68. /** 设置文本 */
  69. setText() {
  70. this.labUpdate.string = gData.appData.updateDes;
  71. this.labFix.string = gData.appData.fixDes;
  72. }
  73. }