App.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <script>
  2. export default {
  3. data() {
  4. return {}
  5. },
  6. onLoad() {},
  7. onShow() {},
  8. onLaunch() {
  9. const that = this;
  10. // 设备信息
  11. let system = that.$config.system;
  12. if (system.uniPlatform == 'app') {
  13. that.appCheck()
  14. } else if (system.uniPlatform == 'mp-weixin') {
  15. that.weixinCheck()
  16. }
  17. },
  18. methods: {
  19. // app检查版本
  20. appCheck() {
  21. const that = this;
  22. plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
  23. uni.request({
  24. url: `${that.$config.serverUrl}/files/project/appVersion.json`,
  25. method: 'GET',
  26. success: (res) => {
  27. console.log(res.data);
  28. if (wgtinfo.version === res.data.version) return;
  29. uni.showModal({
  30. title: '更新',
  31. content: "有新版本,是否下载?",
  32. success: (oneres) => {
  33. if (oneres.confirm) {
  34. // 下载app
  35. this.toUpdateAPK(res.data.url);
  36. }
  37. }
  38. })
  39. }
  40. })
  41. })
  42. },
  43. toUpdateAPK(url) {
  44. if (!url) return;
  45. uni.showLoading({
  46. title: '更新中……',
  47. mask: true,
  48. })
  49. uni.downloadFile({
  50. url: url,
  51. success: (res) => {
  52. uni.hideLoading();
  53. if (res.statusCode == 200) {
  54. uni.showModal({
  55. content: '更新成功,确定现在重启吗?',
  56. confirmText: '重启',
  57. confirmColor: '#EE8F57',
  58. success: modalRes => {
  59. if (modalRes.confirm) {
  60. plus.runtime.install(
  61. res.tempFilePath, {
  62. force: true
  63. },
  64. function(res) {
  65. plus.runtime.restart();
  66. })
  67. }
  68. }
  69. })
  70. }
  71. }
  72. })
  73. },
  74. // 微信检查版本
  75. weixinCheck() {
  76. console.log('微信检查本版');
  77. }
  78. },
  79. }
  80. </script>
  81. <style>
  82. @import url('@/uni.scss');
  83. .textOver {
  84. overflow: hidden;
  85. text-overflow: ellipsis;
  86. white-space: nowrap;
  87. }
  88. page {
  89. /* 主要背景色 */
  90. --rgb000: #000000;
  91. --rgb111: #111111;
  92. --rgbfff: #ffffff;
  93. --rgbf1f: #f1f1f1;
  94. --rgb161: #161616;
  95. --rgbfa4: #FA4343;
  96. }
  97. </style>