import http from '../../../api/fastposter'

const state = {
    items: [],
}
const getters = {}

const actions = {
    getItems({commit}) {
        return new Promise((resolve) => {
            http.loadPosters(r => {
                let posters = r.data.posters
                posters.forEach(a => {
                    // 处理路径
                    a.preview = a.preview.startsWith('http') ? a.preview : http.baseURL + a.preview
                });
                commit('setItems', posters)
                resolve(posters)
            })
        });
    }
}
const mutations = {
    setItems(state, items) {
        state.items = items;
    }
}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations,
}
