App.vue 4.0 KB

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