App.vue 4.6 KB

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