Files
console-dev/app/components/instance/DcimReinstallStatus.vue
T
2026-11-06 00:04:38 +08:00

164 lines
5.0 KiB
Vue

<script>
import "~/assets/styles/DcimReinstallStatus.CuXeXmZ3.css";
import { toDisplayString } from "vue";
import { onMounted } from "vue";
import { onBeforeUnmount } from "vue";
import { watch } from "vue";
import { ref } from "vue";
import { createCommentVNode } from "vue";
import { createElementBlock } from "vue";
import { unref } from "vue";
import { defineComponent } from "vue";
import { createVNode } from "vue";
import { openBlock } from "vue";
import { useApi } from "~/lib/auth.js";
import button from "primevue/button";
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
var m = {
class: `task-status`,
},
h = {
key: 0,
role: `status`,
},
g = [`aria-label`, `title`],
_ = Object.assign(
_plugin_vue_export_helper_t(
defineComponent({
__name: `DcimReinstallStatus`,
props: {
hostId: {},
module: {},
refreshVersion: {},
},
setup(c) {
let p = c,
_ = useApi(),
v = ref(!1),
y = ref(``),
b = ref(!1),
x = ref(!1),
S = 0,
C = !1,
w = 0,
T;
function E() {
T = setTimeout(() => {
if (!C) {
if (
document.visibilityState !== `visible` ||
document.querySelector(`.p-dialog-mask`)
) {
E();
return;
}
D(!1);
}
}, 1e4);
}
async function D(e = !0) {
if (v.value || C) return;
(clearTimeout(T), e && (w = 0));
let t = ++S;
((v.value = !0), (y.value = ``));
try {
let e = await _.get(`/${p.module}/${p.hostId}/reinstall_status`);
if (C || t !== S) return;
if (
!Array.isArray(e) ||
e.some(
(e) =>
!e ||
e.task_type === null ||
e.task_type === void 0 ||
!Number.isInteger(Number(e.task_type)),
)
)
throw Error(`重装任务状态响应无效`);
((x.value = e.some((e) => Number(e.task_type) === 0)),
(b.value = !0),
x.value && ++w < 60 && E());
} catch (e) {
!C &&
t === S &&
(y.value =
e instanceof Error ? e.message : `重装任务状态加载失败`);
} finally {
t === S && (v.value = !1);
}
}
return (
watch(
[() => p.hostId, () => p.module, () => p.refreshVersion],
() => {
(S++, clearTimeout(T), (v.value = !1), (b.value = !1), D());
},
),
onMounted(D),
onBeforeUnmount(() => {
((C = !0), S++, clearTimeout(T));
}),
(t, n) => {
let r = button;
return (
openBlock(),
createElementBlock(`div`, m, [
unref(b) && !unref(y)
? (openBlock(),
createElementBlock(
`span`,
h,
toDisplayString(
unref(x)
? `系统正在重装,请等待任务结束`
: `当前未检测到进行中的重装任务`,
),
1,
))
: createCommentVNode(``, !0),
unref(y)
? (openBlock(),
createElementBlock(
`span`,
{
key: 1,
class: `task-error`,
role: `alert`,
"aria-label": `重装任务状态加载失败:${unref(y)}`,
title: unref(y),
},
`重装状态加载失败,可点刷新重试`,
8,
g,
))
: createCommentVNode(``, !0),
createVNode(
r,
{
label: `刷新重装状态`,
icon: `pi pi-refresh`,
text: ``,
size: `small`,
loading: unref(v),
onClick: (n[0] ||= (e) => D()),
},
null,
8,
[`loading`],
),
])
);
}
);
},
}),
[[`__scopeId`, `data-v-d99d9473`]],
),
{
__name: `DcimReinstallStatus`,
},
);
export {};
export default _;
</script>