43 lines
1.2 KiB
Plaintext
43 lines
1.2 KiB
Plaintext
/**
|
||
* 页面导航封装
|
||
* 所有跳转统一走这里,便于集中做「角色权限拦截 / 埋点 / 登录校验」。
|
||
*/
|
||
import { canAccess } from './role.uts'
|
||
|
||
/** 普通跳转(保留当前页) */
|
||
export function navTo(url : string) : void {
|
||
if (!canAccess(url)) {
|
||
uni.showToast({ title: '当前角色无权访问该页面', icon: 'none' })
|
||
return
|
||
}
|
||
uni.navigateTo({ url: url })
|
||
}
|
||
|
||
/** 替换当前页(不可返回) */
|
||
export function redirectTo(url : string) : void {
|
||
uni.redirectTo({ url: url })
|
||
}
|
||
|
||
/** 关闭所有页面并打开 */
|
||
export function relaunchTo(url : string) : void {
|
||
uni.reLaunch({ url: url })
|
||
}
|
||
|
||
/** 返回上一页 */
|
||
export function navBack() : void {
|
||
uni.navigateBack()
|
||
}
|
||
|
||
/** Tab 切换(uni-app x 无原生 tabBar,用 reLaunch 保证栈干净) */
|
||
export function switchTab(url : string) : void {
|
||
uni.reLaunch({ url: url })
|
||
}
|
||
|
||
/** uni.showToast 支持的 icon 取值 */
|
||
export type HrToastIcon = 'success' | 'error' | 'fail' | 'exception' | 'loading' | 'none'
|
||
|
||
/** 轻提示(统一出口,避免页面直接散落 uni.showToast) */
|
||
export function toast(title : string, icon : HrToastIcon = 'none') : void {
|
||
uni.showToast({ title: title, icon: icon, duration: 1600 })
|
||
}
|