import { Effect, ModuleControl } from "queenjs"; import { EditorModule } from "../../module"; import { reactive } from "vue"; import { DesignComp } from "../../objects/DesignTemp/DesignComp"; import { RxValue } from "../ReactCtrl/rxValue"; import { CardState } from "../../objects/DesignTemp"; import { isPc } from "@queenjs/utils"; const PCConst = { minRate: 0.42, maxRate: 0.8, height: 1520, factor: 0.8067, widths: [1900, 2356, 2920], ranges: [[0.64537, 0.8], [0.52063, 0.64537], [0.42, 0.52063]] } const MobileConst = { minRate: 0.4495, maxRate: 0.75, width: 750, factor: 0.84312, heights: [1000, 1186, 1406], ranges: [[0.63234, 0.75], [0.5331387120830735, 0.632340125298328], [0.4495, 0.5331387120830735]] } const AllSize = ["short","normal", "long"]; export const MobleScreenNames = ["短屏", "普通", "长屏幕"]; export class ScreenCtrl extends ModuleControl { state = RxValue.create({ screen: { useFor: "mobile" as "mobile" | "pc", // pc 还是 手机 pageMode: "long" as "long" | "short", //长页面还是短页面(一屏高度) pageSizeType: "normal" as "normal" | "long" | "short", //适配类型 长屏 正常 短屏幕 }, docWidth: window.innerWidth, //实际屏幕宽度 docHeight: window.innerHeight, //实际屏幕高度 safeFactor: 0.8, }) get isShortPage () { return this.state.screen.pageMode == "short"; } get isLongPage() { return this.state.screen.pageMode == "long"; } get currScreenId() { return this.state.screen.useFor + this.state.screen.pageMode + this.state.screen.pageSizeType; } initEvent() { if ( !this.store.isEditMode ) return; this.state.onScreenChanged(()=>this.updateAdapterState()); const {factor, sizes, ranges} = this.createSteps(MobileConst.width, MobileConst.minRate, MobileConst.maxRate) console.log("range=>", ranges, factor, sizes); console.log( this.getRightScreenId() ); } createSteps(base: number, min:number, max:number, size = 3) { const factor = Math.pow((min / max) , 1.0 / size); const ranges = []; const sizes = []; for (let i=0; i= m[0]) { index = n; } } if (this.state.screen.pageMode == "long") index = 1; console.log("rate=>", rate); const sreenId = currScreen + this.state.screen.pageMode + ["short", "normal", "long"][index]; return {sreenId, index, device: currScreen, pageMode: this.state.screen.pageMode}; } updateAdapterState() { if (!this.store.rootPage) return; this.restorScreenPage(); this.store.streamCardIds.forEach(c=>{ const card = this.helper.findComp(c) as DesignComp; card.setW(this.getCurrScreenWidth()); this.helper.extendStreamCard(card.id); }) const w = this.helper.designSizeToPx(this.getCurrScreenWidth()); const h = this.helper.designSizeToPx(this.getCurrScreenHeight()); this.controls.editorCtrl.state.setPage({w, h}); this.store.rootPage.layout.size[0] = this.getCurrScreenWidth(); this.store.rootPage.layout.size[1] = this.getCurrScreenHeight(); this.state.safeFactor = this.state.screen.useFor == "pc" ? PCConst.factor : MobileConst.factor; } isScreenExit(screenId:string) { return !!this.store.designData.compScreenMap[screenId] && this.store.designData.compScreenMap[screenId].length > 0 && this.store.designData.compScreenMap[screenId][1].children.length > 0; } restorScreenPage(screenId = "") { if (!this.store.rootPage) return; //获取当前screen的配置 screenId = screenId ? screenId : this.state.screen.useFor + this.state.screen.pageMode + this.state.screen.pageSizeType; const screenCards = this.store.designData.compScreenMap[screenId] || []; console.log("apply screen=>", screenId); //刷新当前card的配置 this.store.streamCardIds.forEach(c=>{ const card = this.helper.findComp(c) as DesignComp; const screenCard = screenCards.find(item=>item.id == c) let newChilds:string[] = []; let childrs = screenCard?.children || []; childrs.forEach(item=>{ newChilds.push(item.id); const screenComp = this.helper.findComp(item.id) as DesignComp; screenComp.layout.size[0] = item.size[0]; screenComp.layout.size[1] = item.size[1]; screenComp.layout.transformMatrix = item.matrix; }) card.children.default = newChilds; }) } saveScreenPage() { //获取当前screen的配置 const screenId = this.state.screen.useFor + this.state.screen.pageMode + this.state.screen.pageSizeType; const screenCards = ScreenCtrl.createScreenCards(this.store.compMap, this.store.rootPage); if (!this.store.designData.compScreenMap) this.store.designData.compScreenMap = {}; this.store.designData.compScreenMap[screenId] = screenCards; } static createScreenCards(compMap:any, rootPage: DesignComp) { //获取当前screen的配置 const screenCards = [] as CardState []; const streamCardIds = rootPage.children.default || []; streamCardIds.forEach(c=>{ const card = compMap[c] as DesignComp; const screenCard :CardState = { id: c, children: [] } let childrs = card.children.default || []; childrs.forEach(item=>{ const c = compMap[item] as DesignComp; screenCard.children.push({id: item, size: c.layout.size, matrix: c.layout.transformMatrix as string} ); }) screenCards.push(screenCard); }) return screenCards; } getCurrScreenHeight() { const pageValue = this.state if ( pageValue.screen.useFor == "pc") { return PCConst.height; } const currScreenIndex = this.getAdapterIndex(); return MobileConst.heights[currScreenIndex]; } getCurrScreenWidth() { const currScreenIndex = this.getAdapterIndex(); const pageValue = this.state if ( pageValue.screen.useFor == "pc" ) { return PCConst.widths[currScreenIndex]; } return MobileConst.width; } }