refactor: 完成项目目录重构与代码迁移

本次提交完成了整体项目的目录梳理与代码迁移:
1.  将根级controlplane、webhost等目录的代码迁移至desktop/对应子目录,统一桌面端架构
2.  移动并整理了插件目录结构,将插件统一放入根级plugins/
3.  调整了前端项目的路径与配置,统一前后端开发构建流程
4.  清理了废弃的旧版app/目录与冗余的构建中间文件
5.  更新了.gitignore与README.md,适配新的项目结构
This commit is contained in:
2026-09-14 17:46:09 +08:00
parent a1a06504a5
commit 0ab43d0ed8
131 changed files with 4071 additions and 38034 deletions
@@ -0,0 +1,227 @@
<template>
<div class="page">
<div class="page-head cp-rise">
<div>
<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>
</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>
<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>
</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>
<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>
</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>
<n-empty v-else description="先在上方选择一个账号" class="no-acc cp-rise" />
</div>
</template>
<script setup>
import { computed, onMounted, ref, watch } from 'vue'
import { Refresh } from '@element-plus/icons-vue'
import { overview, overviewBusy, loadOverview } from '../store'
import { adminGrant, adminPlatformGrant, adminPlatforms } from '../api'
import { message } from '../naive'
const PLATFORM_OPTS = ref([])
const plugins = computed(() => overview.value?.plugins || [])
const accounts = computed(() => overview.value?.accounts || [])
const accountOptions = computed(() => accounts.value.map(a => ({
label: a.dept ? `${a.account} · ${a.dept}` : a.account,
value: a.account,
})))
const account = ref('')
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()
function setGrant(pid, patch) {
grantState.value[pid] = { ...grantState.value[pid], ...patch }
grantState.value = { ...grantState.value }
}
// 选中账号即自动载入其现有授权
watch(account, (acc) => {
const a = accounts.value.find(x => x.account === acc)
const state = {}
;(a?.plugins || []).forEach(pid => {
const g = a?.grants?.[pid] || {}
state[pid] = { granted: true, canRun: g.canRun !== false, canDownload: g.canDownload !== false }
})
heldGrantState = JSON.parse(JSON.stringify(state))
grantState.value = JSON.parse(JSON.stringify(state))
grantedIds.value = [...(a?.plugins || [])]
heldPlatforms = new Set(a?.platforms || [])
platChecked.value = [...heldPlatforms]
})
// 勾选/取消勾选插件时同步 granted 状态
watch(grantedIds, (ids) => {
const state = { ...grantState.value }
ids.forEach(pid => {
if (!state[pid]) state[pid] = { granted: true, canRun: true, canDownload: true }
else state[pid].granted = true
})
Object.keys(state).forEach(pid => {
if (!ids.includes(pid)) state[pid].granted = false
})
grantState.value = state
})
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
// 拉取可授权平台列表(后端只读接口,替代写死 hr/oa)
async function loadPlatforms() {
try {
const r = await adminPlatforms()
PLATFORM_OPTS.value = (r.platforms || []).map(p => ({ id: p.id, label: p.label }))
} catch (e) { message.error('平台列表读取失败:' + (e.message || e)) }
}
async function saveGrant() {
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))
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 }
}
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; }
/* 授权项:卡片式勾选 */
.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);
border-radius: 12px;
background: rgba(255, 255, 255, .65);
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);
}
:deep(.n-checkbox .n-checkbox__label) { padding-left: 4px; flex: 1; min-width: 0; }
</style>