本次提交包含多项安全加固和体验优化: 1. 分离管理密钥与传输凭证,避免持 API Token 者伪造管理员票据 2. 钉钉回调地址增加白名单校验,防止开放重定向钓鱼 3. 初始管理员密码改为随机生成并日志记录,移除硬编码 123456 4. 新增登录防爆破计数表,支持 MySQL 多 worker 共享 5. 统一分页规范,新增 usePagedList composable 和 PagerBar 组件 6. 控制面 CORS 收敛为白名单,避免公网环境下任意站点跨域 7. 插件管理、凭证管理等列表接口支持分页和搜索 8. 强制初始密码修改,未改密前禁止使用管理功能 9. 定时任务触发被拒日志节流,避免授权失效时刷屏 10. 健康检查接口移除环境信息泄露,返回固定响应
380 lines
19 KiB
Vue
380 lines
19 KiB
Vue
<template>
|
||
<div class="page">
|
||
<div class="page-head cp-rise">
|
||
<div>
|
||
<h3>插件管理 <span class="badge">Plugins</span></h3>
|
||
<p>上传发布插件包 · 每插件保留最近 3 个版本,超出自动清理</p>
|
||
</div>
|
||
<el-button :loading="listBusy" :icon="Refresh" @click="refresh">刷新</el-button>
|
||
</div>
|
||
|
||
<div class="cp-card block cp-rise up-card">
|
||
<div class="card-title">上传插件包</div>
|
||
<el-form inline class="up-form" @submit.prevent>
|
||
<el-form-item label="插件 ID">
|
||
<el-input v-model="pid" placeholder="如 seal_check" style="width: 160px" class="mono" />
|
||
</el-form-item>
|
||
<el-form-item label="名称">
|
||
<el-input v-model="pname" placeholder="插件显示名" style="width: 160px" />
|
||
</el-form-item>
|
||
<el-form-item label="版本">
|
||
<el-input v-model="pver" placeholder="如 1.1.0" style="width: 120px" class="mono" />
|
||
</el-form-item>
|
||
<el-form-item label="包文件">
|
||
<div class="file-row">
|
||
<el-upload :auto-upload="false" :show-file-list="false" accept=".zip" :on-change="onFileChange" ref="upRef">
|
||
<el-button :type="pfile ? 'primary' : 'default'" plain :icon="FolderOpened">
|
||
{{ pfile ? '重新选择' : '选择 ZIP 包' }}
|
||
</el-button>
|
||
</el-upload>
|
||
<el-tag v-if="pfile" size="small" round effect="plain" type="primary" class="mono">{{ pfile.name }}</el-tag>
|
||
</div>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" :loading="uploading" :icon="UploadFilled" @click="upload">上传发布</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
<div class="hint">包根目录需含 plugin.json / main.py / requirements.txt,ZIP 完整性校验通过才会发布。</div>
|
||
</div>
|
||
|
||
<div class="cp-card block cp-rise list-card">
|
||
<div class="list-head">
|
||
<div class="card-title">插件列表</div>
|
||
<el-input v-model="kw" placeholder="搜索插件 ID / 名称" clearable :prefix-icon="Search" size="small" style="width: 230px" @keyup.enter="onSearch" @clear="onSearch" />
|
||
</div>
|
||
<el-table :data="plugins" size="small" :loading="listBusy" :row-key="r => r.id">
|
||
<el-table-column label="插件 ID" min-width="160">
|
||
<template #default="{ row }"><b class="cell-strong mono">{{ row.id }}</b></template>
|
||
</el-table-column>
|
||
<el-table-column label="名称" min-width="180" show-overflow-tooltip prop="name" />
|
||
<el-table-column label="分类" min-width="110">
|
||
<template #default="{ row }">
|
||
<el-tag v-if="row.category" size="small" effect="plain" type="info" round>{{ row.category }}</el-tag>
|
||
<span v-else class="dim">—</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="状态" min-width="100">
|
||
<template #default="{ row }">
|
||
<el-tag size="small" round effect="light" :type="statusMeta[row.status]?.type || 'info'">
|
||
{{ statusMeta[row.status]?.label || row.status || '—' }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="最新版" min-width="110">
|
||
<template #default="{ row }"><span class="mono">{{ row.latest_version || '—' }}</span></template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="210" fixed="right">
|
||
<template #default="{ row }">
|
||
<div class="cell-ops">
|
||
<el-button link type="info" :icon="View" @click="openDetail(row)">详情</el-button>
|
||
<el-button link type="primary" :icon="Edit" @click="openEdit(row)">编辑</el-button>
|
||
<el-button link type="danger" :icon="Delete" @click="delPlugin(row)">删除</el-button>
|
||
</div>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<PagerBar :total="total" :page="page" :page-size="pageSize" @change="onPageChange" />
|
||
</div>
|
||
|
||
<!-- 编辑插件 -->
|
||
<el-dialog v-model="editShow" width="720px" align-center destroy-on-close>
|
||
<template #header>
|
||
<div class="ed-head">
|
||
<span class="ed-avatar">{{ (edit.name || edit.pid || '?').slice(0, 1) }}</span>
|
||
<div class="ed-headmeta">
|
||
<div class="ed-title mono">{{ edit.pid }}</div>
|
||
<div class="ed-sub">修改基础信息、发布状态与强制更新策略</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
<el-form label-position="top" class="ed-form">
|
||
<div class="ed-sec">
|
||
<div class="ed-sec-title">基本信息</div>
|
||
<div class="form-2col">
|
||
<el-form-item label="插件名称">
|
||
<el-input v-model="edit.name" placeholder="插件显示名" />
|
||
</el-form-item>
|
||
<el-form-item label="分类">
|
||
<el-input v-model="edit.category" placeholder="如 薪酬 / 考勤 / 社保" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
<div class="ed-sec">
|
||
<div class="ed-sec-title">插件描述</div>
|
||
<el-form-item>
|
||
<el-input v-model="edit.description" type="textarea" :autosize="{ minRows: 5, maxRows: 12 }"
|
||
maxlength="500" show-word-limit placeholder="插件用途说明(支持换行,执行端与详情页均会展示)" />
|
||
</el-form-item>
|
||
</div>
|
||
<div class="ed-sec">
|
||
<div class="ed-sec-title">发布状态</div>
|
||
<el-form-item>
|
||
<el-radio-group v-model="edit.status">
|
||
<el-radio-button value="published">正常发布</el-radio-button>
|
||
<el-radio-button value="disabled">禁用(停止分发)</el-radio-button>
|
||
<el-radio-button value="revoked">下架(禁止运行)</el-radio-button>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
</div>
|
||
<div class="ed-sec">
|
||
<div class="ed-sec-title">强制更新 <span class="ed-opt">可选 · 两项都填才会生效</span></div>
|
||
<div class="force-box">
|
||
<div class="force-line">
|
||
<el-input v-model="edit.force_min" placeholder="最低版本,如 1.2.0" style="width: 190px" class="mono" />
|
||
<el-date-picker v-model="edit.force_dl" type="datetime" value-format="YYYY-MM-DD[T]HH:mm"
|
||
format="YYYY-MM-DD HH:mm" placeholder="截止时间" style="width: 220px" class="mono" />
|
||
</div>
|
||
<div class="hint">到达截止时间后,未升级到该版本的部署机会被禁止启动;留空表示不强制</div>
|
||
</div>
|
||
</div>
|
||
</el-form>
|
||
<template #footer>
|
||
<div class="modal-foot">
|
||
<el-button @click="editShow = false">取消</el-button>
|
||
<el-button type="primary" :loading="saving" @click="saveEdit">保存修改</el-button>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 插件详情 -->
|
||
<el-dialog v-model="detailShow" width="780px" align-center destroy-on-close>
|
||
<template #header>
|
||
<div class="dt-head" v-if="detail">
|
||
<span class="dt-avatar">{{ (detail.name || detail.id || '?').slice(0, 1) }}</span>
|
||
<div class="dt-headmeta">
|
||
<div class="dt-title-row">
|
||
<span class="dt-id mono">{{ detail.id }}</span>
|
||
<el-tag size="small" round effect="light" :type="statusMeta[detail.status]?.type || 'info'">
|
||
{{ statusMeta[detail.status]?.label || detail.status || '—' }}
|
||
</el-tag>
|
||
<el-tag v-if="detail.category" size="small" round effect="plain" type="info">{{ detail.category }}</el-tag>
|
||
</div>
|
||
<div class="dt-name">{{ detail.name || '未命名插件' }}</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
<div v-if="detail" class="plg-detail">
|
||
<div class="dt-grid">
|
||
<div class="dt-item">
|
||
<el-icon class="dt-ic"><Box /></el-icon>
|
||
<div><label>最新版本</label><span class="mono">{{ detail.latest_version || '—' }}</span></div>
|
||
</div>
|
||
<div class="dt-item">
|
||
<el-icon class="dt-ic"><Files /></el-icon>
|
||
<div><label>表单字段</label><span class="mono">{{ detail.field_count || 0 }} 项</span></div>
|
||
</div>
|
||
<div class="dt-item">
|
||
<el-icon class="dt-ic"><User /></el-icon>
|
||
<div><label>授权账号</label><span class="mono">{{ detail.accounts?.length || 0 }} 个</span></div>
|
||
</div>
|
||
<div class="dt-item">
|
||
<el-icon class="dt-ic" :class="{ 'dt-ic-on': detail.force_min_version && detail.force_deadline }"><Clock /></el-icon>
|
||
<div><label>强制更新</label><span>{{ forceText(detail) }}</span></div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="dt-sec">
|
||
<div class="ed-sec-title">插件描述</div>
|
||
<p class="dt-desc">{{ detail.description || '暂无描述' }}</p>
|
||
</div>
|
||
|
||
<div class="dt-sec">
|
||
<div class="ed-sec-title">能力声明</div>
|
||
<div class="tags" v-if="detail.capabilities?.length">
|
||
<el-tag v-for="c in detail.capabilities" :key="c" size="small" effect="plain" round class="mono">{{ c }}</el-tag>
|
||
</div>
|
||
<span v-else class="dim">—</span>
|
||
</div>
|
||
|
||
<div class="dt-cols">
|
||
<div class="dt-sec">
|
||
<div class="ed-sec-title">版本历史</div>
|
||
<div class="vlist" v-if="detail.versions?.length">
|
||
<div class="vrow" v-for="v in detail.versions" :key="v.version">
|
||
<el-tag size="small" round effect="light" class="mono"
|
||
:type="v.version === detail.latest_version ? 'primary' : 'info'">{{ v.version }}</el-tag>
|
||
<el-tag v-if="v.version === detail.latest_version" size="small" round effect="plain"
|
||
type="success" class="v-latest">当前</el-tag>
|
||
<span class="vtime mono dim-sm">{{ fmtTime(v.uploaded_at) }}</span>
|
||
</div>
|
||
</div>
|
||
<span v-else class="dim">暂无版本</span>
|
||
</div>
|
||
<div class="dt-sec">
|
||
<div class="ed-sec-title">授权账号</div>
|
||
<div class="tags" v-if="detail.accounts?.length">
|
||
<el-tag v-for="a in detail.accounts" :key="a.account" size="small" effect="plain" type="success" round class="mono">{{ a.nickname ? `${a.nickname} · ${a.account}` : a.account }}</el-tag>
|
||
</div>
|
||
<span v-else class="dim">未授权任何账号,执行端不可见</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<template #footer>
|
||
<el-button @click="detailShow = false">关闭</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { onMounted, reactive, ref } from 'vue'
|
||
import { ElMessage as message, ElMessageBox as dialog } from 'element-plus'
|
||
import { Refresh, UploadFilled, FolderOpened, Edit, Delete, View, Box, Files, User, Clock, Search } from '@element-plus/icons-vue'
|
||
import { adminPlugins, adminUpload, adminPluginDelete, adminPluginPatch } from '../api'
|
||
import { fmtTime } from '../format'
|
||
import PagerBar from '../components/PagerBar.vue'
|
||
import { usePagedList } from '../composables/usePagedList'
|
||
|
||
const kw = ref('')
|
||
const list = usePagedList((p, s) => adminPlugins(p, s, kw.value), { onError: e => message.error('读取失败:' + (e.message || e)) })
|
||
const { items: plugins, total, page, size: pageSize, busy: listBusy, load: refresh, onPageChange, reset } = list
|
||
const pid = ref(''); const pname = ref(''); const pver = ref(''); const pfile = ref(null)
|
||
function onSearch() { reset() }
|
||
const uploading = ref(false)
|
||
const upRef = ref()
|
||
|
||
// 状态徽标文案与配色
|
||
const statusMeta = {
|
||
published: { label: '正常', type: 'success' },
|
||
disabled: { label: '禁用', type: 'warning' },
|
||
revoked: { label: '已下架', type: 'danger' },
|
||
}
|
||
|
||
function onFileChange(uploadFile) {
|
||
pfile.value = uploadFile.raw || null
|
||
}
|
||
|
||
// —— 详情弹窗 ——
|
||
const detailShow = ref(false)
|
||
const detail = ref(null)
|
||
function openDetail(row) {
|
||
detail.value = row
|
||
detailShow.value = true
|
||
}
|
||
function forceText(p) {
|
||
if (p.force_min_version && p.force_deadline) return `${p.force_min_version} 起 · 截止 ${fmtTime(p.force_deadline)}`
|
||
return '无'
|
||
}
|
||
|
||
// —— 编辑弹窗状态 ——
|
||
const editShow = ref(false)
|
||
const saving = ref(false)
|
||
const edit = reactive({ pid: '', name: '', category: '', description: '', status: 'published', force_min: '', force_dl: '' })
|
||
function openEdit(row) {
|
||
edit.pid = row.id
|
||
edit.name = row.name || ''
|
||
edit.category = row.category || ''
|
||
edit.description = row.description || ''
|
||
edit.status = row.status || 'published'
|
||
edit.force_min = row.force_min_version || ''
|
||
edit.force_dl = toLocalInput(row.force_deadline)
|
||
editShow.value = true
|
||
}
|
||
// ISO 时间 → datetime-local 输入框可识别的本地格式
|
||
function toLocalInput(iso) {
|
||
if (!iso) return ''
|
||
const d = new Date(iso.endsWith('Z') ? iso : iso + 'Z')
|
||
return isNaN(d) ? '' : `${String(d.getFullYear()).padStart(4, '0')}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}T${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
|
||
}
|
||
async function saveEdit() {
|
||
if (!edit.pid) return
|
||
saving.value = true
|
||
try {
|
||
const body = { name: edit.name, category: edit.category, description: edit.description, status: edit.status }
|
||
// 强制更新:min 与 deadline 均填则成对下发;否则清除强制更新。
|
||
// 注意:后端 PluginPatchIn 的 str 字段不接受 null,空值必须传 ''(否则 422 保存失败)
|
||
body.force_min_version = edit.force_min || ''
|
||
body.force_deadline = edit.force_dl ? new Date(edit.force_dl).toISOString() : ''
|
||
body.clear_force = !(edit.force_min && edit.force_dl)
|
||
await adminPluginPatch(edit.pid, body)
|
||
message.success(`已更新插件 ${edit.pid}`)
|
||
editShow.value = false
|
||
await refresh()
|
||
} catch (e) { message.error('保存失败:' + (e.message || e)) }
|
||
finally { saving.value = false }
|
||
}
|
||
|
||
async function upload() {
|
||
if (!pid.value || !pver.value || !pfile.value) { message.warning('请填写插件 ID / 版本并选择 ZIP 包'); return }
|
||
uploading.value = true
|
||
try {
|
||
await adminUpload(pid.value, pname.value || pid.value, pver.value, pfile.value)
|
||
message.success(`已发布 ${pid.value}@${pver.value}`)
|
||
pid.value = ''; pname.value = ''; pver.value = ''; pfile.value = null
|
||
upRef.value?.clearFiles()
|
||
await refresh()
|
||
} catch (e) { message.error('上传失败:' + (e.message || e)) }
|
||
finally { uploading.value = false }
|
||
}
|
||
function delPlugin(p) {
|
||
dialog.confirm(`确认删除插件 ${p.id}?其全部版本与授权将一并清除`, '删除插件', {
|
||
type: 'warning',
|
||
confirmButtonText: '删除',
|
||
cancelButtonText: '取消',
|
||
}).then(async () => {
|
||
try { await adminPluginDelete({ plugin_id: p.id }); message.success(`已删除插件 ${p.id}`); await refresh() }
|
||
catch (e) { message.error(e.message || e) }
|
||
}).catch(() => {})
|
||
}
|
||
onMounted(refresh)
|
||
</script>
|
||
|
||
<style scoped>
|
||
.up-card, .list-card { padding: 20px 22px; }
|
||
.up-card .card-title { margin-bottom: 16px; }
|
||
.list-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
|
||
.list-head .card-title { margin-bottom: 0; }
|
||
.up-form :deep(.el-form-item) { margin-bottom: 16px; }
|
||
.file-row { display: flex; align-items: center; gap: 10px; }
|
||
.hint { font-size: 12px; color: var(--cp-ink-3); margin-top: 2px; line-height: 1.7; }
|
||
.force-line { display: flex; gap: 10px; }
|
||
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
|
||
.cell-ops { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
|
||
.cell-ops .el-button { padding: 0 4px; }
|
||
.cell-ops .el-button + .el-button { margin-left: 0; }
|
||
|
||
/* 弹窗通用 */
|
||
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
|
||
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
|
||
.hint { font-size: 12px; color: var(--cp-ink-3); line-height: 1.7; }
|
||
|
||
/* 编辑弹窗:分区卡片 */
|
||
.ed-head { display: flex; align-items: center; gap: 12px; }
|
||
.ed-avatar { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-size: 18px; font-weight: 800; background: linear-gradient(135deg, var(--cp-blue), var(--cp-teal)); box-shadow: var(--cp-shadow); flex-shrink: 0; }
|
||
.ed-headmeta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
||
.ed-title { font-size: 15px; font-weight: 800; color: var(--cp-ink-1); }
|
||
.ed-sub { font-size: 12px; color: var(--cp-ink-3); }
|
||
.ed-sec { margin-bottom: 12px; padding: 13px 16px 3px; background: var(--cp-panel-2); border-radius: 12px; }
|
||
.ed-sec :deep(.el-form-item) { margin-bottom: 13px; }
|
||
.ed-sec-title { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 800; color: var(--cp-ink-2); letter-spacing: .5px; margin-bottom: 10px; }
|
||
.ed-sec-title::before { content: ''; width: 3px; height: 13px; border-radius: 2px; background: var(--cp-blue); }
|
||
.ed-opt { font-weight: 500; color: var(--cp-ink-3); letter-spacing: 0; }
|
||
.force-box { display: flex; flex-direction: column; gap: 8px; padding-bottom: 13px; }
|
||
.force-line { display: flex; gap: 10px; }
|
||
|
||
/* 详情弹窗:头部 + 统计卡 + 分区 */
|
||
.plg-detail { display: flex; flex-direction: column; gap: 14px; max-height: 66vh; overflow-y: auto; padding-right: 6px; }
|
||
.dt-head { display: flex; align-items: center; gap: 12px; }
|
||
.dt-avatar { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; color: #fff; font-size: 20px; font-weight: 800; background: linear-gradient(135deg, var(--cp-blue), var(--cp-teal)); box-shadow: var(--cp-shadow); flex-shrink: 0; }
|
||
.dt-headmeta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
|
||
.dt-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||
.dt-id { font-size: 15px; font-weight: 800; color: var(--cp-ink-1); }
|
||
.dt-name { font-size: 13px; color: var(--cp-ink-2); }
|
||
.dt-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
|
||
.dt-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--cp-panel-2); border-radius: 12px; min-width: 0; }
|
||
.dt-ic { font-size: 20px; color: var(--cp-ink-3); flex-shrink: 0; }
|
||
.dt-ic-on { color: var(--cp-amber); }
|
||
.dt-item div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
|
||
.dt-item label { font-size: 11px; font-weight: 700; color: var(--cp-ink-3); letter-spacing: .4px; }
|
||
.dt-item span { font-size: 13px; font-weight: 600; color: var(--cp-ink-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
.dt-sec { display: flex; flex-direction: column; }
|
||
.dt-desc { margin: 0; font-size: 13px; line-height: 1.9; color: var(--cp-ink); background: var(--cp-panel-2); padding: 12px 16px; border-radius: 10px; white-space: pre-wrap; word-break: break-word; }
|
||
.dt-cols { display: grid; grid-template-columns: 1.15fr .85fr; gap: 14px; align-items: start; }
|
||
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
|
||
.vlist { display: flex; flex-direction: column; gap: 8px; }
|
||
.vrow { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--cp-panel-2); border-radius: 9px; }
|
||
.vtime { font-size: 12px; margin-left: auto; }
|
||
.dim-sm { color: var(--cp-ink-3); }
|
||
.dim { font-size: 12px; color: var(--cp-ink-3); }
|
||
</style>
|