App.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <script>
  2. export default {
  3. data() {
  4. return {
  5. progress: 0
  6. }
  7. },
  8. onLaunch: function() {
  9. console.log('App Launch')
  10. // #ifdef APP-PLUS
  11. // this.checkUpdate();
  12. // #endif
  13. const value = uni.getStorageSync('launchFlag');
  14. if (!value) {
  15. // launchFlag=true直接跳转到首页
  16. uni.reLaunch({
  17. url: '/pages/index/index'
  18. });
  19. }
  20. this.$on("login", () => {
  21. if(this.$store.state.user.group_id === 2){
  22. uni.setTabBarItem({
  23. index: 3,
  24. text: '我的商品',
  25. pagePath:'/pages/product/my-product-tabbar'
  26. })
  27. }
  28. })
  29. },
  30. onShow: function() {
  31. console.log('App Show')
  32. this.$store.commit("user/load")
  33. this.$store.dispatch("cart/load");
  34. this.$emit("login");
  35. },
  36. onHide: function() {
  37. console.log('App Hide')
  38. },
  39. methods: {
  40. checkUpdate() {
  41. this.$http.get({
  42. url: '/update',
  43. success: (res) => {
  44. let temp = [];
  45. let last_version = res.data.data.versionName.substring(1);
  46. temp = last_version.substring(1).split(".");
  47. let last_version_code = parseInt(temp[0]) * 10000 + parseInt(temp[1]) * 100 + parseInt(
  48. temp[2]);
  49. let cur_version = plus.runtime.version;
  50. temp = cur_version.substring(1).split(".");
  51. let cur_version_code = parseInt(temp[0]) * 10000 + parseInt(temp[1]) * 100 + parseInt(
  52. temp[2]);
  53. console.log(`最新版本:${last_version} 当前版本${cur_version}`)
  54. // uni.showModal({
  55. // content:`最新版本:${last_version} 当前版本${cur_version} 当前环境 ${process.env.NODE_ENV}`
  56. // })
  57. if (last_version_code > cur_version_code || process.env.NODE_ENV === 'development') {
  58. uni.showModal({
  59. title: "版本更新",
  60. content: `检测到新版本,是否更新?`,
  61. confirmText: "立即更新",
  62. success: (e) => {
  63. if (e.confirm) {
  64. console.log('用户点击确定');
  65. if (plus.os.name === 'iOS') {
  66. plus.runtime.openURL(
  67. "https://apps.apple.com/cn/app/id387682726")
  68. }
  69. if (plus.os.name === 'Android') {
  70. let downloadTask = uni.downloadFile({
  71. url: this.$http.baseUrl + res.data.data
  72. .apk_file,
  73. success: (downloadResult) => {
  74. if (downloadResult.statusCode ===
  75. 200) {
  76. plus.runtime.install(
  77. downloadResult
  78. .tempFilePath, {
  79. force: false
  80. },
  81. function() {
  82. console.log(
  83. 'install success...'
  84. );
  85. plus.runtime
  86. .restart();
  87. },
  88. function(e) {
  89. console.error(
  90. 'install fail...'
  91. );
  92. });
  93. }
  94. }
  95. });
  96. let loading = plus.nativeUI.showWaiting("已下载0%", {
  97. width: "30%",
  98. height: "15%"
  99. })
  100. downloadTask.onProgressUpdate((e) => {
  101. // console.log('下载进度' + e.progress);
  102. // console.log('已经下载的数据长度' + e.totalBytesWritten);
  103. // console.log('预期需要下载的数据总长度' + e.totalBytesExpectedToWrite);
  104. if (e.progress % 5 === 0) {
  105. loading.setTitle("已下载" + e.progress +
  106. "%")
  107. }
  108. if (e.progress === 100) {
  109. loading.close();
  110. }
  111. })
  112. }
  113. } else if (e.cancel) {
  114. console.log('用户点击取消');
  115. }
  116. }
  117. })
  118. }
  119. }
  120. });
  121. }
  122. }
  123. }
  124. </script>
  125. <style>
  126. page {
  127. background: #F8F8F8;
  128. }
  129. /*每个页面公共css */
  130. ::-webkit-scrollbar {
  131. display: none;
  132. width: 0 !important;
  133. height: 0 !important;
  134. -webkit-appearance: none;
  135. background: transparent;
  136. }
  137. </style>