news.js
2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import moment from 'moment';
import * as Types from './types';
export default function() {
return {
namespaced: true,
state: {
newsList: {
list: [],
tabList: [],
page: 0,
limit: 10,
totalPage: 0,
isMoreData: true,
},
newsDeatilList: {
list: [],
tabList: [],
page: 0,
limit: 10,
totalPage: 0,
isMoreData: true,
}
},
mutations: {
[Types.FETCH_NEWS_LIST](state, { list }) {
state.newsList.list = list.page > 1 ? state.newsList.list.concat(list.list) : list.list;
state.newsList.page = list.page;
state.newsList.totalPage = list.totalPage;
list.page < list.totalPage ? state.newsList.isMoreData = true : state.newsList.isMoreData = false;
},
[Types.FETCH_NEWSDETAIL_LIST](state, { list }) {
state.newsDeatilList.list = list.page > 1 ? state.newsDeatilList.list.concat(list.list) : list.list;
state.newsDeatilList.page = list.page;
state.newsDeatilList.totalPage = list.totalPage;
list.page < list.totalPage ? state.newsDeatilList.isMoreData = true : state.newsDeatilList.isMoreData = false;
},
// resPages(state, {page, isMoreData}) {
// state.newsDeatilList.page = page;
// state.newsDeatilList.isMoreData = isMoreData;
// },
[Types.FETCH_NEWS_TAB_LIST](state, { list }) {
state.newsList.tabList = list;
},
},
actions: {
async fetchNewsList({ commit, state }, obj) {
// console.log(obj);
let { isResetPage, limit, page, totalPage, type } = obj;
const result = await this.$api.post('/api/ufo/home/newsList', {
page, type: type || '', limit
});
if (result.code === 200) {
result.data.list && result.data.list.map((res) => {
res.createTime = moment(new Date(res.createTime * 1000)).format('YYYY.MM.DD HH:mm');
});
// if (type) {
// commit(Types.FETCH_NEWSDETAIL_LIST, {list: result.data});
// } else {
// commit(Types.FETCH_NEWS_LIST, {list: result.data});
// }
return result;
}
},
async fetchNewsTabList({ commit }) {
const result = await this.$api.post('/api/ufo/home/newsListTab', {});
if (result.code === 200) {
commit(Types.FETCH_NEWS_TAB_LIST, {list: result.data});
return result;
}
},
},
};
}