index.jsx 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, Dialog } 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, duty } = 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. Taro.useShareAppMessage(() => {
  25. return {
  26. title: '文明霍山'
  27. };
  28. });
  29. return (
  30. <View className={laySty['page-wrapper']}>
  31. <Notify id="vanNotify" />
  32. <Dialog id="vanDialog" />
  33. <NavLoading loading={loading} />
  34. <View className={containerClass} style={style}>
  35. {
  36. !person && (
  37. <View className={laySty.loading}>
  38. <Loading size="32px" vertical>
  39. 加载中...
  40. </Loading>
  41. </View>
  42. )
  43. }
  44. <Auth roles={roles}>
  45. {props.children}
  46. </Auth>
  47. {
  48. !tabBar && (
  49. <View className={laySty['pdm-space']}></View>
  50. )
  51. }
  52. </View>
  53. {
  54. tabBar && <TabBar className={laySty['page-tabbar']} active={tabBar} duty={duty} />
  55. }
  56. </View>
  57. )
  58. }