mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
feat(editor): 属性表单大小配置;记住编辑器分栏宽度
This commit is contained in:
parent
1f93b4e93c
commit
04d7725db9
@ -1,9 +1,9 @@
|
||||
<template>
|
||||
<m-form
|
||||
class="m-editor-props-panel"
|
||||
:class="`m-editor-props-panel ${propsPanelSize}`"
|
||||
popper-class="m-editor-props-panel-popper"
|
||||
ref="configForm"
|
||||
size="small"
|
||||
:size="propsPanelSize"
|
||||
:init-values="values"
|
||||
:config="curFormConfig"
|
||||
@change="submit"
|
||||
@ -55,6 +55,7 @@ export default defineComponent({
|
||||
values,
|
||||
configForm,
|
||||
curFormConfig,
|
||||
propsPanelSize: computed(() => services?.uiService.get('propsPanelSize') || 'small'),
|
||||
|
||||
async submit() {
|
||||
try {
|
||||
|
@ -28,6 +28,14 @@ import BaseService from './BaseService';
|
||||
const DEFAULT_LEFT_COLUMN_WIDTH = 310;
|
||||
const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
|
||||
|
||||
const COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorColumnWidthData';
|
||||
|
||||
const defaultColumnWidth = {
|
||||
left: DEFAULT_LEFT_COLUMN_WIDTH,
|
||||
center: globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH,
|
||||
right: DEFAULT_RIGHT_COLUMN_WIDTH,
|
||||
};
|
||||
|
||||
const state = reactive<UiState>({
|
||||
uiSelectMode: false,
|
||||
showSrc: false,
|
||||
@ -40,13 +48,10 @@ const state = reactive<UiState>({
|
||||
width: 375,
|
||||
height: 817,
|
||||
},
|
||||
columnWidth: {
|
||||
left: DEFAULT_LEFT_COLUMN_WIDTH,
|
||||
center: globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH,
|
||||
right: DEFAULT_RIGHT_COLUMN_WIDTH,
|
||||
},
|
||||
columnWidth: defaultColumnWidth,
|
||||
showGuides: true,
|
||||
showRule: true,
|
||||
propsPanelSize: 'small',
|
||||
});
|
||||
|
||||
class Ui extends BaseService {
|
||||
@ -57,6 +62,16 @@ class Ui extends BaseService {
|
||||
center: 'auto',
|
||||
});
|
||||
});
|
||||
|
||||
const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
|
||||
if (columnWidthCacheData) {
|
||||
try {
|
||||
const columnWidthCache = JSON.parse(columnWidthCacheData);
|
||||
this.setColumnWidth(columnWidthCache);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public set<T = any>(name: keyof UiState, value: T) {
|
||||
@ -112,10 +127,17 @@ class Ui extends BaseService {
|
||||
if (!center || center === 'auto') {
|
||||
const bodyWidth = globalThis.document.body.clientWidth;
|
||||
columnWidth.center = bodyWidth - (columnWidth?.left || 0) - (columnWidth?.right || 0);
|
||||
if (columnWidth.center <= 0) {
|
||||
columnWidth.left = defaultColumnWidth.left;
|
||||
columnWidth.center = defaultColumnWidth.center;
|
||||
columnWidth.right = defaultColumnWidth.right;
|
||||
}
|
||||
} else {
|
||||
columnWidth.center = center;
|
||||
}
|
||||
|
||||
globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
|
||||
|
||||
state.columnWidth = columnWidth;
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,20 @@
|
||||
.m-editor-props-panel {
|
||||
padding: 0 10px;
|
||||
|
||||
.el-form-item__label {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.m-fieldset {
|
||||
legend {
|
||||
&.small {
|
||||
.el-form-item__label {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.el-tabs__item {
|
||||
font-size: 12px;
|
||||
.m-fieldset {
|
||||
legend {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.el-tabs__item {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.el-input__wrapper {
|
||||
|
@ -99,6 +99,8 @@ export interface UiState {
|
||||
showGuides: boolean;
|
||||
/** 是否显示标尺,true: 显示,false: 不显示,默认为true */
|
||||
showRule: boolean;
|
||||
/** 用于控制该属性配置表单内组件的尺寸 */
|
||||
propsPanelSize: 'large' | 'default' | 'small';
|
||||
}
|
||||
|
||||
export interface EditorNodeInfo {
|
||||
|
Loading…
x
Reference in New Issue
Block a user