import { post, get, getL, postL } from '@/utils/http'
import { SERVICE_URL } from '@/utils/config'

export const trans = (promise) => {
    return promise
        .then((data) => {
            return data
        })
        .catch((err) => {
            return err
        })
}

export default {
    apis: {
        UPLOAD: SERVICE_URL + '/api/oss/file/upload',
        MESSAGE: SERVICE_URL + '/api/app/message',
        PAGE_CONFIG: SERVICE_URL + '/api/app/page/getByPageId',
        MiNI_CODE: SERVICE_URL + '/api/wechatMa/getWxaCodeUnlimitBytes',
        TRACK: SERVICE_URL + '/api/track',
        VERSION_TRACK: SERVICE_URL + '/api/app/version/track',
        FEEDBACK: SERVICE_URL + '/api/app/feedback/submit'
    },
    async track() {
        const res = await trans(get(this.apis.TRACK))
        return res.data
    },
    async track2() {
        const res = await trans(getL(this.apis.VERSION_TRACK))
        return res.data
    },
    async message(current, size, type) {
        let param = {
            current,
            size
        }
        !!type && (param.type = type)
        const res = await trans(get(this.apis.MESSAGE, param))
        return res.success ? res.data : null
    },
    async pageConfig(pageId) {
        let res = await trans(get(this.apis.PAGE_CONFIG, { pageId }))
        return res.data
    },
    async feedbackSubmit(data, loading = false) {
        let res = await trans(post(this.apis.FEEDBACK, data, { loading }))
        return res.data
    },
	async feedbackSubmit(data, loading = false) {
	    let res = await trans(post(this.apis.FEEDBACK, data, { loading }))
	    return res.data
	},
	async getLatest() {
        let res = await trans(get(SERVICE_URL + '/api/app/version/getLatest'))
        return res.data
    },
	
}
