fix: refresh VM data from user goods detail #33
@@ -10,7 +10,7 @@
|
||||
<el-tag v-if="detail" :type="currentTag === '云服务器' ? 'primary' : 'info'" size="small" style="margin-left:8px">{{ detail.tag || detail.good?.tag || '通用' }}</el-tag>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<el-button plain @click="loadDetail" :loading="loading">
|
||||
<el-button plain @click="refreshDetail" :loading="loading || refreshing">
|
||||
<el-icon><Refresh /></el-icon> 刷新
|
||||
</el-button>
|
||||
<el-button type="success" plain @click="openRenew" :disabled="!detail || isDeleted">
|
||||
@@ -210,7 +210,7 @@
|
||||
</el-card>
|
||||
|
||||
<!-- 类型适配栏目区域 -->
|
||||
<UserVmDetail v-else-if="currentTag === '云服务器'" embedded :goods-id="goodsId" />
|
||||
<UserVmDetail v-else-if="currentTag === '云服务器'" ref="vmDetailRef" embedded :goods-id="goodsId" />
|
||||
|
||||
<el-card v-else-if="detail.good" shadow="hover" class="related-card">
|
||||
<template #header>
|
||||
@@ -327,7 +327,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, onMounted, onActivated, watch } from 'vue'
|
||||
import { ref, reactive, computed, nextTick, onMounted, onActivated, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { ArrowLeft, ArrowDown, Refresh, Edit, Delete } from '@element-plus/icons-vue'
|
||||
@@ -343,6 +343,8 @@ const router = useRouter()
|
||||
const goodsId = computed(() => parseInt(route.params.id) || 0)
|
||||
|
||||
const loading = ref(false)
|
||||
const refreshing = ref(false)
|
||||
const vmDetailRef = ref(null)
|
||||
const submitLoading = ref(false)
|
||||
const detail = ref(null)
|
||||
const detailExpanded = ref(false)
|
||||
@@ -446,6 +448,21 @@ const loadDetail = async () => {
|
||||
finally { loading.value = false }
|
||||
}
|
||||
|
||||
const refreshDetail = async () => {
|
||||
if (refreshing.value) return
|
||||
refreshing.value = true
|
||||
try {
|
||||
await loadDetail()
|
||||
const isVm = currentTag.value === '云服务器' || detail.value?.good?.table === 'kvm_service'
|
||||
if (isVm && !isDeleted.value) {
|
||||
await nextTick()
|
||||
await vmDetailRef.value?.refresh?.()
|
||||
}
|
||||
} finally {
|
||||
refreshing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const goToUser = () => {
|
||||
const uid = detail.value?.userId || detail.value?.user_id
|
||||
if (!uid) return
|
||||
|
||||
@@ -1385,6 +1385,8 @@ const loadDetail = async () => {
|
||||
} catch (e) { ElMessage.error(extractApiError(e?.response?.data, '加载失败')) } finally { loading.value = false }
|
||||
}
|
||||
|
||||
defineExpose({ refresh: loadDetail })
|
||||
|
||||
const handleTabChange = (tab) => {
|
||||
if (tab === 'snapshot') { loadSnapshots(); loadSnapshotQuota() }
|
||||
if (tab === 'backup') { loadBackups(); loadBackupQuota() }
|
||||
|
||||
Reference in New Issue
Block a user