Commit 2020d6b4 by 姜雷

修改分页以及筛选模块

parent f10eb982
const UPDATE_FILTERS = 'UPDATE_FILTERS'; const UPDATE_FILTERS = 'UPDATE_FILTERS';
const RESET_FILTERS = 'RESET_FILTERS';
const initFiltersStore = ( const initFiltersStore = (
initState = {}, initState = () => ({}),
otherGetters = {}, otherGetters = {},
otherActions = {}, otherActions = {},
otherMutations = {} otherMutations = {}
) => { ) => {
const state = () => ({ const state = () => ({
filters: initState, filters: initState(),
}); });
const getters = { const getters = {
filters: state => state.filters, filters: state => state.filters,
...@@ -17,6 +18,9 @@ const initFiltersStore = ( ...@@ -17,6 +18,9 @@ const initFiltersStore = (
updateFilters({ commit }, filters) { updateFilters({ commit }, filters) {
commit(UPDATE_FILTERS, filters); commit(UPDATE_FILTERS, filters);
}, },
resetFilters({ commit }) {
commit(RESET_FILTERS);
},
...otherActions, ...otherActions,
}; };
const mutations = { const mutations = {
...@@ -26,6 +30,9 @@ const initFiltersStore = ( ...@@ -26,6 +30,9 @@ const initFiltersStore = (
...filters, ...filters,
}; };
}, },
[RESET_FILTERS]() {
state.filters = initState();
},
...otherMutations, ...otherMutations,
}; };
......
import { UPDATE_PAGINATION } from '../mutation-types'; const UPDATE_PAGINATION = 'UPDATE_PAGINATION';
const RESET_PAGINATION = 'RESET_PAGINATION';
const state = () => ({ const state = () => ({
pageNum: 1, // 当前分页 pageNum: 1, // 当前分页
...@@ -17,6 +18,9 @@ const actions = { ...@@ -17,6 +18,9 @@ const actions = {
updatePagination({ commit }, pagination) { updatePagination({ commit }, pagination) {
commit(UPDATE_PAGINATION, pagination); commit(UPDATE_PAGINATION, pagination);
}, },
resetPagination({ commit }) {
commit(RESET_PAGINATION);
},
}; };
const mutations = { const mutations = {
...@@ -25,6 +29,14 @@ const mutations = { ...@@ -25,6 +29,14 @@ const mutations = {
...pagination, ...pagination,
}); });
}, },
[RESET_PAGINATION](state) {
state = Object.assign(state, {
pageNum: 1, // 当前分页
pageSize: 10, // 分页大小
total: 0,
pages: 0,
});
},
}; };
export default { export default {
......
export const USER_LOGIN = 'USER_LOGIN'; export const USER_LOGIN = 'USER_LOGIN';
export const FETCH_PRODUCT_LIST = 'FETCH_PRODUCT_LIST'; export const FETCH_PRODUCT_LIST = 'FETCH_PRODUCT_LIST';
// pagination
export const UPDATE_PAGINATION = 'UPDATE_PAGINATION';
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment