mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-08-23 22:20:05 +08:00
fix(runtime): 切换设计窗体大小时,同时修改app
This commit is contained in:
parent
024e908947
commit
b3bae36d94
@ -70,8 +70,7 @@ class App extends EventEmitter {
|
|||||||
// 根据屏幕大小计算出跟节点的font-size,用于rem样式的适配
|
// 根据屏幕大小计算出跟节点的font-size,用于rem样式的适配
|
||||||
if (this.platform === 'mobile' || this.platform === 'editor') {
|
if (this.platform === 'mobile' || this.platform === 'editor') {
|
||||||
const calcFontsize = () => {
|
const calcFontsize = () => {
|
||||||
let { width } = document.documentElement.getBoundingClientRect();
|
const { width } = document.documentElement.getBoundingClientRect();
|
||||||
width = Math.min(800, width);
|
|
||||||
const fontSize = width / (this.designWidth / 100);
|
const fontSize = width / (this.designWidth / 100);
|
||||||
document.documentElement.style.fontSize = `${fontSize}px`;
|
document.documentElement.style.fontSize = `${fontSize}px`;
|
||||||
};
|
};
|
||||||
|
@ -49,10 +49,9 @@ export default defineComponent({
|
|||||||
|
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const calcFontsize = (width: number) => {
|
const calcFontsize = (width: number) => {
|
||||||
const fontSize = width / 3.75;
|
|
||||||
const { iframe } = editorService.get<StageCore>('stage').renderer;
|
const { iframe } = editorService.get<StageCore>('stage').renderer;
|
||||||
if (!iframe?.contentWindow) return;
|
if (!iframe?.contentWindow) return;
|
||||||
iframe.contentWindow.document.documentElement.style.fontSize = `${fontSize}px`;
|
iframe.contentWindow.appInstance.designWidth = width;
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewerDevice = ref(DeviceType.Phone);
|
const viewerDevice = ref(DeviceType.Phone);
|
||||||
|
@ -50,7 +50,10 @@ const getLocalConfig = (): MApp[] => {
|
|||||||
|
|
||||||
window.magicDSL = [];
|
window.magicDSL = [];
|
||||||
|
|
||||||
|
const designWidth = document.documentElement.getBoundingClientRect().width;
|
||||||
|
|
||||||
const app = new Core({
|
const app = new Core({
|
||||||
|
designWidth,
|
||||||
config: ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {},
|
config: ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {},
|
||||||
curPage: getUrlParam('page'),
|
curPage: getUrlParam('page'),
|
||||||
});
|
});
|
||||||
|
@ -29,11 +29,16 @@ import plugins from '../.tmagic/plugin-entry';
|
|||||||
|
|
||||||
import App from './App';
|
import App from './App';
|
||||||
|
|
||||||
|
const designWidth = document.documentElement.getBoundingClientRect().width;
|
||||||
|
|
||||||
const app = new Core({
|
const app = new Core({
|
||||||
|
designWidth,
|
||||||
config: {},
|
config: {},
|
||||||
platform: 'editor',
|
platform: 'editor',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.appInstance = app;
|
||||||
|
|
||||||
let curPageId = '';
|
let curPageId = '';
|
||||||
|
|
||||||
const updateConfig = (root: MApp) => {
|
const updateConfig = (root: MApp) => {
|
||||||
|
@ -30,7 +30,10 @@ import { getLocalConfig } from './utils';
|
|||||||
|
|
||||||
Vue.use(request);
|
Vue.use(request);
|
||||||
|
|
||||||
|
const designWidth = document.documentElement.getBoundingClientRect().width;
|
||||||
|
|
||||||
const app = new Core({
|
const app = new Core({
|
||||||
|
designWidth,
|
||||||
config: ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {},
|
config: ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {},
|
||||||
curPage: getUrlParam('page'),
|
curPage: getUrlParam('page'),
|
||||||
});
|
});
|
||||||
|
@ -26,11 +26,16 @@ export default defineComponent({
|
|||||||
() => root.value?.items?.find((item: MNode) => item.id === curPageId.value) || root.value?.items?.[0],
|
() => root.value?.items?.find((item: MNode) => item.id === curPageId.value) || root.value?.items?.[0],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const designWidth = document.documentElement.getBoundingClientRect().width;
|
||||||
|
|
||||||
const app = new Core({
|
const app = new Core({
|
||||||
|
designWidth,
|
||||||
config: root.value,
|
config: root.value,
|
||||||
platform: 'editor',
|
platform: 'editor',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
globalThis.appInstance = app;
|
||||||
|
|
||||||
provide('app', app);
|
provide('app', app);
|
||||||
|
|
||||||
watch(pageConfig, async () => {
|
watch(pageConfig, async () => {
|
||||||
|
@ -43,7 +43,10 @@ Object.values(plugins).forEach((plugin: any) => {
|
|||||||
magicApp.use(plugin);
|
magicApp.use(plugin);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const designWidth = document.documentElement.getBoundingClientRect().width;
|
||||||
|
|
||||||
const app = new Core({
|
const app = new Core({
|
||||||
|
designWidth,
|
||||||
config: ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {},
|
config: ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {},
|
||||||
curPage: getUrlParam('page'),
|
curPage: getUrlParam('page'),
|
||||||
});
|
});
|
||||||
|
@ -26,11 +26,15 @@ export default defineComponent({
|
|||||||
() => root.value?.items?.find((item: MNode) => item.id === curPageId.value) || root.value?.items?.[0],
|
() => root.value?.items?.find((item: MNode) => item.id === curPageId.value) || root.value?.items?.[0],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const designWidth = document.documentElement.getBoundingClientRect().width;
|
||||||
const app = new Core({
|
const app = new Core({
|
||||||
|
designWidth,
|
||||||
config: root.value,
|
config: root.value,
|
||||||
platform: 'editor',
|
platform: 'editor',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
globalThis.appInstance = app;
|
||||||
|
|
||||||
provide('app', app);
|
provide('app', app);
|
||||||
|
|
||||||
watch(pageConfig, async () => {
|
watch(pageConfig, async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user