import { callHandler } from 'nejsbridge/dist/bridge.lofter.es' import { isLofter } from 'nw-detect'; import { openAppLofter } from 'nw-app-lofter'; import { showMessage } from '../common/toast/toast' const USER_AGENT = navigator.userAgent; function isWeixin() { return /micromessenger/i.test(USER_AGENT); } export function redirectToLogin() { var locationNow = window.location.href; if (!isWeixin()) {//非微信,则进入手机号登录入口 window.location.href = "//www.lofter.com/login?subtype=mobilelogin&target=" + encodeURIComponent(locationNow) + "&fromBenefitProduct=1"; } else { window.location.href = '//www.lofter.com/benefit/main/login?target=' + encodeURIComponent(locationNow) + "&fromBenefitProduct=1"; } }; export function goToLogin(callback?: (...reset: any[]) => any, theme = 'default', forceApp = false) { if (isLofter()) { callHandler('njb_login', (data: any) => { if (data.code === 200) { callback && callback() } }) } else if (forceApp) { openAppLofter({ path: 'webview', query: { url: location.href } }) } else { let loginUrl = 'https://www.lofter.com/front/login?target=' + encodeURIComponent(location.href); if (theme === 'card') { loginUrl += '&theme=card'; } location.href = loginUrl; } }