feat(electron-shell): 补录壳子源码(排除运行环境与构建产物)
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
<template>
|
||||
<div class="paccs">
|
||||
<div v-for="p in platStatus" :key="p.id" class="pacc card">
|
||||
<div class="p-top">
|
||||
<span class="p-dot" :class="{ on: p.online }"></span>
|
||||
<span class="p-name">{{ p.label }}</span>
|
||||
<span class="p-state" :class="{ on: p.online }">{{ p.online ? '已登录' : '未登录' }}</span>
|
||||
</div>
|
||||
<div class="p-user" :class="{ none: !p.has_creds }">{{ p.has_creds ? p.user : '未配置个人账号' }}</div>
|
||||
<div class="p-acts">
|
||||
<el-button v-if="!p.online" size="small" :loading="busy === p.id" @click="login(p.id)">
|
||||
{{ busy === p.id ? '登录中…' : '登录' }}
|
||||
</el-button>
|
||||
<el-button v-else size="small" plain type="danger" :disabled="!!busy" @click="logout(p.id)">
|
||||
登出
|
||||
</el-button>
|
||||
<el-button size="small" text @click="openEdit(p)">配置账号</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="p-hint">账号密码仅本机加密保存;登录后场景按<b>你的身份</b>执行。</p>
|
||||
|
||||
<!-- 账号配置弹窗 -->
|
||||
<el-dialog v-model="dlg" :title="`配置 ${editLabel} 账号`" width="380px" align-center class="pacc-dlg">
|
||||
<el-form label-width="72px" @submit.prevent>
|
||||
<el-form-item label="登录账号">
|
||||
<el-input v-model="form.user" placeholder="平台登录账号" maxlength="64" />
|
||||
</el-form-item>
|
||||
<el-form-item label="登录密码">
|
||||
<el-input v-model="form.pass" type="password" show-password
|
||||
:placeholder="hasCreds ? '新密码(留空表示不修改)' : '平台登录密码'" maxlength="64" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dlg = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="save">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { reactive, ref, onMounted, computed } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { store, log } from '../store'
|
||||
import { loginPlatform, logoutPlatform, getPlatformStatus, savePlatformCreds } from '../api'
|
||||
|
||||
// 当前账号的平台状态(按账号隔离:各自 HR/OA 账号密码 + 各自会话)
|
||||
const platStatus = ref([]) // [{id, label, online, has_creds, user}]
|
||||
const dlg = ref(false) // 配置弹窗开关
|
||||
const editing = ref(null) // 正在配置的平台对象
|
||||
const form = reactive({ user: '', pass: '' })
|
||||
const busy = ref('')
|
||||
const saving = ref(false)
|
||||
|
||||
const editLabel = computed(() => (editing.value ? editing.value.label : ''))
|
||||
const hasCreds = computed(() => !!(editing.value && editing.value.has_creds))
|
||||
|
||||
async function refresh() {
|
||||
try {
|
||||
const r = await getPlatformStatus()
|
||||
platStatus.value = (r && r.platforms) || []
|
||||
// 同步全局平台在线态(首页统计/场景徽章按当前账号展示)
|
||||
for (const ps of platStatus.value) {
|
||||
const p = store.platforms.find((x) => x.id === ps.id)
|
||||
if (p) p.online = ps.online
|
||||
}
|
||||
} catch (_) { /* 静默 */ }
|
||||
}
|
||||
|
||||
onMounted(refresh)
|
||||
|
||||
function openEdit(p) {
|
||||
editing.value = p
|
||||
form.user = p.user || ''
|
||||
form.pass = ''
|
||||
dlg.value = true
|
||||
}
|
||||
|
||||
async function save() {
|
||||
saving.value = true
|
||||
try {
|
||||
await savePlatformCreds({ [editing.value.id]: { user: form.user, pass: form.pass } })
|
||||
ElMessage.success(`已保存 ${editing.value.label} 账号配置`)
|
||||
dlg.value = false
|
||||
await refresh()
|
||||
} catch (e) {
|
||||
ElMessage.error('保存失败:' + (e.message || e))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function login(id) {
|
||||
if (busy.value) return
|
||||
const p = platStatus.value.find((x) => x.id === id)
|
||||
if (p?.online) { ElMessage.success(`${p.label} 已登录`); return }
|
||||
busy.value = id
|
||||
try {
|
||||
const r = await loginPlatform(id)
|
||||
const ok = !!(r && r.online)
|
||||
if (ok) log('INFO', `平台 ${p?.label || id} 登录成功`)
|
||||
else log('ERROR', `平台 ${p?.label || id} 登录未生效:${(r && r.message) || ''}`)
|
||||
ElMessage[ok ? 'success' : 'error'](
|
||||
`${p?.label || id} ${ok ? '登录成功' : '登录失败:' + ((r && r.message) || '登录态未生效')}`
|
||||
)
|
||||
await refresh()
|
||||
} catch (e) {
|
||||
log('ERROR', `平台 ${p?.label || id} 登录失败:${e.message || e}`)
|
||||
ElMessage.error(`登录失败:${e.message || e}`)
|
||||
} finally {
|
||||
busy.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
async function logout(id) {
|
||||
busy.value = id
|
||||
try {
|
||||
const r = await logoutPlatform(id)
|
||||
const p = platStatus.value.find((x) => x.id === id)
|
||||
if (p) p.online = !!r.online
|
||||
log('INFO', `平台 ${p?.label || id} 已登出`)
|
||||
ElMessage.success(`平台 ${p?.label || id} 已登出`)
|
||||
await refresh()
|
||||
} catch (e) {
|
||||
log('ERROR', `平台 ${(platStatus.value.find((x) => x.id === id) || {}).label || id} 登出失败:${e.message || e}`)
|
||||
ElMessage.error(`登出失败:${e.message || e}`)
|
||||
} finally {
|
||||
busy.value = ''
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.paccs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
|
||||
.pacc { padding: 13px 14px; display: flex; flex-direction: column; gap: 8px; }
|
||||
.p-top { display: flex; align-items: center; gap: 8px; }
|
||||
.p-dot {
|
||||
flex: none; width: 8px; height: 8px; border-radius: 50%;
|
||||
background: var(--sep-warm);
|
||||
}
|
||||
.p-dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(var(--ok-rgb), .16); }
|
||||
.p-name { font-size: 13.5px; font-weight: 600; color: var(--text); }
|
||||
.p-state {
|
||||
margin-left: auto; font-size: 11px; color: var(--text-faint);
|
||||
padding: 2px 9px; border-radius: 999px; background: var(--surface-2);
|
||||
}
|
||||
.p-state.on { color: var(--ok); background: var(--ok-weak); }
|
||||
.p-user {
|
||||
font-size: 11.5px; color: var(--text); font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||||
}
|
||||
.p-user.none { color: var(--text-faint); }
|
||||
.p-acts { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
|
||||
.p-acts .el-button + .el-button { margin-left: 0; }
|
||||
.p-hint {
|
||||
grid-column: 1 / -1;
|
||||
margin: 2px 0 0; font-size: 11px; color: var(--text-faint); line-height: 1.7;
|
||||
}
|
||||
.p-hint b { color: var(--text-sub); }
|
||||
|
||||
/* 与首页常用场景共用同一容器查询断点:窄容器时同步降为 1 列,保证上下卡片始终对齐 */
|
||||
@container (max-width: 380px) { .paccs { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
Reference in New Issue
Block a user