perf: 快速修改文档名称和问题,支持回车保存

This commit is contained in:
wangdan-fit2cloud 2024-04-22 14:59:51 +08:00 committed by GitHub
parent bc57f17337
commit 7be349c937
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 12 deletions

View File

@ -21,6 +21,8 @@
autofocus autofocus
:maxlength="maxlength || '-'" :maxlength="maxlength || '-'"
:show-word-limit="maxlength ? true : false" :show-word-limit="maxlength ? true : false"
@blur="isEdit = false"
@keyup.enter="submit"
></el-input> ></el-input>
</div> </div>
@ -64,6 +66,10 @@ const loading = ref(false)
watch(isEdit, (bool) => { watch(isEdit, (bool) => {
if (!bool) { if (!bool) {
writeValue.value = '' writeValue.value = ''
} else {
nextTick(() => {
inputRef.value?.focus()
})
} }
}) })
@ -80,10 +86,6 @@ function editNameHandle() {
isEdit.value = true isEdit.value = true
} }
onMounted(() => { onMounted(() => {})
nextTick(() => {
inputRef.value?.focus()
})
})
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>

View File

@ -54,7 +54,7 @@
<el-table-column prop="name" label="文件名称" min-width="280"> <el-table-column prop="name" label="文件名称" min-width="280">
<template #default="{ row }"> <template #default="{ row }">
<ReadWrite <ReadWrite
@change="editName" @change="editName($event, row.id)"
:data="row.name" :data="row.name"
:showEditIcon="row.id === currentMouseId" :showEditIcon="row.id === currentMouseId"
/> />
@ -354,12 +354,12 @@ function changeState(bool: Boolean, row: any) {
currentMouseId.value && updateData(row.id, obj, str) currentMouseId.value && updateData(row.id, obj, str)
} }
function editName(val: string) { function editName(val: string, id: string) {
if (val) { if (val) {
const obj = { const obj = {
name: val name: val
} }
currentMouseId.value && updateData(currentMouseId.value, obj, '修改成功') updateData(id, obj, '修改成功')
} else { } else {
MsgError('文件名称不能为空!') MsgError('文件名称不能为空!')
} }

View File

@ -42,7 +42,7 @@
<el-table-column prop="content" label="问题" min-width="280"> <el-table-column prop="content" label="问题" min-width="280">
<template #default="{ row }"> <template #default="{ row }">
<ReadWrite <ReadWrite
@change="editName" @change="editName($event, row.id)"
:data="row.content" :data="row.content"
:showEditIcon="row.id === currentMouseId" :showEditIcon="row.id === currentMouseId"
:maxlength="256" :maxlength="256"
@ -121,7 +121,7 @@ import useStore from '@/stores'
const route = useRoute() const route = useRoute()
const { const {
params: { id } params: { id } // id
} = route as any } = route as any
const { problem } = useStore() const { problem } = useStore()
@ -216,12 +216,12 @@ function deleteProblem(row: any) {
.catch(() => {}) .catch(() => {})
} }
function editName(val: string) { function editName(val: string, problemId: string) {
if (val) { if (val) {
const obj = { const obj = {
content: val content: val
} }
problemApi.putProblems(id, currentMouseId.value, obj, loading).then(() => { problemApi.putProblems(id, problemId, obj, loading).then(() => {
getList() getList()
MsgSuccess('修改成功') MsgSuccess('修改成功')
}) })