switchStatus.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { modifyStatusBatchApi } from "@/services/gameData"
  3. import { message, notification, Switch } from "antd"
  4. import React from "react"
  5. /**
  6. * 修改启停
  7. */
  8. interface Props {
  9. configuredStatus: string,
  10. accountId: number
  11. adgroupId: number
  12. isDeleted?: boolean,
  13. onChange?: () => void
  14. }
  15. const SwitchStatus: React.FC<Props> = (prosp) => {
  16. const { configuredStatus, isDeleted, adgroupId, accountId, onChange } = prosp
  17. const modifyStatusBatch = useAjax((params) => modifyStatusBatchApi(params))
  18. const switchHandle = (accountAdgroupMaps: string[], type: boolean) => {
  19. modifyStatusBatch.run({ accountAdgroupMaps, suspend: !type }).then(res => {
  20. if (res?.data?.failIdList?.length === 0) {
  21. message.success(`${type ? '启动' : '暂停'}成功,结果有延迟请手动刷新`)
  22. // onChange?.()
  23. } else {
  24. message.success(`${type ? '启动' : '暂停'}失败,${JSON.stringify(res?.data?.failIdList)}`)
  25. }
  26. })
  27. }
  28. return <Switch size="small" checked={configuredStatus === 'AD_STATUS_NORMAL'} loading={modifyStatusBatch.loading} disabled={isDeleted} onChange={(checked) => switchHandle([accountId + ',' + adgroupId] ,checked)}/>
  29. }
  30. export default React.memo(SwitchStatus)