Files

175 lines
6.0 KiB
Vue

<script>
// 为 mf_cloud/remf_cloud 的 Windows 实例提供 RDP 文件下载,其他模块或镜像不启用。
import "~/assets/styles/CloudAccessExtras.CnBJlFAZ.css";
import { toDisplayString } 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 { createElementBlock } 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 button from "primevue/button";
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
import message from "primevue/message";
var y = {
key: 0,
class: `cloud-extras`,
},
b = {
class: `info-table`,
},
x = {
key: 0,
class: `kv`,
},
S = {
class: `action-cell`,
},
C = Object.assign(
_plugin_vue_export_helper_t(
defineComponent({
__name: `CloudAccessExtras`,
props: {
hostId: {},
module: {},
imageName: {},
config: {},
},
emits: [`refresh`],
setup(f) {
let _ = f,
C = useApi(),
w = computed(() => [`mf_cloud`, `remf_cloud`].includes(_.module)),
T = computed(() => /windows/i.test(_.imageName)),
E = ref(!1),
D = ref(``),
O = 0,
k = !1;
// 将接口文本转成临时下载链接,净化文件名并释放 Blob URL;实例变更后忽略旧响应。
async function A() {
if (!w.value || !T.value || E.value || k) return;
let e = O;
((E.value = !0), (D.value = ``));
try {
let t = await C.get(`/${_.module}/${_.hostId}/download_rdp`);
if (k || e !== O) return;
if (typeof t.content != `string` || !t.content.trim())
throw Error(`远程桌面文件内容为空`);
let n = URL.createObjectURL(
new Blob([t.content], {
type: `application/x-rdp`,
}),
),
r = document.createElement(`a`);
((r.href = n),
(r.download = String(
t.name || `instance-${_.hostId}.rdp`,
).replace(/[\\/\0]/g, `_`)),
r.click(),
setTimeout(() => URL.revokeObjectURL(n), 1e3));
} catch (t) {
!k &&
e === O &&
(D.value = t instanceof Error ? t.message : `RDP 文件下载失败`);
} finally {
e === O && (E.value = !1);
}
}
return (
watch([() => _.hostId, () => _.module, () => _.imageName], () => {
(O++, (E.value = !1), (D.value = ``));
}),
onBeforeUnmount(() => {
((k = !0), O++);
}),
(t, n) => {
let i = button,
s = message;
return unref(w) && unref(T)
? (openBlock(),
createElementBlock(`section`, y, [
(n[2] ||= createElementVNode(
`h4`,
{
class: `block-title`,
},
`远程桌面连接`,
-1,
)),
createElementVNode(`div`, b, [
unref(T)
? (openBlock(),
createElementBlock(`div`, x, [
(n[1] ||= createElementVNode(
`span`,
null,
`远程桌面`,
-1,
)),
createElementVNode(`div`, S, [
createVNode(
i,
{
label: `下载远程桌面连接文件`,
icon: `pi pi-download`,
loading: unref(E),
onClick: A,
},
null,
8,
[`loading`],
),
(n[0] ||= createElementVNode(
`p`,
{
class: `action-desc`,
},
`下载连接文件后,使用远程桌面客户端连接您的实例。`,
-1,
)),
]),
]))
: createCommentVNode(``, !0),
]),
unref(D)
? (openBlock(),
createBlock(
s,
{
key: 0,
severity: `error`,
closable: !1,
},
{
default: withCtx(() => [
createTextVNode(toDisplayString(unref(D)), 1),
]),
_: 1,
},
))
: createCommentVNode(``, !0),
]))
: createCommentVNode(``, !0);
}
);
},
}),
[[`__scopeId`, `data-v-94e7f654`]],
),
{
__name: `CloudAccessExtras`,
},
);
export {};
export default C;
</script>