2020-08-02 19:22:39 +08:00
|
|
|
export const DRAFT_API_PATH = '/api/article'
|
|
|
|
|
|
|
|
const getDefaultListData = () => {
|
|
|
|
return {
|
|
|
|
articles: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const state = () => {
|
|
|
|
return {
|
|
|
|
list: {
|
|
|
|
fetching: false,
|
|
|
|
data: getDefaultListData()
|
|
|
|
},
|
|
|
|
detail: {
|
|
|
|
fetching: false,
|
|
|
|
data: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
// 文章列表
|
|
|
|
updateListFetching(state, action) {
|
|
|
|
state.list.fetching = action
|
|
|
|
},
|
|
|
|
updateListData(state, action) {
|
2022-07-25 06:45:33 +08:00
|
|
|
console.log(action)
|
2020-08-02 19:22:39 +08:00
|
|
|
state.list.data = action
|
|
|
|
},
|
|
|
|
// 文章详情
|
|
|
|
updateDetailFetching(state, action) {
|
|
|
|
state.detail.fetching = action
|
|
|
|
},
|
|
|
|
updateDetailData(state, action) {
|
2022-07-25 06:45:33 +08:00
|
|
|
state.detail.data = action
|
2020-08-02 19:22:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
// 获取消息列表
|
|
|
|
fetchList({commit}, params = {}) {
|
|
|
|
// 清空已有数据
|
|
|
|
commit('updateListData', getDefaultListData())
|
|
|
|
commit('updateListFetching', true)
|
|
|
|
let data = {
|
|
|
|
page: params.page || 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${DRAFT_API_PATH}/drafts`, {
|
|
|
|
params: data
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateListFetching', false);
|
|
|
|
commit('updateListData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateListFetching', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// 获取文章详情
|
|
|
|
fetchDetail({ commit }, params = {}) {
|
|
|
|
// const delay = fetchDelay(
|
|
|
|
// isBrowser
|
|
|
|
// )
|
|
|
|
// if (isBrowser) {
|
|
|
|
// Vue.nextTick(() => {
|
|
|
|
// window.scrollTo(0, 300);
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
commit('updateDetailFetching', true)
|
|
|
|
// commit('updateDetailData', {})
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${DRAFT_API_PATH}/detail/${params.draft_id}`, {
|
|
|
|
params: {
|
|
|
|
type: 3
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
commit('updateDetailData', response)
|
|
|
|
commit('updateDetailFetching', false)
|
|
|
|
resolve(response)
|
|
|
|
// delay(() => {
|
|
|
|
// resolve(response)
|
|
|
|
// })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateDetailFetching', false)
|
|
|
|
return Promise.reject(error)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|