1
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref, onMounted } from 'vue'
|
import { reactive, ref, onMounted, nextTick } from 'vue'
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
data: {
|
data: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
})
|
})
|
||||||
const emit = defineEmits(['update-data'])
|
const emit = defineEmits(['update-data'])
|
||||||
const data = reactive({
|
const data = reactive({
|
||||||
text: props.data?.text || '双击编辑文本'
|
text: props.data?.text || '点击编辑文本'
|
||||||
})
|
})
|
||||||
const edit = ref(false)
|
const edit = ref(false)
|
||||||
const time = ref(null)
|
const time = ref(null)
|
||||||
@@ -44,10 +44,16 @@
|
|||||||
}
|
}
|
||||||
const onClick = () => {
|
const onClick = () => {
|
||||||
if (edit.value) return
|
if (edit.value) return
|
||||||
time.value = setTimeout(() => {
|
|
||||||
edit.value = false
|
|
||||||
}, 500)
|
|
||||||
edit.value = true
|
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 = () => {
|
const onDoubleClick = () => {
|
||||||
clearTimeout(time.value)
|
clearTimeout(time.value)
|
||||||
@@ -65,7 +71,10 @@
|
|||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.text {
|
.text {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
padding: 2px;
|
||||||
&.edit {
|
&.edit {
|
||||||
|
border-color: #000;
|
||||||
> .input {
|
> .input {
|
||||||
cursor: text;
|
cursor: text;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user