59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
const CUSTOMER_HOME_PATH = '/pages/home/index'
|
|
const ADMIN_LOGIN_PATH = '/admin/pages/login/index'
|
|
|
|
function getCurrentApp() {
|
|
return typeof getApp === 'function' ? getApp() : null
|
|
}
|
|
|
|
function clearCustomerSession() {
|
|
const app = getCurrentApp()
|
|
if (app && typeof app.clearUserSession === 'function') {
|
|
app.clearUserSession()
|
|
return
|
|
}
|
|
try {
|
|
wx.removeStorageSync('accessToken')
|
|
wx.removeStorageSync('refreshToken')
|
|
wx.removeStorageSync('userInfo')
|
|
wx.removeStorageSync('needSetPassword')
|
|
} catch (error) {}
|
|
}
|
|
|
|
function clearAdminSession() {
|
|
const app = getCurrentApp()
|
|
if (app && typeof app.clearAdminSession === 'function') {
|
|
app.clearAdminSession()
|
|
return
|
|
}
|
|
try {
|
|
wx.removeStorageSync('adminAccessToken')
|
|
wx.removeStorageSync('adminRefreshToken')
|
|
wx.removeStorageSync('adminUserInfo')
|
|
wx.removeStorageSync('adminPermissions')
|
|
wx.removeStorageSync('adminCurrentShop')
|
|
} catch (error) {}
|
|
}
|
|
|
|
function relaunch(url) {
|
|
wx.reLaunch({ url })
|
|
}
|
|
|
|
function openAdminLogin() {
|
|
clearCustomerSession()
|
|
relaunch(ADMIN_LOGIN_PATH)
|
|
}
|
|
|
|
function openCustomerHome() {
|
|
clearAdminSession()
|
|
relaunch(CUSTOMER_HOME_PATH)
|
|
}
|
|
|
|
module.exports = {
|
|
ADMIN_LOGIN_PATH,
|
|
CUSTOMER_HOME_PATH,
|
|
clearCustomerSession,
|
|
clearAdminSession,
|
|
openAdminLogin,
|
|
openCustomerHome
|
|
}
|