App.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <script>
  2. export default {
  3. data() {
  4. return {}
  5. },
  6. onLoad() {},
  7. onShow() {},
  8. onLaunch() {
  9. const that = this;
  10. that.checkVersion()
  11. },
  12. methods: {
  13. // 检查版本
  14. checkVersion() {
  15. const that = this;
  16. plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
  17. uni.request({
  18. url: `${that.$config.serverUrl}/files/project/appVersion.json`,
  19. method: 'GET',
  20. success: (res) => {
  21. if (wgtinfo.version === res.data.version) return;
  22. uni.showModal({
  23. title: '更新',
  24. content: "有新版本,是否下载?",
  25. success: (oneres) => {
  26. if (oneres.confirm) {
  27. // 下载app
  28. this.toUpdateAPK(res.data.url);
  29. }
  30. }
  31. })
  32. }
  33. })
  34. })
  35. },
  36. toUpdateAPK(url) {
  37. if (!url) return;
  38. uni.showLoading({
  39. title: '更新中……',
  40. mask: true,
  41. })
  42. uni.downloadFile({
  43. url: url,
  44. success: (res) => {
  45. uni.hideLoading();
  46. if (res.statusCode == 200) {
  47. uni.showModal({
  48. content: '更新成功,确定现在重启吗?',
  49. confirmText: '重启',
  50. confirmColor: '#EE8F57',
  51. success: modalRes => {
  52. if (modalRes.confirm) {
  53. plus.runtime.install(
  54. res.tempFilePath, {
  55. force: true
  56. },
  57. function(res) {
  58. plus.runtime.restart();
  59. })
  60. }
  61. }
  62. })
  63. }
  64. }
  65. })
  66. }
  67. },
  68. }
  69. </script>
  70. <style>
  71. @import url('@/uni.scss');
  72. </style>