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