App.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <script>
  2. import initApp from "@/common/appInit.js";
  3. // import openApp from '@/common/openApp.js';
  4. export default {
  5. globalData: {
  6. searchText: "",
  7. appVersion: {},
  8. config: {},
  9. $i18n: {},
  10. $t: {},
  11. tabIndex: "home",
  12. },
  13. onLaunch: function () {
  14. // console.log('App Launch')
  15. this.globalData.$i18n = this.$i18n;
  16. this.globalData.$t = (str) => this.$t(str);
  17. uni.hideTabBar();
  18. initApp();
  19. // #ifdef H5
  20. // openApp() //创建在h5端全局悬浮引导用户下载app的功能
  21. // #endif
  22. // #ifdef APP-PLUS
  23. //checkIsAgree(); APP端暂时先用原生默认生成的。目前,自定义方式启动vue界面时,原生层已经请求了部分权限这并不符合国家的法规
  24. // #endif
  25. // #ifdef H5
  26. // checkIsAgree(); // 默认不开启。目前全球,仅欧盟国家有网页端同意隐私权限的需要。如果需要可以自己去掉注视后生效
  27. // #endif
  28. // #ifdef APP-PLUS
  29. //idfa有需要的用户在应用首次启动时自己获取存储到storage中
  30. //https://ask.dcloud.net.cn/article/36107
  31. /*if(~plus.storage.getItem('idfa')){
  32. plus.device.getInfo({//需要勾选IDFA
  33. success:function(e){
  34. console.log('idfa = '+JSON.stringify(e.idfa));
  35. },
  36. fail:function(e){
  37. console.log('getDeviceInfo failed: '+JSON.stringify(e));
  38. }
  39. });
  40. }*/
  41. // #endif
  42. // #ifdef MP-WEIXIN
  43. //定义更新方法
  44. function VersionUpdate() {
  45. // 判断应用的 getUpdateManager 是否在当前版本可用
  46. if (uni.canIUse("getUpdateManager")) {
  47. const updateManager = uni.getUpdateManager();
  48. // 向小程序后台请求完新版本信息
  49. updateManager.onCheckForUpdate(function (res) {
  50. if (res.hasUpdate) {
  51. //小程序有新版本,静默下载新版本,新版本下载完成
  52. updateManager.onUpdateReady(function () {
  53. //模态弹窗(确认、取消)
  54. uni.showModal({
  55. title: "更新提示",
  56. content: "小程序已发布新版本,是否重启?",
  57. success: function (res) {
  58. //用户点击确定
  59. if (res.confirm) {
  60. //当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
  61. updateManager.applyUpdate();
  62. }
  63. //用户点击取消
  64. else if (res.cancel) {
  65. //强制用户更新,弹出第二次弹窗
  66. uni.showModal({
  67. title: "提示",
  68. content: "小程序已发布新版本,是否重启",
  69. showCancel: false, //隐藏取消按钮
  70. success: function (res) {
  71. //第二次提示后,强制更新
  72. if (res.confirm) {
  73. // 当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
  74. updateManager.applyUpdate();
  75. } else if (res.cancel) {
  76. VersionUpdate();
  77. }
  78. },
  79. });
  80. }
  81. },
  82. });
  83. });
  84. // 当新版本下载失败
  85. updateManager.onUpdateFailed(function () {
  86. uni.showModal({
  87. title: "提示",
  88. content: "请您删除当前小程序,重新打开小程序",
  89. });
  90. });
  91. }
  92. });
  93. } else {
  94. // 提示用户在最新版本的客户端上体验
  95. uni.showModal({
  96. title: "温馨提示",
  97. content:
  98. "当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。",
  99. });
  100. }
  101. }
  102. //调用定义的更新方法
  103. VersionUpdate();
  104. // #endif
  105. },
  106. onShow: function () {
  107. console.log("App Show");
  108. uni.hideTabBar();
  109. },
  110. onHide: function () {
  111. console.log("App Hide");
  112. },
  113. };
  114. </script>
  115. <style>
  116. @import "@/static/iconfont.css";
  117. button {
  118. background: linear-gradient(to right, #6db4ff 0%, #2f71f4 100%);
  119. line-height: 80rpx;
  120. color: #fff;
  121. font-size: 30rpx;
  122. margin: 10rpx 0 0;
  123. border-radius: 40rpx;
  124. border: none;
  125. }
  126. .data-empty {
  127. padding: 60rpx;
  128. display: flex;
  129. flex-direction: column;
  130. align-items: center;
  131. }
  132. .data-empty .empty-text {
  133. color: #999999;
  134. }
  135. </style>
  136. <style lang="scss">
  137. @import "@/uni_modules/uview-ui/index.scss";
  138. /*每个页面公共css */
  139. button::after {
  140. border: none;
  141. }
  142. uni-modal {
  143. z-index: 999999 !important;
  144. }
  145. </style>