App.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <page style="color: #007AFF;"></page>
  3. </template>
  4. <script>
  5. export default {
  6. globalData: {
  7. detail: null,
  8. choosedAddress: null
  9. },
  10. async onLaunch () { //app 初始化
  11. let f = uni.canIUse('getUpdateManager') // 获取小程序更新机制兼容
  12. if(f) {
  13. const _u = uni.getUpdateManager()
  14. _u.onCheckForUpdate(res => { // // 请求完新版本信息的回调
  15. console.log('版本信息',res.hasUpdate)
  16. if(res.hasUpdate) { // 是否有新的版本
  17. _u.onUpdateReady(() => { // 当新版本下载完成,会进行回调
  18. uni.showModal({
  19. title: '更新提示',
  20. content: '新版本已发布,请重启当前应用!',
  21. showCancel: false,
  22. success(c_res) {
  23. if(c_res.confirm) {
  24. _u.applyUpdate() // 当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
  25. }
  26. }
  27. })
  28. })
  29. }
  30. })
  31. _u.onUpdateFailed(() => { // 当新版本下载失败,会进行回调
  32. uni.showModal({
  33. title: '发现新版本',
  34. content: '请删除当前小程序,重新搜索打开'
  35. })
  36. })
  37. }
  38. uni.loading = () => uni.showLoading({ mask: true, title: '加载中' })
  39. if (!uni.getStorageSync('warn')) {
  40. uni.setStorageSync('warn', 'false')
  41. }
  42. uni.onNetworkStatusChange(({ networkType, isConnected }) => { //监听网络类型变化
  43. if (isConnected) { //当网络类型却换后
  44. if (!this.$verified()) { //如果用户未登录,就触发 初始化方法。用户用户初次打开小程序时没有网络,随即又有网络的情况
  45. // this.$store.dispatch('onLaunch')
  46. }
  47. if ('2g3g'.indexOf(networkType) !== -1) {
  48. uni.showToast({ title: '网络似乎不太稳定', icon: 'none' })
  49. }
  50. } else {
  51. uni.showToast({ title: '似乎已经断开网络连接', icon: 'none' })
  52. }
  53. this.$store.commit('CHANGENETWORKSTATUS', networkType)
  54. })
  55. uni.showLoading({ title: '加载中', mask: true }) //显示loading
  56. const [ , { networkType }] = await uni.getNetworkType(); //获取网络类型,给出相应的提示
  57. // console.log('网络状态',networkType)
  58. this.$store.commit('CHANGENETWORKSTATUS', networkType) //获取网络类型并将状态存在 store 里
  59. },
  60. async onShow () {
  61. },
  62. async onHide () {
  63. uni.hideLoading() //app hide 时隐藏loading
  64. }
  65. }
  66. </script>
  67. <style>
  68. @import 'common/styles/main.css'; //引入 ColorUI 组件库主样式
  69. @import 'common/styles/icon.css'; //引入 ColorUI 组件库图标样式
  70. @import 'common/styles/animation.css'; //引入 ColorUI 组件库动画样式
  71. page { //uniapp 中的 page 标签相当于 html 中的 body, 默认高度为 auto, 但是高度为 100% 更利于 app 布局,你也可以在 page 中设置一些全局样式,比如全局背景色
  72. background: #FFFFFF;
  73. height: 100%;
  74. }
  75. </style>