import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        //上传文件前的配置信息
        uploadConfigInfo: {
            dir: "oss_portal/001/uploads/2018/caf78c75-f9a5-4a6e-9e07-6d2871604263",
            host: "http://117.39.29.95:8221/paoyici-city-test-data",
            accessid: "z760kkGR0MTXsJ76",
            policy: "eyJleHBpcmF0aW9uIjoiMjAxOS0wOS0yNFQwMzoxNjoxMi40MTdaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF0sWyJzdGFydHMtd2l0aCIsIiRrZXkiLCJvc3NfcG9ydGFsLzAwMSJdXX0=",
            signature: "p0lO9jNRtasGr8GOWyN06YnB/9s="
        }
    },
    getters : {
        //note 获取上传前的数据
        storeUploadConfigInfo: state => {
            return state.uploadConfigInfo;
        }
    },
    mutations: {
        updateUploadConfigInfo(state, data) {
            state.uploadConfigInfo = {...state.uploadConfigInfo, ...data};
        },
    },
    actions: {
        updateUploadConfigInfo({commit,state}, data) {
            //已经登录，要获取上传前的配置数据，比如ip,文件夹名
            debugger;
            request('file/toUpload',{
                mock:false,
                body:{
                    data:{}
                }
            }).then(data => {
                /*默认获取上次前的接口地址 'http://47.93.79.217:8080/file/toUpload'*/
                commit('updateUploadConfigInfo', data)
            })


        }
    },
    modules: {

    }
});

export default store;
