This commit is contained in:
lzp
2026-03-04 15:06:22 +08:00
parent 9817e5e0db
commit cee42d8b78
28 changed files with 340 additions and 84 deletions

View File

@@ -0,0 +1,74 @@
<template>
<!-- 结果图片 -->
<div
class="text"
:class="{ edit }"
@click="onClick"
@mousedown="onMouseDown"
@dblclick="onDoubleClick"
>
<div
tabindex="0"
class="input"
ref="inputRef"
contenteditable="true"
@input="onInput"
@blur="onBlur"
@paste.prevent
>
双击编辑文本
</div>
</div>
</template>
<script setup lang="ts">
import { reactive, ref, nextTick, useAttrs, inject, watch } from 'vue'
const props = defineProps({
data: {
type: Object,
default: () => ({})
}
})
const emit = defineEmits(['delete-node', 'copy-node'])
const data = reactive({
text: props.data?.text || '双击编辑文本'
})
const edit = ref(false)
const time = ref(null)
const inputRef = ref<any>()
const onInput = () => {
const text = inputRef.value.innerText
data.text = text
}
const onBlur = () => {
edit.value = false
}
const onClick = () => {
if (edit.value) return
time.value = setTimeout(() => {
edit.value = false
}, 500)
edit.value = true
}
const onDoubleClick = () => {
clearTimeout(time.value)
}
const onMouseDown = (e: MouseEvent) => {
if (edit.value) e.stopPropagation()
}
defineExpose({ data })
</script>
<style lang="less" scoped>
.text {
&.edit {
> .input {
cursor: text;
}
}
> .input {
outline: none;
min-width: 1px;
}
}
</style>