App.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <script>
  2. export default {
  3. globalData: {
  4. navHeight: "",
  5. },
  6. onLaunch: function() {
  7. console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
  8. console.log('App Launch')
  9. this.autoUpdate()
  10. this.globalData.navHeight = 44 + uni.getSystemInfoSync().statusBarHeight + "px"
  11. // wx.getSystemInfo({
  12. // success: res => {
  13. // this.globalData.navHeight = res.statusBarHeight + 48 + "px"; // 赋值导航高度
  14. // },
  15. // fail(err) {
  16. // console.log(err);
  17. // }
  18. // })
  19. },
  20. onShow: function() {
  21. console.log('App Show')
  22. },
  23. onHide: function() {
  24. console.log('App Hide')
  25. },
  26. methods: {
  27. autoUpdate: function() {
  28. var self = this
  29. // 获取小程序更新机制兼容
  30. if (wx.canIUse('getUpdateManager')) {
  31. const updateManager = wx.getUpdateManager()
  32. //1. 检查小程序是否有新版本发布
  33. updateManager.onCheckForUpdate(function(res) {
  34. console.log("新版本检测:", res)
  35. // 请求完新版本信息的回调
  36. if (res.hasUpdate) {
  37. //检测到新版本,需要更新,给出提示
  38. wx.showModal({
  39. title: '更新提示',
  40. content: '检测到新版本,是否下载新版本并重启小程序?',
  41. success: function(res) {
  42. if (res.confirm) {
  43. //2. 用户确定下载更新小程序,小程序下载及更新静默进行
  44. self.downLoadAndUpdate(updateManager)
  45. } else if (res.cancel) {
  46. //用户点击取消按钮的处理,如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了
  47. wx.showModal({
  48. title: '温馨提示~',
  49. content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦~',
  50. showCancel: false, //隐藏取消按钮
  51. confirmText: "确定更新", //只保留确定更新按钮
  52. success: function(res) {
  53. if (res.confirm) {
  54. //下载新版本,并重新应用
  55. self.downLoadAndUpdate(
  56. updateManager)
  57. }
  58. }
  59. })
  60. }
  61. }
  62. })
  63. }
  64. })
  65. } else {
  66. // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
  67. wx.showModal({
  68. title: '提示',
  69. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  70. })
  71. }
  72. },
  73. /**
  74. * 下载小程序新版本并重启应用
  75. */
  76. downLoadAndUpdate: function(updateManager) {
  77. var self = this
  78. wx.showLoading();
  79. //静默下载更新小程序新版本
  80. updateManager.onUpdateReady(function() {
  81. wx.hideLoading()
  82. //新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  83. updateManager.applyUpdate()
  84. })
  85. updateManager.onUpdateFailed(function() {
  86. // 新的版本下载失败
  87. wx.showModal({
  88. title: '已经有新版本了哟~',
  89. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
  90. })
  91. })
  92. }
  93. }
  94. }
  95. </script>
  96. <style>
  97. /*每个页面公共css */
  98. /* 解决头条小程序组件内引入字体不生效的问题 */
  99. /* #ifdef MP-TOUTIAO */
  100. @font-face {
  101. font-family: uniicons;
  102. src: url("/static/uni.ttf");
  103. }
  104. /* #endif */
  105. .home {
  106. width: 97%;
  107. margin: 0 auto;
  108. /* padding-top: 23%; */
  109. }
  110. /deep/ textarea {
  111. width: auto;
  112. }
  113. /deep/ .uni-forms-item__content {
  114. display: flex !important;
  115. align-items: center !important;
  116. /* justify-content: space-between; */
  117. }
  118. p {
  119. word-break: break-all;
  120. }
  121. text {
  122. word-break: break-all;
  123. }
  124. /deep/ textarea {
  125. width: auto;
  126. }
  127. /deep/ .uni-forms-item__content {
  128. display: flex !important;
  129. align-items: center !important;
  130. /* justify-content: space-between; */
  131. }
  132. p {
  133. word-break: break-all;
  134. }
  135. text {
  136. word-break: break-all;
  137. }
  138. /deep/.uni-forms-item__inner {
  139. padding-bottom: 0rpx !important;
  140. margin-bottom: 30rpx !important;
  141. border-bottom: 0.5rpx solid #CCCCCC !important;
  142. }
  143. /* /deep/ .share .uni-popup .uni-popup__wrapper{
  144. width: 70% !important;
  145. border-radius: 15rpx !important;
  146. }
  147. /deep/ .share1 .uni-popup .uni-popup__wrapper{
  148. width: 85% !important;
  149. } */
  150. </style>