DownLoadUI.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import Util from "../../../script/before/util/Util";
  2. import JsbSystem from "../../../script/mk/system/JsbSystem";
  3. /** 最新版本下载 */
  4. const { ccclass, property } = cc._decorator;
  5. @ccclass
  6. export default class DownLoadUI extends cc.Component {
  7. @property(cc.Toggle)
  8. skipToggle: cc.Toggle = null
  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. /** 是否显示“不再提醒” */
  22. showToggle = false
  23. start() {
  24. this.setText()
  25. }
  26. init(showToggle) {
  27. this.skipToggle.node.active = showToggle
  28. this.showToggle = showToggle
  29. if (!showToggle) {
  30. this.btnSure.y = -366
  31. }
  32. }
  33. clickDownLoad() {
  34. mk.audio.playEffect("ef_button_click")
  35. this.btnSure.active = false
  36. this.btnCancel.active = false
  37. this.skipToggle.node.active = false
  38. this.fileProgress.node.parent.active = true
  39. let apkUrl = gData.appData.installUrl
  40. let arr = apkUrl.split('/')
  41. let apkName = arr[arr.length - 1]
  42. let installUrl = Util.checkHasApk(apkName)
  43. //已下载过
  44. if (installUrl != '') {
  45. JsbSystem.installApk(installUrl)
  46. }
  47. else {
  48. //未下载过
  49. JsbSystem.downFile2Local(apkUrl, apkName,
  50. (locaPath) => {
  51. JsbSystem.installApk(locaPath)
  52. },
  53. (locaPath) => {
  54. let str = '下载失败,请检查网络后重试'
  55. // if (cc.director.getScene().name == 'Loader') {
  56. // cc.find('Canvas').getComponent(Loader).PlayTip(str)
  57. // }
  58. // else {
  59. // EffectNode.instance.PlayTip(str)
  60. // }
  61. this.fileProgress.node.parent.active = false
  62. this.fileProgress.fillRange = 0
  63. this.labPro.string = '0%'
  64. this.btnSure.active = true
  65. this.btnCancel.active = true
  66. this.skipToggle.node.active = this.showToggle
  67. },
  68. (bytesReceived, totalBytesReceived, totalBytesExpected) => {
  69. let pro = totalBytesReceived / totalBytesExpected
  70. this.setPro(pro)
  71. })
  72. }
  73. }
  74. //更新进度
  75. setPro(pro) {
  76. this.labPro.string = `${Math.floor(pro * 100)}%`
  77. this.fileProgress.fillRange = pro
  78. }
  79. clickSkip() {
  80. // mk.audio.playEffect(AUDIO_TYPE.button)
  81. // if (this.skipToggle.isChecked) {
  82. // let installVersion = gData.appData.installVersion
  83. // GameM.globalStorage.setStorage('installVersion' + installVersion, 'skip', 1)
  84. // }
  85. // UiM.Instance.offPanel(PANEL_NAME.DownLoadUI)
  86. // GameM.commonData.skipUpdate = true
  87. }
  88. /** 设置文本 */
  89. setText() {
  90. this.labUpdate.string = gData.appData.updateDes;
  91. this.labFix.string = gData.appData.fixDes;
  92. }
  93. }