重构:移动源码到 src/ 目录,支持 CLI 构建

This commit is contained in:
kk
2026-06-26 17:55:48 +08:00
parent a85117cca7
commit 437764c9d2
348 changed files with 8914 additions and 40210 deletions
+87
View File
@@ -0,0 +1,87 @@
<script>
import { initEnv } from '@/utils/env.js';
import { handleAuthCallback, onAuthSuccess } from '@/utils/auth-guard.js';
export default {
onLaunch: function(options) {
console.log('App Launch')
// 1. 环境检测 + 缓存 app_no/platform
initEnv();
// #ifdef H5
// 2. 处理授权回调(URL 中带 code/auth_code 参数)
this.handleAuthRedirect();
// 3. 解析 URL 路径中的设备编号(如 /A1036)
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)) {
uni.redirectTo({
url: '/pages/index/index?device_id=' + last
});
return;
}
}
// #endif
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
},
methods: {
// #ifdef H5
async handleAuthRedirect() {
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code') || urlParams.get('auth_code') || '';
if (!code) return;
// 有授权码,调用后端回调接口
const result = await handleAuthCallback();
if (result) {
onAuthSuccess(result);
// 清除 URL 中的 code 参数,避免刷新重复处理
const url = new URL(window.location.href);
url.searchParams.delete('code');
url.searchParams.delete('auth_code');
url.searchParams.delete('state');
window.history.replaceState({}, '', url.toString());
// 如果需要绑定手机号
if (result.need_bindphone) {
uni.setStorageSync('temp_token', result.temp_token);
uni.showToast({ title: '请绑定手机号完成注册', icon: 'none' });
} else {
uni.showToast({ title: '登录成功', icon: 'success' });
}
}
}
// #endif
}
}
</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>