refactor: 整体迁移控制面至MySQL + 替换UI框架为Element Plus
1. 移除naive-ui依赖,迁移前端至Element Plus 2. 重构后端数据库层,切换为MySQL替代SQLite 3. 调整项目部署架构,停止exe打包改为源码部署 4. 新增设备上报接口与相关数据库模型 5. 优化配置路径与SQL语法,替换为MySQL占位符格式 6. 调整站点名称与文案,统一为「37du 插件管理平台」 7. 新增SQLite到MySQL迁移脚本
This commit is contained in:
@@ -5,125 +5,199 @@
|
||||
<h3>插件管理 <span class="badge">Plugins</span></h3>
|
||||
<p>上传发布插件包 · 每插件保留最近 3 个版本,超出自动清理</p>
|
||||
</div>
|
||||
<n-button :loading="overviewBusy" @click="refresh">
|
||||
<template #icon><n-icon><Refresh /></n-icon></template>刷新
|
||||
</n-button>
|
||||
<el-button :loading="overviewBusy" :icon="Refresh" @click="refresh">刷新</el-button>
|
||||
</div>
|
||||
|
||||
<n-card class="block cp-rise" :bordered="false">
|
||||
<template #header><span class="card-title">上传插件包</span></template>
|
||||
<n-form inline>
|
||||
<n-form-item label="插件 ID">
|
||||
<n-input v-model:value="pid" placeholder="如 seal_check" style="width: 150px" />
|
||||
</n-form-item>
|
||||
<n-form-item label="名称">
|
||||
<n-input v-model:value="pname" placeholder="插件显示名" style="width: 150px" />
|
||||
</n-form-item>
|
||||
<n-form-item label="版本">
|
||||
<n-input v-model:value="pver" placeholder="如 1.1.0" style="width: 110px" />
|
||||
</n-form-item>
|
||||
<n-form-item label="包文件">
|
||||
<n-space align="center" :size="8">
|
||||
<n-upload :default-upload="false" :show-file-list="false" accept=".zip" @change="onFileChange">
|
||||
<n-button :type="pfile ? 'info' : 'default'">
|
||||
<template #icon><n-icon><UploadFilled /></n-icon></template>
|
||||
<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 包' }}
|
||||
</n-button>
|
||||
</n-upload>
|
||||
<n-tag v-if="pfile" size="small" round type="info" :bordered="false">{{ pfile.name }}</n-tag>
|
||||
</n-space>
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<n-button type="primary" :loading="uploading" @click="upload">
|
||||
<template #icon v-if="!uploading"><n-icon><UploadFilled /></n-icon></template>上传发布
|
||||
</n-button>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</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>
|
||||
</n-card>
|
||||
</div>
|
||||
|
||||
<n-card class="block cp-rise" :bordered="false">
|
||||
<template #header><span class="card-title">插件列表</span></template>
|
||||
<n-data-table
|
||||
:columns="columns"
|
||||
:data="plugins"
|
||||
:loading="overviewBusy"
|
||||
:row-key="r => r.id"
|
||||
:single-line="false"
|
||||
:row-props="rowProps"
|
||||
/>
|
||||
</n-card>
|
||||
<div class="cp-card block cp-rise list-card">
|
||||
<div class="card-title">插件列表</div>
|
||||
<el-table :data="plugins" size="small" :loading="overviewBusy" :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>
|
||||
</div>
|
||||
|
||||
<n-modal v-model:show="editShow" preset="card" :bordered="false" style="width: 560px" :title="`编辑插件 · ${edit.pid}`">
|
||||
<n-form label-placement="top">
|
||||
<n-form-item label="名称">
|
||||
<n-input v-model:value="edit.name" placeholder="插件显示名" />
|
||||
</n-form-item>
|
||||
<n-form-item label="分类">
|
||||
<n-input v-model:value="edit.category" placeholder="如 薪酬 / 考勤 / 社保" />
|
||||
</n-form-item>
|
||||
<n-form-item label="描述">
|
||||
<n-input v-model:value="edit.description" type="textarea" :rows="2" placeholder="插件用途说明" />
|
||||
</n-form-item>
|
||||
<n-form-item label="状态">
|
||||
<n-radio-group v-model:value="edit.status">
|
||||
<n-radio-button value="published">正常发布</n-radio-button>
|
||||
<n-radio-button value="disabled">禁用(停止分发)</n-radio-button>
|
||||
<n-radio-button value="revoked">下架(禁止运行)</n-radio-button>
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
<n-form-item label="强制更新(留空表示不强制)" :show-feedback="false">
|
||||
<!-- 编辑插件 -->
|
||||
<el-dialog v-model="editShow" :title="`编辑插件 · ${edit.pid}`" width="560px" align-center destroy-on-close>
|
||||
<el-form label-position="top">
|
||||
<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>
|
||||
<el-form-item label="描述">
|
||||
<el-input v-model="edit.description" type="textarea" :rows="2" placeholder="插件用途说明" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<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>
|
||||
<el-form-item label="强制更新(留空表示不强制)">
|
||||
<div class="force-row">
|
||||
<n-input v-model:value="edit.force_min" placeholder="最低版本,如 1.2.0" style="width: 180px" />
|
||||
<n-input v-model:value="edit.force_dl" type="datetime-local" placeholder="截止时间" style="width: 200px" />
|
||||
<div class="force-line">
|
||||
<el-input v-model="edit.force_min" placeholder="最低版本,如 1.2.0" style="width: 180px" class="mono" />
|
||||
<el-input v-model="edit.force_dl" type="datetime-local" placeholder="截止时间" style="width: 200px" class="mono" />
|
||||
</div>
|
||||
<span class="hint">到达截止时间后,未升级到该版本的部署机会被禁止启动</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="modal-foot">
|
||||
<n-button @click="editShow = false">取消</n-button>
|
||||
<n-button type="primary" :loading="saving" @click="saveEdit">保存</n-button>
|
||||
<el-button @click="editShow = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="saveEdit">保存</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 插件详情 -->
|
||||
<el-dialog v-model="detailShow" :title="`插件详情 · ${detail?.id || ''}`" width="640px" align-center destroy-on-close>
|
||||
<div v-if="detail" class="plg-detail">
|
||||
<div class="d-head">
|
||||
<span class="d-id mono">{{ detail.id }}</span>
|
||||
<span class="d-name">{{ detail.name }}</span>
|
||||
<el-tag size="small" round effect="light" :type="statusMeta[detail.status]?.type || 'info'">
|
||||
{{ statusMeta[detail.status]?.label || detail.status || '—' }}
|
||||
</el-tag>
|
||||
</div>
|
||||
|
||||
<div class="d-grid">
|
||||
<div class="d-item"><label>分类</label><span>{{ detail.category || '—' }}</span></div>
|
||||
<div class="d-item"><label>最新版本</label><span class="mono">{{ detail.latest_version || '—' }}</span></div>
|
||||
<div class="d-item"><label>表单字段</label><span class="mono">{{ detail.field_count || 0 }}</span></div>
|
||||
<div class="d-item"><label>强制更新</label><span>{{ forceText(detail) }}</span></div>
|
||||
</div>
|
||||
|
||||
<div class="d-sec"><label>描述</label><p class="d-desc">{{ detail.description || '—' }}</p></div>
|
||||
|
||||
<div class="d-sec">
|
||||
<label>能力</label>
|
||||
<div class="tags" v-if="detail.capabilities?.length">
|
||||
<el-tag v-for="c in detail.capabilities" :key="c" size="small" effect="plain" round>{{ c }}</el-tag>
|
||||
</div>
|
||||
<span v-else class="dim">—</span>
|
||||
</div>
|
||||
|
||||
<div class="d-sec">
|
||||
<label>版本历史</label>
|
||||
<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>
|
||||
<span class="vtime mono dim-sm">{{ fmtTime(v.uploaded_at) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span v-else class="dim">暂无版本</span>
|
||||
</div>
|
||||
|
||||
<div class="d-sec">
|
||||
<label>授权账号</label>
|
||||
<div class="tags" v-if="detail.accounts?.length">
|
||||
<el-tag v-for="a in detail.accounts" :key="a" size="small" effect="plain" type="success" round class="mono">{{ a }}</el-tag>
|
||||
</div>
|
||||
<span v-else class="dim">未授权</span>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="detailShow = false">关闭</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, h, onMounted, reactive, ref } from 'vue'
|
||||
import { NButton, NTag } from 'naive-ui'
|
||||
import { Refresh, UploadFilled } from '@element-plus/icons-vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage as message, ElMessageBox as dialog } from 'element-plus'
|
||||
import { Refresh, UploadFilled, FolderOpened, Edit, Delete, View } from '@element-plus/icons-vue'
|
||||
import { overview, overviewBusy, loadOverview } from '../store'
|
||||
import { adminUpload, adminPluginDelete, adminPluginPatch } from '../api'
|
||||
import { message, dialog } from '../naive'
|
||||
import { fmtTime } from '../format'
|
||||
|
||||
const plugins = computed(() => overview.value?.plugins || [])
|
||||
const pid = ref(''); const pname = ref(''); const pver = ref(''); const pfile = ref(null)
|
||||
const uploading = ref(false)
|
||||
const upRef = ref()
|
||||
|
||||
// 状态徽标文案与配色
|
||||
const STATUS_META = {
|
||||
const statusMeta = {
|
||||
published: { label: '正常', type: 'success' },
|
||||
disabled: { label: '禁用', type: 'warning' },
|
||||
revoked: { label: '已下架', type: 'error' },
|
||||
}
|
||||
function renderStatus(row) {
|
||||
const s = STATUS_META[row.status] || { label: row.status || '—', type: 'default' }
|
||||
return h(NTag, { size: 'small', round: true, bordered: false, type: s.type }, { default: () => s.label })
|
||||
revoked: { label: '已下架', type: 'danger' },
|
||||
}
|
||||
|
||||
function onFileChange(e) {
|
||||
pfile.value = e?.file?.file || null
|
||||
function onFileChange(uploadFile) {
|
||||
pfile.value = uploadFile.raw || null
|
||||
}
|
||||
|
||||
function renderVersions(row) {
|
||||
const list = row.versions || []
|
||||
if (!list.length) return h('span', { class: 'dim' }, '—')
|
||||
return h('div', { class: 'tags' }, list.map(v => h(NTag, {
|
||||
size: 'small', round: true, bordered: false,
|
||||
type: v.version === row.latest_version ? 'primary' : 'default',
|
||||
}, { default: () => v.version })))
|
||||
// —— 详情弹窗 ——
|
||||
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 '无'
|
||||
}
|
||||
|
||||
// —— 编辑弹窗状态 ——
|
||||
@@ -163,37 +237,6 @@ async function saveEdit() {
|
||||
finally { saving.value = false }
|
||||
}
|
||||
|
||||
const columns = computed(() => [
|
||||
{ title: '插件 ID', key: 'id', width: 150, render: r => h('b', { class: 'cell-strong' }, r.id) },
|
||||
{ title: '名称', key: 'name', width: 130, ellipsis: { tooltip: true } },
|
||||
{ title: '分类', key: 'category', width: 90, render: r => r.category ? h(NTag, { size: 'small', bordered: false, type: 'info' }, { default: () => r.category }) : h('span', { class: 'dim' }, '—') },
|
||||
{
|
||||
title: '能力 / 表单', key: 'caps', minWidth: 130,
|
||||
render: r => h('div', { class: 'tags' }, [
|
||||
...(r.capabilities?.length ? r.capabilities.map(c => h(NTag, { size: 'small', bordered: false, type: 'default' }, { default: () => c })) : [h('span', { class: 'dim' }, '—')]),
|
||||
h(NTag, { size: 'small', bordered: false, type: 'info', style: 'margin-left:2px' }, { default: () => `${r.field_count || 0} 字段` }),
|
||||
]),
|
||||
},
|
||||
{ title: '状态', key: 'status', width: 80, render: renderStatus },
|
||||
{ title: '最新版', key: 'latest_version', width: 90 },
|
||||
{ title: '版本历史', key: 'versions', minWidth: 200, render: renderVersions },
|
||||
{
|
||||
title: '授权账号', key: 'accounts', minWidth: 130,
|
||||
render: r => (r.accounts?.length ? r.accounts.join('、') : h('span', { class: 'dim' }, '—')),
|
||||
ellipsis: { tooltip: true },
|
||||
},
|
||||
{
|
||||
title: '操作', key: 'actions', width: 120,
|
||||
render: r => h('div', { class: 'row-acts' }, [
|
||||
h(NButton, { size: 'small', text: true, type: 'primary', onClick: () => openEdit(r) }, { default: () => '编辑' }),
|
||||
h(NButton, { size: 'small', text: true, type: 'error', onClick: () => delPlugin(r) }, { default: () => '删除' }),
|
||||
]),
|
||||
},
|
||||
])
|
||||
function rowProps() {
|
||||
return { style: 'cursor:default' }
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
|
||||
}
|
||||
@@ -204,38 +247,51 @@ async function upload() {
|
||||
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.warning({
|
||||
title: '删除插件',
|
||||
content: `确认删除插件 ${p.id}?其全部版本与授权将一并清除`,
|
||||
positiveText: '删除',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
try { await adminPluginDelete({ plugin_id: p.id }); message.success(`已删除插件 ${p.id}`); await refresh() }
|
||||
catch (e) { message.error(e.message || e) }
|
||||
},
|
||||
})
|
||||
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>
|
||||
.hint { font-size: 12px; color: var(--cp-ink-3); margin-top: 4px; }
|
||||
.up-card, .list-card { padding: 20px 22px; }
|
||||
.up-card .card-title { margin-bottom: 16px; }
|
||||
.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-row { display: flex; flex-direction: column; gap: 8px; width: 100%; }
|
||||
.force-line { display: flex; gap: 10px; }
|
||||
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
|
||||
</style>
|
||||
.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; }
|
||||
|
||||
<!-- 以下类用于 n-data-table 列 render 中由 naive-ui 作用域动态渲染的节点,
|
||||
它们不继承本组件 scoped scopeId,必须用全局(非 scoped)样式才生效。 -->
|
||||
<style>
|
||||
.dim { color: var(--cp-ink-3); }
|
||||
.cell-strong { font-weight: 600; color: var(--cp-ink-1); }
|
||||
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.row-acts { display: flex; align-items: center; gap: 14px; white-space: nowrap; }
|
||||
.row-acts .n-button { --n-padding: 0; }
|
||||
.row-acts .n-button + .n-button { margin-left: 0; }
|
||||
/* 插件详情 */
|
||||
.plg-detail { display: flex; flex-direction: column; gap: 18px; }
|
||||
.d-head { display: flex; align-items: center; gap: 10px; }
|
||||
.d-id { font-size: 16px; font-weight: 800; color: var(--cp-ink-1); }
|
||||
.d-name { font-size: 15px; color: var(--cp-ink-2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.d-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
|
||||
.d-item { display: flex; flex-direction: column; gap: 5px; padding: 12px 14px; background: var(--cp-panel-2); border-radius: 12px; }
|
||||
.d-item label { font-size: 11px; font-weight: 700; color: var(--cp-ink-3); letter-spacing: .4px; }
|
||||
.d-item span { font-size: 13px; font-weight: 600; color: var(--cp-ink-1); }
|
||||
.d-sec { display: flex; flex-direction: column; gap: 8px; }
|
||||
.d-sec > label { font-size: 11px; font-weight: 700; color: var(--cp-ink-3); letter-spacing: .4px; }
|
||||
.d-desc { margin: 0; font-size: 13px; line-height: 1.7; color: var(--cp-ink); background: var(--cp-panel-2); padding: 10px 14px; border-radius: 10px; }
|
||||
.vlist { display: flex; flex-direction: column; gap: 6px; }
|
||||
.vrow { display: flex; align-items: center; gap: 12px; }
|
||||
.vtime { font-size: 12px; }
|
||||
.dim-sm { color: var(--cp-ink-3); }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user