feat(electron-shell): 补录壳子源码(排除运行环境与构建产物)

This commit is contained in:
2026-09-24 16:14:24 +08:00
parent 7e0838de64
commit 3214305dea
56 changed files with 17858 additions and 0 deletions
@@ -0,0 +1,242 @@
<template>
<div class="home">
<!-- 指标行:压缩首屏信息密度(替代问候区与统计卡) -->
<section class="kpis">
<div class="kpi">
<b>{{ store.plugins.length }}<em> 场景</em></b>
<span>可用场景</span>
</div>
<div class="kpi">
<b>{{ scheduleCount }}<em> 任务</em></b>
<span>定时任务</span>
</div>
<div class="kpi" :class="onlineCount ? 'ok' : ''">
<b>{{ onlineCount }}<em>/{{ store.platforms.length }}</em></b>
<span>平台在线</span>
</div>
<div class="kpi" :class="lastOk === null ? '' : (lastOk ? 'ok' : 'err')">
<b>{{ lastOk === null ? '—' : (lastOk ? '成功' : '失败') }}</b>
<span>{{ lastRunTime || '暂无运行' }}</span>
</div>
</section>
<!-- 平台账号(当前登录人的 HR/OA 账号与登录状态,登录后场景按本人身份执行) -->
<section class="block">
<div class="block-head">
<span class="sec-title">平台账号</span>
<span class="rec-note">配置你自己的 HR/OA 账号</span>
</div>
<PlatformAccounts />
</section>
<!-- 常用场景(只放前 6 个快捷入口,全部走「场景」视图) -->
<section class="block">
<div class="block-head">
<span class="sec-title">常用场景</span>
<el-button v-if="store.plugins.length > 6" text size="small" class="more" @click="goScenes">
全部场景 {{ store.plugins.length }} <el-icon><ArrowRight /></el-icon>
</el-button>
</div>
<div v-if="store.plugins.length" class="scenes" :style="{ '--n': Math.min(4, store.plugins.length) }">
<button
v-for="(p, i) in store.plugins.slice(0, 6)" :key="p.id" class="sc card"
:class="{ running: store.running && store.selectedId === p.id }"
@click="openPlugin(p.id)"
>
<span class="sc-ic" :style="{ background: grad(i) }">{{ p.name.slice(0, 1) }}</span>
<span class="sc-body">
<b>{{ p.name }}</b>
<span class="sc-meta">
v{{ p.version }}
<template v-if="p.platform">
<i class="sep-dot"></i>{{ platformLabel(p.platform) }}
<em class="plat-state" :class="{ on: platformOnline(p.platform) }">
{{ platformOnline(p.platform) ? '已登录' : '未登录' }}
</em>
</template>
</span>
</span>
<span class="sc-go">
<template v-if="store.running && store.selectedId === p.id">{{ store.progress }}%</template>
<template v-else>执行</template>
</span>
</button>
</div>
<div v-else class="empty card">
<span class="empty-emoji">🤍</span>
<div>
<b>当前账号暂无可用场景</b>
<span>请联系管理员在控制面进行授权,授权后点击右上角刷新</span>
</div>
<el-button size="small" round type="primary" plain @click="goScenes">去同步</el-button>
</div>
</section>
<!-- 最近动态 -->
<section class="block" v-if="store.recents.length">
<div class="block-head">
<span class="sec-title">最近动态</span>
<span class="rec-note">最近 {{ store.recents.length }} 次执行</span>
</div>
<div class="recent card">
<button v-for="(r, i) in store.recents" :key="i" class="rec" @click="openPlugin(r.pluginId, r.runId)">
<span class="rec-ic" :class="r.ok ? 'ok' : 'err'">{{ r.ok ? '✓' : '✕' }}</span>
<span class="rec-name">{{ r.name }}</span>
<span class="rec-msg" :class="r.ok ? 'ok' : 'err'">{{ r.ok ? '执行完成' : (r.error || '执行失败') }}</span>
<span class="rec-time">{{ r.time }}</span>
</button>
</div>
</section>
</div>
</template>
<script setup>
import { computed, onMounted, ref } from 'vue'
import { ArrowRight } from '@element-plus/icons-vue'
import { store } from '../store'
import { listSchedules } from '../api'
import PlatformAccounts from './PlatformAccounts.vue'
const GRADS = [
'var(--grad-sky)', 'var(--grad-peach)', 'var(--grad-mint)',
'var(--grad-lilac)', 'var(--grad-honey)', 'var(--grad-blush)',
]
function grad(i) { return GRADS[i % GRADS.length] }
const scheduleCount = ref(0)
onMounted(async () => {
try {
const r = await listSchedules()
scheduleCount.value = (r.schedules || []).length
} catch (_) { scheduleCount.value = 0 }
})
const onlineCount = computed(() => (store.platforms || []).filter((p) => p.online).length)
const lastOk = computed(() => (store.lastResult ? !!store.lastResult.ok : null))
const lastRunTime = computed(() => {
const r = store.recents[0]
return r ? r.time : ''
})
function platformLabel(id) {
return (store.platforms.find((p) => p.id === id) || {}).label || id
}
function platformOnline(id) {
return !!(store.platforms.find((p) => p.id === id) || {}).online
}
function openPlugin(id, runId) {
store.selectedId = id
store.view = 'run'
// 最近动态点击:直达该次运行的回看(运行台消费后清空);普通场景点击清掉残留意图
store.pendingReplay = runId ? { pluginId: id, runId } : null
}
function goScenes() {
store.view = 'scenes'
}
</script>
<style scoped>
.home { display: flex; flex-direction: column; gap: 20px; padding: 4px 2px 10px; flex-shrink: 0; }
/* ---------- 指标行(紧凑,替代问候区/统计卡) ---------- */
.kpis { display: flex; gap: 10px; flex-wrap: wrap; }
.kpi {
flex: 1; min-width: 150px;
display: flex; align-items: baseline; gap: 8px;
padding: 10px 14px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
}
.kpi b { font-size: 17px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi b em { font-style: normal; font-size: 11px; color: var(--text-faint); font-weight: 500; }
.kpi span { margin-left: auto; font-size: 11px; color: var(--text-faint); white-space: nowrap; }
.kpi.ok b { color: var(--ok); }
.kpi.err b { color: var(--err); }
/* ---------- 分节 ---------- */
.block { display: flex; flex-direction: column; gap: 10px; container-type: inline-size; }
.block-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px; }
.more { color: var(--text-faint); }
.more:hover { color: var(--primary); }
.rec-note { font-size: 11px; color: var(--text-faint); }
/* ---------- 场景卡:列数 = min(4, 场景数),按实际数量均分并占满整行;
间隔数随列数变化,2 个场景即 2 列(与上方 2 列平台账号完全对齐);
容器变窄时先降为 2 列、再降 1 列,避免卡片过窄 ---------- */
.scenes {
--max: 4;
display: grid;
grid-template-columns: repeat(min(var(--max), var(--n, 1)), 1fr);
gap: 10px;
}
@container (max-width: 620px) { .scenes { --max: 2; } }
@container (max-width: 380px) { .scenes { --max: 1; } }
.sc {
display: flex; align-items: center; gap: 10px;
padding: 11px 13px; text-align: left;
cursor: pointer; font-family: inherit;
transition: border-color .15s ease, box-shadow .15s ease;
}
.sc:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.sc:active { transform: scale(.99); }
.sc.running { border-color: rgba(var(--primary-rgb), .55); background: var(--surface-glow); }
.sc-ic {
width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
display: grid; place-items: center; color: var(--tile-fg);
font-size: 13px; font-weight: 700;
}
.sc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sc-body b { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-meta { font-size: 10.5px; color: var(--text-faint); display: flex; align-items: center; gap: 5px; font-style: normal; white-space: nowrap; }
.sep-dot { width: 3px; height: 3px; border-radius: 50%; background: var(--dot-muted); }
.plat-state { font-style: normal; color: var(--text-muted-warm); }
.plat-state.on { color: var(--ok); }
.sc-go {
flex-shrink: 0;
font-size: 11px; font-weight: 600;
color: var(--primary); background: var(--primary-weak);
border: 1px solid rgba(var(--primary-rgb), .35);
padding: 4px 10px; border-radius: 999px;
transition: all .15s ease;
}
.sc:hover .sc-go { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.sc.running .sc-go { color: var(--on-primary); background: var(--primary); border-color: transparent; font-variant-numeric: tabular-nums; }
.empty {
display: flex; align-items: center; gap: 14px;
padding: 22px 20px; color: var(--text-sub);
}
.empty-emoji { font-size: 26px; }
.empty b { display: block; font-size: 13.5px; color: var(--text); margin-bottom: 3px; font-weight: 600; }
.empty span { font-size: 12px; color: var(--text-faint); }
.empty .el-button { margin-left: auto; }
/* ---------- 最近动态 ---------- */
.recent { padding: 4px 8px; }
.rec {
display: flex; align-items: center; gap: 11px;
width: 100%; padding: 8px; text-align: left;
background: transparent; border: none; border-radius: 8px;
cursor: pointer; font-family: inherit;
transition: background .13s;
}
.rec:hover { background: var(--surface-2); }
.rec-ic {
width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
display: grid; place-items: center; font-size: 10px; font-weight: 700;
}
.rec-ic.ok { background: var(--ok-weak); color: var(--ok); }
.rec-ic.err { background: var(--err-weak); color: var(--err); }
.rec-name { font-size: 12.5px; font-weight: 600; color: var(--text); min-width: 110px; }
.rec-msg { flex: 1; font-size: 12px; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-msg.ok { color: var(--ok); }
.rec-msg.err { color: var(--err); }
.rec-time { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
@media (max-width: 1100px) {
.kpis { flex-direction: column; }
}
</style>