Files
aiot-uniapp/src/utils/toLoginPage.ts
feige996 53f27a1917 refactor: 移除未使用的代码和功能模块
清理未使用的页面、组件、路由配置和主题相关代码
移除登录拦截和分包配置相关逻辑
简化首页和个人中心页面
2025-11-06 16:18:11 +08:00

45 lines
1.0 KiB
TypeScript

import { getLastPage } from '@/utils'
import { debounce } from '@/utils/debounce'
interface ToLoginPageOptions {
/**
* 跳转模式, uni.navigateTo | uni.reLaunch
* @default 'navigateTo'
*/
mode?: 'navigateTo' | 'reLaunch'
/**
* 查询参数
* @example '?redirect=/pages/home/index'
*/
queryString?: string
}
// TODO: 自己增加登录页
const LOGIN_PAGE = '/pages/login/index'
/**
* 跳转到登录页, 带防抖处理
*
* 如果要立即跳转,不做延时,可以使用 `toLoginPage.flush()` 方法
*/
export const toLoginPage = debounce((options: ToLoginPageOptions = {}) => {
const { mode = 'navigateTo', queryString = '' } = options
const url = `${LOGIN_PAGE}${queryString}`
// 获取当前页面路径
const currentPage = getLastPage()
const currentPath = `/${currentPage.route}`
// 如果已经在登录页,则不跳转
if (currentPath === LOGIN_PAGE) {
return
}
if (mode === 'navigateTo') {
uni.navigateTo({ url })
}
else {
uni.reLaunch({ url })
}
}, 500)