This commit is contained in:
lzp
2026-03-05 11:19:44 +08:00
parent 5ce8de423f
commit ea4a763063

View File

@@ -20,7 +20,7 @@
</template>
<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import { reactive, ref, onMounted, nextTick } from 'vue'
const props = defineProps({
data: {
type: Object,
@@ -29,7 +29,7 @@
})
const emit = defineEmits(['update-data'])
const data = reactive({
text: props.data?.text || '击编辑文本'
text: props.data?.text || '击编辑文本'
})
const edit = ref(false)
const time = ref(null)
@@ -44,10 +44,16 @@
}
const onClick = () => {
if (edit.value) return
time.value = setTimeout(() => {
edit.value = false
}, 500)
edit.value = true
nextTick(() => {
// 光标定位到文本末尾
const range = document.createRange()
const selection = window.getSelection()
range.selectNodeContents(inputRef.value)
range.collapse(false)
selection.removeAllRanges()
selection.addRange(range)
})
}
const onDoubleClick = () => {
clearTimeout(time.value)
@@ -65,7 +71,10 @@
<style lang="less" scoped>
.text {
user-select: none;
border: 1px solid transparent;
padding: 2px;
&.edit {
border-color: #000;
> .input {
cursor: text;
}