UNPKG

vue-iscroll-list

Version:
106 lines (102 loc) 2.99 kB
import * as types from '../mutations' import Vue from 'vue' const state = { searchFilter: {}, commonFilter: {}, list: { data: [], error: {}, success: false, page: { page: 1, next: true, count: 0 } } } const actions = { updateCommonFilter ({commit}, params) { commit(types.UPDATE_COMMON_FILTER, params) }, updateSearchFilter ({commit}, params) { commit(types.UPDATE_SEARCH_FILTER, params) }, resetPage ({commit}, appModule) { let distribution = getDistribution(appModule, 'RESET_PAGE') commit(distribution) }, nextPage ({commit}, appModule) { let distribution = getDistribution(appModule, 'NEXT_PAGE') commit(distribution) }, setPage ({commit}, {number, appModule}) { let distribution = getDistribution(appModule, 'SET_PAGE') commit(distribution, number) }, initList ({commit}, appModule) { let distribution = getDistribution(appModule, 'INIT') commit(distribution) }, commonListRequest ({commit}, {params}) { Vue.http.get('/static/list.json') .then(res => { commit(types.COMMON_LIST_SUCCESS, res.body) }, err => { commit(types.COMMON_LIST_FAILURE, err) }) } } const mutations = { [types.UPDATE_COMMON_FILTER] (state, params) { state.commonFilter = Object.assign({}, params) }, [types.UPDATE_SEARCH_FILTER] (state, params) { state.searchFilter = Object.assign({}, params) }, [types.COMMON_LIST_INIT] (state, res) { state.list.success = false state.list.page.count = 0 state.list.page.next = true state.list.data = res }, [types.COMMON_LIST_SUCCESS] (state, res) { state.list.success = true if (state.list.page.page === 1) { state.list.data = res } else { if (state.list.page.page < 10) { state.list.data = state.list.data.concat(res) } else { state.list.page.next = false } } state.list.page.count = state.list.data.length }, [types.COMMON_LIST_FAILURE] (state, err) { state.list.success = false state.list.error = err }, [types.COMMON_LIST_RESET_PAGE] (state) { state.list.page.page = 1 state.list.page.next = true }, [types.COMMON_LIST_NEXT_PAGE] (state) { state.list.page.page += 1 }, [types.COMMON_LIST_SET_PAGE] (state, number) { state.list.page.page = number } } // 拼接分发字符串 function getDistribution (appModule, operation) { let module = appModule || '' module = module.toUpperCase() let distribution = module + '_' + operation distribution = module === '' ? operation : distribution return distribution } export default { state, actions, mutations }