40 lines
1.5 KiB
Vue
40 lines
1.5 KiB
Vue
<script setup lang="ts">
|
||
import { ref, watch } from "vue";
|
||
import { api } from "../api";
|
||
|
||
const props = defineProps<{ projectId: string; deploymentStatus?: string }>();
|
||
const entry = ref<{ status: "ACTIVE" | "WAITING" | "DISABLED"; url: string }>();
|
||
const error = ref("");
|
||
const loading = ref(false);
|
||
let request = 0;
|
||
async function load() {
|
||
const id = props.projectId;
|
||
const current = ++request;
|
||
loading.value = true;
|
||
error.value = "";
|
||
try {
|
||
const result = await api<typeof entry.value>(`/projects/${id}/ip-entry`);
|
||
if (request === current && props.projectId === id) entry.value = result;
|
||
} catch (cause) {
|
||
if (request === current && props.projectId === id) error.value = (cause as Error).message;
|
||
} finally {
|
||
if (request === current) loading.value = false;
|
||
}
|
||
}
|
||
watch([() => props.projectId, () => props.deploymentStatus], load, { immediate: true });
|
||
</script>
|
||
|
||
<template>
|
||
<div class="alert info" aria-label="网站 IP 入口">
|
||
<strong>网站 IP 入口</strong>
|
||
<p v-if="error" role="alert">{{ error }}</p>
|
||
<p v-else-if="entry?.status === 'ACTIVE'">
|
||
<a class="link" :href="entry.url" target="_blank" rel="noopener noreferrer">{{ entry.url }}</a>
|
||
</p>
|
||
<p v-else-if="entry?.status === 'WAITING'">管理员已开启。项目发布并启用域名后,入口会显示在这里。</p>
|
||
<p v-else-if="entry?.status === 'DISABLED'">管理员尚未为此项目开启。</p>
|
||
<p v-else>正在读取 IP 入口…</p>
|
||
<button class="link" :disabled="loading" @click="load">刷新 IP 入口</button>
|
||
</div>
|
||
</template>
|