81 行
1.9 KiB
Plaintext
81 行
1.9 KiB
Plaintext
<script setup lang="uts">
|
|
import { getAuthToken } from './common/request.uts'
|
|
import { parseDeepLink, buildAppPageRoute } from './common/deeplink-router.uts'
|
|
|
|
// #ifdef APP-ANDROID || APP-HARMONY
|
|
let firstBackTime = 0
|
|
// #endif
|
|
|
|
function openDeepLink(scheme : string | null, link : string | null) : boolean {
|
|
const raw = scheme != null && scheme != '' ? scheme! : (link != null ? link! : '')
|
|
const info = parseDeepLink(raw)
|
|
if (!info.isValid) {
|
|
return false
|
|
}
|
|
uni.reLaunch({
|
|
url: buildAppPageRoute(info)
|
|
})
|
|
return true
|
|
}
|
|
|
|
function routeOwnerHome() : void {
|
|
if (getAuthToken() != '') {
|
|
uni.switchTab({
|
|
url: '/pages/owner/card/index'
|
|
})
|
|
return
|
|
}
|
|
uni.reLaunch({
|
|
url: '/pages/common/login'
|
|
})
|
|
}
|
|
|
|
onLaunch((_res : OnLaunchOptions) => {
|
|
// #ifdef APP
|
|
routeOwnerHome()
|
|
// #endif
|
|
// #ifdef H5
|
|
if (typeof window !== 'undefined') {
|
|
const hash = window.location.hash
|
|
if (!hash || hash === '#' || hash === '#/' || hash === '') {
|
|
if (getAuthToken() != '') {
|
|
window.location.hash = '#/pages/owner/card/index'
|
|
} else {
|
|
window.location.hash = '#/pages/common/login'
|
|
}
|
|
}
|
|
}
|
|
// #endif
|
|
})
|
|
|
|
onAppShow((res : OnShowOptions) => {
|
|
openDeepLink(res.appScheme, res.appLink)
|
|
})
|
|
|
|
// #ifdef APP-ANDROID || APP-HARMONY
|
|
onLastPageBackPress(() => {
|
|
if (firstBackTime == 0) {
|
|
uni.showToast({
|
|
title: '再按一次退出应用',
|
|
position: 'bottom',
|
|
})
|
|
firstBackTime = Date.now()
|
|
setTimeout(() => {
|
|
firstBackTime = 0
|
|
}, 2000)
|
|
} else if (Date.now() - firstBackTime < 2000) {
|
|
firstBackTime = Date.now()
|
|
uni.exit()
|
|
}
|
|
})
|
|
// #endif
|
|
</script>
|
|
|
|
<style>
|
|
page {
|
|
background-color: #F7F8FA;
|
|
color: #101828;
|
|
font-family: Inter, "Noto Sans SC", "Noto Sans Arabic", "Noto Sans JP", "Noto Sans KR", sans-serif;
|
|
}
|
|
</style>
|