App.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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","logout"], () => {
  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. uni.$on("refresh_userinfo",()=>{
  62. this.$http.get({
  63. url: "/user/current",
  64. success: (res) => {
  65. this.$store.dispatch("user/save",res.data.data)
  66. }
  67. })
  68. })
  69. },
  70. onShow: function() {
  71. console.log('App Show')
  72. this.$store.commit("user/load")
  73. this.$store.dispatch("cart/load");
  74. uni.$emit("login_succeeded");
  75. },
  76. onHide: function() {
  77. console.log('App Hide')
  78. },
  79. methods: {
  80. checkUpdate() {
  81. this.$http.get({
  82. url: '/update',
  83. success: (res) => {
  84. let temp = [];
  85. let last_version = res.data.data.versionName.substring(1);
  86. temp = last_version.split(".");
  87. let last_version_code = parseInt(temp[0]) * 10000 + parseInt(temp[1]) * 100 + parseInt(
  88. temp[2]);
  89. let cur_version = plus.runtime.version;
  90. temp = cur_version.split(".");
  91. let cur_version_code = parseInt(temp[0]) * 10000 + parseInt(temp[1]) * 100 + parseInt(
  92. temp[2]);
  93. console.log(`最新版本:${last_version} 当前版本${cur_version}`)
  94. // uni.showModal({
  95. // content:`${最新版本:${last_version} ${last_version_code} 当前版本${cur_version} ${cur_version_code} 当前环境 ${process.env.NODE_ENV}`
  96. // })
  97. if (last_version_code > cur_version_code || process.env.NODE_ENV === 'development') {
  98. uni.showModal({
  99. title: "版本更新",
  100. content: `检测到新版本,是否更新?`,
  101. confirmText: "立即更新",
  102. success: (e) => {
  103. if (e.confirm) {
  104. console.log('用户点击确定');
  105. if (plus.os.name === 'iOS') {
  106. plus.runtime.openURL(
  107. "https://apps.apple.com/cn/app/id387682726")
  108. }
  109. if (plus.os.name === 'Android') {
  110. let downloadTask = uni.downloadFile({
  111. url: this.$http.baseUrl + res.data.data
  112. .apk_file,
  113. success: (downloadResult) => {
  114. if (downloadResult.statusCode ===
  115. 200) {
  116. plus.runtime.install(
  117. downloadResult
  118. .tempFilePath, {
  119. force: false
  120. },
  121. function() {
  122. console.log(
  123. 'install success...'
  124. );
  125. plus.runtime
  126. .restart();
  127. },
  128. function(e) {
  129. console.error(
  130. 'install fail...'
  131. );
  132. });
  133. }
  134. }
  135. });
  136. let loading = plus.nativeUI.showWaiting("已下载0%", {
  137. width: "30%",
  138. height: "15%"
  139. })
  140. downloadTask.onProgressUpdate((e) => {
  141. // console.log('下载进度' + e.progress);
  142. // console.log('已经下载的数据长度' + e.totalBytesWritten);
  143. // console.log('预期需要下载的数据总长度' + e.totalBytesExpectedToWrite);
  144. if (e.progress % 5 === 0) {
  145. loading.setTitle("已下载" + e.progress +
  146. "%")
  147. }
  148. if (e.progress === 100) {
  149. loading.close();
  150. }
  151. })
  152. }
  153. } else if (e.cancel) {
  154. console.log('用户点击取消');
  155. }
  156. }
  157. })
  158. }
  159. }
  160. });
  161. }
  162. }
  163. }
  164. </script>
  165. <style>
  166. page {
  167. background: #F8F8F8;
  168. }
  169. uni-button:after {
  170. border: none;
  171. }
  172. @font-face {
  173. font-family:"Roboto";
  174. src: url(static/Roboto-Regular.ttf);
  175. }
  176. @font-face {
  177. font-family:"Roboto-Bold";
  178. src: url(static/Roboto-Bold.ttf);
  179. }
  180. /*每个页面公共css */
  181. ::-webkit-scrollbar {
  182. display: none;
  183. width: 0 !important;
  184. height: 0 !important;
  185. -webkit-appearance: none;
  186. background: transparent;
  187. }
  188. </style>