categoryList.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { getCategoryList, setCategoryList, addCategoryList } from '@/api/categoryList'
  2. const state = {
  3. getCategoryData: [],
  4. getCategoryDataLength: 0
  5. }
  6. const mutations = {
  7. GET_CATEGORY: (state, data) => {
  8. state.getCategoryData = data
  9. },
  10. CATEGORY_LENGTH: (state, length) => {
  11. state.getCategoryDataLength = length
  12. }
  13. }
  14. const actions = {
  15. // 获取课程表专区
  16. getBlockList({ commit, state }, obj) {
  17. const blockType = obj.blockType
  18. const page = (obj.page - 1) * 10
  19. return new Promise((resolve, reject) => {
  20. getCategoryList(blockType).then((res) => {
  21. const list = res.data
  22. commit('CATEGORY_LENGTH', list.length)
  23. commit('GET_CATEGORY', list.splice(page, 10))
  24. resolve()
  25. }).catch(error => {
  26. reject(error)
  27. })
  28. })
  29. },
  30. // 修改课程表专区
  31. setBlockList({ commit, state }, obj) {
  32. return new Promise((resolve, reject) => {
  33. setCategoryList(obj).then((res) => {
  34. resolve()
  35. }).catch(error => {
  36. reject(error)
  37. })
  38. })
  39. },
  40. // 添加课程表专区
  41. addBlockList({ commit, state }, obj) {
  42. return new Promise((resolve, reject) => {
  43. addCategoryList(obj).then((res) => {
  44. resolve()
  45. }).catch(error => {
  46. reject(error)
  47. })
  48. })
  49. }
  50. }
  51. export default {
  52. namespaced: true,
  53. state,
  54. mutations,
  55. actions
  56. }