|
|
|
|
@ -226,10 +226,14 @@
|
|
|
|
|
<script setup>
|
|
|
|
|
import { ref, computed, onMounted } from 'vue'
|
|
|
|
|
import { useItineraryStore } from '../stores/itinerary'
|
|
|
|
|
import { useAuthStore } from '../stores/auth'
|
|
|
|
|
import { trackPlanCreate, trackSchemeSelect } from '../services/statsService'
|
|
|
|
|
import { quickPlan } from '../services/aiService'
|
|
|
|
|
import { exportToMarkdown } from '../services/exportService'
|
|
|
|
|
|
|
|
|
|
const store = useItineraryStore()
|
|
|
|
|
const authStore = useAuthStore()
|
|
|
|
|
const API_BASE = 'http://localhost:3001/api'
|
|
|
|
|
|
|
|
|
|
const allSchemes = computed(() => store.quickSchemes)
|
|
|
|
|
const historySchemes = computed(() => store.historySchemeGroups)
|
|
|
|
|
@ -419,12 +423,51 @@ function selectScheme(index) {
|
|
|
|
|
store.saveSchemesToStore(allSchemes.value, historySchemes.value)
|
|
|
|
|
store.setActiveSchemeIndex(index)
|
|
|
|
|
|
|
|
|
|
// 保存到后端
|
|
|
|
|
savePlanToBackend(scheme)
|
|
|
|
|
|
|
|
|
|
// 使用深拷贝后的数据加载
|
|
|
|
|
const savedScheme = store.quickSchemes[index]
|
|
|
|
|
console.log('[selectScheme] 深拷贝后的方案 points 数量:', savedScheme?.points?.length)
|
|
|
|
|
|
|
|
|
|
store.loadFromAI(savedScheme)
|
|
|
|
|
store.setPhase('workbench')
|
|
|
|
|
|
|
|
|
|
// 统计
|
|
|
|
|
trackSchemeSelect(scheme.name, index)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function savePlanToBackend(scheme) {
|
|
|
|
|
try {
|
|
|
|
|
const headers = { 'Content-Type': 'application/json' }
|
|
|
|
|
if (authStore.token) {
|
|
|
|
|
headers['Authorization'] = `Bearer ${authStore.token}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
|
name: scheme.name,
|
|
|
|
|
description: scheme.route,
|
|
|
|
|
data: scheme,
|
|
|
|
|
guestId: authStore.guestId || undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${API_BASE}/plans`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers,
|
|
|
|
|
body: JSON.stringify(body)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
const data = await res.json()
|
|
|
|
|
console.log('[savePlan] 方案保存成功:', data.id)
|
|
|
|
|
trackPlanCreate(scheme.name, 'quick')
|
|
|
|
|
} else {
|
|
|
|
|
const error = await res.json()
|
|
|
|
|
console.error('[savePlan] 保存失败:', error)
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('[savePlan] 保存异常:', err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openPreview(index) {
|
|
|
|
|
|