index_tab.tsx 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import { View } from "@tarojs/components";
  2. import './index_tab.scss'
  3. import { useEffect, useState } from "react";
  4. import NewButton, { NewButtonType } from "@/_health/base/new_button";
  5. export default function IndexTab(props: { items: any, current: number,onChanged:any }) {
  6. const [selIndex,setSelIndex] = useState(props.current??0)
  7. useEffect(()=>{
  8. setSelIndex(props.current)
  9. },[props.current])
  10. return <View className="index_tabbar" style={{alignItems:'center',justifyContent:'center'}}>
  11. {
  12. props.items.map((item, index) => {
  13. return <NewButton type={NewButtonType.custom} key={index} onClick={()=>{
  14. setSelIndex(index)
  15. props.onChanged(index)
  16. }}>
  17. <View className="index_tabbar_item">
  18. <View className={index==selIndex?'tab_item_sel':'tab_item_nor'}>{item}</View>
  19. <View className={index==selIndex?'tab_item_line_sel':'tab_item_line'}></View>
  20. </View>
  21. </NewButton>
  22. })
  23. }
  24. </View>
  25. }