relation.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { getRelationList, addRelationList, removeRelationList} from '@/api/relation'
  2. const relation = {
  3. state: {
  4. relationList: {}
  5. },
  6. mutations: {
  7. GET_RELATION_LIST(state, data) {
  8. state.relationList = data;
  9. }
  10. },
  11. actions: {
  12. getRelationList({ commit }, params) {
  13. return new Promise((resolve, reject) => {
  14. getRelationList(params).then( res => {
  15. if(res.code == 200) {
  16. commit('GET_RELATION_LIST', res.data);
  17. resolve(res.data);
  18. }
  19. }).catch( error => {
  20. reject(error)
  21. })
  22. })
  23. },
  24. addRelationList ({ dispatch, commit }, {data, params}) {
  25. return new Promise((resolve, reject) => {
  26. addRelationList(data).then( res => {
  27. if(res.code == 200) {
  28. dispatch('getRelationList', params)
  29. resolve(res);
  30. }
  31. }).catch( error => {
  32. reject(error)
  33. })
  34. })
  35. },
  36. removeRelationList ({ dispatch, commit }, {data, params}) {
  37. return new Promise((resolve, reject) => {
  38. removeRelationList(data).then( res => {
  39. if(res.code == 200) {
  40. dispatch('getRelationList', params)
  41. resolve(res);
  42. }
  43. }).catch( error => {
  44. reject(error)
  45. })
  46. })
  47. }
  48. }
  49. }
  50. export default relation;