416 lines
15 KiB
Vue
416 lines
15 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, ref } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
import { Connection, Lock, SwitchButton, Upload } from '@element-plus/icons-vue'
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
import http, { apiErrorMessage } from '../api/http'
|
|
import { type PluginRuntimeItem, usePluginStore } from '../stores/plugins'
|
|
|
|
const pluginStore = usePluginStore()
|
|
const { locale, t } = useI18n()
|
|
const loading = ref(true)
|
|
const changingId = ref('')
|
|
const uploading = ref(false)
|
|
const packageInput = ref<HTMLInputElement>()
|
|
const signatureInput = ref<HTMLInputElement>()
|
|
const packageFile = ref<File>()
|
|
const signatureFile = ref<File>()
|
|
|
|
interface PackageRelease {
|
|
id: string
|
|
pluginId: string
|
|
name: string
|
|
version: string
|
|
publisherId: string
|
|
hostApiVersion: string
|
|
sha256: string
|
|
packageSize: number
|
|
status: 'Staged' | 'PendingActivation' | 'Active' | 'Superseded' | 'Failed'
|
|
createdAt: string
|
|
activationRequestedAt?: string
|
|
failureMessage?: string
|
|
}
|
|
|
|
const packageReleases = ref<PackageRelease[]>([])
|
|
|
|
const groupedPlugins = computed(() => {
|
|
const groups = new Map<string, PluginRuntimeItem[]>()
|
|
for (const plugin of pluginStore.items) {
|
|
const items = groups.get(plugin.category) ?? []
|
|
items.push(plugin)
|
|
groups.set(plugin.category, items)
|
|
}
|
|
return Array.from(groups, ([category, items]) => ({ category, items }))
|
|
})
|
|
|
|
const enabledCount = computed(() =>
|
|
pluginStore.items.filter((plugin) => plugin.isEnabled).length,
|
|
)
|
|
|
|
async function loadPlugins() {
|
|
loading.value = true
|
|
try {
|
|
const [, packageResponse] = await Promise.all([
|
|
pluginStore.load(true),
|
|
http.get<PackageRelease[]>('/plugins/packages'),
|
|
])
|
|
packageReleases.value = packageResponse.data
|
|
} catch (error) {
|
|
ElMessage.error(apiErrorMessage(error))
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function selectFile(event: Event, target: 'package' | 'signature') {
|
|
const file = (event.target as HTMLInputElement).files?.[0]
|
|
if (target === 'package') packageFile.value = file
|
|
else signatureFile.value = file
|
|
}
|
|
|
|
async function uploadPackage() {
|
|
if (!packageFile.value || !signatureFile.value) {
|
|
ElMessage.warning(t('plugins.messages.selectFiles'))
|
|
return
|
|
}
|
|
uploading.value = true
|
|
try {
|
|
const body = new FormData()
|
|
body.append('package', packageFile.value)
|
|
body.append('signature', signatureFile.value)
|
|
await http.post('/plugins/packages', body)
|
|
packageFile.value = undefined
|
|
signatureFile.value = undefined
|
|
if (packageInput.value) packageInput.value.value = ''
|
|
if (signatureInput.value) signatureInput.value.value = ''
|
|
ElMessage.success(t('plugins.messages.staged'))
|
|
await loadPlugins()
|
|
} catch (error) {
|
|
ElMessage.error(apiErrorMessage(error))
|
|
} finally {
|
|
uploading.value = false
|
|
}
|
|
}
|
|
|
|
async function activatePackage(row: unknown) {
|
|
const release = row as PackageRelease
|
|
try {
|
|
await ElMessageBox.confirm(
|
|
t('plugins.messages.activateConfirm', { version: release.version }), t('plugins.messages.activateTitle', { name: release.name }),
|
|
{ confirmButtonText: t('plugins.waitRestart'), cancelButtonText: t('plugins.cancel'), type: 'warning' },
|
|
)
|
|
await http.post(`/plugins/packages/${release.id}/activate`)
|
|
ElMessage.success(t('plugins.messages.activationPending'))
|
|
await loadPlugins()
|
|
} catch (error) {
|
|
if (error === 'cancel' || error === 'close') return
|
|
ElMessage.error(apiErrorMessage(error))
|
|
}
|
|
}
|
|
|
|
async function deletePackage(row: unknown) {
|
|
const release = row as PackageRelease
|
|
try {
|
|
await ElMessageBox.confirm(
|
|
t('plugins.messages.deleteConfirm', { name: release.name, version: release.version }), t('plugins.messages.deleteTitle'),
|
|
{ confirmButtonText: t('plugins.delete'), cancelButtonText: t('plugins.cancel'), type: 'warning' },
|
|
)
|
|
await http.delete(`/plugins/packages/${release.id}`)
|
|
ElMessage.success(t('plugins.messages.deleted'))
|
|
await loadPlugins()
|
|
} catch (error) {
|
|
if (error === 'cancel' || error === 'close') return
|
|
ElMessage.error(apiErrorMessage(error))
|
|
}
|
|
}
|
|
|
|
function packageStatus(status: PackageRelease['status']) {
|
|
return t(`plugins.packageStatuses.${status}`)
|
|
}
|
|
|
|
function formatSize(bytes: number) {
|
|
return bytes < 1024 * 1024
|
|
? `${(bytes / 1024).toFixed(1)} KB`
|
|
: `${(bytes / 1024 / 1024).toFixed(1)} MB`
|
|
}
|
|
|
|
async function changeState(plugin: PluginRuntimeItem, value: string | number | boolean) {
|
|
if (typeof value !== 'boolean' || value === plugin.isEnabled) return
|
|
const action = t(value ? 'plugins.enable' : 'plugins.disable')
|
|
try {
|
|
await ElMessageBox.confirm(
|
|
value
|
|
? t('plugins.messages.enableConfirm', { name: plugin.name })
|
|
: t('plugins.messages.disableConfirm', { name: plugin.name }),
|
|
t('plugins.messages.stateTitle', { action, name: plugin.name }),
|
|
{
|
|
confirmButtonText: t('plugins.messages.confirmState', { action }), cancelButtonText: t('plugins.cancel'),
|
|
type: value ? 'success' : 'warning',
|
|
},
|
|
)
|
|
} catch {
|
|
return
|
|
}
|
|
|
|
changingId.value = plugin.id
|
|
try {
|
|
const { data } = await http.put<PluginRuntimeItem>(
|
|
`/plugins/${encodeURIComponent(plugin.id)}/state`,
|
|
{ isEnabled: value },
|
|
)
|
|
pluginStore.update(data)
|
|
ElMessage.success(t('plugins.messages.stateChanged', { name: plugin.name, action }))
|
|
} catch (error) {
|
|
ElMessage.error(apiErrorMessage(error))
|
|
} finally {
|
|
changingId.value = ''
|
|
}
|
|
}
|
|
|
|
function formatTime(value?: string) {
|
|
return value
|
|
? new Date(value).toLocaleString(locale.value, { hour12: false })
|
|
: t('plugins.bundled')
|
|
}
|
|
|
|
onMounted(loadPlugins)
|
|
</script>
|
|
|
|
<template>
|
|
<main v-loading="loading" class="plugin-center">
|
|
<header class="plugin-heading">
|
|
<div>
|
|
<span>EXTENSION CONTROL PLANE</span>
|
|
<h2>{{ t('plugins.title') }}</h2><p>{{ t('plugins.description') }}</p>
|
|
</div>
|
|
<div class="plugin-summary">
|
|
<strong>{{ enabledCount }}</strong>
|
|
<span>{{ t('plugins.runningCount', { total: pluginStore.items.length }) }}</span>
|
|
</div>
|
|
</header>
|
|
|
|
<section class="safety-strip">
|
|
<el-icon><Lock /></el-icon>
|
|
<div>
|
|
<strong>{{ t('plugins.safetyTitle') }}</strong><p>{{ t('plugins.safetyDescription') }}</p>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="package-panel">
|
|
<div class="package-heading">
|
|
<div>
|
|
<span>SIGNED PACKAGE PIPELINE</span>
|
|
<h3>{{ t('plugins.signedPackages') }}</h3><p>{{ t('plugins.packageDescription') }}</p>
|
|
</div>
|
|
<div class="package-upload">
|
|
<label>
|
|
<input ref="packageInput" type="file" accept=".zip" @change="selectFile($event, 'package')">
|
|
{{ packageFile?.name || t('plugins.selectZip') }}
|
|
</label>
|
|
<label>
|
|
<input ref="signatureInput" type="file" accept=".sig,.bin" @change="selectFile($event, 'signature')">
|
|
{{ signatureFile?.name || t('plugins.selectSignature') }}
|
|
</label>
|
|
<el-button type="primary" :icon="Upload" :loading="uploading" @click="uploadPackage">
|
|
{{ t('plugins.validateStage') }}
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
<el-table :data="packageReleases" :empty-text="t('plugins.noPackages')">
|
|
<el-table-column :label="t('plugins.pluginVersion')" min-width="210">
|
|
<template #default="{ row }">
|
|
<strong>{{ row.name }}</strong>
|
|
<small>{{ row.pluginId }} · v{{ row.version }}</small>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column :label="t('plugins.publisher')" min-width="130">
|
|
<template #default="{ row }">{{ row.publisherId }}</template>
|
|
</el-table-column>
|
|
<el-table-column :label="t('plugins.verification')" min-width="190">
|
|
<template #default="{ row }">
|
|
<code>API {{ row.hostApiVersion }} · {{ formatSize(row.packageSize) }}</code>
|
|
<small>SHA-256 {{ row.sha256.slice(0, 12) }}…</small>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column :label="t('plugins.status')" width="130">
|
|
<template #default="{ row }">
|
|
<el-tag :type="row.status === 'Active' ? 'success' : row.status === 'Failed' ? 'danger' : row.status === 'PendingActivation' ? 'warning' : 'info'">
|
|
{{ packageStatus(row.status) }}
|
|
</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column :label="t('plugins.actions')" width="190" fixed="right">
|
|
<template #default="{ row }">
|
|
<el-button
|
|
v-if="row.status !== 'Active' && row.status !== 'PendingActivation'"
|
|
link
|
|
type="primary"
|
|
@click="activatePackage(row)"
|
|
>
|
|
{{ t(row.status === 'Superseded' ? 'plugins.rollback' : 'plugins.activate') }}
|
|
</el-button>
|
|
<el-button
|
|
v-if="row.status === 'Staged' || row.status === 'Superseded'"
|
|
link
|
|
type="danger"
|
|
@click="deletePackage(row)"
|
|
>{{ t('plugins.delete') }}</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
</section>
|
|
|
|
<section v-for="group in groupedPlugins" :key="group.category" class="plugin-group">
|
|
<div class="group-title">
|
|
<span>{{ group.category }}</span>
|
|
<i>{{ group.items.length }}</i>
|
|
</div>
|
|
<div class="plugin-grid">
|
|
<article
|
|
v-for="plugin in group.items"
|
|
:key="plugin.id"
|
|
class="plugin-card"
|
|
:class="{ disabled: !plugin.isEnabled }"
|
|
>
|
|
<div class="plugin-card-top">
|
|
<div class="plugin-symbol">
|
|
<el-icon><Connection v-if="plugin.isEnabled" /><SwitchButton v-else /></el-icon>
|
|
</div>
|
|
<div class="plugin-state">
|
|
<span :class="plugin.isEnabled ? 'online' : 'offline'">
|
|
{{ t(plugin.requiresRestart ? 'plugins.awaitingRestart' : plugin.isEnabled ? 'plugins.running' : 'plugins.disabled') }}
|
|
</span>
|
|
<el-switch
|
|
:model-value="plugin.isEnabled"
|
|
:loading="changingId === plugin.id"
|
|
:disabled="Boolean(changingId) || (plugin.source === 'package' && plugin.status !== 'Active')"
|
|
@change="(value) => changeState(plugin, value)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<h3>{{ plugin.name }}</h3>
|
|
<code>{{ plugin.id }} · v{{ plugin.version }}</code>
|
|
<p>{{ plugin.description }}</p>
|
|
<div class="capabilities">
|
|
<span v-for="capability in plugin.capabilities" :key="capability">
|
|
{{ capability }}
|
|
</span>
|
|
</div>
|
|
<footer>
|
|
<span>{{ t('plugins.navigationCount', { count: plugin.navigationPaths.length }) }}</span>
|
|
<time>{{ formatTime(plugin.stateChangedAt) }}</time>
|
|
</footer>
|
|
</article>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.plugin-center {
|
|
--ink: #1f2930;
|
|
--muted: #6b7780;
|
|
--line: #d9dfe1;
|
|
--signal: #1f7468;
|
|
color: var(--ink);
|
|
display: grid;
|
|
gap: 18px;
|
|
padding-bottom: 30px;
|
|
}
|
|
|
|
.plugin-heading {
|
|
align-items: flex-end;
|
|
border-bottom: 1px solid var(--line);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 5px 2px 17px;
|
|
}
|
|
|
|
.plugin-heading > div > span,
|
|
.group-title span {
|
|
color: #75828a;
|
|
font-family: "Cascadia Mono", Consolas, monospace;
|
|
font-size: 10px;
|
|
letter-spacing: .1em;
|
|
}
|
|
|
|
.plugin-heading h2 {
|
|
font-size: clamp(26px, 3vw, 38px);
|
|
letter-spacing: -.045em;
|
|
line-height: 1;
|
|
margin: 9px 0;
|
|
}
|
|
|
|
.plugin-heading p,
|
|
.safety-strip p { color: var(--muted); margin: 0; }
|
|
.plugin-summary { color: var(--muted); text-align: right; }
|
|
.plugin-summary strong { color: var(--signal); font-size: 34px; }
|
|
.plugin-summary span { font-size: 12px; }
|
|
|
|
.safety-strip {
|
|
align-items: center;
|
|
background: #f2f7f6;
|
|
border: 1px solid #cbdad7;
|
|
border-left: 4px solid var(--signal);
|
|
display: flex;
|
|
gap: 14px;
|
|
padding: 15px 18px;
|
|
}
|
|
|
|
.safety-strip .el-icon { color: var(--signal); font-size: 22px; }
|
|
.safety-strip strong { font-size: 13px; }
|
|
.safety-strip p { font-size: 12px; margin-top: 3px; }
|
|
.plugin-group { display: grid; gap: 10px; }
|
|
.package-panel { background: #fff; border: 1px solid var(--line); }
|
|
.package-heading { align-items: center; display: flex; gap: 24px; justify-content: space-between; padding: 18px; }
|
|
.package-heading span { color: #75828a; font-family: "Cascadia Mono", Consolas, monospace; font-size: 10px; letter-spacing: .1em; }
|
|
.package-heading h3 { margin: 5px 0; }
|
|
.package-heading p { color: var(--muted); font-size: 12px; margin: 0; }
|
|
.package-upload { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
|
|
.package-upload label { border: 1px dashed #b9c4c7; color: #637078; cursor: pointer; font-size: 11px; max-width: 160px; overflow: hidden; padding: 8px 10px; text-overflow: ellipsis; white-space: nowrap; }
|
|
.package-upload input { display: none; }
|
|
.package-panel strong,.package-panel small { display: block; }
|
|
.package-panel small { color: #7d898f; font-size: 10px; margin-top: 4px; }
|
|
.package-panel code { color: #53636b; font-size: 10px; }
|
|
.group-title { align-items: center; display: flex; gap: 8px; }
|
|
.group-title i { background: #e8eded; border-radius: 9px; font-size: 10px; font-style: normal; padding: 2px 7px; }
|
|
.plugin-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
|
|
.plugin-card {
|
|
background: #fff;
|
|
border: 1px solid var(--line);
|
|
border-top: 3px solid var(--signal);
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 245px;
|
|
padding: 18px;
|
|
transition: border-color .18s ease, opacity .18s ease;
|
|
}
|
|
|
|
.plugin-card.disabled { border-top-color: #9aa4aa; opacity: .72; }
|
|
.plugin-card-top { align-items: flex-start; display: flex; justify-content: space-between; }
|
|
.plugin-symbol { align-items: center; background: #e9f1ef; color: var(--signal); display: flex; height: 34px; justify-content: center; width: 34px; }
|
|
.plugin-card.disabled .plugin-symbol { background: #eef0f1; color: #7d878d; }
|
|
.plugin-state { align-items: center; display: flex; gap: 10px; }
|
|
.plugin-state span { font-size: 10px; font-weight: 750; }
|
|
.plugin-state .online { color: var(--signal); }
|
|
.plugin-state .offline { color: #7d878d; }
|
|
.plugin-card h3 { font-size: 18px; margin: 17px 0 4px; }
|
|
.plugin-card code { color: #7b868d; font-size: 10px; }
|
|
.plugin-card > p { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 14px 0; }
|
|
.capabilities { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
.capabilities span { background: #f1f4f4; color: #56646c; font-family: "Cascadia Mono", Consolas, monospace; font-size: 9px; padding: 4px 7px; }
|
|
.plugin-card footer { border-top: 1px solid #e5e9ea; color: #849097; display: flex; font-size: 9px; justify-content: space-between; margin-top: auto; padding-top: 13px; }
|
|
|
|
@media (prefers-reduced-motion: reduce) { .plugin-card { transition: none; } }
|
|
@media (max-width: 850px) { .plugin-grid { grid-template-columns: 1fr; } }
|
|
@media (max-width: 560px) {
|
|
.plugin-heading { align-items: flex-start; flex-direction: column; gap: 15px; }
|
|
.plugin-summary { text-align: left; }
|
|
.safety-strip { align-items: flex-start; }
|
|
.plugin-card footer { align-items: flex-start; flex-direction: column; gap: 5px; }
|
|
.package-heading { align-items: flex-start; flex-direction: column; }
|
|
.package-upload { justify-content: flex-start; }
|
|
}
|
|
</style>
|