import request from "@/common/request/index.js"; // 请求前拦截 const BEFOREINTERCEPT = (axios,currentPage, totalPage) => { return {} } //参数处理 const AFTERINTERCEPT=(result,currentPage, totalPage)=>{ return {} } // 报错拦截 const ERRINTERCPTOR = function(err) { uni.showModal({ title:"警告", content:err.message || JSON.stringify(err), confirmText:"关闭", showCancel:false, confirmColor:"#fbbd08" }) return err } export default { namespaced: true, state: { value: [], //数据 currentPage: 1, // 当前页 totalPage: 1, //总页数 }, mutations: { increment(state, options) { state = { ...state, ...options } } }, actions: { async requestFunc({ commit, state }, options) { try{ let { axios = {}, reset = false } = options; let { value, currentPage, totalPage } = state; // true 重置数据 if (reset) { value = []; currentPage = 1; totalPage = 1; } if (currentPage > totalPage) return false; axios = BEFOREINTERCEPT(axios, currentPage, totalPage); var result =await request(axios); result==AFTERINTERCEPT(result); commit('increment',result,currentPage, totalPage) }catch(err){ ERRINTERCPTOR(err) } } } }