App.vue 5.4 KB

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