App.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <script>
  2. import config from './config'
  3. import { getToken } from '@/utils/auth'
  4. import {updateUserProfile,findVersion} from "@/api/system/user.js"
  5. const baseUrl = config.baseUrl
  6. export default {
  7. data(){
  8. return{
  9. platform:'Android',
  10. }
  11. },
  12. onLaunch: function() {
  13. // #ifdef APP
  14. this.onlineWgt(); //版本更新
  15. // #endif
  16. this.initApp()
  17. },
  18. methods: {
  19. // 在线跟新
  20. onlineWgt() {
  21. let that = this;
  22. plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
  23. that.comparisonVersionNo(widgetInfo.versionCode);
  24. });
  25. // that.comparisonVersionNo()
  26. },
  27. comparisonVersionNo(versionCode) {
  28. let that = this;
  29. // console.log("aaaaaaa===versionCode", versionCode);
  30. const parmas = {
  31. model: that.platform,
  32. appPort:that.appPort
  33. }
  34. findVersion(parmas).then(res => {
  35. console.log(res)
  36. if (res.code == "200") {
  37. let versionNos = res.data.code;
  38. // console.log(versionNos,'versionNos')
  39. let filePath = res.data.path;
  40. if (Number(versionNos) > Number(versionCode)) { //服务器返回1更新,0则不更新
  41. uni.showModal({
  42. title: '提示',
  43. content: '发现新版本,是否升级',
  44. success: function(res) {
  45. // console.log(widgetInfo.version);
  46. if (res.confirm) {
  47. console.log('用户点击确定');
  48. that.getProperty(filePath);
  49. } else if (res.cancel) {
  50. console.log('用户点击取消');
  51. }
  52. }
  53. });
  54. }
  55. }
  56. }).catch(error=>{
  57. uni.hideLoading()
  58. console.log(error)
  59. })
  60. },
  61. getProperty(getProperty) {
  62. // console.log("bbbbbbbbb----------->", getProperty)
  63. let that = this;
  64. // console.log(baseUrl + getProperty)
  65. // 在线升级app/热更新
  66. that.showwri = true;
  67. const downloadTask = uni.downloadFile({ //下载文件
  68. url: baseUrl + getProperty,
  69. success: (downloadResult) => {
  70. // console.log(downloadResult);
  71. if (downloadResult.statusCode == 200) {
  72. // 更新升级
  73. plus.runtime.install(downloadResult.tempFilePath, {
  74. force: true
  75. }, function() {
  76. // console.log('install success...');
  77. that.showwri = false;
  78. plus.nativeUI.alert("应用资源更新完成!", function() {
  79. plus.runtime.restart();
  80. });
  81. }, function(e) {
  82. that.showwri = false;
  83. plus.nativeUI.alert("更新失败,请稍后再试");
  84. });
  85. }
  86. }
  87. });
  88. downloadTask.onProgressUpdate((res) => { //下载文件的进度
  89. that.totalBytesWritten = res.totalBytesWritten; //当前下载大小
  90. that.progress = res.progress; //当前下载比例
  91. that.totalBytesExpectedToWrite = res.totalBytesExpectedToWrite; //
  92. });
  93. },
  94. // 初始化应用
  95. initApp() {
  96. // 初始化应用配置
  97. this.initConfig()
  98. // 检查用户登录状态
  99. //#ifdef H5
  100. this.checkLogin()
  101. //#endif
  102. },
  103. initConfig() {
  104. this.globalData.config = config
  105. },
  106. checkLogin() {
  107. if (!getToken()) {
  108. this.$tab.reLaunch('/pages/login')
  109. }
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss">
  115. @import '@/static/scss/index.scss';
  116. @import "@/static/style.css";
  117. @import "@/static/rich.css";
  118. </style>