single.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // 单例控制器
  2. export default {
  3. namespace: 'single',
  4. state: {
  5. drawer: {
  6. visible: false,
  7. config: {}
  8. },
  9. modal: {
  10. visible: false,
  11. // search: null,
  12. config: {}
  13. }
  14. },
  15. effects: {
  16. *toggleDrawer({ payload }, { put }) {
  17. yield put({
  18. type: 'changeDrawer',
  19. payload
  20. })
  21. },
  22. *toggleModal({ payload }, { put }) {
  23. yield put({
  24. type: 'changeModal',
  25. payload
  26. })
  27. },
  28. *setProps({ payload }, { put }) {
  29. yield put({
  30. type: 'changeState',
  31. payload
  32. })
  33. }
  34. // *setModalSearchVal({ payload }, { put }) {
  35. // yield put({
  36. // type: 'changeState',
  37. // payload
  38. // })
  39. // }
  40. },
  41. reducers: {
  42. // 改变state对应type的config
  43. changeState(state, action) {
  44. return {
  45. ...state,
  46. [action.payload.type]: { ...state[action.payload.type], config: action.payload.config }
  47. }
  48. },
  49. changeDrawer(state) {
  50. return {
  51. ...state,
  52. drawer: { ...state.drawer, visible: !state.drawer.visible }
  53. }
  54. },
  55. changeModal(state) {
  56. return {
  57. ...state,
  58. modal: { ...state.modal, visible: !state.modal.visible }
  59. }
  60. }
  61. // changeModalSearch(state, action) {
  62. // return {
  63. // ...state,
  64. // modal: { ...state.modal, search: action.payload }
  65. // }
  66. // }
  67. }
  68. }