2023-11-09 10:52:06 +00:00
|
|
|
<template>
|
2024-04-09 03:33:28 +00:00
|
|
|
<div class="cursor w-full">
|
2023-11-09 10:52:06 +00:00
|
|
|
<slot name="read">
|
2024-07-01 10:17:08 +00:00
|
|
|
<div class="flex align-center" v-if="!isEdit" @dblclick="dblclick">
|
2024-01-25 07:08:25 +00:00
|
|
|
<auto-tooltip :content="data">
|
|
|
|
|
{{ data }}
|
|
|
|
|
</auto-tooltip>
|
|
|
|
|
|
2024-07-01 10:17:08 +00:00
|
|
|
<el-button v-if="!trigger && showEditIcon" class="ml-4" @click.stop="editNameHandle" text>
|
2024-04-09 03:33:28 +00:00
|
|
|
<el-icon><EditPen /></el-icon>
|
2023-11-09 10:52:06 +00:00
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</slot>
|
|
|
|
|
<slot>
|
2024-04-09 03:33:28 +00:00
|
|
|
<div class="flex align-center" @click.stop v-if="isEdit">
|
|
|
|
|
<div class="w-full">
|
|
|
|
|
<el-input
|
|
|
|
|
ref="inputRef"
|
|
|
|
|
v-model="writeValue"
|
|
|
|
|
placeholder="请输入"
|
|
|
|
|
autofocus
|
2024-04-10 06:16:56 +00:00
|
|
|
:maxlength="maxlength || '-'"
|
2024-04-09 03:33:28 +00:00
|
|
|
:show-word-limit="maxlength ? true : false"
|
2024-04-22 06:59:51 +00:00
|
|
|
@blur="isEdit = false"
|
|
|
|
|
@keyup.enter="submit"
|
2024-05-07 09:06:39 +00:00
|
|
|
clearable
|
2024-04-09 03:33:28 +00:00
|
|
|
></el-input>
|
2023-11-14 10:12:55 +00:00
|
|
|
</div>
|
|
|
|
|
|
2023-11-09 10:52:06 +00:00
|
|
|
<span class="ml-4">
|
2024-05-07 09:06:39 +00:00
|
|
|
<el-button type="primary" text @mousedown="submit" :disabled="loading">
|
2023-11-09 10:52:06 +00:00
|
|
|
<el-icon><Select /></el-icon>
|
|
|
|
|
</el-button>
|
|
|
|
|
</span>
|
|
|
|
|
<span>
|
2023-11-10 11:05:52 +00:00
|
|
|
<el-button text @click.stop="isEdit = false" :disabled="loading">
|
2023-11-09 10:52:06 +00:00
|
|
|
<el-icon><CloseBold /></el-icon>
|
|
|
|
|
</el-button>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</slot>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup lang="ts">
|
2023-11-14 10:12:55 +00:00
|
|
|
import { ref, watch, onMounted, nextTick } from 'vue'
|
2023-11-09 10:52:06 +00:00
|
|
|
defineOptions({ name: 'ReadWrite' })
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
data: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
|
|
|
|
},
|
|
|
|
|
showEditIcon: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2024-04-09 03:33:28 +00:00
|
|
|
},
|
|
|
|
|
maxlength: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: () => 0
|
2024-07-01 10:17:08 +00:00
|
|
|
},
|
|
|
|
|
trigger: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: '',
|
|
|
|
|
validator: (value: string) => ['dblclick'].includes(value)
|
2023-11-09 10:52:06 +00:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
const emit = defineEmits(['change'])
|
2023-11-14 10:12:55 +00:00
|
|
|
const inputRef = ref()
|
2023-11-09 10:52:06 +00:00
|
|
|
const isEdit = ref(false)
|
|
|
|
|
const writeValue = ref('')
|
2023-11-10 03:36:04 +00:00
|
|
|
const loading = ref(false)
|
2023-11-09 10:52:06 +00:00
|
|
|
|
|
|
|
|
watch(isEdit, (bool) => {
|
|
|
|
|
if (!bool) {
|
|
|
|
|
writeValue.value = ''
|
2024-04-22 06:59:51 +00:00
|
|
|
} else {
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
inputRef.value?.focus()
|
|
|
|
|
})
|
2023-11-09 10:52:06 +00:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2024-07-01 10:17:08 +00:00
|
|
|
function dblclick() {
|
|
|
|
|
if (props.trigger === 'dblclick') {
|
|
|
|
|
editNameHandle()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-10 03:36:04 +00:00
|
|
|
function submit() {
|
|
|
|
|
loading.value = true
|
2023-11-09 10:52:06 +00:00
|
|
|
emit('change', writeValue.value)
|
2023-11-10 03:36:04 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
|
isEdit.value = false
|
|
|
|
|
loading.value = false
|
|
|
|
|
}, 200)
|
2023-11-09 10:52:06 +00:00
|
|
|
}
|
2024-04-10 06:16:56 +00:00
|
|
|
function editNameHandle() {
|
2023-11-09 10:52:06 +00:00
|
|
|
writeValue.value = props.data
|
|
|
|
|
isEdit.value = true
|
|
|
|
|
}
|
2023-11-14 10:12:55 +00:00
|
|
|
|
2024-04-22 06:59:51 +00:00
|
|
|
onMounted(() => {})
|
2023-11-09 10:52:06 +00:00
|
|
|
</script>
|
|
|
|
|
<style lang="scss" scoped></style>
|