categoryList.js 1.8 KB

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