news.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import NewsService from "@/services/NewsService";
  2. export const state = () => ({
  3. newsItem: {},
  4. categoryNewsList: [],
  5. indexNewsList: {},
  6. categoriesList: [],
  7. newsFeedList: [],
  8. stories: []
  9. });
  10. export const mutations = {
  11. SET_NEWS_ITEM(state, newsItem) {
  12. state.newsItem = newsItem;
  13. },
  14. SET_CATEGORY_NEWS_LIST(state, categoryNewsList) {
  15. state.categoryNewsList = categoryNewsList;
  16. },
  17. SET_INDEX_NEWS_LIST(state, indexNewsList) {
  18. state.indexNewsList = indexNewsList
  19. },
  20. SET_CATEGORIES_LIST(state, categoriesList) {
  21. state.categoriesList = categoriesList
  22. },
  23. LOAD_NEWS(state, newsList) {
  24. const oldNewsList = state.categoryNewsList.news
  25. const newCategoryNewsList = oldNewsList.concat(newsList.news)
  26. state.categoryNewsList.news = newCategoryNewsList
  27. },
  28. SET_STORIES(state, stories) {
  29. state.stories = stories
  30. },
  31. SET_NEWS_FEED_LIST(state, stories) {
  32. state.newsFeedList = stories
  33. }
  34. };
  35. export const actions = {
  36. loadCategoryNews({commit}, params,) {
  37. return NewsService.getCategoryNewsList(params)
  38. .then((categoryNewsList) => {
  39. commit("LOAD_NEWS", categoryNewsList)
  40. })
  41. },
  42. setCategoriesList({commit}) {
  43. return NewsService.getCategoriesList().then(list => {
  44. commit("SET_CATEGORIES_LIST", list)
  45. })
  46. },
  47. setNewsItem({commit}, params) {
  48. return NewsService.getNewsItem(params)
  49. .then((newsItem) => {
  50. commit("SET_NEWS_ITEM", newsItem)
  51. })
  52. },
  53. setCategoryNewsList({commit}, params) {
  54. return NewsService.getCategoryNewsList(params)
  55. .then((categoryNewsList) => {
  56. commit("SET_CATEGORY_NEWS_LIST", categoryNewsList)
  57. //console.log(categoryNewsList)
  58. return categoryNewsList
  59. })
  60. },
  61. setIndexNewsList({commit}) {
  62. return NewsService.getIndexNewsList()
  63. .then((indexNewsList) => {
  64. commit("SET_INDEX_NEWS_LIST", indexNewsList)
  65. })
  66. },
  67. setStories({commit, $axios}) {
  68. return NewsService.getStories().then(res => {
  69. commit("SET_STORIES", res)
  70. return res
  71. })
  72. },
  73. getNewsFeedList({ commit }) {
  74. return NewsService.getNewsFeedList()
  75. .then((newsFeedList) => {
  76. commit("SET_NEWS_FEED_LIST", newsFeedList)
  77. return newsFeedList
  78. })
  79. },
  80. };
  81. export const getters = {
  82. newsItem: state => state.newsItem,
  83. indexNewsList: state => state.indexNewsList,
  84. categoryNewsList: state => state.categoryNewsList,
  85. categoriesList: state => state.categoriesList,
  86. stories: state => state.stories,
  87. newsFeedList: state => state.newsFeedList
  88. };
  89. export default {
  90. namespaced: true,
  91. state,
  92. getters,
  93. actions,
  94. mutations
  95. }