2024-07-07 18:14:03 +08:00
|
|
|
<template>
|
|
|
|
<div class="h-full box-border py-6 px-7">
|
2024-07-08 00:41:20 +08:00
|
|
|
<div class="w-full h-full relative bg-white box-border p-3 sm:p-16 pr-0">
|
|
|
|
<!-- 展示在右上角 -->
|
|
|
|
<el-button
|
|
|
|
color="#846af7"
|
|
|
|
v-show="showCopy"
|
2024-07-09 00:44:27 +08:00
|
|
|
@click="copyContent"
|
|
|
|
class="absolute top-2 right-2"
|
2024-07-08 00:41:20 +08:00
|
|
|
>
|
|
|
|
复制
|
|
|
|
</el-button>
|
|
|
|
<!-- 展示在下面中间的位置 -->
|
|
|
|
<el-button
|
|
|
|
v-show="isWriting"
|
|
|
|
class="absolute bottom-2 left-1/2 -translate-x-1/2"
|
|
|
|
@click="emits('stopStream')"
|
|
|
|
>
|
|
|
|
终止生成
|
|
|
|
</el-button>
|
|
|
|
<div ref="contentRef" class="w-full h-full pr-3 sm:pr-16 overflow-y-auto">
|
|
|
|
<el-input
|
|
|
|
id="inputId"
|
|
|
|
type="textarea"
|
2024-07-09 00:44:27 +08:00
|
|
|
v-model="compContent"
|
2024-07-08 00:41:20 +08:00
|
|
|
autosize
|
|
|
|
:input-style="{ boxShadow: 'none' }"
|
|
|
|
resize="none"
|
|
|
|
placeholder="生成的内容……"
|
|
|
|
/>
|
|
|
|
</div>
|
2024-07-07 18:14:03 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-07-08 12:39:49 +08:00
|
|
|
import { useClipboard } from '@vueuse/core'
|
2024-07-07 18:14:03 +08:00
|
|
|
|
2024-07-08 12:39:49 +08:00
|
|
|
const message = useMessage()
|
|
|
|
const { copied, copy } = useClipboard()
|
2024-07-08 00:41:20 +08:00
|
|
|
|
2024-07-08 12:39:49 +08:00
|
|
|
const props = defineProps({
|
2024-07-09 00:44:27 +08:00
|
|
|
content: {
|
|
|
|
// 生成的结果
|
2024-07-08 12:39:49 +08:00
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
isWriting: {
|
2024-07-09 00:44:27 +08:00
|
|
|
// 是否正在生成文章
|
2024-07-08 12:39:49 +08:00
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
})
|
2024-07-08 00:41:20 +08:00
|
|
|
|
2024-07-09 00:44:27 +08:00
|
|
|
const emits = defineEmits(['update:content', 'stopStream'])
|
2024-07-08 00:41:20 +08:00
|
|
|
|
2024-07-09 00:44:27 +08:00
|
|
|
// 通过计算属性,双向绑定,更改生成的内容,考虑到用户想要更改生成文章的情况
|
|
|
|
const compContent = computed({
|
2024-07-08 12:39:49 +08:00
|
|
|
get() {
|
2024-07-09 00:44:27 +08:00
|
|
|
return props.content
|
2024-07-08 12:39:49 +08:00
|
|
|
},
|
|
|
|
set(val) {
|
2024-07-09 00:44:27 +08:00
|
|
|
emits('update:content', val)
|
2024-07-08 12:39:49 +08:00
|
|
|
}
|
|
|
|
})
|
2024-07-08 00:41:20 +08:00
|
|
|
|
2024-07-08 12:39:49 +08:00
|
|
|
/** 滚动 */
|
|
|
|
const contentRef = ref<HTMLDivElement>()
|
|
|
|
defineExpose({
|
|
|
|
scrollToBottom() {
|
|
|
|
contentRef.value?.scrollTo(0, contentRef.value?.scrollHeight)
|
|
|
|
}
|
|
|
|
})
|
2024-07-08 00:41:20 +08:00
|
|
|
|
2024-07-08 12:39:49 +08:00
|
|
|
/** 点击复制的时候复制内容 */
|
2024-07-09 00:44:27 +08:00
|
|
|
const showCopy = computed(() => props.content && !props.isWriting) // 是否展示复制按钮,在生成内容完成的时候展示
|
|
|
|
const copyContent = () => {
|
|
|
|
copy(props.content)
|
2024-07-08 12:39:49 +08:00
|
|
|
}
|
2024-07-08 00:41:20 +08:00
|
|
|
|
2024-07-09 00:44:27 +08:00
|
|
|
// 复制成功的时候copied.value为true
|
2024-07-08 12:39:49 +08:00
|
|
|
watch(copied, (val) => {
|
|
|
|
if (val) {
|
|
|
|
message.success('复制成功')
|
2024-07-08 00:41:20 +08:00
|
|
|
}
|
2024-07-08 12:39:49 +08:00
|
|
|
})
|
2024-07-08 00:41:20 +08:00
|
|
|
</script>
|