wanyu_frontend/utils/helpers.js
2025-03-27 17:18:23 +08:00

71 lines
1.4 KiB
JavaScript

class helpers {
/**
* 跳转页面
* @param pathName //路径名
* @param params //查询参数
* id=12
* @param type //跳转类型
* navigateTo = 保留当前页面,跳转到应用内的某个页面
* redirectTo = 关闭当前页面,跳转到应用内的某个页面
* reLaunch = 关闭所有页面,打开到应用内的某个页面
* switchTab = 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
*/
static jumpToPage(pathName, params = '', type = 'navigateTo') {
let url
let paths = {
//登录页
'login': '/pages/user/login',
//订单详情
'order-info': '/pages/order/order-info',
//提交订单
'order-submit': '/pages/order/order-submit',
}
url = paths[pathName]
if (url === undefined) {
return this.showToast('跳转页面不存在')
}
if (params !== '') {
url += `?${params}`
}
uni[type]({
url
})
}
static showToast(msg) {
let duration = 1500
if (msg.length > 7) {
duration = 2000
}
if (msg.length > 14) {
duration = 4000
}
uni.showToast({
title: msg,
icon: "none",
duration: duration
})
}
/**
* 深拷贝数据
* @param data
* @returns {any}
*/
static deepObj(data) {
if (typeof data === 'string' || typeof data === 'number') {
return data;
}
if (data) {
return JSON.parse(JSON.stringify(data));
}
return data;
}
}
export default helpers