mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-05 15:49:47 +08:00
fix(editor): 首次选中组件后拖动,更新节点无效
This commit is contained in:
parent
12de0f5414
commit
dee685f0b3
@ -10,7 +10,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, getCurrentInstance, inject, onMounted, ref, watchEffect } from 'vue';
|
import { computed, defineComponent, getCurrentInstance, inject, onMounted, ref, watchEffect } from 'vue';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import type { FormValue, MForm } from '@tmagic/form';
|
import type { FormValue, MForm } from '@tmagic/form';
|
||||||
@ -30,21 +30,16 @@ export default defineComponent({
|
|||||||
// ts类型应该是FormConfig, 但是打包时会出错,所以暂时用any
|
// ts类型应该是FormConfig, 但是打包时会出错,所以暂时用any
|
||||||
const curFormConfig = ref<any>([]);
|
const curFormConfig = ref<any>([]);
|
||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
|
const node = computed(() => services?.editorService.get<MNode | null>('node'));
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
const node = services?.editorService.get<MNode | null>('node');
|
if (!node.value) {
|
||||||
|
|
||||||
if (!node) {
|
|
||||||
curFormConfig.value = [];
|
curFormConfig.value = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.devconfig && node.style && !isNaN(+node.style.height) && !isNaN(+node.style.width)) {
|
values.value = node.value;
|
||||||
node.devconfig.ratio = node.style.height / node.style.width || 1;
|
const type = node.value.type || (node.value.items ? 'container' : 'text');
|
||||||
}
|
|
||||||
|
|
||||||
values.value = node;
|
|
||||||
const type = node.type || (node.items ? 'container' : 'text');
|
|
||||||
curFormConfig.value = (await services?.propsService.getPropsConfig(type)) || [];
|
curFormConfig.value = (await services?.propsService.getPropsConfig(type)) || [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { reactive, toRaw } from 'vue';
|
import { reactive, toRaw } from 'vue';
|
||||||
import { cloneDeep } from 'lodash-es';
|
import { cloneDeep, mergeWith } from 'lodash-es';
|
||||||
import serialize from 'serialize-javascript';
|
import serialize from 'serialize-javascript';
|
||||||
|
|
||||||
import type { Id, MApp, MComponent, MContainer, MNode, MPage } from '@tmagic/schema';
|
import type { Id, MApp, MComponent, MContainer, MNode, MPage } from '@tmagic/schema';
|
||||||
@ -31,7 +31,6 @@ import { LayerOffset, Layout } from '@editor/type';
|
|||||||
import {
|
import {
|
||||||
change2Fixed,
|
change2Fixed,
|
||||||
COPY_STORAGE_KEY,
|
COPY_STORAGE_KEY,
|
||||||
defaults,
|
|
||||||
Fixed2Other,
|
Fixed2Other,
|
||||||
getNodeIndex,
|
getNodeIndex,
|
||||||
initPosition,
|
initPosition,
|
||||||
@ -292,7 +291,11 @@ class Editor extends BaseService {
|
|||||||
|
|
||||||
let newConfig = await this.toggleFixedPosition(toRaw(config), node, this.get<MApp>('root'));
|
let newConfig = await this.toggleFixedPosition(toRaw(config), node, this.get<MApp>('root'));
|
||||||
|
|
||||||
defaults(newConfig, node);
|
newConfig = mergeWith(node, newConfig, (objValue, srcValue) => {
|
||||||
|
if (Array.isArray(srcValue)) {
|
||||||
|
return srcValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (!newConfig.type) throw new Error('配置缺少type值');
|
if (!newConfig.type) throw new Error('配置缺少type值');
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { cloneDeep, random } from 'lodash-es';
|
import { random } from 'lodash-es';
|
||||||
|
|
||||||
import { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
|
import { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
|
||||||
import { getNodePath, isPop } from '@tmagic/utils';
|
import { getNodePath, isPop } from '@tmagic/utils';
|
||||||
@ -223,22 +223,3 @@ export const Fixed2Other = async (node: MNode, root: MApp, getLayout: (node: MNo
|
|||||||
|
|
||||||
return toRelative(node);
|
return toRelative(node);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const defaults = (object: any, source: any) => {
|
|
||||||
let o = source;
|
|
||||||
if (Array.isArray(object)) {
|
|
||||||
o = object;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.entries(o).forEach(([key, value]: [string, any]) => {
|
|
||||||
if (typeof object[key] === 'undefined') {
|
|
||||||
object[key] = value;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value && typeof value !== 'string' && Object.keys(value).length) {
|
|
||||||
object[key] = defaults(cloneDeep(object[key]), value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return object;
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user