2025-12-19 12:27:55 +00:00
|
|
|
|
<script>
|
|
|
|
|
|
export default {
|
|
|
|
|
|
globalData: {
|
|
|
|
|
|
// 用于从首页跳转到服务页面时传递需要高亮的分类
|
|
|
|
|
|
serviceCategory: null
|
|
|
|
|
|
},
|
|
|
|
|
|
onLaunch: function() {
|
|
|
|
|
|
console.log('App Launch')
|
|
|
|
|
|
// 检查登录状态
|
|
|
|
|
|
this.checkLoginStatus()
|
|
|
|
|
|
},
|
|
|
|
|
|
onShow: function() {
|
|
|
|
|
|
console.log('App Show')
|
2026-02-27 08:48:28 +00:00
|
|
|
|
// 1. uni-app 中通过 uni.getEnterOptionsSync() 调用(和微信小程序API一致,只是前缀改为uni)
|
|
|
|
|
|
const options = uni.getEnterOptionsSync();
|
|
|
|
|
|
console.log("查询到的返回数据")
|
|
|
|
|
|
console.log(options)
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 注意:scene 返回的是数字类型,不是字符串!原生代码中写 '1038' 会导致判断失败
|
|
|
|
|
|
if (options.scene === 1038 &&
|
|
|
|
|
|
options.referrerInfo?.appId === 'wxef277996acc166c3') {
|
|
|
|
|
|
|
|
|
|
|
|
// 从收银台小程序返回的逻辑
|
|
|
|
|
|
const extraData = options.referrerInfo.extraData;
|
|
|
|
|
|
|
|
|
|
|
|
if (!extraData) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '当前通过物理按键返回,未接收到返参,建议自行查询交易结果',
|
|
|
|
|
|
icon: 'none',
|
|
|
|
|
|
duration: 3000
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (extraData.code === 'success') {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '支付成功',
|
|
|
|
|
|
icon: 'success'
|
|
|
|
|
|
});
|
|
|
|
|
|
} else if (extraData.code === 'cancel') {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '支付已取消',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: `支付失败:${extraData.errmsg || '未知错误'}`,
|
|
|
|
|
|
icon: 'none',
|
|
|
|
|
|
duration: 3000
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-19 12:27:55 +00:00
|
|
|
|
},
|
|
|
|
|
|
onHide: function() {
|
|
|
|
|
|
console.log('App Hide')
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
// 检查登录状态
|
|
|
|
|
|
checkLoginStatus() {
|
|
|
|
|
|
const token = uni.getStorageSync('token')
|
2026-02-27 08:48:28 +00:00
|
|
|
|
|
2025-12-19 12:27:55 +00:00
|
|
|
|
// 如果有token,且当前在登录页,则跳转到首页
|
|
|
|
|
|
if (token) {
|
|
|
|
|
|
// 延迟一下,确保页面已经初始化
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
const pages = getCurrentPages()
|
|
|
|
|
|
const currentPage = pages[pages.length - 1]
|
|
|
|
|
|
const currentRoute = currentPage ? currentPage.route : ''
|
2026-02-27 08:48:28 +00:00
|
|
|
|
|
2025-12-19 12:27:55 +00:00
|
|
|
|
// 如果当前在登录页,跳转到首页
|
|
|
|
|
|
if (currentRoute === 'pages/login/login') {
|
|
|
|
|
|
uni.switchTab({
|
|
|
|
|
|
url: '/pages/index/index',
|
|
|
|
|
|
fail: () => {
|
|
|
|
|
|
// 如果switchTab失败(可能不在tabBar页面),使用reLaunch
|
|
|
|
|
|
uni.reLaunch({
|
|
|
|
|
|
url: '/pages/index/index'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 100)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
/*每个页面公共css */
|
2026-02-27 08:48:28 +00:00
|
|
|
|
</style>
|