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.
38 lines
1.1 KiB
38 lines
1.1 KiB
import { PropsWithChildren } from 'react' |
|
import { useLaunch } from '@tarojs/taro' |
|
import Taro from '@tarojs/taro' |
|
import { userStore } from './store' |
|
import { getCustomerByOpenId } from './api/customer' |
|
import './app.scss' |
|
|
|
function App({ children }: PropsWithChildren<any>) { |
|
useLaunch(() => { |
|
console.log('台球馆小程序启动') |
|
|
|
// 先从本地缓存恢复用户信息(快速) |
|
try { |
|
const savedUserInfo = Taro.getStorageSync('userInfo') |
|
if (savedUserInfo) { |
|
userStore.setUserInfo(savedUserInfo) |
|
} |
|
} catch (error) { |
|
console.warn('初始化用户信息失败:', error) |
|
} |
|
|
|
// 后台静默刷新(获取最新余额等信息),不阻塞启动 |
|
const openId = userStore.userInfo?.wxOpenId || Taro.getStorageSync('openId') |
|
if (openId) { |
|
getCustomerByOpenId(openId) |
|
.then(res => { |
|
if (res.data) { |
|
userStore.setUserInfoFromWechat(res.data) |
|
} |
|
}) |
|
.catch(e => console.warn('启动刷新用户信息失败:', e)) |
|
} |
|
}) |
|
|
|
return children |
|
} |
|
|
|
export default App
|
|
|