| <span class="breadcrumb-current">{{ visitorName }}</span> |
| 9 | </nav> |
| 10 |
| 11 | <template v-if="visitor"> |
| 12 | <div class="detail-header"> |
| 13 | <div> |
| 14 | <h2 class="detail-title">{{ visitor.name }}</h2> |
| 15 | <p class="header-subtitle">Type: {{ visitor.type.toUpperCase() }}</p> |
| 16 | </div> |
| 17 | <div v-if="isStore" class="header-actions"> |
| 18 | <ActionButton variant="outline" size="small" @click="handleEdit"> |
| 19 | Edit |
| 20 | </ActionButton> |
| 21 | </div> |
| 22 | </div> |
| 23 | </template> |
| 24 | </div> |
| 25 |
| 26 | <div v-if="notFound" class="not-found"> |
| 27 | <p class="empty-text">Visitor not found</p> |
| 28 | <p class="empty-hint">The visitor "{{ visitorName }}" does not exist.</p> |
| 29 | <ActionButton variant="outline" @click="router.push('/visitors')"> |
| 30 | Back to Visitors |
| 31 | </ActionButton> |
| 32 | </div> |
| 33 |
| 34 | <div v-else-if="visitor" v-loading="loading" class="detail-content"> |
| 35 | <VisitorFormLayout |
| 36 | v-if="formData" |
| 37 | :model-value="formData" |
| 38 | readonly |
| 39 | /> |
| 40 | </div> |
| 41 |
| 42 | <div v-else v-loading="loading" class="loading-area"></div> |
| 43 |
| 44 | </div> |
| 45 | </template> |
| 46 |
| 47 | <script setup lang="ts"> |
| 48 | import { ref, computed, onMounted } from 'vue' |
| 49 | import { useRoute, useRouter } from 'vue-router' |
| 50 | import { ElMessage } from 'element-plus' |
| 51 | import ActionButton from '@shared/components/ActionButton.vue' |
| 52 | import VisitorFormLayout from '../components/visitor-form/VisitorFormLayout.vue' |
| 53 | import { getVisitorConfig, getStoreVisitor } from '../api/frpc' |
| 54 | import type { VisitorDefinition, VisitorFormData } from '../types' |
| 55 | import { storeVisitorToForm } from '../types' |
| 56 |
| 57 | const route = useRoute() |
| 58 | const router = useRouter() |
| 59 |
| 60 | const visitorName = route.params.name as string |
| 61 | const visitor = ref<VisitorDefinition | null>(null) |
| 62 | const loading = ref(true) |
| 63 | const notFound = ref(false) |
| 64 | const isStore = ref(false) |
| 65 |
| 66 | onMounted(async () => { |
| 67 | try { |
| 68 | const config = await getVisitorConfig(visitorName) |
| 69 | visitor.value = config |
| 70 |
| 71 | // Check if visitor is from the store (for Edit/Delete buttons) |
| 72 | try { |
| 73 | await getStoreVisitor(visitorName) |
| 74 | isStore.value = true |
| 75 | } catch { |
| 76 | // Not a store visitor — Edit/Delete not available |
| 77 | } |
| 78 | } catch (err: any) { |
| 79 | if (err?.status === 404 || err?.response?.status === 404) { |
| 80 | notFound.value = true |
| 81 | } else { |
| 82 | notFound.value = true |
| 83 | ElMessage.error('Failed to load visitor: ' + err.message) |
| 84 | } |
| 85 | } finally { |
| 86 | loading.value = false |
| 87 | } |
| 88 | }) |
| 89 |
| 90 | const formData = computed<VisitorFormData | null>(() => { |
| 91 | if (!visitor.value) return null |
| 92 | return storeVisitorToForm(visitor.value) |
| 93 | }) |
| 94 |
| 95 | const handleEdit = () => { |
| 96 | router.push('/visitors/' + encodeURIComponent(visitorName) + '/edit') |
| 97 | } |
| 98 |
| 99 | </script> |
| 100 |
| 101 | <style scoped lang="scss"> |
| 102 | .visitor-detail-page { |
| 103 | display: flex; |
| 104 | flex-direction: column; |
| 105 | height: 100%; |
| 106 | max-width: 960px; |
| 107 | margin: 0 auto; |
| 108 | } |
| 109 |
| 110 | .detail-top { |
| 111 | flex-shrink: 0; |
| 112 | padding: $spacing-xl 24px 0; |
| 113 | } |
| 114 |
| 115 | .detail-content { |
| 116 | flex: 1; |
| 117 | overflow-y: auto; |
| 118 | padding: 0 24px 160px; |
| 119 | } |
| 120 |
| 121 | .breadcrumb { |
| 122 | display: flex; |
| 123 | align-items: center; |
| 124 | gap: $spacing-sm; |
| 125 | font-size: $font-size-md; |
| 126 | margin-bottom: $spacing-lg; |
| 127 | } |
| 128 |
| 129 | .breadcrumb-link { |
| 130 | color: $color-text-secondary; |
| 131 | text-decoration: none; |
| 132 |
| 133 | &:hover { |
| 134 | color: $color-text-primary; |
| 135 | } |
| 136 | } |
| 137 |
| 138 | .breadcrumb-sep { |
| 139 | color: $color-text-light; |
| 140 | } |
| 141 |
| 142 | .breadcrumb-current { |
| 143 | color: $color-text-primary; |
| 144 | font-weight: $font-weight-medium; |
| 145 | } |
| 146 |
| 147 | .detail-header { |
| 148 | display: flex; |
| 149 | justify-content: space-between; |
| 150 | align-items: flex-start; |
| 151 | margin-bottom: $spacing-xl; |
| 152 | } |
| 153 |
| 154 | .detail-title { |
| 155 | margin: 0; |
| 156 | font-size: 22px; |
| 157 | font-weight: $font-weight-semibold; |
| 158 | color: $color-text-primary; |
| 159 | margin-bottom: $spacing-sm; |
| 160 | } |
| 161 |
| 162 | .header-subtitle { |
| 163 | font-size: $font-size-sm; |
| 164 | color: $color-text-muted; |
| 165 | margin: 0; |
| 166 | } |
| 167 |
| 168 | .header-actions { |
| 169 | display: flex; |
| 170 | gap: $spacing-sm; |
| 171 | } |
| 172 |
| 173 | .not-found, |
| 174 | .loading-area { |
| 175 | text-align: center; |
| 176 | padding: 60px $spacing-xl; |
| 177 | } |
| 178 |
| 179 | .empty-text { |
| 180 | font-size: $font-size-lg; |
| 181 | font-weight: $font-weight-medium; |
| 182 | color: $color-text-secondary; |
| 183 | margin: 0 0 $spacing-xs; |
| 184 | } |
| 185 |
| 186 | .empty-hint { |
| 187 | font-size: $font-size-sm; |
| 188 | color: $color-text-muted; |
| 189 | margin: 0 0 $spacing-lg; |
| 190 | } |
| 191 |
| 192 | @include mobile { |
| 193 | .detail-top { |
| 194 | padding: $spacing-xl $spacing-lg 0; |
| 195 | } |
| 196 |
| 197 | .detail-content { |
| 198 | padding: 0 $spacing-lg $spacing-xl; |
| 199 | } |
| 200 |
| 201 | .detail-header { |
| 202 | flex-direction: column; |
| 203 | gap: $spacing-md; |
| 204 | } |
| 205 | } |
| 206 | </style> |