feat: 交付任务005-021全量改动(自动化/AI/联系人中心、消息中心改造、运维与容器化)
- 自动化中心:规则引擎、流程画布与触发器(V7/V10/V12/V18/V21)、测试全流程、安全边界、执行记录 - AI 中心:服务商/模型/调用与工具授权/治理(V8/V17)及配套前端页面 - 联系人中心:联系人目录、分组/标签、同步幂等(V19)与实装页面 - 消息中心:三栏布局重做、头像昵称服务端抓取与缓存(V16 conversation_profile)、出站归属修复 - 接入管理:NapCat 反向 WS/HTTP 回调多通道发送传输、连接状态统一口径 - 运维中心:备份保留与恢复确认(V13/V22/V24)、监控告警(V23)、日志与审计 - 全局:账号上下文切换(V20 account_profile)、统一 UI 基础组件、分页样式、Flyway 增量迁移护栏 - 部署:Dockerfile/docker-compose/Nginx 容器化编排与 CI 校验脚本 - 文档:任务 005-021 交付记录、设计画板导出、接口/数据库/架构文档同步
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import { reactive } from 'vue'
|
||||
import { api } from './api.js'
|
||||
import { bindingStatusLabel } from './binding-status.js'
|
||||
|
||||
/**
|
||||
* 当前 QQ 账号选择的持久化键。
|
||||
* 账号是全局必需上下文:不再支持「全部账号」,仅当实例没有任何 ACTIVE 且回填 QQ 号的绑定时,
|
||||
* current 才为 null(此时各页面显示空态并提示去接入管理绑定)。
|
||||
*/
|
||||
const STORAGE_KEY = 'qlinker.account.current'
|
||||
|
||||
function readStored() {
|
||||
const value = localStorage.getItem(STORAGE_KEY)
|
||||
return value && value.trim() ? value.trim() : null
|
||||
}
|
||||
|
||||
export const accountState = reactive({
|
||||
loaded: false,
|
||||
loading: false,
|
||||
items: [],
|
||||
unattributedBindings: 0,
|
||||
/** 当前 qqAccountId;仅在没有可用账号时为 null。 */
|
||||
current: readStored(),
|
||||
/** 加载/回退提示,供切换器展示,不代表后端错误。 */
|
||||
message: '',
|
||||
error: ''
|
||||
})
|
||||
|
||||
export function accountParam() {
|
||||
return accountState.current
|
||||
}
|
||||
|
||||
/** 是否有可用的当前账号;无账号时页面应展示空态而不是拉全量数据。 */
|
||||
export function hasCurrentAccount() {
|
||||
return Boolean(accountState.current)
|
||||
}
|
||||
|
||||
export function isCurrent(qqAccountId) {
|
||||
return String(qqAccountId) === String(accountState.current)
|
||||
}
|
||||
|
||||
export function currentAccount() {
|
||||
return accountState.items.find((item) => isCurrent(item.qqAccountId)) || null
|
||||
}
|
||||
|
||||
export function setCurrentAccount(qqAccountId) {
|
||||
const next = qqAccountId == null ? '' : String(qqAccountId).trim()
|
||||
// 不再允许空值代表「全部账号」;空值仅用于无账号可选的场景。
|
||||
if (!next) return
|
||||
accountState.current = next
|
||||
accountState.message = ''
|
||||
localStorage.setItem(STORAGE_KEY, next)
|
||||
}
|
||||
|
||||
function eventTime(item) {
|
||||
const time = Date.parse(item?.lastEventAt || '')
|
||||
return Number.isFinite(time) ? time : 0
|
||||
}
|
||||
|
||||
/** 默认账号:优先在线,其次最近有事件的(lastEventAt),最后回退目录首项。 */
|
||||
function pickDefaultAccount(items) {
|
||||
if (!items.length) return null
|
||||
const online = items.filter((item) => item.online === true)
|
||||
const pool = online.length ? online : items
|
||||
const latest = [...pool].sort((a, b) => eventTime(b) - eventTime(a))[0]
|
||||
return latest || items[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载账号目录并校正当前账号(绑定可能停用或 QQ 号变更)。
|
||||
* 当前账号失效时自动切到默认账号;没有任何可用账号时置空并提示去接入管理,
|
||||
* 不回退到「全部账号」聚合,避免不同账号的数据混在一起。
|
||||
*/
|
||||
export async function loadAccounts() {
|
||||
if (accountState.loading) return
|
||||
accountState.loading = true
|
||||
try {
|
||||
const data = await api.accounts()
|
||||
accountState.items = data?.items || []
|
||||
accountState.unattributedBindings = Number(data?.unattributedBindings || 0)
|
||||
accountState.loaded = true
|
||||
accountState.error = ''
|
||||
if (!accountState.items.length) {
|
||||
accountState.current = null
|
||||
localStorage.removeItem(STORAGE_KEY)
|
||||
accountState.message = '当前实例没有可用 QQ 账号,请先到接入管理绑定并确认连接在线。'
|
||||
return
|
||||
}
|
||||
if (!accountState.current || !accountState.items.some((item) => isCurrent(item.qqAccountId))) {
|
||||
const fallback = pickDefaultAccount(accountState.items)
|
||||
const hadCurrent = Boolean(accountState.current)
|
||||
accountState.current = fallback.qqAccountId
|
||||
localStorage.setItem(STORAGE_KEY, fallback.qqAccountId)
|
||||
accountState.message = hadCurrent
|
||||
? '原选账号已不可用,已切换到当前在线账号'
|
||||
: ''
|
||||
}
|
||||
} catch (e) {
|
||||
accountState.error = e?.message || '账号目录加载失败'
|
||||
accountState.message = ''
|
||||
} finally {
|
||||
accountState.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 账号在线文案与接入管理、画布共用同一判定(connection_status),避免各处口径分裂。 */
|
||||
export function statusText(status) {
|
||||
return bindingStatusLabel({ connectionStatus: status })
|
||||
}
|
||||
Reference in New Issue
Block a user