Skip to content

Commit

Permalink
perf: editor
Browse files Browse the repository at this point in the history
  • Loading branch information
supercll committed Sep 10, 2024
1 parent 881213d commit 0cae993
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/components/EditGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const defaultEditGroups: GroupProps[] = [
export default defineComponent({
props: {
props: {
type: Object as PropType<AllComponentProps>,
type: Object as PropType<Partial<AllComponentProps>>,
required: true,
},
groups: {
Expand Down Expand Up @@ -83,7 +83,7 @@ export default defineComponent({
})
const editGroups = computed(() => {
return newGroups.value.map((group) => {
const propsMap = {} as AllComponentProps
const propsMap = {} as Partial<AllComponentProps>
group.items.forEach((item) => {
const key = item as keyof AllComponentProps
propsMap[key] = props.props[key]
Expand Down
18 changes: 10 additions & 8 deletions src/components/EditWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
:data-component-id="id"
@click="onItemClick(id)"
@mousedown="startMove"
:class="{ active: active && isEditing, hidden: hidden }"
:class="{ active: active && isEditing && !isLocked, hidden: hidden }"
>
<slot></slot>
<div class="resizers">
<div class="resizers" v-if="active && isEditing && !isLocked">
<div
class="resizer top-left"
@mousedown.stop="startResize('top-left')"
Expand Down Expand Up @@ -58,6 +58,7 @@ export default defineComponent({
type: String,
required: true,
},
isLocked: Boolean,
active: {
type: Boolean,
default: false,
Expand All @@ -77,20 +78,19 @@ export default defineComponent({
const editWrapper = ref<null | HTMLElement>(null)
const onItemClick = (id: string) => {
if (store.state.editor.isEditing) {
if (isEditing.value) {
context.emit('set-active', id)
}
}
const onChangeEditStatus = (id: string) => {
const isEditing = store.state.editor.isEditing
store.commit('clearClickTimeout')
store.commit('setEditStatus', !isEditing)
if (!isEditing) {
store.commit('setEditStatus', !isEditing.value)
if (!isEditing.value) {
onItemClick(id)
}
}
const removeEditComponent = (id: string) => {
if (store.state.editor.isEditing) {
if (isEditing.value) {
context.emit('remove-component', id)
}
}
Expand All @@ -113,7 +113,9 @@ export default defineComponent({
}
}
const startMove = (e: MouseEvent) => {
// e.preventDefault && e.preventDefault()
if (props.isLocked || !isEditing.value) {
return
}
const currentElement = editWrapper.value
if (currentElement) {
const { left, top } = currentElement.getBoundingClientRect()
Expand Down
2 changes: 1 addition & 1 deletion src/components/PropsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default defineComponent({
name: 'props-table',
props: {
props: {
type: Object as PropType<AllComponentProps>,
type: Object as PropType<Partial<AllComponentProps>>,
required: true,
},
},
Expand Down
3 changes: 2 additions & 1 deletion src/views/EditorView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<div class="preview-list" :class="{ 'canvas-fix': canvasFix }">
<div class="body-container" id="canvas-area" :style="page.props">
<edit-wrapper
:isLocked="currentElement?.isLocked"
@setActive="setActive"
@removeComponent="removeComponent"
@update-position="updatePosition"
Expand Down Expand Up @@ -115,7 +116,7 @@
<div v-else>
<a-empty>
<template #description>
<p>该元素被锁定,无法编辑</p>
<p>该元素被锁定,只允许在画布编辑文字内容</p>
</template>
</a-empty>
</div>
Expand Down

0 comments on commit 0cae993

Please sign in to comment.