index.jsx 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React from 'react';
  2. import Taro from '@tarojs/taro';
  3. import { View, Image } from '@tarojs/components';
  4. import { useModel } from '@/store';
  5. import { Loading, Notify } from '@antmjs/vantui';
  6. import NavLoading from '@/components/NavLoading';
  7. import Auth from '@/components/Auth';
  8. import TabBar from './TabBar';
  9. import laySty from './layout.module.less';
  10. export default (props) => {
  11. const { className, style, roles, tabBar = false, loading } = props;
  12. const { person, user } = useModel('user');
  13. const containerClass = `${laySty['page-conatiner']} ${tabBar ? laySty['with-tabbar'] : ''} ${className}`;
  14. React.useEffect(() => {
  15. if (person && !user) {
  16. const currentPage = Taro.getCurrentPages().slice().pop();
  17. if ('pages/login/index' !== currentPage.route) {
  18. Taro.navigateTo({
  19. url: '/pages/login/index',
  20. })
  21. }
  22. }
  23. }, [person, user]);
  24. return (
  25. <View className={laySty['page-wrapper']}>
  26. <Notify id="vanNotify" />
  27. <NavLoading loading={loading} />
  28. <View className={containerClass} style={style}>
  29. {
  30. !person && (
  31. <View className={laySty.loading}>
  32. <Loading size="32px" vertical>
  33. 加载中...
  34. </Loading>
  35. </View>
  36. )
  37. }
  38. <Auth roles={roles}>
  39. {props.children}
  40. </Auth>
  41. {
  42. !tabBar && (
  43. <View className={laySty['pdm-space']}></View>
  44. )
  45. }
  46. </View>
  47. {
  48. tabBar && <TabBar className={laySty['page-tabbar']} active={tabBar} user={user} />
  49. }
  50. </View>
  51. )
  52. }