1234567891011121314151617181920212223242526272829303132333435363738
  1. import React from "react";
  2. import { View } from "@tarojs/components";
  3. import { useModel } from "@/store";
  4. export default (props) => {
  5. const { roles = [] } = props;
  6. // console.log(props);
  7. const { duty } = useModel("user");
  8. // console.log("---------------------************-----------------");
  9. // const hasRights = roles.indexOf(duty) > -1;
  10. const hasRights = roles.includes(duty);
  11. // console.log(duty);
  12. // console.log("!roles.length", !roles.length);
  13. // console.log("hasRights", hasRights);
  14. // console.log("roles", roles);
  15. // console.log("!roles.length || hasRights", !roles.length || hasRights);
  16. const filteredChildren = React.Children.toArray(props.children).filter(
  17. child => React.isValidElement(child)
  18. );
  19. return !roles.length || hasRights ? (
  20. <div>{filteredChildren}</div>
  21. ) : (
  22. <View
  23. style={{
  24. width: "100%",
  25. height: "100%",
  26. display: "grid",
  27. placeItems: "center",
  28. }}
  29. >
  30. <View>暂无权限</View>
  31. </View>
  32. );
  33. };