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,88 +5,87 @@
|
||||
<h3>权限授权 <span class="badge">Grants</span></h3>
|
||||
<p>按账号勾选可用插件与可登录平台,保存时仅提交差异项</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">
|
||||
<n-form inline>
|
||||
<n-form-item label="选择账号">
|
||||
<n-select
|
||||
v-model:value="account"
|
||||
:options="accountOptions"
|
||||
placeholder="选择账号…"
|
||||
style="width: 240px"
|
||||
filterable
|
||||
clearable
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="account">
|
||||
<span class="sel-hint">{{ account }} · 已授权 {{ grantedIds.length }} 个插件 / {{ platChecked.length }} 个平台</span>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</n-card>
|
||||
<div class="cp-card panel cp-rise">
|
||||
<!-- 账号选择 -->
|
||||
<div class="pick-row">
|
||||
<div class="pick-label">选择账号</div>
|
||||
<el-select v-model="account" filterable clearable placeholder="选择账号…" style="width: 260px" :prefix-icon="User">
|
||||
<el-option v-for="a in accountOptions" :key="a.value" :label="a.label" :value="a.value" />
|
||||
</el-select>
|
||||
<div class="pick-hint" v-if="account">
|
||||
已授权 <b class="mono">{{ grantedIds.length }}</b> 个插件 / <b class="mono">{{ platChecked.length }}</b> 个平台
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-if="account">
|
||||
<n-card class="block cp-rise" :bordered="false">
|
||||
<template #header>
|
||||
<div class="card-head">
|
||||
<b>插件授权</b>
|
||||
<n-button type="primary" size="small" :loading="saving" @click="saveGrant">保存插件授权</n-button>
|
||||
<template v-if="account">
|
||||
<!-- 插件授权 -->
|
||||
<div class="section">
|
||||
<div class="section-head">
|
||||
<div class="card-title">插件授权</div>
|
||||
<el-checkbox :model-value="allChecked" :indeterminate="someChecked" @change="toggleAll">全选</el-checkbox>
|
||||
</div>
|
||||
</template>
|
||||
<n-checkbox-group v-model:value="grantedIds" v-if="plugins.length">
|
||||
<div class="ck-grid">
|
||||
<n-checkbox v-for="p in plugins" :key="p.id" :value="p.id" class="ck">
|
||||
<span class="ck-main">
|
||||
<span>{{ p.id }}<span class="dim">({{ p.name }})</span></span>
|
||||
<span class="ck-sub" v-if="grantState[p.id]?.granted">
|
||||
<n-switch size="small" :value="grantState[p.id].canRun"
|
||||
@update:value="v => setGrant(p.id, { canRun: v })">
|
||||
<template #checked>可运行</template>
|
||||
<template #unchecked>禁运行</template>
|
||||
</n-switch>
|
||||
<n-switch size="small" :value="grantState[p.id].canDownload"
|
||||
@update:value="v => setGrant(p.id, { canDownload: v })">
|
||||
<template #checked>可下载</template>
|
||||
<template #unchecked>禁下载</template>
|
||||
</n-switch>
|
||||
</span>
|
||||
</span>
|
||||
</n-checkbox>
|
||||
</div>
|
||||
</n-checkbox-group>
|
||||
<n-empty v-else description="暂无插件,请先在「插件管理」上传" size="small" />
|
||||
</n-card>
|
||||
<el-checkbox-group v-model="grantedIds" class="plist">
|
||||
<div class="prow" v-for="p in plugins" :key="p.id" :class="{ on: grantedIds.includes(p.id) }">
|
||||
<el-checkbox :value="p.id" class="pck">
|
||||
<span class="pname mono">{{ p.id }}</span>
|
||||
<span class="psub dim">{{ p.name }}</span>
|
||||
</el-checkbox>
|
||||
<div class="pswitches">
|
||||
<div class="psw">
|
||||
<span class="psw-label" :class="{ on: canRun(p.id) }">可运行</span>
|
||||
<el-switch size="small" :model-value="canRun(p.id)" :disabled="!grantedIds.includes(p.id)" @change="v => setGrant(p.id, { canRun: v })" />
|
||||
</div>
|
||||
<div class="psw">
|
||||
<span class="psw-label" :class="{ on: canDownload(p.id) }">可下载</span>
|
||||
<el-switch size="small" :model-value="canDownload(p.id)" :disabled="!grantedIds.includes(p.id)" @change="v => setGrant(p.id, { canDownload: v })" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-checkbox-group>
|
||||
<el-empty v-if="!plugins.length" description="暂无插件,请先在「插件管理」上传" :image-size="60" />
|
||||
</div>
|
||||
|
||||
<n-card class="block cp-rise" :bordered="false">
|
||||
<template #header>
|
||||
<div class="card-head">
|
||||
<b>平台授权</b>
|
||||
<n-button type="primary" size="small" :loading="savingPlat" @click="savePlat">保存平台授权</n-button>
|
||||
<!-- 平台授权 -->
|
||||
<div class="section">
|
||||
<div class="section-head">
|
||||
<div class="card-title">平台授权</div>
|
||||
</div>
|
||||
</template>
|
||||
<n-checkbox-group v-model:value="platChecked">
|
||||
<div class="ck-grid">
|
||||
<n-checkbox v-for="pf in PLATFORM_OPTS" :key="pf.id" :value="pf.id" class="ck">
|
||||
{{ pf.label }}<span class="dim">({{ pf.id }})</span>
|
||||
</n-checkbox>
|
||||
</div>
|
||||
</n-checkbox-group>
|
||||
</n-card>
|
||||
</template>
|
||||
<el-checkbox-group v-model="platChecked" class="pf-list">
|
||||
<el-checkbox v-for="pf in PLATFORM_OPTS" :key="pf.id" :value="pf.id" class="pf-chip">
|
||||
<span>{{ pf.label }}</span>
|
||||
<span class="dim mono">({{ pf.id }})</span>
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<n-empty v-else description="先在上方选择一个账号" class="no-acc cp-rise" />
|
||||
<el-empty v-else description="先在上方选择一个账号" :image-size="80" class="no-acc" />
|
||||
</div>
|
||||
|
||||
<!-- 底部保存栏 -->
|
||||
<transition name="savebar">
|
||||
<div class="savebar cp-card cp-rise" v-if="account">
|
||||
<div class="save-hint">
|
||||
<span class="dot" :class="{ dirty: dirtyCount > 0 }"></span>
|
||||
{{ dirtyCount > 0 ? `有 ${dirtyCount} 项授权变更待保存` : '授权已是最新' }}
|
||||
</div>
|
||||
<el-button type="primary" :loading="saving" :disabled="dirtyCount === 0" :icon="Check" @click="saveAll">
|
||||
保存授权
|
||||
</el-button>
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { Refresh } from '@element-plus/icons-vue'
|
||||
import { Refresh, User, Check } from '@element-plus/icons-vue'
|
||||
import { ElMessage as message } from 'element-plus'
|
||||
import { overview, overviewBusy, loadOverview } from '../store'
|
||||
import { adminGrant, adminPlatformGrant, adminPlatforms } from '../api'
|
||||
import { message } from '../naive'
|
||||
|
||||
const PLATFORM_OPTS = ref([])
|
||||
|
||||
@@ -102,7 +101,6 @@ const grantedIds = ref([])
|
||||
const grantState = ref({}) // plugin_id -> { granted, canRun, canDownload }
|
||||
const platChecked = ref([])
|
||||
const saving = ref(false)
|
||||
const savingPlat = ref(false)
|
||||
let heldGrantState = {} // 已保存快照,用于差异比对
|
||||
let heldPlatforms = new Set()
|
||||
|
||||
@@ -110,6 +108,15 @@ function setGrant(pid, patch) {
|
||||
grantState.value[pid] = { ...grantState.value[pid], ...patch }
|
||||
grantState.value = { ...grantState.value }
|
||||
}
|
||||
function canRun(pid) { return grantState.value[pid]?.canRun !== false }
|
||||
function canDownload(pid) { return grantState.value[pid]?.canDownload !== false }
|
||||
|
||||
// 全选 / 半选
|
||||
const allChecked = computed(() => plugins.value.length > 0 && grantedIds.value.length === plugins.value.length)
|
||||
const someChecked = computed(() => grantedIds.value.length > 0 && !allChecked.value)
|
||||
function toggleAll(v) {
|
||||
grantedIds.value = v ? plugins.value.map(p => p.id) : []
|
||||
}
|
||||
|
||||
// 选中账号即自动载入其现有授权
|
||||
watch(account, (acc) => {
|
||||
@@ -139,10 +146,27 @@ watch(grantedIds, (ids) => {
|
||||
grantState.value = state
|
||||
})
|
||||
|
||||
// 差异计算
|
||||
const pluginDirty = computed(() => {
|
||||
const want = {}
|
||||
Object.entries(grantState.value).forEach(([pid, s]) => { if (s.granted) want[pid] = s })
|
||||
const allPids = [...new Set([...Object.keys(want), ...Object.keys(heldGrantState)])]
|
||||
return allPids.filter(pid => {
|
||||
const w = want[pid]; const h = heldGrantState[pid]
|
||||
if (!!w !== !!h) return true
|
||||
if (w && h) return w.canRun !== h.canRun || w.canDownload !== h.canDownload
|
||||
return false
|
||||
})
|
||||
})
|
||||
const platDirty = computed(() => {
|
||||
const want = new Set(platChecked.value)
|
||||
return [...new Set([...want, ...heldPlatforms])].filter(pf => want.has(pf) !== heldPlatforms.has(pf))
|
||||
})
|
||||
const dirtyCount = computed(() => pluginDirty.value.length + platDirty.value.length)
|
||||
|
||||
async function refresh() {
|
||||
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
|
||||
}
|
||||
// 拉取可授权平台列表(后端只读接口,替代写死 hr/oa)
|
||||
async function loadPlatforms() {
|
||||
try {
|
||||
const r = await adminPlatforms()
|
||||
@@ -150,78 +174,121 @@ async function loadPlatforms() {
|
||||
} catch (e) { message.error('平台列表读取失败:' + (e.message || e)) }
|
||||
}
|
||||
|
||||
async function saveGrant() {
|
||||
async function savePluginDiff() {
|
||||
const acc = account.value
|
||||
const want = {}
|
||||
Object.entries(grantState.value).forEach(([pid, s]) => { if (s.granted) want[pid] = s })
|
||||
const diff = pluginDirty.value
|
||||
const results = await Promise.allSettled(diff.map(pid => adminGrant({
|
||||
account: acc, plugin_id: pid, granted: !!want[pid],
|
||||
can_run: want[pid]?.canRun !== false, can_download: want[pid]?.canDownload !== false,
|
||||
})))
|
||||
const failed = results.filter(r => r.status === 'rejected')
|
||||
failed.forEach(r => message.error(r.reason?.message || String(r.reason)))
|
||||
if (failed.length) { message.warning(`插件授权:${diff.length - failed.length} 项成功,${failed.length} 项失败`); return 0 }
|
||||
heldGrantState = JSON.parse(JSON.stringify(grantState.value))
|
||||
return diff.length
|
||||
}
|
||||
async function savePlatDiff() {
|
||||
const acc = account.value
|
||||
const want = new Set(platChecked.value)
|
||||
const diff = platDirty.value
|
||||
const results = await Promise.allSettled(diff.map(pf => adminPlatformGrant({
|
||||
account: acc, platform_id: pf, granted: want.has(pf),
|
||||
})))
|
||||
const failed = results.filter(r => r.status === 'rejected')
|
||||
failed.forEach(r => message.error(r.reason?.message || String(r.reason)))
|
||||
if (failed.length) { message.warning(`平台授权:${diff.length - failed.length} 项成功,${failed.length} 项失败`); return 0 }
|
||||
heldPlatforms = new Set(platChecked.value)
|
||||
return diff.length
|
||||
}
|
||||
|
||||
async function saveAll() {
|
||||
const acc = account.value; if (!acc) return
|
||||
saving.value = true
|
||||
try {
|
||||
const want = {}
|
||||
Object.entries(grantState.value).forEach(([pid, s]) => {
|
||||
if (s.granted) want[pid] = s
|
||||
})
|
||||
const allPids = [...new Set([...Object.keys(want), ...Object.keys(heldGrantState)])]
|
||||
const diff = allPids.filter(pid => {
|
||||
const w = want[pid]; const h = heldGrantState[pid]
|
||||
if (!!w !== !!h) return true
|
||||
if (w && h) return w.canRun !== h.canRun || w.canDownload !== h.canDownload
|
||||
return false
|
||||
})
|
||||
if (!diff.length) { message.info('插件授权无需变更'); return }
|
||||
const results = await Promise.allSettled(diff.map(pid => adminGrant({
|
||||
account: acc, plugin_id: pid, granted: !!want[pid],
|
||||
can_run: want[pid]?.canRun !== false, can_download: want[pid]?.canDownload !== false,
|
||||
})))
|
||||
const failed = results.filter(r => r.status === 'rejected')
|
||||
failed.forEach(r => message.error(r.reason?.message || String(r.reason)))
|
||||
if (failed.length) { message.warning(`插件授权:${diff.length - failed.length} 项成功,${failed.length} 项失败`); return }
|
||||
message.success(`已更新 ${diff.length} 项插件授权`)
|
||||
heldGrantState = JSON.parse(JSON.stringify(grantState.value))
|
||||
let okP = 0, okPl = 0
|
||||
if (pluginDirty.value.length) okP = await savePluginDiff()
|
||||
if (platDirty.value.length) okPl = await savePlatDiff()
|
||||
if (!pluginDirty.value.length && !platDirty.value.length) { message.info('授权无需变更'); return }
|
||||
message.success(`已保存:插件 ${okP} 项,平台 ${okPl} 项`)
|
||||
await refresh()
|
||||
} finally { saving.value = false }
|
||||
}
|
||||
async function savePlat() {
|
||||
const acc = account.value; if (!acc) return
|
||||
savingPlat.value = true
|
||||
try {
|
||||
const want = new Set(platChecked.value)
|
||||
const diff = [...new Set([...want, ...heldPlatforms])].filter(pf => want.has(pf) !== heldPlatforms.has(pf))
|
||||
if (!diff.length) { message.info('平台授权无需变更'); return }
|
||||
const results = await Promise.allSettled(diff.map(pf => adminPlatformGrant({
|
||||
account: acc, platform_id: pf, granted: want.has(pf),
|
||||
})))
|
||||
const failed = results.filter(r => r.status === 'rejected')
|
||||
failed.forEach(r => message.error(r.reason?.message || String(r.reason)))
|
||||
if (failed.length) { message.warning(`平台授权:${diff.length - failed.length} 项成功,${failed.length} 项失败`); return }
|
||||
message.success(`已更新 ${diff.length} 项平台授权`)
|
||||
heldPlatforms = new Set(platChecked.value)
|
||||
await refresh()
|
||||
} finally { savingPlat.value = false }
|
||||
} catch (e) { message.error('保存失败:' + (e.message || e)) }
|
||||
finally { saving.value = false }
|
||||
}
|
||||
onMounted(() => { refresh(); loadPlatforms() })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.card-head { display: flex; justify-content: space-between; align-items: center; }
|
||||
.sel-hint { font-size: 12px; color: var(--cp-ink-2); }
|
||||
.no-acc { margin-top: 60px; }
|
||||
.panel { padding: 22px 24px 26px; }
|
||||
|
||||
/* 授权项:卡片式勾选 */
|
||||
.ck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
|
||||
.ck-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; line-height: 1.2; }
|
||||
.ck-sub { display: flex; align-items: center; gap: 10px; }
|
||||
:deep(.n-checkbox) {
|
||||
display: flex; align-items: center; margin: 0;
|
||||
width: 100%;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--cp-border);
|
||||
.pick-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding-bottom: 20px; border-bottom: 1px dashed var(--cp-line-strong); }
|
||||
.pick-label { font-size: 13px; font-weight: 700; color: var(--cp-ink-1); }
|
||||
.pick-hint { font-size: 12.5px; color: var(--cp-ink-3); }
|
||||
.pick-hint b { color: var(--cp-blue); font-size: 13px; }
|
||||
|
||||
.section { margin-top: 24px; }
|
||||
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
|
||||
.section-head .card-title { margin-bottom: 0; }
|
||||
|
||||
/* 插件授权行 */
|
||||
.plist { display: flex; flex-direction: column; gap: 8px; }
|
||||
.prow {
|
||||
display: flex; align-items: center; justify-content: space-between; gap: 16px;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid var(--cp-line);
|
||||
border-radius: 12px;
|
||||
background: rgba(255, 255, 255, .65);
|
||||
background: var(--cp-panel);
|
||||
transition: border-color .18s, background .18s, box-shadow .18s;
|
||||
}
|
||||
:deep(.n-checkbox:hover) { border-color: rgba(59, 108, 255, .4); }
|
||||
:deep(.n-checkbox.n-checkbox--checked) {
|
||||
border-color: rgba(59, 108, 255, .45);
|
||||
background: linear-gradient(135deg, rgba(59, 108, 255, .08), rgba(34, 199, 232, .06));
|
||||
box-shadow: 0 8px 18px -10px rgba(59, 108, 255, .35);
|
||||
.prow:hover { border-color: rgba(47, 92, 240, .35); }
|
||||
.prow.on {
|
||||
border-color: rgba(47, 92, 240, .4);
|
||||
background: linear-gradient(90deg, rgba(47, 92, 240, .05), rgba(15, 159, 155, .03));
|
||||
box-shadow: 0 8px 18px -12px rgba(47, 92, 240, .4);
|
||||
}
|
||||
:deep(.n-checkbox .n-checkbox__label) { padding-left: 4px; flex: 1; min-width: 0; }
|
||||
.prow .pck { flex: 1; min-width: 0; }
|
||||
.pname { font-weight: 700; color: var(--cp-ink-1); font-size: 13px; }
|
||||
.psub { font-size: 12px; margin-left: 8px; }
|
||||
|
||||
.pswitches { display: flex; gap: 22px; flex-shrink: 0; }
|
||||
.psw { display: flex; align-items: center; gap: 8px; }
|
||||
.psw-label { font-size: 12px; color: var(--cp-ink-3); transition: color .18s; }
|
||||
.psw-label.on { color: var(--cp-blue); font-weight: 600; }
|
||||
|
||||
/* 平台授权 chips */
|
||||
.pf-list { display: flex; flex-wrap: wrap; gap: 10px; }
|
||||
.pf-chip { margin: 0 !important; }
|
||||
.pf-chip :deep(.el-checkbox__input) { display: none; }
|
||||
.pf-chip :deep(.el-checkbox__label) {
|
||||
display: inline-flex; align-items: center; gap: 6px;
|
||||
padding: 8px 16px;
|
||||
border: 1px solid var(--cp-line);
|
||||
border-radius: 12px;
|
||||
background: var(--cp-panel);
|
||||
font-weight: 600;
|
||||
transition: border-color .18s, background .18s, box-shadow .18s, color .18s;
|
||||
}
|
||||
.pf-chip:hover :deep(.el-checkbox__label) { border-color: rgba(47, 92, 240, .4); }
|
||||
.pf-chip.is-checked :deep(.el-checkbox__label) {
|
||||
border-color: rgba(47, 92, 240, .55);
|
||||
background: linear-gradient(135deg, rgba(47, 92, 240, .10), rgba(15, 159, 155, .06));
|
||||
color: var(--cp-blue);
|
||||
box-shadow: 0 6px 14px -10px rgba(47, 92, 240, .5);
|
||||
}
|
||||
.no-acc { padding: 30px 0; }
|
||||
|
||||
/* 底部保存栏 */
|
||||
.savebar {
|
||||
position: sticky; bottom: 18px; z-index: 10;
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
margin-top: 20px; padding: 14px 20px;
|
||||
background: rgba(255, 253, 248, .92);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
.save-hint { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--cp-ink-2); font-weight: 600; }
|
||||
.save-hint .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--cp-success); }
|
||||
.save-hint .dot.dirty { background: var(--cp-amber); box-shadow: 0 0 0 4px rgba(217, 119, 6, .18); }
|
||||
.savebar-enter-active, .savebar-leave-active { transition: opacity .25s ease, transform .25s ease; }
|
||||
.savebar-enter-from, .savebar-leave-to { opacity: 0; transform: translateY(10px); }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user