del_hosts.js 584 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * @author oldj
  3. * @blog https://oldj.net
  4. */
  5. 'use strict'
  6. import Agent from '../Agent'
  7. module.exports = (app, hosts) => {
  8. let list = app.state.list
  9. let idx = list.findIndex(item => item.id === hosts.id)
  10. if (idx === -1) {
  11. return
  12. }
  13. list.splice(idx, 1)
  14. Agent.pact('saveHosts', list)
  15. .then(() => {
  16. app.setState({list}, () => {
  17. // 选中下一个 hosts
  18. let next_hosts = list[idx] || list[idx - 1] || null
  19. if (next_hosts) {
  20. app.setState({current: next_hosts})
  21. }
  22. })
  23. })
  24. .catch(e => console.log(e))
  25. }