index.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { Select } from "antd";
  2. import { Menu, Dropdown } from 'antd';
  3. import { connect } from "dva";
  4. import router from 'umi/router';
  5. import { webSiteContactRelation } from "@/utils/utils"
  6. const SiteSelector = ({ siteList, currentSite, dispatch }) => {
  7. const handleChange = (value) => {
  8. dispatch({ type: "global/setCurrentSite", payload: value });
  9. dispatch({ type: "global/setCurrentContactType", payload: webSiteContactRelation[value] });
  10. const targetSite = siteList.find(item => item.value === value);
  11. dispatch({ type: "global/setCurrentSiteName", payload: targetSite.title });
  12. };
  13. return (
  14. siteList.length ? (
  15. <Select
  16. value={currentSite}
  17. style={{ width: 150 }}
  18. onChange={handleChange}
  19. >
  20. {siteList.map((site) => (
  21. <Select.Option key={site.name} value={site.value}>
  22. {site.title}
  23. </Select.Option>
  24. ))}
  25. </Select>
  26. ) : null
  27. );
  28. };
  29. export default connect(({ global }) => ({
  30. siteList: global.siteList,
  31. currentSite: global.currentSite,
  32. }))(SiteSelector);