Files
dianxiaorui-uniapp/hooks/useNav.js
PC-202306242200\Administrator 4d06351f6a no message
2026-03-28 23:00:29 +08:00

74 lines
1.1 KiB
JavaScript

import {
ref,
watch
} from 'vue';
export function useNav() {
const nav = (e) => {
if (e.call) {
uni.makePhoneCall({
phoneNumber: '4008005326' //仅为示例
});
return
}
if (!uni.getStorageSync('token')) {
uni.showModal({
title: '提示',
content: '为提供更好的服务,请前往登录',
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/login/login'
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
})
return
}
uni[e.type == 'nav' || !e.type ? 'navigateTo' : e.type == 'switchTab' ? 'switchTab' : 'navigateTo']({
url: e.path
})
}
const navTo = (path, token, call) => {
if (!uni.getStorageSync('token')) {
uni.showModal({
title: '提示',
content: '为提供更好的服务,请前往登录',
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/login/login'
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
})
return
}
uni.navigateTo({
url: path
})
}
return {
nav,
navTo
}
}
export default useNav