texts.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import api from '@/api'
  2. import { print } from 'graphql/language/printer'
  3. import {
  4. TextsDepart, TextRef, TextdepartRecursive
  5. } from '@/api/queries'
  6. export default {
  7. state: {
  8. textsDepart: undefined
  9. },
  10. mutations: {
  11. 'SET_TEXTS_DEPART' (state, texts) {
  12. state.textsDepart = texts
  13. }
  14. },
  15. actions: {
  16. 'GET_TEXTS_DEPART' ({ state, commit }) {
  17. return api.post('', { query: print(TextsDepart) }).then(({ data }) => {
  18. commit('SET_TEXTS_DEPART', data.data.textsdepart)
  19. return state.textsDepart
  20. })
  21. },
  22. 'GET_TEXT' ({ state }, { id }) {
  23. return api.post('', { query: print(TextRef), variables: { id } })
  24. .then(data => (data.data.data))
  25. },
  26. 'GET_TREE' ({ dispatch }, id) {
  27. return api.post('', { query: print(TextdepartRecursive), variables: { id } })
  28. .then(({ data }) => (data.data.textref))
  29. }
  30. },
  31. getters: {
  32. textsDepartOptions: state => {
  33. if (!state.textsDepart) return undefined
  34. return state.textsDepart.map(({ id, title }) => ({
  35. value: id,
  36. text: `(${id}) ${title}`
  37. }))
  38. }
  39. }
  40. }