|
@@ -3,6 +3,7 @@ import { EditorModule } from "../../module";
|
|
import { reactive } from "vue";
|
|
import { reactive } from "vue";
|
|
import { DesignComp } from "../../objects/DesignTemp/DesignComp";
|
|
import { DesignComp } from "../../objects/DesignTemp/DesignComp";
|
|
import { RxValue } from "../ReactCtrl/rxValue";
|
|
import { RxValue } from "../ReactCtrl/rxValue";
|
|
|
|
+import { CardState } from "../../objects/DesignTemp";
|
|
|
|
|
|
|
|
|
|
// const WidthHeightRatios = [1.377, 1.777, 2.177];
|
|
// const WidthHeightRatios = [1.377, 1.777, 2.177];
|
|
@@ -19,24 +20,29 @@ const PCRates = [0.42, 0.8];
|
|
export const MobleScreenNames = ["短屏", "普通", "长屏幕"];
|
|
export const MobleScreenNames = ["短屏", "普通", "长屏幕"];
|
|
export class ScreenCtrl extends ModuleControl<EditorModule> {
|
|
export class ScreenCtrl extends ModuleControl<EditorModule> {
|
|
state = RxValue.create({
|
|
state = RxValue.create({
|
|
- useFor: "mobile" as "mobile" | "pc", // pc 还是 手机
|
|
|
|
- pageMode: "long" as "long" | "short", //长页面还是短页面(一屏高度)
|
|
|
|
- pageSizeType: "normal" as "normal" | "long" | "short", //适配类型 长屏 正常 短屏幕
|
|
|
|
-
|
|
|
|
|
|
+ screen: {
|
|
|
|
+ useFor: "mobile" as "mobile" | "pc", // pc 还是 手机
|
|
|
|
+ pageMode: "long" as "long" | "short", //长页面还是短页面(一屏高度)
|
|
|
|
+ pageSizeType: "normal" as "normal" | "long" | "short", //适配类型 长屏 正常 短屏幕
|
|
|
|
+ },
|
|
docWidth: window.innerWidth, //实际屏幕宽度
|
|
docWidth: window.innerWidth, //实际屏幕宽度
|
|
docHeight: window.innerHeight, //实际屏幕高度
|
|
docHeight: window.innerHeight, //实际屏幕高度
|
|
safeFactor: 0.8,
|
|
safeFactor: 0.8,
|
|
})
|
|
})
|
|
|
|
+
|
|
get isShortPage () {
|
|
get isShortPage () {
|
|
- return this.state.pageMode == "short";
|
|
|
|
|
|
+ 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() {
|
|
initEvent() {
|
|
if ( !this.store.isEditMode ) return;
|
|
if ( !this.store.isEditMode ) return;
|
|
-
|
|
|
|
- this.state.onUseForChanged(()=>this.updateAdapterState());
|
|
|
|
- this.state.onPageModeChanged(()=>this.updateAdapterState());
|
|
|
|
- this.state.onPageSizeTypeChanged(()=>this.updateAdapterState());
|
|
|
|
|
|
+ this.state.onScreenChanged(()=>this.updateAdapterState());
|
|
|
|
|
|
const size = 3;
|
|
const size = 3;
|
|
const safeFactor = Math.pow((PCRates[0] / PCRates[1]) , 1.0 / size);
|
|
const safeFactor = Math.pow((PCRates[0] / PCRates[1]) , 1.0 / size);
|
|
@@ -56,12 +62,14 @@ export class ScreenCtrl extends ModuleControl<EditorModule> {
|
|
}
|
|
}
|
|
|
|
|
|
getAdapterIndex() {
|
|
getAdapterIndex() {
|
|
- if(this.state.pageMode == "long") return 1;
|
|
|
|
- return ["short", "normal", "long"].indexOf(this.state.pageSizeType)
|
|
|
|
|
|
+ if(this.state.screen.pageMode == "long") return 1;
|
|
|
|
+ return ["short", "normal", "long"].indexOf(this.state.screen.pageSizeType)
|
|
}
|
|
}
|
|
|
|
|
|
updateAdapterState() {
|
|
updateAdapterState() {
|
|
if (!this.store.rootPage) return;
|
|
if (!this.store.rootPage) return;
|
|
|
|
+
|
|
|
|
+ this.restorScreenPage();
|
|
|
|
|
|
this.store.streamCardIds.forEach(c=>{
|
|
this.store.streamCardIds.forEach(c=>{
|
|
const card = this.helper.findComp(c) as DesignComp;
|
|
const card = this.helper.findComp(c) as DesignComp;
|
|
@@ -72,15 +80,65 @@ export class ScreenCtrl extends ModuleControl<EditorModule> {
|
|
const h = this.helper.designSizeToPx(this.getCurrScreenHeight());
|
|
const h = this.helper.designSizeToPx(this.getCurrScreenHeight());
|
|
|
|
|
|
this.controls.editorCtrl.state.setPage({w, h});
|
|
this.controls.editorCtrl.state.setPage({w, h});
|
|
-
|
|
|
|
-
|
|
|
|
this.store.rootPage.layout.size[0] = this.getCurrScreenWidth();
|
|
this.store.rootPage.layout.size[0] = this.getCurrScreenWidth();
|
|
- this.store.rootPage.layout.size[1] = this.getCurrScreenHeight();
|
|
|
|
|
|
+ this.store.rootPage.layout.size[1] = this.getCurrScreenHeight();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ restorScreenPage() {
|
|
|
|
+ if (!this.store.rootPage) return;
|
|
|
|
+
|
|
|
|
+ //获取当前screen的配置
|
|
|
|
+ const screenId = this.state.screen.useFor + this.state.screen.pageMode + this.state.screen.pageSizeType;
|
|
|
|
+ const screenCards = this.store.designData.compScreenMap[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() {
|
|
getCurrScreenHeight() {
|
|
const pageValue = this.state
|
|
const pageValue = this.state
|
|
- if ( pageValue.useFor == "pc") {
|
|
|
|
|
|
+ if ( pageValue.screen.useFor == "pc") {
|
|
return PCDesignHeight;
|
|
return PCDesignHeight;
|
|
}
|
|
}
|
|
const currScreenIndex = this.getAdapterIndex();
|
|
const currScreenIndex = this.getAdapterIndex();
|
|
@@ -90,7 +148,7 @@ export class ScreenCtrl extends ModuleControl<EditorModule> {
|
|
getCurrScreenWidth() {
|
|
getCurrScreenWidth() {
|
|
const currScreenIndex = this.getAdapterIndex();
|
|
const currScreenIndex = this.getAdapterIndex();
|
|
const pageValue = this.state
|
|
const pageValue = this.state
|
|
- if ( pageValue.useFor == "pc" ) {
|
|
|
|
|
|
+ if ( pageValue.screen.useFor == "pc" ) {
|
|
return PCWidths[currScreenIndex];
|
|
return PCWidths[currScreenIndex];
|
|
}
|
|
}
|
|
return MobleDesignWidth
|
|
return MobleDesignWidth
|