App.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. uni.$on("login", () => {
  21. if (this.$store.state.user.group_id === 2) {
  22. let iconIndex = 2
  23. // #ifdef H5
  24. iconIndex = 3
  25. // #endif
  26. uni.setTabBarItem({
  27. index: iconIndex,
  28. text: '我的商品',
  29. pagePath: '/pages/product/my-product-tabbar',
  30. iconPath: "static/images/kan.png",
  31. selectedIconPath: "static/images/kan_selected.png",
  32. })
  33. } else {
  34. let iconIndex = 2
  35. // #ifdef H5
  36. iconIndex = 3
  37. // #endif
  38. uni.setTabBarItem({
  39. index: iconIndex,
  40. text: '购物车',
  41. pagePath: '/pages/shopping-cart/shopping-cart',
  42. iconPath: "static/images/kan.png",
  43. selectedIconPath: "static/images/kan_selected.png",
  44. })
  45. }
  46. });
  47. uni.onTabBarMidButtonTap(() => {
  48. uni.chooseImage({
  49. count: 1,
  50. sourceType: ['camera']
  51. })
  52. })
  53. },
  54. onShow: function() {
  55. console.log('App Show')
  56. this.$store.commit("user/load")
  57. this.$store.dispatch("cart/load");
  58. uni.$emit("login");
  59. },
  60. onHide: function() {
  61. console.log('App Hide')
  62. },
  63. methods: {
  64. checkUpdate() {
  65. this.$http.get({
  66. url: '/update',
  67. success: (res) => {
  68. let temp = [];
  69. let last_version = res.data.data.versionName.substring(1);
  70. temp = last_version.split(".");
  71. let last_version_code = parseInt(temp[0]) * 10000 + parseInt(temp[1]) * 100 + parseInt(
  72. temp[2]);
  73. let cur_version = plus.runtime.version;
  74. temp = cur_version.split(".");
  75. let cur_version_code = parseInt(temp[0]) * 10000 + parseInt(temp[1]) * 100 + parseInt(
  76. temp[2]);
  77. console.log(`最新版本:${last_version} 当前版本${cur_version}`)
  78. // uni.showModal({
  79. // content:`${最新版本:${last_version} ${last_version_code} 当前版本${cur_version} ${cur_version_code} 当前环境 ${process.env.NODE_ENV}`
  80. // })
  81. if (last_version_code > cur_version_code || process.env.NODE_ENV === 'development') {
  82. uni.showModal({
  83. title: "版本更新",
  84. content: `检测到新版本,是否更新?`,
  85. confirmText: "立即更新",
  86. success: (e) => {
  87. if (e.confirm) {
  88. console.log('用户点击确定');
  89. if (plus.os.name === 'iOS') {
  90. plus.runtime.openURL(
  91. "https://apps.apple.com/cn/app/id387682726")
  92. }
  93. if (plus.os.name === 'Android') {
  94. let downloadTask = uni.downloadFile({
  95. url: this.$http.baseUrl + res.data.data
  96. .apk_file,
  97. success: (downloadResult) => {
  98. if (downloadResult.statusCode ===
  99. 200) {
  100. plus.runtime.install(
  101. downloadResult
  102. .tempFilePath, {
  103. force: false
  104. },
  105. function() {
  106. console.log(
  107. 'install success...'
  108. );
  109. plus.runtime
  110. .restart();
  111. },
  112. function(e) {
  113. console.error(
  114. 'install fail...'
  115. );
  116. });
  117. }
  118. }
  119. });
  120. let loading = plus.nativeUI.showWaiting("已下载0%", {
  121. width: "30%",
  122. height: "15%"
  123. })
  124. downloadTask.onProgressUpdate((e) => {
  125. // console.log('下载进度' + e.progress);
  126. // console.log('已经下载的数据长度' + e.totalBytesWritten);
  127. // console.log('预期需要下载的数据总长度' + e.totalBytesExpectedToWrite);
  128. if (e.progress % 5 === 0) {
  129. loading.setTitle("已下载" + e.progress +
  130. "%")
  131. }
  132. if (e.progress === 100) {
  133. loading.close();
  134. }
  135. })
  136. }
  137. } else if (e.cancel) {
  138. console.log('用户点击取消');
  139. }
  140. }
  141. })
  142. }
  143. }
  144. });
  145. }
  146. }
  147. }
  148. </script>
  149. <style>
  150. page {
  151. background: #F8F8F8;
  152. }
  153. uni-button:after {
  154. border: none;
  155. }
  156. /*每个页面公共css */
  157. ::-webkit-scrollbar {
  158. display: none;
  159. width: 0 !important;
  160. height: 0 !important;
  161. -webkit-appearance: none;
  162. background: transparent;
  163. }
  164. </style>