123456789101112131415161718192021222324252627282930313233 |
- import { usePermissions } from '../../composables/permissions'
- export const back = () => {
- uni.navigateBack()
- }
- export const useRouter = () => {
- const { routes, isLogined } = usePermissions()
- const push = async (url: string, switchTab = false) => {
- const path = url.split('?')[0]
- const route = routes.find((it) => it.path === path)
- if (route && !route.meta.canNotLogin && !isLogined.value) {
- if (route.meta.showToast) {
- uni.showToast({ title: '暂无权限', icon: 'none' })
- }
- if (route.meta.toLogin) {
- push('/pages/login/index')
- }
- return false
- }
- if (switchTab) {
- uni.switchTab({ url })
- } else {
- uni.navigateTo({ url })
- }
- }
- const replace = async (path: string) => {
- uni.redirectTo({ url: path })
- }
- const back = () => {
- uni.navigateBack()
- }
- return { push, replace, back }
- }
|