2026-06-26 17:55:48 +08:00
|
|
|
<script>
|
|
|
|
|
import { initEnv } from '@/utils/env.js';
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
onLaunch: function(options) {
|
|
|
|
|
console.log('App Launch')
|
|
|
|
|
|
|
|
|
|
// 1. 环境检测 + 缓存 app_no/platform
|
|
|
|
|
initEnv();
|
|
|
|
|
|
|
|
|
|
// #ifdef H5
|
2026-07-02 18:25:23 +08:00
|
|
|
// 2. 解析 URL 路径中的设备编号(如 /A1036)
|
|
|
|
|
let deviceId = '';
|
2026-06-26 17:55:48 +08:00
|
|
|
const path = window.location.pathname;
|
|
|
|
|
const segments = path.split('/').filter(Boolean);
|
|
|
|
|
if (segments.length > 0) {
|
|
|
|
|
const last = segments[segments.length - 1];
|
|
|
|
|
if (/^[A-Z][A-Z0-9]+$/.test(last)) {
|
2026-07-02 18:25:23 +08:00
|
|
|
deviceId = last;
|
2026-06-26 17:55:48 +08:00
|
|
|
}
|
|
|
|
|
}
|
2026-07-02 18:25:23 +08:00
|
|
|
|
|
|
|
|
// 3. 检查 URL 中是否有授权回调的 code
|
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
|
const code = urlParams.get('code');
|
|
|
|
|
|
|
|
|
|
if (code) {
|
|
|
|
|
// 有 code → 进入授权 Loading 页处理
|
|
|
|
|
const loadingUrl = deviceId
|
|
|
|
|
? `/pages/auth/loading?device_id=${deviceId}`
|
|
|
|
|
: '/pages/auth/loading';
|
|
|
|
|
uni.redirectTo({ url: loadingUrl });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 4. 检查 JWT
|
|
|
|
|
const token = uni.getStorageSync('token');
|
|
|
|
|
|
|
|
|
|
if (token) {
|
|
|
|
|
// 有 JWT → 直接进入首页
|
|
|
|
|
const homeUrl = deviceId
|
|
|
|
|
? `/pages/index/index?device_id=${deviceId}`
|
|
|
|
|
: '/pages/index/scan';
|
|
|
|
|
uni.redirectTo({ url: homeUrl });
|
|
|
|
|
} else {
|
|
|
|
|
// 无 JWT → 进入授权 Loading 页
|
|
|
|
|
const loadingUrl = deviceId
|
|
|
|
|
? `/pages/auth/loading?device_id=${deviceId}`
|
|
|
|
|
: '/pages/auth/loading';
|
|
|
|
|
uni.redirectTo({ url: loadingUrl });
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
// #ifndef H5
|
|
|
|
|
// 小程序环境:直接进入扫码页
|
|
|
|
|
uni.redirectTo({ url: '/pages/index/scan' });
|
2026-06-26 17:55:48 +08:00
|
|
|
// #endif
|
|
|
|
|
},
|
|
|
|
|
onShow: function() {
|
|
|
|
|
console.log('App Show')
|
|
|
|
|
},
|
|
|
|
|
onHide: function() {
|
|
|
|
|
console.log('App Hide')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
/*每个页面公共css */
|
|
|
|
|
@import '@/uni_modules/uni-scss/index.scss';
|
|
|
|
|
/* #ifndef APP-NVUE */
|
|
|
|
|
@import '@/static/customicons.css';
|
|
|
|
|
// 设置整个项目的背景色
|
|
|
|
|
page {
|
|
|
|
|
background-color: #f5f5f5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* #endif */
|
|
|
|
|
.example-info {
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
color: #333;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|