import Taro from "@tarojs/taro";

export default class Utils {

    static getSystemInfo() {
        let sysInfo: any = {};

        let res = Taro.getSystemInfoSync();

        sysInfo.WIN_WIDTH = res.screenWidth;
        sysInfo.WIN_HEIGHT = res.screenHeight;
        sysInfo.IS_IOS = /ios/i.test(res.system);
        sysInfo.IS_ANDROID = /android/i.test(res.system);
        sysInfo.STATUS_BAR_HEIGHT = res.statusBarHeight;
        sysInfo.DEFAULT_HEADER_HEIGHT = 46;

        sysInfo.DEFAULT_CONTENT_HEIGHT = res.screenHeight - res.statusBarHeight - sysInfo.DEFAULT_HEADER_HEIGHT;

        sysInfo.IS_APP = true;
        return sysInfo;
    }

    /**
     * @description 获取当前页url
     */
    static getCurrentPageUrl() {
        let pages = Taro.getCurrentPages()
        let currentPage = pages[pages.length - 1]
        let url = currentPage.route
        return url
    }
  
    static pageToLogin() {
        let path = Utils.getCurrentPageUrl()
        if (!path.includes('login')) {
        Taro.navigateTo({
            url: "/pages/login/login"
        });
        }
    }
  
}
