import {get, post, json} from "@utils/ajax";
import {GET_COPY_MESSAGE, GET_DISCLAIMER_MESSAGE, GET_VERSION} from "../types/copyRight";
import { storageLocal } from "@utils/tools"

export const getMessage = (dispatch, getState) => {
    const state = getState();
    // 请求地址
    post('/versionInfo/getVersionInfoAlls')
    .then((data) => {
        
        const versionInfo = JSON.parse(storageLocal.get('versionInfo'));
        if(versionInfo) {
            if(versionInfo.data.data.name !==  data.data.data.name)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   {
                storageLocal.set('hasNewVersion','true');
                storageLocal.set('versionInfo',data);
                dispatch({
                    type: GET_VERSION,
                    hasNewVersion: true
                })
            }
        } else {
            storageLocal.set('hasNewVersion','true'); 
            storageLocal.set('versionInfo',data); 
        }
        
        dispatch({
            type: GET_COPY_MESSAGE,
            data:data
        });
    })
};

export const getDisMessage = (dispatch, getState) => {
    const state = getState();
    // 请求地址
    post('/disclaimerInformation/getDisclaimerInformations')
    .then((data) => {
        dispatch({
            type: GET_DISCLAIMER_MESSAGE,
            data:data
        });
    })
};