import axios from 'axios'
import store from '../store'
export function $post(url, params, config = {}) {
    return new Promise(resolve => {
        if (config.takeUserIdAndAppToken === false) {
            /**将对象转换成字符串 */
            axios.post(url, params).then(res => {
                resolve(res)
            }).catch(error => {
                console.log(error)
            })
        } else {
            store.ready(state => {
                params.userid = state.userid
                params.apptoken = state.apptoken
                if(state.vesion == 'saas'){
                    params.schoolid = state.schoolid
                }
                axios.post(url, params).then(res => {
                    resolve(res)
                }).catch(error => {
                    console.log(error)
                })
            })
        }
    })
}

export function $get(url, params = {}, config = {}) {
    return new Promise(resolve => {
        if (config.takeUserIdAndAppToken === false) {
            axios.get(url, {
                params: params
            }).then(res => {
                resolve(res)
            }).catch(error => {
                console.log(error)
            })
        } else {
            store.ready(state => {
                params.userid = state.userid
                params.apptoken = state.apptoken
                if(state.vesion == 'saas'){
                    params.schoolid = state.schoolid
                }
                axios.get(url, {
                    params: params
                }).then(res => {
                    resolve(res)
                }).catch(error => {
                    console.log(error)
                })
            })

        }

    })
}