You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.5 KiB
73 lines
1.5 KiB
1 year ago
|
import {useEffect} from 'react'
|
||
|
import Taro, {useDidShow, useDidHide} from '@tarojs/taro'
|
||
|
import './app.scss'
|
||
|
import {CustomWrapper} from "@tarojs/components";
|
||
|
|
||
|
function updateApp() {
|
||
|
if (Taro.canIUse('getUpdateManager')) {
|
||
|
const updateManager = Taro.getUpdateManager()
|
||
|
updateManager.onCheckForUpdate((res) => {
|
||
|
console.log('新版本', res.hasUpdate)
|
||
|
})
|
||
|
|
||
|
|
||
|
updateManager.onUpdateReady(() => {
|
||
|
Taro.showModal({
|
||
|
title: '更新提示',
|
||
|
content: '新版本已经准备好,是否重启应用?',
|
||
|
success(res) {
|
||
|
if (res.confirm) {
|
||
|
updateManager.applyUpdate()
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
updateManager.onUpdateFailed(() => {
|
||
|
// 新版本下载失败
|
||
|
Taro.showToast({title: '新版本下载失败'})
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
function App(props) {
|
||
|
// 可以使用所有的 React Hooks
|
||
|
useEffect(() => {
|
||
|
updateApp()
|
||
|
const token = JSON.parse(Taro.getStorageSync('profile') || '{}')?.token
|
||
|
if (!token) {
|
||
|
Taro.switchTab({url: '/pages/login/login'})
|
||
|
}
|
||
|
}, [])
|
||
|
|
||
|
|
||
|
Taro.getSystemInfo({
|
||
|
success(res) {
|
||
|
Taro.getApp().globalData = {
|
||
|
statusBarHeight: res.statusBarHeight,
|
||
|
screenWidth: res.screenWidth,
|
||
|
screenHeight: res.screenHeight,
|
||
|
safeArea: res.safeArea,
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
|
||
|
|
||
|
// 对应 onShow
|
||
|
useDidShow(() => {
|
||
|
})
|
||
|
|
||
|
// 对应 onHide
|
||
|
useDidHide(() => {
|
||
|
})
|
||
|
|
||
|
|
||
|
return (
|
||
|
<CustomWrapper>
|
||
|
{props.children}
|
||
|
</CustomWrapper>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
export default App
|