fix(huya): 区分当前绑定与待确认角色
This commit is contained in:
@@ -67,6 +67,58 @@ class BindMixin:
|
||||
"game_role": game_role.to_dict(),
|
||||
}
|
||||
|
||||
def _bind_query_roles(
|
||||
self, bind_status: Any, bind_query_result: dict[str, Any]
|
||||
) -> tuple[dict, dict | None, dict | None]:
|
||||
"""从统一查询结果中取当前绑定和待确认角色。
|
||||
|
||||
新查询结果带 ``current_role`` / ``pending_role``;兼容旧测试桩或旧任务数据时,
|
||||
没有这两个标记就继续把 ``bind_status`` 当成唯一的当前角色。
|
||||
"""
|
||||
has_role_split = (
|
||||
"current_role" in bind_query_result or "pending_role" in bind_query_result
|
||||
)
|
||||
current = bind_query_result.get("current_role")
|
||||
pending = bind_query_result.get("pending_role")
|
||||
selected = (
|
||||
{}
|
||||
if has_role_split and (current or pending)
|
||||
else self._bind_role_result(bind_status)
|
||||
)
|
||||
if not has_role_split:
|
||||
current = selected if selected.get("role_name") else None
|
||||
pending = None
|
||||
return (
|
||||
selected,
|
||||
current if isinstance(current, dict) else None,
|
||||
pending if isinstance(pending, dict) else None,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _bind_change_state_from_role(role_info: dict | None) -> dict:
|
||||
"""用标准角色候选计算绑定/换绑时间状态。"""
|
||||
if not role_info:
|
||||
return {
|
||||
"is_bound": False,
|
||||
"can_change_bind": True,
|
||||
"change_bind_time": 0,
|
||||
"change_available_at": "",
|
||||
"change_bind_day": 0,
|
||||
}
|
||||
is_bound = bool(
|
||||
role_info.get("is_bind_account") and role_info.get("is_bind_role")
|
||||
)
|
||||
change_time = int(role_info.get("change_bind_time") or 0)
|
||||
now = int(datetime.now(UTC).timestamp())
|
||||
can_change = not is_bound or not change_time or change_time <= now
|
||||
return {
|
||||
"is_bound": is_bound,
|
||||
"can_change_bind": can_change,
|
||||
"change_bind_time": change_time,
|
||||
"change_available_at": HuyaBatchRunnerCore._format_local_time(change_time),
|
||||
"change_bind_day": int(role_info.get("change_bind_day") or 0),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _role_channel(bind_status) -> str:
|
||||
game_role = bind_status.accountData.gameRole
|
||||
@@ -190,10 +242,27 @@ class BindMixin:
|
||||
)
|
||||
|
||||
def _apply_role_to_account(self, account: HuyaAccount, bind_status, status: str):
|
||||
role_name = self._role_name(bind_status)
|
||||
role_info = self._bind_role_result(bind_status)
|
||||
self._apply_role_info_to_account(account, role_info, status)
|
||||
|
||||
@staticmethod
|
||||
def _apply_role_info_to_account(
|
||||
account: HuyaAccount, role_info: dict | None, status: str
|
||||
) -> None:
|
||||
"""只允许“当前已绑定角色”调用这里;待确认角色不得污染账号主角色。"""
|
||||
role_name = str((role_info or {}).get("role_name") or "")
|
||||
game_role = (role_info or {}).get("game_role") or {}
|
||||
channel = " / ".join(
|
||||
str(part)
|
||||
for part in (
|
||||
game_role.get("plat_name") if isinstance(game_role, dict) else "",
|
||||
game_role.get("area_name") if isinstance(game_role, dict) else "",
|
||||
)
|
||||
if part
|
||||
)
|
||||
account.status = status
|
||||
account.game_name = role_name or account.game_name
|
||||
account.game_channel = self._role_channel(bind_status) or account.game_channel
|
||||
account.game_channel = channel or account.game_channel
|
||||
account.updated_at = datetime.now(UTC)
|
||||
|
||||
@staticmethod
|
||||
@@ -300,8 +369,33 @@ class BindMixin:
|
||||
|
||||
previous_phase = result.get("bind_phase")
|
||||
ready = self._bind_ready_result(bind_status)
|
||||
selected_info, current_info, pending_info = self._bind_query_roles(
|
||||
bind_status, bind_query_result
|
||||
)
|
||||
has_role_split = (
|
||||
"current_role" in bind_query_result
|
||||
or "pending_role" in bind_query_result
|
||||
)
|
||||
target_info = pending_info or (
|
||||
selected_info
|
||||
if not has_role_split and selected_info.get("role_name")
|
||||
else None
|
||||
)
|
||||
current_role_name = str((current_info or {}).get("role_name") or "")
|
||||
pending_role_name = str((target_info or {}).get("role_name") or "")
|
||||
ready.update(
|
||||
{
|
||||
"current_role_name": current_role_name,
|
||||
"current_game_role": (current_info or {}).get("game_role"),
|
||||
"current_game_channel": (current_info or {}).get("channel", ""),
|
||||
"pending_role_name": pending_role_name,
|
||||
"pending_game_role": (target_info or {}).get("game_role"),
|
||||
"pending_game_channel": (target_info or {}).get("channel", ""),
|
||||
"role_name": pending_role_name,
|
||||
}
|
||||
)
|
||||
# 角色未就绪时保留扫码阶段文案,避免状态来回跳。
|
||||
if not ready["role_name"] and previous_phase in {
|
||||
if not pending_role_name and previous_phase in {
|
||||
"waiting_scan",
|
||||
"qrcode_scanned",
|
||||
"qrcode_completed",
|
||||
@@ -309,9 +403,8 @@ class BindMixin:
|
||||
ready["bind_phase"] = previous_phase
|
||||
result.update(ready)
|
||||
result["bind_polling"] = True
|
||||
role_name = ready["role_name"]
|
||||
role_name = pending_role_name
|
||||
if role_name:
|
||||
self._apply_role_to_account(account, bind_status, "game_queried")
|
||||
result["bind_polling"] = False
|
||||
self._update_task_progress(
|
||||
worker_db,
|
||||
@@ -598,8 +691,17 @@ class BindMixin:
|
||||
)
|
||||
return
|
||||
|
||||
role_info = self._bind_role_result(bind_status)
|
||||
change_state = self._bind_change_state(bind_status)
|
||||
selected_info, current_info, pending_info = self._bind_query_roles(
|
||||
bind_status, bind_query_result
|
||||
)
|
||||
role_info = current_info or pending_info or selected_info
|
||||
current_role_name = str((current_info or {}).get("role_name") or "")
|
||||
pending_role_name = str((pending_info or {}).get("role_name") or "")
|
||||
change_state = (
|
||||
self._bind_change_state_from_role(current_info)
|
||||
if current_info
|
||||
else self._bind_change_state(bind_status)
|
||||
)
|
||||
result = {
|
||||
"bind_act_id": b_act_id_int,
|
||||
"bind_gid": protocol["bind_gid"],
|
||||
@@ -607,13 +709,40 @@ class BindMixin:
|
||||
**role_info,
|
||||
**change_state,
|
||||
**bind_query_result,
|
||||
"bind_ready_for_confirm": bool(role_info["role_name"]),
|
||||
"bind_phase": "role_ready" if role_info["role_name"] else "waiting_role",
|
||||
"role_name": current_role_name or pending_role_name,
|
||||
"current_role_name": current_role_name,
|
||||
"current_game_role": (current_info or {}).get("game_role"),
|
||||
"current_game_channel": (current_info or {}).get("channel", ""),
|
||||
"pending_role_name": pending_role_name,
|
||||
"pending_game_role": (pending_info or {}).get("game_role"),
|
||||
"pending_game_channel": (pending_info or {}).get("channel", ""),
|
||||
"bind_ready_for_confirm": bool(pending_role_name),
|
||||
"bind_confirmed": bool(current_role_name),
|
||||
"bind_phase": (
|
||||
"role_ready"
|
||||
if pending_role_name
|
||||
else ("confirmed" if current_role_name else "waiting_role")
|
||||
),
|
||||
}
|
||||
role_name = role_info["role_name"]
|
||||
if role_name:
|
||||
if current_info:
|
||||
self._apply_role_info_to_account(account, current_info, "game_queried")
|
||||
elif pending_info:
|
||||
# 待确认角色只供页面展示和后续确认,不写账号主角色。
|
||||
account.status = "game_not_bound"
|
||||
account.updated_at = datetime.now(UTC)
|
||||
elif selected_info.get("role_name"):
|
||||
self._apply_role_to_account(account, bind_status, "game_queried")
|
||||
self._mark_task(worker_db, task, "success", f"角色: {role_name}", result)
|
||||
|
||||
if current_role_name or pending_role_name:
|
||||
if current_role_name and pending_role_name:
|
||||
message = (
|
||||
f"当前已绑定: {current_role_name};待确认: {pending_role_name}"
|
||||
)
|
||||
elif current_role_name:
|
||||
message = f"角色: {current_role_name}"
|
||||
else:
|
||||
message = f"待确认角色: {pending_role_name}"
|
||||
self._mark_task(worker_db, task, "success", message, result)
|
||||
return
|
||||
|
||||
account.status = "game_not_bound"
|
||||
@@ -668,8 +797,11 @@ class BindMixin:
|
||||
)
|
||||
return
|
||||
|
||||
role_info = self._bind_role_result(role_status)
|
||||
role_name = role_info["role_name"]
|
||||
selected_info, current_info, pending_info = self._bind_query_roles(
|
||||
role_status, role_query_result
|
||||
)
|
||||
role_info = pending_info or current_info or selected_info
|
||||
role_name = str(role_info.get("role_name") or "")
|
||||
if not role_name:
|
||||
result = {
|
||||
"bind_act_id": b_act_id_int,
|
||||
@@ -706,6 +838,12 @@ class BindMixin:
|
||||
"confirm_result": confirm_resp.to_dict(),
|
||||
"before_bind_status": role_status.to_dict(),
|
||||
**role_query_result,
|
||||
"before_current_role_name": str(
|
||||
(current_info or {}).get("role_name") or ""
|
||||
),
|
||||
"before_pending_role_name": str(
|
||||
(pending_info or {}).get("role_name") or ""
|
||||
),
|
||||
}
|
||||
self._mark_task(
|
||||
worker_db,
|
||||
@@ -736,8 +874,9 @@ class BindMixin:
|
||||
"before_bind_status": role_status.to_dict(),
|
||||
**role_info,
|
||||
**role_query_result,
|
||||
"bind_role_name": role_name,
|
||||
}
|
||||
self._apply_role_to_account(account, role_status, "bind_confirmed")
|
||||
self._apply_role_info_to_account(account, role_info, "bind_confirmed")
|
||||
self._mark_task(
|
||||
worker_db, task, "success", f"确认绑定: {role_name}", result
|
||||
)
|
||||
@@ -753,23 +892,40 @@ class BindMixin:
|
||||
**role_info,
|
||||
**role_query_result,
|
||||
"refresh_error": refreshed_query_result,
|
||||
"bind_role_name": role_name,
|
||||
}
|
||||
self._apply_role_to_account(account, role_status, "bind_confirmed")
|
||||
self._apply_role_info_to_account(account, role_info, "bind_confirmed")
|
||||
self._mark_task(
|
||||
worker_db, task, "success", f"确认绑定: {role_name}", result
|
||||
)
|
||||
return
|
||||
|
||||
refreshed_confirmed = bool(
|
||||
refreshed_status.accountData.isBindAcount
|
||||
and refreshed_status.accountData.isBindRole
|
||||
refreshed_selected, refreshed_current, refreshed_pending = (
|
||||
self._bind_query_roles(refreshed_status, refreshed_query_result)
|
||||
)
|
||||
refreshed_role_info = self._bind_role_result(refreshed_status)
|
||||
final_status = (
|
||||
refreshed_status if refreshed_role_info["role_name"] else role_status
|
||||
refreshed_confirmed = bool(
|
||||
refreshed_current or refreshed_selected.get("role_name")
|
||||
)
|
||||
confirmed_target = (
|
||||
refreshed_pending
|
||||
if refreshed_pending
|
||||
and str(refreshed_pending.get("role_name") or "") == role_name
|
||||
else None
|
||||
)
|
||||
confirmed_pending_role = bool(pending_info)
|
||||
refreshed_current_is_target = bool(
|
||||
refreshed_current
|
||||
and str(refreshed_current.get("role_name") or "") == role_name
|
||||
)
|
||||
final_role_info = (
|
||||
refreshed_role_info if refreshed_role_info["role_name"] else role_info
|
||||
(refreshed_current if refreshed_current_is_target else confirmed_target)
|
||||
if confirmed_pending_role
|
||||
else refreshed_current
|
||||
)
|
||||
final_role_info = (
|
||||
final_role_info
|
||||
or (refreshed_selected if refreshed_selected.get("role_name") else None)
|
||||
or role_info
|
||||
)
|
||||
result = {
|
||||
"bind_act_id": b_act_id_int,
|
||||
@@ -782,7 +938,8 @@ class BindMixin:
|
||||
**role_query_result,
|
||||
"refresh_result": refreshed_query_result,
|
||||
**final_role_info,
|
||||
"bind_role_name": final_role_info.get("role_name") or role_name,
|
||||
}
|
||||
self._apply_role_to_account(account, final_status, "bind_confirmed")
|
||||
self._apply_role_info_to_account(account, final_role_info, "bind_confirmed")
|
||||
role_name = final_role_info["role_name"] or role_name or "已绑定"
|
||||
self._mark_task(worker_db, task, "success", f"确认绑定: {role_name}", result)
|
||||
|
||||
@@ -74,8 +74,17 @@ class EliteMixin:
|
||||
def _bind_role_result(bind_status) -> dict: ...
|
||||
@staticmethod
|
||||
def _bind_change_state(bind_status) -> dict: ...
|
||||
def _bind_query_roles(
|
||||
self, bind_status: Any, bind_query_result: dict[str, Any]
|
||||
) -> tuple[dict, dict | None, dict | None]: ...
|
||||
@staticmethod
|
||||
def _bind_change_state_from_role(role_info: dict | None) -> dict: ...
|
||||
@staticmethod
|
||||
def _role_channel(bind_status) -> str: ...
|
||||
@staticmethod
|
||||
def _apply_role_info_to_account(
|
||||
account: HuyaAccount, role_info: dict | None, status: str
|
||||
) -> None: ...
|
||||
def _resolve_bind_status(
|
||||
self, client: Any, uid: int, cookie: str, b_act_id_int: int
|
||||
): ...
|
||||
@@ -363,7 +372,8 @@ class EliteMixin:
|
||||
result: dict[str, Any] = {"uid": uid}
|
||||
failures: list[str] = []
|
||||
message_parts: list[str] = []
|
||||
role_name = ""
|
||||
current_role_name = ""
|
||||
pending_role_name = ""
|
||||
|
||||
# ---- 角色绑定 / CK 有效性(先做,失效就不空跑后面两个接口) ----
|
||||
protocol = self._bind_protocol(config_info, self.payload)
|
||||
@@ -411,21 +421,55 @@ class EliteMixin:
|
||||
bind_status.msg or f"角色信息查询失败: {bind_status.status}"
|
||||
)
|
||||
else:
|
||||
role_info = self._bind_role_result(bind_status)
|
||||
role_name = role_info.get("role_name") or ""
|
||||
selected_info, current_info, pending_info = self._bind_query_roles(
|
||||
bind_status, bind_query_result
|
||||
)
|
||||
role_info = current_info or pending_info or selected_info
|
||||
current_role_name = str((current_info or {}).get("role_name") or "")
|
||||
pending_role_name = str((pending_info or {}).get("role_name") or "")
|
||||
has_role_split = (
|
||||
"current_role" in bind_query_result
|
||||
or "pending_role" in bind_query_result
|
||||
)
|
||||
change_state = (
|
||||
self._bind_change_state_from_role(current_info)
|
||||
if has_role_split and current_info
|
||||
else self._bind_change_state(bind_status)
|
||||
)
|
||||
result.update(
|
||||
{
|
||||
**role_info,
|
||||
**self._bind_change_state(bind_status),
|
||||
**change_state,
|
||||
**bind_query_result,
|
||||
"role_name": current_role_name or pending_role_name,
|
||||
"current_role_name": current_role_name,
|
||||
"current_game_role": (current_info or {}).get("game_role"),
|
||||
"current_game_channel": (current_info or {}).get("channel", ""),
|
||||
"pending_role_name": pending_role_name,
|
||||
"pending_game_role": (pending_info or {}).get("game_role"),
|
||||
"pending_game_channel": (pending_info or {}).get("channel", ""),
|
||||
"bind_ready_for_confirm": bool(pending_role_name),
|
||||
"bind_confirmed": bool(current_role_name),
|
||||
}
|
||||
)
|
||||
if role_name:
|
||||
account.game_name = role_name
|
||||
if current_info and has_role_split:
|
||||
self._apply_role_info_to_account(
|
||||
account, current_info, account.status or "all_queried"
|
||||
)
|
||||
elif selected_info.get("role_name") and not has_role_split:
|
||||
account.game_name = str(selected_info.get("role_name") or "")
|
||||
account.game_channel = (
|
||||
self._role_channel(bind_status) or account.game_channel
|
||||
)
|
||||
message_parts.append(f"角色 {role_name}")
|
||||
|
||||
if current_role_name and pending_role_name:
|
||||
message_parts.append(
|
||||
f"角色 {current_role_name},待确认 {pending_role_name}"
|
||||
)
|
||||
elif current_role_name:
|
||||
message_parts.append(f"角色 {current_role_name}")
|
||||
elif pending_role_name:
|
||||
message_parts.append(f"待确认角色 {pending_role_name}")
|
||||
else:
|
||||
message_parts.append("未绑定角色")
|
||||
|
||||
@@ -524,7 +568,11 @@ class EliteMixin:
|
||||
account.points = points if points is not None else account.points
|
||||
result["failures"] = failures
|
||||
|
||||
fetched_anything = points is not None or role_name or opened is not None
|
||||
fetched_anything = (
|
||||
points is not None
|
||||
or bool(current_role_name or pending_role_name)
|
||||
or opened is not None
|
||||
)
|
||||
if not fetched_anything:
|
||||
self._mark_task(
|
||||
worker_db,
|
||||
|
||||
@@ -114,6 +114,27 @@ function resultText(task: HuyaTaskItem | undefined, key: string): string {
|
||||
return value == null ? '' : String(value);
|
||||
}
|
||||
|
||||
function roleDisplay(task: HuyaTaskItem | undefined, row: HuyaAccountItem) {
|
||||
const hasRoleSplit = Boolean(
|
||||
task?.result
|
||||
&& ('current_role_name' in task.result || 'pending_role_name' in task.result),
|
||||
);
|
||||
if (!hasRoleSplit) {
|
||||
return {
|
||||
currentName: row.game_name || '',
|
||||
currentChannel: row.game_channel || '',
|
||||
pendingName: '',
|
||||
pendingChannel: '',
|
||||
};
|
||||
}
|
||||
return {
|
||||
currentName: resultText(task, 'current_role_name'),
|
||||
currentChannel: resultText(task, 'current_game_channel'),
|
||||
pendingName: resultText(task, 'pending_role_name'),
|
||||
pendingChannel: resultText(task, 'pending_game_channel'),
|
||||
};
|
||||
}
|
||||
|
||||
/** mini_qrcode_image 可能存裸 base64,也可能存 livelink 返回的 data URI;统一成 img src。 */
|
||||
function miniQrcodeSrc(image: string): string {
|
||||
return image.startsWith('data:image/') ? image : `data:image/png;base64,${image}`;
|
||||
@@ -181,6 +202,14 @@ function latestTask(tasks: HuyaTaskItem[], accountId: number): HuyaTaskItem | un
|
||||
return tasks.filter((task) => task.account_id === accountId).sort((a, b) => b.id - a.id)[0];
|
||||
}
|
||||
|
||||
function latestRoleTask(tasks: HuyaTaskItem[], accountId: number): HuyaTaskItem | undefined {
|
||||
return tasks
|
||||
.filter((task) => task.account_id === accountId)
|
||||
.filter((task) => ['query_game_name', 'query_all', 'get_bind_qr', 'confirm_bind'].includes(task.task_type)
|
||||
|| Boolean(task.result && ('current_role_name' in task.result || 'pending_role_name' in task.result)))
|
||||
.sort((a, b) => b.id - a.id)[0];
|
||||
}
|
||||
|
||||
function taskResultRecords(task: HuyaTaskItem | null | undefined): Record<string, unknown>[] {
|
||||
const records = task?.result?.records;
|
||||
return Array.isArray(records)
|
||||
@@ -784,10 +813,43 @@ export default function HuyaElitePage() {
|
||||
{ title: '#', width: '4%', align: 'center', render: (_value, _row, index) => <Text type="secondary">{index + 1}</Text> },
|
||||
{ title: '账号', width: '15%', align: 'center', ellipsis: true, render: (_value, row) => <Space direction="vertical" align="center" size={0} style={{ width: '100%' }}><Text strong ellipsis title={row.nickname || row.username || row.uid}>{row.nickname || row.username || row.uid}</Text><Text type="secondary" style={{ fontSize: 12 }} ellipsis title={row.username}>UID {row.uid || '-'}</Text></Space> },
|
||||
{ title: '手机号', width: '10%', align: 'center', ellipsis: true, render: (_value, row) => row.game_phone || <Text type="secondary">-</Text> },
|
||||
{ title: '游戏名', width: '13%', align: 'center', ellipsis: true, render: (_value, row) => { const expired = ckExpired(latestTask(tasks, row.id), row); return <Space direction="vertical" align="center" size={0} style={{ width: '100%' }}><Text ellipsis title={row.game_name || row.game_channel}>{row.game_name || <Text type={expired ? 'danger' : 'secondary'}>{expired ? '角色未查到' : '未查询'}</Text>}</Text>{row.game_channel && <Text type="secondary" style={{ fontSize: 12 }} ellipsis>{row.game_channel}</Text>}</Space>; } },
|
||||
{
|
||||
title: '游戏名',
|
||||
width: '20%',
|
||||
align: 'center',
|
||||
ellipsis: true,
|
||||
render: (_value, row) => {
|
||||
const task = latestTask(tasks, row.id);
|
||||
const roleTask = latestRoleTask(tasks, row.id);
|
||||
const expired = ckExpired(task, row);
|
||||
const role = roleDisplay(roleTask, row);
|
||||
const hasRoleSplit = Boolean(
|
||||
roleTask?.result
|
||||
&& ('current_role_name' in roleTask.result || 'pending_role_name' in roleTask.result),
|
||||
);
|
||||
return (
|
||||
<Space direction="vertical" align="center" size={1} style={{ width: '100%' }}>
|
||||
<Text ellipsis title={role.currentName || role.currentChannel}>
|
||||
{role.currentName || (
|
||||
<Text type={expired ? 'danger' : 'secondary'}>
|
||||
{expired ? '角色未查到' : hasRoleSplit ? '当前未绑定' : '未查询'}
|
||||
</Text>
|
||||
)}
|
||||
</Text>
|
||||
{role.currentChannel && <Text type="secondary" style={{ fontSize: 12 }} ellipsis>{role.currentChannel}</Text>}
|
||||
{role.pendingName && (
|
||||
<>
|
||||
<Tag color="processing" style={{ marginInlineEnd: 0 }}>待确认 {role.pendingName}</Tag>
|
||||
{role.pendingChannel && <Text type="secondary" style={{ fontSize: 12 }} ellipsis>{role.pendingChannel}</Text>}
|
||||
</>
|
||||
)}
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
},
|
||||
{ title: '精英宝典', width: '13%', align: 'center', ellipsis: true, render: (_value, row) => { const task = latestTask(tasks, row.id); const opening = task?.result?.elite_opening === true; return <Space direction="vertical" align="center" size={0} style={{ width: '100%' }}><Tag color={opening ? 'processing' : row.elite_opened === true ? 'success' : row.elite_opened === false ? 'default' : undefined}>{opening ? '开通中' : row.elite_opened === true ? '已开通' : row.elite_opened === false ? '未开通' : '未查询'}</Tag>{row.elite_opened === true && row.elite_open_time ? <Text type="secondary" style={{ fontSize: 12 }} ellipsis>{`开通 ${formatUnixSeconds(row.elite_open_time)}`}</Text> : null}{row.elite_expire_time ? <Text type="secondary" style={{ fontSize: 12 }} ellipsis>{`有效期至 ${formatUnixSeconds(row.elite_expire_time)}`}</Text> : null}</Space>; } },
|
||||
{ title: '积分', dataIndex: 'points', width: '7%', align: 'center', render: (value: number | null) => value ?? <Text type="secondary">-</Text> },
|
||||
{ title: '最近操作', width: '25%', align: 'center', ellipsis: true, render: (_value, row) => { const task = latestTask(tasks, row.id); const expired = ckExpired(task, row); const records = taskResultRecords(task); return task ? <Space direction="vertical" align="center" size={1} style={{ width: '100%' }}><Text strong ellipsis>{TASK_LABELS[task.task_type] || task.task_type}</Text><Text type={expired ? 'danger' : 'secondary'} ellipsis title={task.message}>{task.message || '-'}</Text><Text type="secondary" style={{ fontSize: 12 }}>{formatTime(task.finished_at || task.created_at)}</Text>{task.task_type === 'query_exchange_records' && records.length > 0 && <Button size="small" type="link" onClick={(event) => { event.stopPropagation(); setRecordsTask(task); }}>查看记录</Button>}</Space> : <Text type="secondary">暂无操作</Text>; } },
|
||||
{ title: '最近操作', width: '18%', align: 'center', ellipsis: true, render: (_value, row) => { const task = latestTask(tasks, row.id); const expired = ckExpired(task, row); const records = taskResultRecords(task); return task ? <Space direction="vertical" align="center" size={1} style={{ width: '100%' }}><Text strong ellipsis>{TASK_LABELS[task.task_type] || task.task_type}</Text><Text type={expired ? 'danger' : 'secondary'} ellipsis title={task.message}>{task.message || '-'}</Text><Text type="secondary" style={{ fontSize: 12 }}>{formatTime(task.finished_at || task.created_at)}</Text>{task.task_type === 'query_exchange_records' && records.length > 0 && <Button size="small" type="link" onClick={(event) => { event.stopPropagation(); setRecordsTask(task); }}>查看记录</Button>}</Space> : <Text type="secondary">暂无操作</Text>; } },
|
||||
{ title: '二维码', width: '6%', align: 'center', render: (_value, row) => { const task = latestTask(tasks, row.id); if (!task) return <Text type="secondary">-</Text>; const url = taskQrUrl(task); const image = resultText(task, 'mini_qrcode_image'); if (task.task_type === 'get_bind_qr' && !image) { const hasMini = task.result?.has_mini_qrcode === true; if (!hasMini) return <Text type="secondary">-</Text>; return <div onClick={(event) => { event.stopPropagation(); void openQrTask(task); }} style={{ cursor: 'pointer', display: 'inline-block', lineHeight: 0, background: '#fff', padding: 6, borderRadius: 4 }} title="点击查看小程序码"><QrcodeOutlined style={{ fontSize: 26, color: '#000' }} /></div>; } if (!url && !image) return <Text type="secondary">-</Text>; const doneLabel = qrDoneLabel(task); if (doneLabel) return <Text type="secondary">{doneLabel}</Text>; return <div onClick={(event) => { event.stopPropagation(); if (!task) return; if (['create_recharge_order', 'exchange_goods'].includes(task.task_type)) setZoomPayTask(task); else void openQrTask(task); }} style={{ cursor: 'pointer', display: 'inline-block', lineHeight: 0, background: '#fff', padding: 3, borderRadius: 4 }} title="点击放大扫码">{image ? <img src={miniQrcodeSrc(image)} alt="二维码" style={{ width: 52, height: 52, objectFit: 'contain' }} /> : <QRCode value={url} size={52} type="svg" errorLevel="L" bordered={false} color="#000" bgColor="#fff" />}</div>; } },
|
||||
{ title: '状态', width: '7%', align: 'center', render: (_value, row) => { const task = latestTask(tasks, row.id); if (ckExpired(task, row)) return <Tooltip title={`${resultText(task, 'ck_expired_reason') || '角色信息查不到'} —— 请重新登录或重新导入 Cookie`}><Tag color="error">CK 失效</Tag></Tooltip>; const status = task?.status || row.status || ''; return <Tag color={TASK_COLORS[status] || 'default'}>{TASK_STATUS_LABELS[status] || status || '待操作'}</Tag>; } },
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user