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

871 lines
34 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script>
import "~/assets/styles/LegacyDcimActions.DcIrQby6.css";
import { toDisplayString } from "vue";
import { renderList } from "vue";
import { useId } from "vue";
import { onBeforeUnmount } from "vue";
import { watch } from "vue";
import { createBlock } from "vue";
import { ref } from "vue";
import { withCtx } from "vue";
import { createCommentVNode } from "vue";
import { computed } from "vue";
import { isRef } from "vue";
import { createElementBlock } from "vue";
import { Fragment } from "vue";
import { createElementVNode } from "vue";
import { createTextVNode } 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 dialog from "primevue/dialog";
import button from "primevue/button";
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
import message from "primevue/message";
import inputtext from "primevue/inputtext";
import { n as product_name_n } from "~/lib/product-name.js";
import select from "primevue/select";
import inputnumber from "primevue/inputnumber";
import checkbox from "primevue/checkbox";
import OperationNotice from "~/components/OperationNotice.vue";
import OperatePasswordGate from "~/components/OperatePasswordGate.vue";
import { t as os_name_t } from "~/lib/os-name.js";
import { t as remote_console_t } from "~/lib/remote-console.js";
var de = {
class: `legacy-actions`,
},
fe = {
class: `action-buttons`,
},
pe = {
class: `action-form`,
},
me = {
class: `target`,
},
he = [`for`],
ge = {
key: 0,
class: `muted`,
},
_e = [`for`],
ve = [`for`],
ye = [`for`],
be = {
key: 0,
class: `muted`,
},
xe = [`for`],
Se = [`for`],
Ce = {
key: 4,
class: `ack`,
},
we = [`for`],
S = Object.assign(
_plugin_vue_export_helper_t(
defineComponent({
__name: `LegacyDcimActions`,
props: {
hostId: {},
host: {},
data: {},
disabled: {
type: Boolean,
},
},
emits: [`refresh`],
setup(g, { expose: b, emit: S }) {
let C = g,
Te = S,
Ee = useApi(),
w = useId(),
T = (e) =>
e && typeof e == `object` && !Array.isArray(e) ? e : null,
E = (e) =>
e === !0 || e === 1 || e === `1` || e === `on` || e === `true`,
D = (e) =>
e === !1 || e === 0 || e === `0` || e === `off` || e === `false`,
O = {
vnc: `打开 VNC 控制台`,
reset_password: `重置密码`,
reinstall: `重装系统`,
rescue: `进入救援模式`,
cancel_task: `取消当前任务`,
reset_bmc: `重置 BMC`,
},
k = {
vnc: `novnc`,
reset_password: `crack_pass`,
reinstall: `reinstall`,
rescue: `rescue`,
cancel_task: `rescue`,
reset_bmc: `reset_bmc`,
},
A = computed(() => T(C.data)),
j = computed(() => T(A.value?.dcim)),
De = ref(C.hostId),
M = computed(
() =>
!C.disabled &&
/^[1-9]\d*$/.test(C.hostId) &&
String(C.host.id) === C.hostId &&
De.value === C.hostId &&
C.host.status === `Active` &&
!!A.value &&
!!j.value,
);
function Oe(e) {
let t = A.value?.module_button,
n = Array.isArray(t) ? t : [t];
for (let t of n) {
let n = T(t);
if (!n) continue;
let r =
`func` in n
? [n]
: [n.console, n.control].flatMap((e) =>
Array.isArray(e) ? e : [],
);
for (let t of r) {
let n = T(t);
if (
!(
!n ||
(n.type && n.type !== "default") ||
![e, k[e]].includes(String(n.func))
) &&
(E(n.disabled) || D(n.enabled) || D(n.enable))
)
return !0;
}
}
return !1;
}
function N(e) {
if (!Object.hasOwn(O, e) || !j.value || Oe(e)) return !1;
let t = j.value.auth,
n = T(t);
return e === `reset_bmc`
? !!n && E(n.reset_bmc)
: D(t) || (n && (D(n[k[e]]) || D(n[e])))
? !1
: E(t) || !!(n && E(n[k[e]]));
}
let ke = computed(() => Object.keys(O).filter(N)),
P = computed(() => {
let e = [
...(Array.isArray(A.value?.cloud_os_group)
? A.value.cloud_os_group
: []),
...(Array.isArray(j.value?.os_group) ? j.value.os_group : []),
],
t = Array.isArray(A.value?.cloud_os) ? A.value.cloud_os : [],
n = Array.isArray(j.value?.os) ? j.value.os : [],
r = [];
for (let i of t.length ? t : n) {
let t = T(i);
if (
!t ||
!Number.isSafeInteger(Number(t.id)) ||
Number(t.id) <= 0 ||
typeof t.name != `string` ||
!t.name.trim()
)
continue;
let n = t.group ?? t.group_id,
a = e.map(T).find((e) => e && String(e.id) === String(n)),
o = typeof a?.name == `string` ? a.name : ``;
r.some((e) => e.id === Number(t.id)) ||
r.push({
id: Number(t.id),
name: t.name,
group: o,
windows:
Number(t.ostype) === 1 ||
/windows/i.test(t.name + ` ` + o),
});
}
return r;
}),
Ae = (e) => os_name_t(e.name),
F = ref(null),
I = ref(``),
L = ref(!1),
R = ref(``),
z = ref(``),
B = ref(null),
V = ref(22),
H = ref(0),
U = ref(2),
W = ref(!1),
G = ref(``),
K = ref(!1),
q = ref(``),
J = computed(() => P.value.find((e) => e.id === B.value)),
Y = computed(
() => F.value === `reset_password` || F.value === `reinstall`,
),
je = computed(() =>
F.value === `reinstall`
? J.value?.windows && H.value === 1
? `重装将格式化第一分区并删除其中的数据。请先完成备份,再确认继续。`
: `重装将格式化全盘并删除数据。请先完成备份,再确认继续。`
: F.value === `rescue`
? `进入救援模式可能中断当前连接和服务,请确认可以暂时停止业务。`
: F.value === `cancel_task`
? `取消当前重装或救援任务可能使系统暂时不可用,请确认后继续。`
: F.value === `reset_bmc`
? `重置 BMC 会暂时中断带外管理连接,请确认后继续。`
: `重置后请使用新密码连接服务器。部分系统可能需要重启后生效。`,
),
Me = computed(() => {
let e = T(T(A.value?.host_data)?.password_rule),
t = T(e?.rule);
if (!t) return ``;
let n = [],
r = Number(t.len_num);
Number.isSafeInteger(r) && r > 0 && r <= 128 && n.push(`${r} 位`);
for (let [e, r] of [
[`upper`, `大写字母`],
[`lower`, `小写字母`],
[`num`, `数字`],
[`special`, `特殊字符`],
])
e && r && E(t[e]) && n.push(r);
return n.length
? `服务器密码要求:${n.join(`、`)},具体规则由服务器校验。`
: ``;
}),
X = 0,
Z = !1,
Q = null;
function Ne(e) {
return (
!Z && M.value && N(e) && I.value === C.hostId && Q === C.data
);
}
function $() {
(X++,
(F.value = null),
(I.value = ``),
(Q = null),
(L.value = !1),
(R.value = ``),
(z.value = ``),
(G.value = ``),
(q.value = ``),
(K.value = !1));
}
function Pe() {
L.value || $();
}
function Fe(e) {
if (!Z && !L.value && M.value && N(e)) {
if (e === `vnc`) {
remote_console_t(C.hostId, `remf_finance_dcim`);
return;
}
(X++,
(I.value = C.hostId),
(Q = C.data),
(F.value = e),
(R.value = ``),
(z.value = ``),
(G.value = ``),
(q.value = ``),
(K.value = !1),
(B.value = null),
(V.value = 22),
(H.value = 0),
(U.value = 2),
(W.value = !1));
}
}
async function Ie() {
let e = F.value;
if (!e || e === `vnc` || L.value || !Ne(e)) return;
if (
((G.value = ``),
(K.value = !1),
Y.value && (!R.value.trim() || R.value.includes(`\0`)))
) {
G.value = `请输入有效的新密码`;
return;
}
if (e === `reinstall`) {
if (!J.value) {
G.value = `请选择可用的操作系统`;
return;
}
if (
!Number.isInteger(V.value) ||
Number(V.value) < 1 ||
Number(V.value) > 65535
) {
G.value = `请输入 1 到 65535 之间的端口`;
return;
}
if (![0, 1].includes(H.value)) {
G.value = `请选择有效的分区方式`;
return;
}
if (!W.value) {
G.value = `请确认已备份数据并了解重装影响`;
return;
}
}
if (e === `rescue` && ![1, 2].includes(U.value)) {
G.value = `请选择救援系统`;
return;
}
let t = X,
n = C.hostId,
r = {
client_operate_password: z.value,
};
(Y.value && (r.password = R.value),
e === `rescue` && (r.type = U.value),
e === `reinstall` &&
Object.assign(r, {
os: B.value,
port: V.value,
part_type: J.value?.windows ? H.value : 0,
}));
let i = () => t === X && Ne(e);
L.value = !0;
try {
if ((await Ee.post(`/remf_finance_dcim/${n}/${e}`, r), !i()))
return;
((q.value = `${O[e]}指令已提交,请等待实例状态更新。`),
(F.value = null),
(R.value = ``),
(z.value = ``),
Te(`refresh`));
} catch (t) {
i() &&
((K.value = !0),
(G.value =
t instanceof Error ? t.message : `${O[e]}失败,请重试`));
} finally {
t === X && (L.value = !1);
}
}
return (
watch(
[
() => C.hostId,
() => C.host.id,
() => C.host.status,
() => C.host.module,
() => C.data,
() => C.disabled,
],
$,
{
flush: `sync`,
},
),
watch(
() => C.data,
() => {
De.value = C.hostId;
},
{
flush: `sync`,
},
),
watch(B, () => {
((V.value = J.value?.windows ? 3389 : 22), (H.value = 0));
}),
onBeforeUnmount(() => {
((Z = !0), $());
}),
b({
request: Fe,
busy: L,
}),
(n, r) => {
let i = button,
o = OperationNotice,
l = message,
y = select,
b = inputnumber,
x = inputtext,
ue = OperatePasswordGate,
S = checkbox,
C = dialog;
return (
openBlock(),
createElementBlock(`div`, de, [
createElementVNode(`div`, fe, [
(openBlock(!0),
createElementBlock(
Fragment,
null,
renderList(
unref(ke),
(e) => (
openBlock(),
createBlock(
i,
{
key: e,
label: O[e],
icon:
e === `vnc`
? `pi pi-desktop`
: e === `reset_password`
? `pi pi-key`
: `pi pi-wrench`,
outlined: ``,
size: `small`,
disabled: !unref(M) || unref(L),
onClick: (t) => Fe(e),
},
null,
8,
[`label`, `icon`, `disabled`, `onClick`],
)
),
),
128,
)),
]),
unref(q)
? (openBlock(),
createBlock(
o,
{
key: 0,
message: unref(q),
},
null,
8,
[`message`],
))
: createCommentVNode(``, !0),
unref(G) && unref(K)
? (openBlock(),
createBlock(
o,
{
key: 1,
severity: `error`,
message: unref(G),
},
null,
8,
[`message`],
))
: createCommentVNode(``, !0),
createVNode(
C,
{
visible: !!unref(F),
header: unref(F) ? O[unref(F)] : ``,
modal: ``,
style: {
width: `540px`,
maxWidth: `calc(100vw - 24px)`,
},
draggable: !1,
closable: !unref(L),
"close-on-escape": !unref(L),
"onUpdate:visible": (r[7] ||= (e) => {
e || Pe();
}),
},
{
footer: withCtx(() => [
createVNode(
i,
{
label: `取消`,
outlined: ``,
severity: `secondary`,
disabled: unref(L),
onClick: Pe,
},
null,
8,
[`disabled`],
),
createVNode(
i,
{
label: `确认${unref(F) ? O[unref(F)] : ``}`,
severity: `danger`,
loading: unref(L),
disabled:
unref(L) ||
!unref(M) ||
!unref(F) ||
!N(unref(F)),
onClick: Ie,
},
null,
8,
[`label`, `loading`, `disabled`],
),
]),
default: withCtx(() => [
createElementVNode(`div`, pe, [
createElementVNode(`p`, me, [
(r[8] ||= createTextVNode(`目标实例:`, -1)),
createElementVNode(
`strong`,
null,
toDisplayString(
g.host.name ||
unref(product_name_n)(g.host.product_name),
),
1,
),
createTextVNode(
`(#` + toDisplayString(g.hostId) + `)`,
1,
),
]),
createVNode(
l,
{
severity: `warn`,
closable: !1,
},
{
default: withCtx(() => [
createTextVNode(toDisplayString(unref(je)), 1),
]),
_: 1,
},
),
unref(G) && !unref(K)
? (openBlock(),
createBlock(
l,
{
key: 0,
severity: `error`,
closable: !1,
},
{
default: withCtx(() => [
createTextVNode(
toDisplayString(unref(G)),
1,
),
]),
_: 1,
},
))
: createCommentVNode(``, !0),
unref(F) === `reinstall`
? (openBlock(),
createElementBlock(
Fragment,
{
key: 1,
},
[
createElementVNode(
`label`,
{
for: `${unref(w)}-image`,
},
`操作系统`,
8,
he,
),
createVNode(
y,
{
modelValue: unref(B),
"onUpdate:modelValue": (r[0] ||= (e) =>
isRef(B) ? (B.value = e) : null),
"input-id": `${unref(w)}-image`,
options: unref(P),
"option-label": Ae,
"option-value": `id`,
placeholder: `请选择操作系统`,
disabled: unref(L),
fluid: ``,
},
null,
8,
[
`modelValue`,
`input-id`,
`options`,
`disabled`,
],
),
unref(P).length
? createCommentVNode(``, !0)
: (openBlock(),
createElementBlock(
`p`,
ge,
`此实例暂无可用系统镜像,请刷新详情后重试。`,
)),
createElementVNode(
`label`,
{
for: `${unref(w)}-port`,
},
`连接端口`,
8,
_e,
),
createVNode(
b,
{
modelValue: unref(V),
"onUpdate:modelValue": (r[1] ||= (e) =>
isRef(V) ? (V.value = e) : null),
"input-id": `${unref(w)}-port`,
min: 1,
max: 65535,
"use-grouping": !1,
disabled: unref(L),
fluid: ``,
},
null,
8,
[`modelValue`, `input-id`, `disabled`],
),
unref(J)?.windows
? (openBlock(),
createElementBlock(
Fragment,
{
key: 1,
},
[
createElementVNode(
`label`,
{
for: `${unref(w)}-partition`,
},
`分区方式`,
8,
ve,
),
createVNode(
y,
{
modelValue: unref(H),
"onUpdate:modelValue": (r[2] ||= (
e,
) =>
isRef(H)
? (H.value = e)
: null),
"input-id": `${unref(w)}-partition`,
options: [
{
label: `格式化全盘`,
value: 0,
},
{
label: `仅格式化第一分区`,
value: 1,
},
],
"option-label": `label`,
"option-value": `value`,
disabled: unref(L),
fluid: ``,
},
null,
8,
[
`modelValue`,
`input-id`,
`disabled`,
],
),
],
64,
))
: createCommentVNode(``, !0),
],
64,
))
: createCommentVNode(``, !0),
unref(Y)
? (openBlock(),
createElementBlock(
Fragment,
{
key: 2,
},
[
createElementVNode(
`label`,
{
for: `${unref(w)}-password`,
},
`新密码`,
8,
ye,
),
createVNode(
x,
{
id: `${unref(w)}-password`,
modelValue: unref(R),
"onUpdate:modelValue": (r[3] ||= (e) =>
isRef(R) ? (R.value = e) : null),
type: `password`,
autocomplete: `new-password`,
disabled: unref(L),
fluid: ``,
},
null,
8,
[`id`, `modelValue`, `disabled`],
),
unref(Me)
? (openBlock(),
createElementBlock(
`p`,
be,
toDisplayString(unref(Me)),
1,
))
: createCommentVNode(``, !0),
],
64,
))
: createCommentVNode(``, !0),
unref(F) === `rescue`
? (openBlock(),
createElementBlock(
Fragment,
{
key: 3,
},
[
createElementVNode(
`label`,
{
for: `${unref(w)}-rescue`,
},
`救援系统`,
8,
xe,
),
createVNode(
y,
{
modelValue: unref(U),
"onUpdate:modelValue": (r[4] ||= (e) =>
isRef(U) ? (U.value = e) : null),
"input-id": `${unref(w)}-rescue`,
options: [
{
label: `Linux`,
value: 2,
},
{
label: `Windows`,
value: 1,
},
],
"option-label": `label`,
"option-value": `value`,
disabled: unref(L),
fluid: ``,
},
null,
8,
[`modelValue`, `input-id`, `disabled`],
),
],
64,
))
: createCommentVNode(``, !0),
createVNode(ue, null, {
default: withCtx(() => [
createElementVNode(
`label`,
{
for: `${unref(w)}-operate`,
},
`操作密码(如已设置)`,
8,
Se,
),
createVNode(
x,
{
id: `${unref(w)}-operate`,
modelValue: unref(z),
"onUpdate:modelValue": (r[5] ||= (e) =>
isRef(z) ? (z.value = e) : null),
type: `password`,
autocomplete: `off`,
disabled: unref(L),
fluid: ``,
},
null,
8,
[`id`, `modelValue`, `disabled`],
),
]),
_: 1,
}),
unref(F) === `reinstall`
? (openBlock(),
createElementBlock(`div`, Ce, [
createVNode(
S,
{
modelValue: unref(W),
"onUpdate:modelValue": (r[6] ||= (e) =>
isRef(W) ? (W.value = e) : null),
"input-id": `${unref(w)}-ack`,
binary: ``,
disabled: unref(L),
},
null,
8,
[`modelValue`, `input-id`, `disabled`],
),
createElementVNode(
`label`,
{
for: `${unref(w)}-ack`,
},
`我已备份数据,了解所选分区的数据将被清除`,
8,
we,
),
]))
: createCommentVNode(``, !0),
]),
]),
_: 1,
},
8,
[`visible`, `header`, `closable`, `close-on-escape`],
),
])
);
}
);
},
}),
[[`__scopeId`, `data-v-e3236d5c`]],
),
{
__name: `LegacyDcimActions`,
},
);
export {};
export default S;
</script>