2020-09-08 07:59:16 +08:00
|
|
|
import {ARTICLE_API_PATH} from "@/store/article";
|
|
|
|
|
2020-08-11 22:39:12 +08:00
|
|
|
/**
|
|
|
|
* @file 分类数据状态 / ES module
|
|
|
|
* @module store/category
|
|
|
|
* @author Ronger <https://github.com/ronger-x>
|
|
|
|
*/
|
|
|
|
|
|
|
|
export const ADMIN_API_PATH = '/api/admin'
|
2020-09-08 07:59:16 +08:00
|
|
|
export const TAG_API_PATH = '/api/tag'
|
2020-08-11 22:39:12 +08:00
|
|
|
|
|
|
|
const getDefaultListData = () => {
|
|
|
|
return {
|
|
|
|
tags: [],
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
}
|
2020-09-08 07:59:16 +08:00
|
|
|
const getDefaultData = () => {
|
|
|
|
return {
|
|
|
|
tagIconPath: '',
|
|
|
|
tagStatus: '0',
|
|
|
|
tagReservation: '0'
|
|
|
|
}
|
|
|
|
}
|
2020-08-11 22:39:12 +08:00
|
|
|
|
|
|
|
export const state = () => {
|
|
|
|
return {
|
|
|
|
fetching: false,
|
|
|
|
data: [],
|
|
|
|
list: {
|
|
|
|
fetching: false,
|
|
|
|
data: getDefaultListData()
|
2020-09-08 07:59:16 +08:00
|
|
|
},
|
|
|
|
detail: {
|
|
|
|
fetching: false,
|
|
|
|
data: getDefaultData()
|
2020-08-11 22:39:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
updateListFetching(state, action) {
|
|
|
|
state.list.fetching = action
|
|
|
|
},
|
|
|
|
updateListData(state, action) {
|
|
|
|
state.list.data = action
|
|
|
|
},
|
|
|
|
updateFetching(state, action) {
|
|
|
|
state.fetching = action
|
|
|
|
},
|
2020-09-08 07:59:16 +08:00
|
|
|
updateDetailFetching(state, action) {
|
|
|
|
state.detail.fetching = action
|
|
|
|
},
|
2020-08-11 22:39:12 +08:00
|
|
|
updateDetailData(state, action) {
|
2020-09-08 07:59:16 +08:00
|
|
|
state.detail.data = action
|
2020-08-11 22:39:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
fetchList({commit}, params = {}) {
|
|
|
|
// 清空已有数据
|
|
|
|
commit('updateListData', getDefaultListData())
|
|
|
|
commit('updateListFetching', true)
|
|
|
|
let data = {
|
|
|
|
page: params.page || 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${ADMIN_API_PATH}/tags`, {
|
|
|
|
params: data
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
commit('updateListFetching', false);
|
|
|
|
commit('updateListData', response);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
commit('updateListFetching', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchDetail({ commit }, params) {
|
|
|
|
commit('updateFetching', true);
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${ADMIN_API_PATH}/tag/${params.tag_id}`)
|
|
|
|
.then(response => {
|
|
|
|
commit('updateDetailData', response)
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
commit('updateFetching', false)
|
|
|
|
})
|
2020-09-08 07:59:16 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// 获取文章详情
|
|
|
|
fetchPostDetail({ commit }, params = {}) {
|
|
|
|
// const delay = fetchDelay(
|
|
|
|
// isBrowser
|
|
|
|
// )
|
|
|
|
// if (isBrowser) {
|
|
|
|
// Vue.nextTick(() => {
|
|
|
|
// window.scrollTo(0, 300);
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (typeof params.tag_id === 'undefined') {
|
|
|
|
commit('updateDetailData', getDefaultData())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
commit('updateDetailFetching', true)
|
|
|
|
// commit('updateDetailData', {})
|
|
|
|
return this.$axios
|
|
|
|
.$get(`${ADMIN_API_PATH}/tag/detail/${params.tag_id}`)
|
|
|
|
.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)
|
|
|
|
})
|
2020-08-11 22:39:12 +08:00
|
|
|
}
|
|
|
|
}
|