fix(runtime): 切换设计窗体大小时,同时修改app

This commit is contained in:
i33 2022-09-27 12:37:14 +08:00 committed by jia000
parent 024e908947
commit b3bae36d94
8 changed files with 25 additions and 4 deletions

View File

@ -70,8 +70,7 @@ class App extends EventEmitter {
// 根据屏幕大小计算出跟节点的font-size用于rem样式的适配
if (this.platform === 'mobile' || this.platform === 'editor') {
const calcFontsize = () => {
let { width } = document.documentElement.getBoundingClientRect();
width = Math.min(800, width);
const { width } = document.documentElement.getBoundingClientRect();
const fontSize = width / (this.designWidth / 100);
document.documentElement.style.fontSize = `${fontSize}px`;
};

View File

@ -49,10 +49,9 @@ export default defineComponent({
setup(props, { emit }) {
const calcFontsize = (width: number) => {
const fontSize = width / 3.75;
const { iframe } = editorService.get<StageCore>('stage').renderer;
if (!iframe?.contentWindow) return;
iframe.contentWindow.document.documentElement.style.fontSize = `${fontSize}px`;
iframe.contentWindow.appInstance.designWidth = width;
};
const viewerDevice = ref(DeviceType.Phone);

View File

@ -50,7 +50,10 @@ const getLocalConfig = (): MApp[] => {
window.magicDSL = [];
const designWidth = document.documentElement.getBoundingClientRect().width;
const app = new Core({
designWidth,
config: ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {},
curPage: getUrlParam('page'),
});

View File

@ -29,11 +29,16 @@ import plugins from '../.tmagic/plugin-entry';
import App from './App';
const designWidth = document.documentElement.getBoundingClientRect().width;
const app = new Core({
designWidth,
config: {},
platform: 'editor',
});
window.appInstance = app;
let curPageId = '';
const updateConfig = (root: MApp) => {

View File

@ -30,7 +30,10 @@ import { getLocalConfig } from './utils';
Vue.use(request);
const designWidth = document.documentElement.getBoundingClientRect().width;
const app = new Core({
designWidth,
config: ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {},
curPage: getUrlParam('page'),
});

View File

@ -26,11 +26,16 @@ export default defineComponent({
() => root.value?.items?.find((item: MNode) => item.id === curPageId.value) || root.value?.items?.[0],
);
const designWidth = document.documentElement.getBoundingClientRect().width;
const app = new Core({
designWidth,
config: root.value,
platform: 'editor',
});
globalThis.appInstance = app;
provide('app', app);
watch(pageConfig, async () => {

View File

@ -43,7 +43,10 @@ Object.values(plugins).forEach((plugin: any) => {
magicApp.use(plugin);
});
const designWidth = document.documentElement.getBoundingClientRect().width;
const app = new Core({
designWidth,
config: ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {},
curPage: getUrlParam('page'),
});

View File

@ -26,11 +26,15 @@ export default defineComponent({
() => root.value?.items?.find((item: MNode) => item.id === curPageId.value) || root.value?.items?.[0],
);
const designWidth = document.documentElement.getBoundingClientRect().width;
const app = new Core({
designWidth,
config: root.value,
platform: 'editor',
});
globalThis.appInstance = app;
provide('app', app);
watch(pageConfig, async () => {