index.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React from "react";
  2. import { View, Image } from "@tarojs/components";
  3. import "./index.scss";
  4. class LocalFooter extends React.Component<any, any> {
  5. static defaultProps = {
  6. list: [],
  7. onClick: () => {},
  8. };
  9. constructor(props: any) {
  10. super(props);
  11. this.state = {
  12. selectAct: 0,
  13. };
  14. }
  15. #clickItem = (i: number) => {
  16. this.setState({ selectAct: i });
  17. this.props.onClick(i);
  18. };
  19. render() {
  20. const { list } = this.props;
  21. const element = list.map((item, i) => {
  22. return (
  23. <view
  24. key={i}
  25. onClick={() => this.#clickItem(i)}
  26. className={
  27. "footer-item " +
  28. (i === this.state.selectAct ? "footer-item-active" : "")
  29. }
  30. >
  31. <Image
  32. className="footer-item-icon"
  33. mode="aspectFit"
  34. src={i === this.state.selectAct ? item.icon_act : item.icon}
  35. ></Image>
  36. <View className="footer-item-label">{item.title}</View>
  37. </view>
  38. );
  39. });
  40. return <View className="footer">{element}</View>;
  41. }
  42. }
  43. export { LocalFooter };