文件
OmniCard/mpuniapp/App.uvue

81 行
2.0 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/workplace/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/workplace/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: #F5F8FC;
color: #101828;
font-family: Inter, "Noto Sans SC", "Noto Sans Arabic", "Noto Sans JP", "Noto Sans KR", "SF Pro Display", sans-serif;
}
</style>