Files
yunzerwebsiteallinone/uniapp/App.vue
T
2026-11-03 11:13:59 +08:00

107 lines
3.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script>
import { getBaseURL } from '@/api/request.js'
import { isLoggedIn } from '@/utils/auth.js'
import { getGuestToken } from '@/utils/guest.js'
const LOGIN_PAGE = '/pages/login/login'
// 不需要登录即可停留的页面:门户首页(默认落地)/ 登录 / 注册 / 忘记密码 / 人机验证 / 小程序码确认页 / 启动跳板页
const PUBLIC_ROUTES = [
'pages/nav/nav',
'pages/login/login',
'pages/login/register',
'pages/login/forget',
'pages/login/geetest-webview',
'pages/register/confirm',
'pages/index/index'
]
/** 当前页面路由(取不到时返回空串,交给页面级检测兜底) */
function currentRoute() {
try {
const pages = getCurrentPages()
if (!pages.length) return ''
const cur = pages[pages.length - 1]
return (cur && (cur.route || (cur.$page && cur.$page.path))) || ''
} catch (e) {
return ''
}
}
/** 未登录一律回登录页:覆盖「切后台回来」「从其他入口直接进内页」等场景。
* 游客令牌(手机号授权签发)可停留任意页面:免登录范围由菜单级配置决定,
* 能进哪些页、能调哪些接口由后端公开菜单与控制器 guest 分支兜底;
* 无令牌时回门户 nav 触发授权引导,而不是直接甩进登录页。 */
function ensureLogin() {
const route = currentRoute()
if (!route || PUBLIC_ROUTES.indexOf(route) !== -1) return
if (isLoggedIn()) return
if (getGuestToken()) return
uni.reLaunch({ url: LOGIN_PAGE })
}
export default {
onLaunch() {
console.log('App Launch, API:', getBaseURL())
},
onShow() {
console.log('App Show')
ensureLogin()
},
onHide() {
console.log('App Hide')
}
}
</script>
<style lang="scss">
@import 'uview-plus/index.scss';
@import './src/styles/theme.scss';
@import './src/styles/tint.scss';
@import './src/styles/fontawesome.scss';
@import './src/styles/rich-content.scss';
page {
height: 100%;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
background-color: $color-bg-page;
color: $color-text;
box-sizing: border-box;
}
/* 全局统一 border-box:必须显式覆盖 scroll-view / swiper / input 等盒元素,
否则它们 width:100% + padding 会按 content-box 溢出视口(小程序端高发),
导致带左右内边距的列表/弹层右侧内容被裁切。 */
view,
text,
scroll-view,
swiper,
swiper-item,
button,
input,
textarea,
label,
navigator {
box-sizing: border-box;
}
/* ============ 全局自适应(宽屏:桌面 / 平板 H5)============
说明:手机竖屏 CSS 宽度普遍 < 560px,此断链不会命中,App / 小程
序 / 手机 H5 行为完全不变;仅在宽屏下把整个应用收敛为居中的手机列,
避免页面铺满超宽屏、两侧大片留白。配合 pages.json 的 rpx 上限,
无需逐页适配。 */
@media (min-width: 560px) {
body {
background: #e9edf3;
}
#app {
max-width: 560px;
min-height: 100vh;
margin-left: auto;
margin-right: auto;
background: $color-bg-page;
box-shadow: 0 0 1px rgba(15, 23, 42, 0.16), 0 10px 40px rgba(15, 23, 42, 0.08);
}
}
</style>