export default {
    namespaced: true,
    state: {
        config: {},
    },
    getters: {
        config(state) {
            return state.config;
        },
    },
    mutations: {
        setConfig(state, data) {
            state.config = { ...state.config, ...data };
        },
    },
    actions: {
        initConfig(context) {
            let config = uni.getStorageSync('system_config');
            if (!config) {
                const { windowWidth, windowHeight, statusBarHeight, safeAreaInsets } = uni.getSystemInfoSync();
                // #ifndef H5
                const { height, top } = uni.getMenuButtonBoundingClientRect();
                const headerHeight = height + ((top - statusBarHeight) * 2);
                // #endif
                // #ifdef H5
                const headerHeight = 40; // 乘2再使用rpx2px转px使用
                // #endif
                config = { windowWidth, windowHeight, statusBarHeight, headerHeight, safeAreaInsets };
                uni.setStorageSync('system_config', config);
            }
            context.commit('setConfig', config);
        }
    }
}
