You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.8 KiB
82 lines
1.8 KiB
import store from '@/store/index'
|
|
// 框架方法封装
|
|
const tabList = ['client', 'trade', 'mall', 'mine']
|
|
|
|
/**
|
|
* @param {string} 跳转的tabBar页面
|
|
* @return {null}
|
|
*/
|
|
export function tab2(tabPage) {
|
|
if (tabList.includes(tabPage)) {
|
|
uni.switchTab({
|
|
url: `/pages/${tabPage}/index`
|
|
})
|
|
}
|
|
}
|
|
/**
|
|
* @param {string} 返回上一级
|
|
* @return {null}
|
|
*/
|
|
export function back() {
|
|
if (getCurrentPages().length > 1) {
|
|
uni.navigateBack({
|
|
delta: 1
|
|
})
|
|
} else {
|
|
go2('client')
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 跳转到指定页面,包括tabBar页面
|
|
* @param {string} url 页面名称
|
|
* @param {object} data 页面参数
|
|
* @param {string} isRedirect 是否重定向 默认false
|
|
* @return {null}
|
|
*/
|
|
export function go2(url, data = {}, isRedirect = false) {
|
|
if (!url) {
|
|
console.error('请选择页面')
|
|
return
|
|
}
|
|
let param = ''
|
|
Object.keys(data).forEach((key) => {
|
|
if (param === '') {
|
|
param = `${key}=${data[key]}`
|
|
} else {
|
|
param += `&${key}=${data[key]}`
|
|
}
|
|
})
|
|
if (tabList.includes(url)) {
|
|
uni.switchTab({
|
|
url: `/pages/${url}/index${param ? '?' + param : ''}`
|
|
})
|
|
} else {
|
|
if (isRedirect) {
|
|
uni.redirectTo({
|
|
url: `/pages/${url}/index${param ? '?' + param : ''}`
|
|
})
|
|
} else {
|
|
uni.navigateTo({
|
|
url: `/pages/${url}/index${param ? '?' + param : ''}`
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 跳转到指定页面,包括tabBar页面,校验是否已登录,未登录则跳转到登录页面
|
|
* @param {string} url 页面名称
|
|
* @param {object} data 页面参数
|
|
* @param {string} isRedirect 是否重定向 默认false
|
|
* @return {null}
|
|
*/
|
|
export function loginGo2(url, data = {}, isRedirect) {
|
|
const token = store.state.qnToken
|
|
if (token) {
|
|
go2(url, data, isRedirect)
|
|
} else {
|
|
store.commit('setNextPage', { name: url, data })
|
|
go2('login')
|
|
}
|
|
}
|