123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import NewsService from "@/services/NewsService";
- export const state = () => ({
- newsItem: {},
- categoryNewsList: [],
- indexNewsList: {},
- categoriesList: [],
- newsFeedList: [],
- stories: []
- });
- export const mutations = {
- SET_NEWS_ITEM(state, newsItem) {
- state.newsItem = newsItem;
- },
- SET_CATEGORY_NEWS_LIST(state, categoryNewsList) {
- state.categoryNewsList = categoryNewsList;
- },
- SET_INDEX_NEWS_LIST(state, indexNewsList) {
- state.indexNewsList = indexNewsList
- },
- SET_CATEGORIES_LIST(state, categoriesList) {
- state.categoriesList = categoriesList
- },
- LOAD_NEWS(state, newsList) {
- const oldNewsList = state.categoryNewsList.news
- const newCategoryNewsList = oldNewsList.concat(newsList.news)
- state.categoryNewsList.news = newCategoryNewsList
- },
- SET_STORIES(state, stories) {
- state.stories = stories
- },
- SET_NEWS_FEED_LIST(state, stories) {
- state.newsFeedList = stories
- }
- };
- export const actions = {
- loadCategoryNews({commit}, params,) {
- return NewsService.getCategoryNewsList(params)
- .then((categoryNewsList) => {
- commit("LOAD_NEWS", categoryNewsList)
- })
- },
- setCategoriesList({commit}) {
- return NewsService.getCategoriesList().then(list => {
- commit("SET_CATEGORIES_LIST", list)
- })
- },
- setNewsItem({commit}, params) {
- return NewsService.getNewsItem(params)
- .then((newsItem) => {
- commit("SET_NEWS_ITEM", newsItem)
- })
- },
- setCategoryNewsList({commit}, params) {
- return NewsService.getCategoryNewsList(params)
- .then((categoryNewsList) => {
- commit("SET_CATEGORY_NEWS_LIST", categoryNewsList)
- //console.log(categoryNewsList)
- return categoryNewsList
- })
- },
- setIndexNewsList({commit}) {
- return NewsService.getIndexNewsList()
- .then((indexNewsList) => {
- commit("SET_INDEX_NEWS_LIST", indexNewsList)
- })
- },
- setStories({commit, $axios}) {
- return NewsService.getStories().then(res => {
- commit("SET_STORIES", res)
- return res
- })
- },
- getNewsFeedList({ commit }) {
- return NewsService.getNewsFeedList()
- .then((newsFeedList) => {
- commit("SET_NEWS_FEED_LIST", newsFeedList)
- return newsFeedList
- })
- },
- };
- export const getters = {
- newsItem: state => state.newsItem,
- indexNewsList: state => state.indexNewsList,
- categoryNewsList: state => state.categoryNewsList,
- categoriesList: state => state.categoriesList,
- stories: state => state.stories,
- newsFeedList: state => state.newsFeedList
- };
- export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations
- }
|