2023-11-09 10:52:06 +00:00
|
|
|
<template>
|
|
|
|
|
<div class="cursor">
|
|
|
|
|
<slot name="read">
|
|
|
|
|
<div class="flex align-center" v-if="!isEdit">
|
|
|
|
|
<span>{{ data }}</span>
|
|
|
|
|
<el-button @click.prevent="editNameHandle" text v-if="showEditIcon">
|
|
|
|
|
<el-icon><Edit /></el-icon>
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</slot>
|
|
|
|
|
<slot>
|
|
|
|
|
<div class="flex align-center" v-if="isEdit">
|
|
|
|
|
<el-input ref="inputRef" v-model="writeValue" placeholder="请输入"></el-input>
|
|
|
|
|
<span class="ml-4">
|
2023-11-10 03:36:04 +00:00
|
|
|
<el-button type="primary" text @click="submit" :disabled="loading">
|
2023-11-09 10:52:06 +00:00
|
|
|
<el-icon><Select /></el-icon>
|
|
|
|
|
</el-button>
|
|
|
|
|
</span>
|
|
|
|
|
<span>
|
2023-11-10 03:36:04 +00:00
|
|
|
<el-button text @click="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">
|
|
|
|
|
import { ref, watch } from 'vue'
|
|
|
|
|
defineOptions({ name: 'ReadWrite' })
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
data: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
|
|
|
|
},
|
|
|
|
|
showEditIcon: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
const emit = defineEmits(['change'])
|
|
|
|
|
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 = ''
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
function editNameHandle(row: any) {
|
|
|
|
|
writeValue.value = props.data
|
|
|
|
|
isEdit.value = true
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss" scoped></style>
|