Files
houyi-uniapp/utils/index.js
PC-202306242200\Administrator 85b89ccea7 first commit
2026-03-28 23:27:25 +08:00

90 lines
1.7 KiB
JavaScript

import store from '../store'
export default {
token() {
const token = uni.getStorageSync('token');
if (!token.access_token) {
uni.showModal({
title: '提示',
content: '为提供更好的服务,请登录后继续',
cancelText: "随便逛逛",
confirmText: '立即登录',
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/me/login'
})
} else if (res.cancel) {
}
}
});
return true
}
},
// 页面路由跳转
tn(url, autn) {
const token = uni.getStorageSync('token');
if (autn && !token.access_token) return this.token();
uni.navigateTo({
url: url
})
},
// 退出登录
logOut() {
const token = uni.getStorageSync('token');
if (!token.access_token) {
uni.showModal({
title: '提示',
content: '您还未进行登录,是否前往登录?',
cancelText: "取消",
confirmText: '确定',
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/me/login'
})
} else if (res.cancel) {
}
}
});
return
}
uni.showModal({
title: '提示',
content: '是否确认退出登录',
cancelText: "取消",
confirmText: '确定',
success: (res) => {
if (res.confirm) {
// uni.clearStorage();
store.commit('auth/resetUser');
store.commit('auth/resetToken');
uni.navigateTo({
url: '/pages/me/login'
})
} else if (res.cancel) {
}
}
});
},
// 拨打电话
call(e) {
uni.makePhoneCall({
phoneNumber: e
});
},
copy(e, tit) {
uni.setClipboardData({
data: e,
success: function() {
uni.showToast({
title: tit ? tit : '复制成功',
icon: "none"
})
}
});
}
}