<script setup>
import { useUserStore } from '@/store/user'
const { setUserInfo, setUserRoles, setPlace } = useUserStore()

const launchUpdate = () => {
  const updateManager = uni.getUpdateManager()
  const onUpdateReady = () => {
    updateManager.onUpdateReady(() => {
      uni.showModal({
        title: '更新提示',
        content: '新版本已经准备好，是否重启应用？',
        success(res) {
          if (res.confirm) {
            updateManager.applyUpdate()
          }
        }
      })
    })
  }

  updateManager &&
    updateManager.onCheckForUpdate((res) => {
      console.log(`是否检测到有新版本更新: ${res.hasUpdate ? '是' : '否'}`)
      res.hasUpdate && onUpdateReady()
    })

  updateManager &&
    updateManager.onUpdateFailed((err) => {
      console.log('新的版本下载失败', err)
    })
}

onLaunch(() => {
  console.log('App Launch')
  setPlace()
  setUserInfo()
  setUserRoles()
})

onShow(() => {
  console.log('App Show')
  launchUpdate()
})

onHide(() => {
  console.log('App Hide')
})
</script>

<style lang="scss">
/* uview-plus styles */
@import 'uview-plus/index.scss';
/* iconfont custom icon */
@import './static/iconfont/iconfont.css';
</style>

<style>
/*每个页面公共css */
view {
  box-sizing: border-box;
}
.hold-table::before {
  content: '';
  display: table;
}

/* 重置 cell 样式 */
.u-cell__body .u-cell__body__content {
  flex: none;
}
.u-cell__body .u-cell__value {
  max-width: 420rpx;
}
</style>
