| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <template>
- <el-dialog v-model="dialogVisible" title="场景图生成" width="600px" :close-on-click-modal="false"
- :close-on-press-escape="false" custom-class="scene-prompt-dialog" @close="handleClose">
- <div class="scene-prompt-container">
- <!-- 场景提示词输入区域 -->
- <div class="input-section">
- <div class="input-wrapper">
- <el-input v-model="scenePrompt" type="textarea" :rows="8" placeholder="请输入场景提示词" class="scene-input"
- resize="none" maxlength="500" />
- <!-- AI帮我写按钮 -->
- <div class="ai-help-button-container">
- <el-button type="primary" @click="handleAIHelp" :loading="aiLoading" class="ai-help-button">
- AI帮我写
- </el-button>
- </div>
- </div>
- </div>
- </div>
- <template #footer>
- <div class="dialog-footer">
- <el-button type="primary" @click="handleConfirm" :disabled="!canConfirm" class="confirm-button">
- 确认
- </el-button>
- </div>
- </template>
- </el-dialog>
- </template>
- <script setup lang="ts">
- import { ref, computed, watch } from 'vue'
- import { ElMessage } from 'element-plus'
- import { expandCameraWordsApi } from '@/apis/other'
- // 定义组件的 props
- interface Props {
- modelValue: boolean
- initialPrompt?: string
- }
- const props = defineProps<Props>()
- // 定义组件的事件
- const emit = defineEmits<{
- 'update:modelValue': [value: boolean]
- confirm: [prompt: string]
- cancel: []
- }>()
- // Dialog 显示状态
- const dialogVisible = computed({
- get: () => props.modelValue,
- set: (value) => emit('update:modelValue', value)
- })
- // 场景提示词
- const scenePrompt = ref('')
- // 本地缓存 key
- const SCENE_PROMPT_CACHE_KEY = 'scene_prompt_cache'
- // 从本地缓存读取
- const loadScenePromptFromCache = () => {
- try {
- const cache = localStorage.getItem(SCENE_PROMPT_CACHE_KEY)
- if (cache && !props.initialPrompt) {
- scenePrompt.value = cache
- }
- } catch {}
- }
- // 写入本地缓存
- const saveScenePromptToCache = () => {
- try {
- const value = (scenePrompt.value || '').trim()
- if (value) {
- localStorage.setItem(SCENE_PROMPT_CACHE_KEY, value)
- }
- } catch {}
- }
- // AI 加载状态
- const aiLoading = ref(false)
- // 是否可以确认
- const canConfirm = computed(() => {
- return scenePrompt.value.trim().length > 0
- })
- // AI 帮我写
- const handleAIHelp = async () => {
- if (aiLoading.value) return
- aiLoading.value = true
- try {
- // 调用后端接口生成场景提示词
- const res: any = await expandCameraWordsApi()
- const result = res?.data?.result || ''
- if (result) {
- scenePrompt.value = result
- ElMessage.success('AI 已为您生成场景提示词')
- } else {
- ElMessage.error('AI 未返回结果,请稍后重试')
- }
- } catch (error) {
- ElMessage.error('AI 生成失败,请重试')
- } finally {
- aiLoading.value = false
- }
- }
- // 确认
- const handleConfirm = () => {
- if (!canConfirm.value) return
- saveScenePromptToCache()
- emit('confirm', scenePrompt.value.trim())
- dialogVisible.value = false
- resetForm()
- }
- // 关闭弹窗
- const handleClose = () => {
- emit('cancel')
- }
- // 重置表单
- const resetForm = () => {
- scenePrompt.value = ''
- }
- // 监听弹窗显示状态变化,初始化场景提示词
- watch(dialogVisible, (newValue) => {
- if (newValue) {
- if (props.initialPrompt) {
- scenePrompt.value = props.initialPrompt
- } else {
- loadScenePromptFromCache()
- }
- }
- }, { immediate: true })
- </script>
- <style lang="scss" scoped>
- .scene-prompt-container {
- padding: 20px;
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
- background: #EAECED;
- }
- .input-section {
- position: relative;
- }
- .input-wrapper {
- position: relative;
- background: #f8f9fa;
- border-radius: 8px;
- border: 1px solid #e4e7ed;
- }
- .scene-input {
- :deep(.el-textarea__inner) {
- border: none;
- background: transparent;
- font-size: 16px;
- line-height: 1.6;
- color: #303133;
- resize: none;
- &::placeholder {
- color: #c0c4cc;
- }
- &:focus {
- box-shadow: none;
- }
- }
- }
- .ai-help-button-container {
- position: absolute;
- bottom: 15px;
- height: 25px;
- right: 6px;
- }
- .ai-help-button {
- background: #2957FF;
- border: none;
- border-radius: 20px;
- padding: 8px 16px;
- font-size: 13px;
- font-weight: 500;
- color: white;
- box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
- transition: all 0.3s ease;
- &:hover {
- transform: translateY(-2px);
- box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4);
- }
- &:active {
- transform: translateY(0);
- }
- .ai-icon {
- margin-right: 6px;
- font-size: 14px;
- }
- }
- .dialog-footer {
- display: flex;
- justify-content: center;
- gap: 16px;
- padding: 14px 20px;
- }
- .confirm-button {
- background: linear-gradient(135deg, #409eff 0%, #a855f7 100%);
- border: none;
- border-radius: 6px;
- height: 36px;
- padding: 12px 32px;
- font-size: 14px;
- font-weight: 500;
- color: white;
- box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
- transition: all 0.3s ease;
- &:hover {
- transform: translateY(-1px);
- box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4);
- }
- &:active {
- transform: translateY(0);
- }
- &:disabled {
- background: #c0c4cc;
- transform: none;
- box-shadow: none;
- cursor: not-allowed;
- }
- }
- </style>
- <style lang="scss">
- .scene-prompt-dialog {
- .el-dialog__body {
- padding: 0;
- }
- .el-dialog__footer {
- padding: 0 !important;
- background: #EAECED;
- }
- .el-dialog {
- border-radius: 12px !important;
- overflow: hidden;
- }
- .el-dialog__header {
- background: #f8f9fa;
- }
- .el-dialog__title {
- font-size: 18px !important;
- font-weight: 600 !important;
- color: #303133 !important;
- text-align: center !important;
- }
- }
- </style>
|