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.
48 lines
1.0 KiB
48 lines
1.0 KiB
import {useEffect} from 'react'
|
|
import Taro, {useDidShow, useDidHide} from '@tarojs/taro'
|
|
|
|
// 全局样式
|
|
import './app.scss'
|
|
import {loginByOpenId} from "@/api/layout";
|
|
import {TenantId} from "@/config/app";
|
|
import {saveStorageByLoginUser} from "@/utils/server";
|
|
|
|
function App(props) {
|
|
const reload = () => {
|
|
Taro.login({
|
|
success: (res) => {
|
|
loginByOpenId({
|
|
code: res.code,
|
|
tenantId: TenantId
|
|
}).then(data => {
|
|
if (data) {
|
|
saveStorageByLoginUser(data.access_token, data.user)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
};
|
|
// 可以使用所有的 React Hooks
|
|
useEffect(() => {
|
|
// Taro.getSetting:获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。
|
|
Taro.getSetting({
|
|
success: (res) => {
|
|
if (res.authSetting['scope.userInfo']) {
|
|
reload();
|
|
}
|
|
}
|
|
});
|
|
}, []);
|
|
|
|
// 对应 onShow
|
|
useDidShow(() => {
|
|
})
|
|
|
|
// 对应 onHide
|
|
useDidHide(() => {
|
|
})
|
|
|
|
return props.children
|
|
}
|
|
|
|
export default App
|