- rem 基准:设计宽 1280 / 底座 100 / 缩放 1(只缩不放),html font-size = clamp(50px, 7.8125vw, 100px) - App.vue 改为调用 applyRemBase(),APP-PLUS 侧 !important 覆盖与 H5 同一公式(平板 960 宽 → 75px) - styles/base.css::root 设计 token、12 类元素 ::after 重置、.page/.page-main 骨架、H5 组件库(picker/uni-*)修正由 App.vue 迁入 - electron/main.js 限制最小窗口 1024x640,避免窄窗横向溢出;pages.json 背景色改 token #E8EAED
141 lines
5.7 KiB
Vue
141 lines
5.7 KiB
Vue
<script>
|
||
import { guardCurrentPage } from './core/nav-guard'
|
||
import { flushClientErrorReport } from './core/error-report'
|
||
// rem 基准统一走 render-common/rem-base.js:底座 100 × 缩放 1 = 满格 100px(宽度 ≥1280 一律 100px),
|
||
// 缩放默认 1(只缩不放、只看宽度):窄于 1280 才按比例缩小,大屏/矮窗口只做布局变更
|
||
// 真机 APP-PLUS 的 rem 由下方全局纯 CSS 承担(7.8125vw = 100/1280;框架会以内联样式锁死 html font-size,故用 !important 覆盖),JS 仅 H5 参与计算
|
||
import { applyRemBase } from './render-common/rem-base.js'
|
||
|
||
// #ifdef APP-PLUS
|
||
// 打开应用后将系统音量调至最大(仓库环境语音播报需要;setStreamVolume 无需额外权限)
|
||
function setSystemVolumeMax () {
|
||
try {
|
||
const main = plus.android.runtimeMainActivity()
|
||
const Context = plus.android.importClass('android.content.Context')
|
||
// Context.AUDIO_SERVICE 常量值为 "audio",访问失败时兜底用字符串
|
||
const serviceName = Context.AUDIO_SERVICE || 'audio'
|
||
const audioManager = main.getSystemService(serviceName)
|
||
const streams = {
|
||
music: 3, // STREAM_MUSIC 媒体音量(语音播报 innerAudioContext 走此通道)
|
||
system: 1, // STREAM_SYSTEM 系统音量
|
||
notification: 5, // STREAM_NOTIFICATION 通知音量
|
||
alarm: 4, // STREAM_ALARM 闹钟音量
|
||
ring: 2 // STREAM_RING 铃声音量
|
||
}
|
||
for (const name in streams) {
|
||
// Native.js 桥接对象在 service 层不支持点方法调用,必须用 plus.android.invoke
|
||
const max = plus.android.invoke(audioManager, 'getStreamMaxVolume', streams[name])
|
||
plus.android.invoke(audioManager, 'setStreamVolume', streams[name], max, 0)
|
||
}
|
||
} catch (e) {
|
||
// 音量设置失败不阻断启动
|
||
}
|
||
}
|
||
// #endif
|
||
|
||
function logScreenInfo () {
|
||
try {
|
||
const info = uni.getSystemInfoSync()
|
||
console.log('[screen] uni =', JSON.stringify({
|
||
screenWidth: info.screenWidth,
|
||
screenHeight: info.screenHeight,
|
||
windowWidth: info.windowWidth,
|
||
windowHeight: info.windowHeight,
|
||
pixelRatio: info.pixelRatio,
|
||
platform: info.platform,
|
||
statusBarHeight: info.statusBarHeight,
|
||
safeArea: info.safeArea
|
||
}))
|
||
} catch (e) {
|
||
console.log('[screen] uni 失败 =', JSON.stringify(e))
|
||
}
|
||
|
||
// #ifdef APP-PLUS
|
||
try {
|
||
console.log('[screen] plus.screen =', JSON.stringify({
|
||
resolutionWidth: plus.screen.resolutionWidth,
|
||
resolutionHeight: plus.screen.resolutionHeight,
|
||
scale: plus.screen.scale,
|
||
dpiX: plus.screen.dpiX,
|
||
dpiY: plus.screen.dpiY
|
||
}))
|
||
} catch (e) {
|
||
console.log('[screen] plus.screen 失败 =', JSON.stringify(e))
|
||
}
|
||
// #endif
|
||
}
|
||
|
||
function setRemBase () {
|
||
// #ifdef H5
|
||
if (typeof document !== 'undefined' && document.documentElement) {
|
||
const docEl = document.documentElement
|
||
const width = docEl.clientWidth
|
||
const height = docEl.clientHeight
|
||
// 基准计算与写入集中在 render-common/rem-base.js,与各页面 renderjs 共用同一套基准
|
||
applyRemBase()
|
||
console.log('[screen-h5] screenWidth =', window.screen.width, 'screenHeight =', window.screen.height,
|
||
'availWidth =', window.screen.availWidth, 'availHeight =', window.screen.availHeight,
|
||
'devicePixelRatio =', window.devicePixelRatio)
|
||
console.log('[viewport-h5] clientWidth =', width, 'clientHeight =', height,
|
||
'innerWidth =', window.innerWidth, 'innerHeight =', window.innerHeight)
|
||
}
|
||
// #endif
|
||
|
||
logScreenInfo()
|
||
}
|
||
|
||
export default {
|
||
onLaunch: function () {
|
||
console.log('App Launch')
|
||
setRemBase()
|
||
// #ifdef APP-PLUS
|
||
setSystemVolumeMax()
|
||
// #endif
|
||
// #ifdef H5
|
||
window.addEventListener('resize', setRemBase)
|
||
// #endif
|
||
},
|
||
onShow: function () {
|
||
console.log('App Show')
|
||
setRemBase()
|
||
// 页面级守卫:覆盖直接打开/刷新进入受保护页面的场景(跳转 API 已由 installNavGuard 接管)
|
||
guardCurrentPage()
|
||
},
|
||
onHide: function () {
|
||
console.log('App Hide')
|
||
// 退到后台立即把待上报的错误日志发出去(后台可能被系统回收,晚发就没了)
|
||
flushClientErrorReport()
|
||
},
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
/* 全局基准样式全在 src/styles/base.css(设计 token / 元素重置 / 页面骨架 .page、.page-main /
|
||
公共工具类 .scan-hidden-input / H5 组件库修正),页面只写自己的个性化差异 */
|
||
@import './styles/base.css';
|
||
|
||
/* 本文件只保留 rem 基准相关的全局规则(与 render-common/rem-base.js 强绑定,且含条件编译) */
|
||
/* rem 基准:底座 100 × 缩放 1 = 满格 100px(宽度 ≥1280 一律 100px,窄于 1280 按比例缩,下限 50px)
|
||
H5/Electron:由 render-common/rem-base.js 的 applyRemBase() 以内联样式运行时计算,
|
||
此处仅首帧兜底,数值与 JS 一致(7.8125vw = 100/1280,50px = 缩放下限 0.5);
|
||
真机 APP-PLUS:由下方 #ifdef APP-PLUS 的 !important 规则承担(见下) */
|
||
html {
|
||
font-size: clamp(50px, 7.8125vw, 100px);
|
||
}
|
||
|
||
/* #ifdef APP-PLUS */
|
||
/* 真机修复:uni-app 框架(uni-app-view.umd.js)运行时把 html font-size 以内联样式锁为
|
||
窗口宽度/23.4375;真机 innerWidth=961 刚好超过框架 rpxCalcMaxDeviceWidth=960 →
|
||
走 base 375 → 16px。内联样式优先级高于普通样式表,故上面的 CSS 对真机无效。
|
||
用 !important 让样式表反超非 important 的内联样式。
|
||
目标:与 H5 公式同一结果(7.8125vw = 100/1280,平板 960 宽 → 75px);
|
||
老 WebView 可能不支持 CSS min(),真机恒为 960 宽(宽度就是瓶颈),故直接用 vw。 */
|
||
html {
|
||
font-size: 7.8125vw !important;
|
||
}
|
||
/* #endif */
|
||
|
||
/* 原先放在这里的 H5/Electron picker 样式修正(下拉宽度/选项居左)已移入
|
||
src/styles/base.css 第 5 节「H5/Electron 组件库修正」 */
|
||
</style>
|