1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { CUSTOM_TABBAR_NO_CACHE } from '@/layouts/fg-tabbar/tabbarList'
- // uniapp 返回 入参为堆栈
- export function goBack(delta = 1) {
- console.log(delta)
- uni.navigateBack({ delta })
- }
- // uniapp 跳转页面 可携带参数
- // 示例: toPage('/pages/productDetail/productDetail', { id: 123 })
- export function toPage(url: string, params?: Record<string, any>, isRedirect = false) {
- let targetUrl = url
- const tabBarPages = ['/pages/index/index', '/pages/income/income', '/pages/mine/mine']
- if (params && Object.keys(params).length > 0) {
- const data = JSON.stringify(params)
- targetUrl = `${url}?params=${encodeURIComponent(data)}`
- }
- if (tabBarPages.includes(url)) {
- if (CUSTOM_TABBAR_NO_CACHE) {
- uni.navigateTo({ url: targetUrl })
- }
- else {
- uni.switchTab({
- url: targetUrl,
- })
- }
- }
- else {
- if (isRedirect) {
- uni.redirectTo({
- url: targetUrl,
- })
- }
- else {
- uni.navigateTo({
- url: targetUrl,
- })
- }
- }
- }
- // page参数解析方法
- export function getPageParams(options: any) {
- if (options && options.params) {
- try {
- return JSON.parse(decodeURIComponent(options.params))
- }
- catch (e) {
- console.error('解析页面参数失败:', e)
- return {}
- }
- }
- return {}
- }
|