This commit is contained in:
24kycj
2026-05-22 20:01:34 +08:00
parent d0c3fd162a
commit 79174e7e03
5 changed files with 15 additions and 18 deletions
+8 -8
View File
@@ -10,17 +10,13 @@ import { setupNativeWorkingDir } from './services/native-path'
suppressKnownDllStderr() suppressKnownDllStderr()
import { registerIpcHandlers, handleBeforeQuit } from './ipc/register-handlers' import { registerIpcHandlers, handleBeforeQuit } from './ipc/register-handlers'
import { setPollMainWindow } from './services/poll-manager' import { setPollMainWindow } from './services/poll-manager'
import { import { DESIGN_WIDTH, DESIGN_HEIGHT, contentHeightForWidth } from '@shared/viewport'
DESIGN_WIDTH,
contentHeightForWidth,
CONTENT_VIEWPORT_HEIGHT
} from '@shared/viewport'
let mainWindow: BrowserWindow | null = null let mainWindow: BrowserWindow | null = null
const MIN_CONTENT_WIDTH = 960 const MIN_CONTENT_WIDTH = 960
/** 默认内容区:约 85% 工作区宽,高按 720:390 */ /** 默认内容区:约 85% 工作区宽,高 = 宽×360/720 */
function getDefaultWindowSize(): { width: number; height: number } { function getDefaultWindowSize(): { width: number; height: number } {
const { width: sw, height: sh } = screen.getPrimaryDisplay().workAreaSize const { width: sw, height: sh } = screen.getPrimaryDisplay().workAreaSize
let w = Math.max(1280, Math.min(Math.floor(sw * 0.85), 1600)) let w = Math.max(1280, Math.min(Math.floor(sw * 0.85), 1600))
@@ -28,7 +24,7 @@ function getDefaultWindowSize(): { width: number; height: number } {
const maxH = Math.floor(sh * 0.85) const maxH = Math.floor(sh * 0.85)
if (h > maxH) { if (h > maxH) {
h = Math.max(contentHeightForWidth(MIN_CONTENT_WIDTH), maxH) h = Math.max(contentHeightForWidth(MIN_CONTENT_WIDTH), maxH)
w = Math.round((h * DESIGN_WIDTH) / CONTENT_VIEWPORT_HEIGHT) w = Math.round((h * DESIGN_WIDTH) / DESIGN_HEIGHT)
} }
return { width: w, height: h } return { width: w, height: h }
} }
@@ -54,6 +50,10 @@ function createWindow(): void {
setPollMainWindow(mainWindow) setPollMainWindow(mainWindow)
mainWindow.on('ready-to-show', () => { mainWindow.on('ready-to-show', () => {
if (mainWindow) {
const [cw] = mainWindow.getContentSize()
mainWindow.setContentSize(cw, contentHeightForWidth(cw))
}
mainWindow?.center() mainWindow?.center()
mainWindow?.show() mainWindow?.show()
if (!app.isPackaged) { if (!app.isPackaged) {
@@ -67,7 +67,7 @@ function createWindow(): void {
} }
}) })
// 内容区 720:390画布仍 360 高,按宽缩放后底部可完整显示 // 内容区锁定 720:360与 useScale(scale = innerWidth/720) 一致
mainWindow.on('resize', () => { mainWindow.on('resize', () => {
if (!mainWindow) return if (!mainWindow) return
const [cw, ch] = mainWindow.getContentSize() const [cw, ch] = mainWindow.getContentSize()
+2 -3
View File
@@ -3,17 +3,16 @@ import { DESIGN_WIDTH, DESIGN_HEIGHT } from '@shared/viewport'
export { DESIGN_WIDTH, DESIGN_HEIGHT } export { DESIGN_WIDTH, DESIGN_HEIGHT }
/** 按内容区宽度铺满画布,垂直居中;内容区高按 720:390 预留时底部完整可见 */ /** 按内容区宽度缩放 720×360;内容区高由主进程按同比例设置,顶对齐无底部留白 */
export function useScale(shellRef: Ref<HTMLElement | null>): void { export function useScale(shellRef: Ref<HTMLElement | null>): void {
function updateScale(): void { function updateScale(): void {
const shell = shellRef.value const shell = shellRef.value
if (!shell) return if (!shell) return
const scale = window.innerWidth / DESIGN_WIDTH const scale = window.innerWidth / DESIGN_WIDTH
const offsetY = Math.max(0, (window.innerHeight - DESIGN_HEIGHT * scale) / 2)
shell.style.transformOrigin = '0 0' shell.style.transformOrigin = '0 0'
shell.style.transform = `translate(0px, ${offsetY}px) scale(${scale})` shell.style.transform = `translate(0px, 0px) scale(${scale})`
} }
onMounted(() => { onMounted(() => {
+1 -1
View File
@@ -13,7 +13,7 @@ body,
position: relative; position: relative;
} }
/* 720×360 逻辑画布;窗口内容区高 720:390useScale 按宽 scale */ /* 720×360 逻辑画布;内容区同比例useScale 按 innerWidth/720 顶对齐 */
.app-shell { .app-shell {
position: absolute; position: absolute;
left: 0; left: 0;
+3 -5
View File
@@ -1,10 +1,8 @@
/** 设计稿逻辑画布 720×360 */ /** 设计稿逻辑画布 */
export const DESIGN_WIDTH = 720 export const DESIGN_WIDTH = 720
export const DESIGN_HEIGHT = 360 export const DESIGN_HEIGHT = 360
/** 内容区高度(720 宽时 390):比画布多约 30px,避免按宽缩放后底部被裁 */ /** 内容区高度 = 宽 × (360/720),与 useScale 按宽缩放后的画布高一致 */
export const CONTENT_VIEWPORT_HEIGHT = 390
export function contentHeightForWidth(contentWidth: number): number { export function contentHeightForWidth(contentWidth: number): number {
return Math.round((contentWidth * CONTENT_VIEWPORT_HEIGHT) / DESIGN_WIDTH) return Math.ceil((contentWidth * DESIGN_HEIGHT) / DESIGN_WIDTH)
} }
File diff suppressed because one or more lines are too long