1105 lines
44 KiB
Python
1105 lines
44 KiB
Python
"""Account login window for the doctor workstation."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from contextlib import suppress
|
|
from typing import Any
|
|
|
|
from PySide6.QtCore import QEvent, QPoint, QPointF, QRectF, QSettings, Qt, QTimer, Signal
|
|
from PySide6.QtGui import (
|
|
QColor,
|
|
QFont,
|
|
QIcon,
|
|
QPainter,
|
|
QPainterPath,
|
|
QPen,
|
|
QPixmap,
|
|
QResizeEvent,
|
|
)
|
|
from PySide6.QtWidgets import (
|
|
QApplication,
|
|
QCheckBox,
|
|
QFrame,
|
|
QHBoxLayout,
|
|
QLabel,
|
|
QLayout,
|
|
QLineEdit,
|
|
QMainWindow,
|
|
QPushButton,
|
|
QScrollArea,
|
|
QSizePolicy,
|
|
QSpinBox,
|
|
QStyle,
|
|
QStyleOptionButton,
|
|
QToolButton,
|
|
QVBoxLayout,
|
|
QWidget,
|
|
)
|
|
|
|
from doctor_workstation import __version__
|
|
from doctor_workstation.resources import app_icon_path, brand_lockup_path
|
|
|
|
from . import icons
|
|
from .design_system import PALETTE, clinical_stylesheet
|
|
from .widgets import BusyOverlay, MessageBanner, friendly_error, invoke, run_async
|
|
|
|
|
|
def _setting_bool(value: Any, default: bool = False) -> bool:
|
|
if isinstance(value, bool):
|
|
return value
|
|
if value is None:
|
|
return default
|
|
return str(value).strip().lower() in {"1", "true", "yes", "on", "y"}
|
|
|
|
|
|
class _VisibleCheckBox(QCheckBox):
|
|
"""Draw the check mark that Qt QSS omits from a colored indicator."""
|
|
|
|
def paintEvent(self, event: Any) -> None: # noqa: N802 - Qt API
|
|
super().paintEvent(event)
|
|
if not self.isChecked():
|
|
return
|
|
option = QStyleOptionButton()
|
|
self.initStyleOption(option)
|
|
indicator = self.style().subElementRect(
|
|
QStyle.SubElement.SE_CheckBoxIndicator,
|
|
option,
|
|
self,
|
|
)
|
|
painter = QPainter(self)
|
|
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
color = QColor("#FFFFFF" if self.isEnabled() else "#8E8F90")
|
|
painter.setPen(QPen(color, 2, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap))
|
|
painter.drawLine(
|
|
QPoint(indicator.left() + 4, indicator.center().y()),
|
|
QPoint(indicator.left() + 7, indicator.bottom() - 4),
|
|
)
|
|
painter.drawLine(
|
|
QPoint(indicator.left() + 7, indicator.bottom() - 4),
|
|
QPoint(indicator.right() - 3, indicator.top() + 4),
|
|
)
|
|
|
|
|
|
class _AccountLineEdit(QLineEdit):
|
|
"""Account field with the reference's 1.5 px, 20 px user outline."""
|
|
|
|
def paintEvent(self, event: Any) -> None: # noqa: N802 - Qt API
|
|
super().paintEvent(event)
|
|
painter = QPainter(self)
|
|
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
painter.setPen(_round_pen("#6A6B6D", 1.5))
|
|
painter.setBrush(Qt.BrushStyle.NoBrush)
|
|
painter.drawEllipse(QRectF(24, 14.5, 8, 8))
|
|
painter.drawRoundedRect(QRectF(19, 27, 18, 9), 4.5, 4.5)
|
|
|
|
|
|
class _DemoCheckBox(_VisibleCheckBox):
|
|
"""Demo option with the painted information mark visible in the comp."""
|
|
|
|
def paintEvent(self, event: Any) -> None: # noqa: N802 - Qt API
|
|
super().paintEvent(event)
|
|
painter = QPainter(self)
|
|
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
center = QPointF(self.width() - 9, self.height() / 2)
|
|
painter.setPen(_round_pen("#8E8F90", 1.4))
|
|
painter.setBrush(Qt.BrushStyle.NoBrush)
|
|
painter.drawEllipse(center, 7, 7)
|
|
painter.drawLine(center + QPointF(0, -1), center + QPointF(0, 4))
|
|
painter.drawPoint(center + QPointF(0, -4))
|
|
|
|
|
|
def _font(pixel_size: int, weight: QFont.Weight = QFont.Weight.Normal) -> QFont:
|
|
font = QFont(QApplication.font())
|
|
font.setPixelSize(pixel_size)
|
|
font.setWeight(weight)
|
|
return font
|
|
|
|
|
|
def _round_pen(color: QColor | str, width: float) -> QPen:
|
|
pen = QPen(QColor(color), width)
|
|
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
|
pen.setJoinStyle(Qt.PenJoinStyle.RoundJoin)
|
|
return pen
|
|
|
|
|
|
class _BrandPanel(QWidget):
|
|
"""A flat, readable introduction to the clinician's daily workflow."""
|
|
|
|
def __init__(self, parent: QWidget | None = None) -> None:
|
|
super().__init__(parent)
|
|
self.setObjectName("LoginBrandPanel")
|
|
self.setMinimumWidth(320)
|
|
self.setMaximumWidth(824)
|
|
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
|
self._brand_lockup = QPixmap(str(brand_lockup_path()))
|
|
|
|
def paintEvent(self, event: Any) -> None: # noqa: N802 - Qt API
|
|
del event
|
|
painter = QPainter(self)
|
|
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
bounds = QRectF(self.rect()).adjusted(1, 1, -1, -1)
|
|
painter.setPen(Qt.PenStyle.NoPen)
|
|
painter.setBrush(QColor(PALETTE["sidebar"]))
|
|
painter.drawRoundedRect(bounds, 20, 20)
|
|
left = 36.0
|
|
width = max(240.0, self.width() - 72.0)
|
|
if not self._brand_lockup.isNull():
|
|
brand = self._brand_lockup.scaled(
|
|
226, 58, Qt.AspectRatioMode.KeepAspectRatio,
|
|
Qt.TransformationMode.SmoothTransformation,
|
|
)
|
|
painter.drawPixmap(QPointF(left, 36), brand)
|
|
else:
|
|
painter.setFont(_font(22, QFont.Weight.DemiBold))
|
|
painter.setPen(QColor(PALETTE["heading"]))
|
|
painter.drawText(QPointF(left, 70), "甄养堂 · 医生工作站")
|
|
|
|
heading_y = max(158.0, min(218.0, self.height() * .27))
|
|
painter.setPen(QColor(PALETTE["muted"]))
|
|
painter.setFont(_font(13, QFont.Weight.Medium))
|
|
painter.drawText(QPointF(left, heading_y - 36), "医 生 工 作 台")
|
|
painter.setPen(QColor(PALETTE["heading"]))
|
|
painter.setFont(_font(30, QFont.Weight.DemiBold))
|
|
painter.drawText(QPointF(left, heading_y), "让诊疗有序,")
|
|
painter.drawText(QPointF(left, heading_y + 44), "让沟通更专注。")
|
|
painter.setFont(_font(14))
|
|
painter.setPen(QColor(PALETTE["muted"]))
|
|
painter.drawText(QPointF(left, heading_y + 82), "从接诊、病历到处方,在一个工作台完成。")
|
|
|
|
row_y = heading_y + 122
|
|
for index, (title, detail) in enumerate((
|
|
("今日接诊", "快速找到待接诊患者与预约安排"),
|
|
("诊疗记录", "病历、随访与面诊资料集中查看"),
|
|
("处方协作", "开方与审核流程清晰衔接"),
|
|
), start=1):
|
|
row = QRectF(left, row_y, width, 66)
|
|
painter.setPen(Qt.PenStyle.NoPen)
|
|
painter.setBrush(QColor(PALETTE["surface"]))
|
|
painter.drawRoundedRect(row, 12, 12)
|
|
painter.setFont(_font(13, QFont.Weight.DemiBold))
|
|
painter.setPen(QColor(PALETTE["accent"]))
|
|
painter.drawText(QRectF(left + 16, row_y, 28, 66), Qt.AlignmentFlag.AlignCenter, f"0{index}")
|
|
painter.setFont(_font(15, QFont.Weight.Medium))
|
|
painter.setPen(QColor(PALETTE["heading"]))
|
|
painter.drawText(QPointF(left + 58, row_y + 27), title)
|
|
painter.setFont(_font(12))
|
|
painter.setPen(QColor(PALETTE["muted"]))
|
|
painter.drawText(QPointF(left + 58, row_y + 47), detail)
|
|
row_y += 78
|
|
if self.height() > row_y + 50:
|
|
painter.setFont(_font(12))
|
|
painter.setPen(QColor(PALETTE["muted"]))
|
|
painter.drawText(QPointF(left, self.height() - 28), "仅供获授权的医疗人员使用")
|
|
painter.end()
|
|
|
|
|
|
class _PasswordField(QFrame):
|
|
"""Keep the grouped password control visibly focused for keyboard users."""
|
|
|
|
def eventFilter(self, watched: Any, event: QEvent) -> bool: # noqa: N802
|
|
if event.type() in (QEvent.Type.FocusIn, QEvent.Type.FocusOut):
|
|
self.setProperty("focused", event.type() == QEvent.Type.FocusIn)
|
|
self.style().unpolish(self)
|
|
self.style().polish(self)
|
|
self.update()
|
|
return super().eventFilter(watched, event)
|
|
|
|
|
|
class _RevealButton(QToolButton):
|
|
def paintEvent(self, event: Any) -> None: # noqa: N802 - Qt API
|
|
del event
|
|
painter = QPainter(self)
|
|
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
color = QColor("#6A6B6D" if self.isEnabled() else "#BDBDBE")
|
|
painter.setPen(_round_pen(color, 2))
|
|
painter.setBrush(Qt.BrushStyle.NoBrush)
|
|
eye = QPainterPath(QPointF(7, self.height() / 2))
|
|
eye.cubicTo(
|
|
12, self.height() / 2 - 8, 20, self.height() / 2 - 8, 25, self.height() / 2
|
|
)
|
|
eye.cubicTo(
|
|
20, self.height() / 2 + 8, 12, self.height() / 2 + 8, 7, self.height() / 2
|
|
)
|
|
painter.drawPath(eye)
|
|
painter.drawEllipse(QPointF(16, self.height() / 2), 3.2, 3.2)
|
|
painter.setFont(_font(16))
|
|
painter.drawText(
|
|
QRectF(33, 0, self.width() - 36, self.height()),
|
|
Qt.AlignmentFlag.AlignCenter,
|
|
self.text(),
|
|
)
|
|
|
|
|
|
class _ServerButton(QPushButton):
|
|
def paintEvent(self, event: Any) -> None: # noqa: N802 - Qt API
|
|
del event
|
|
painter = QPainter(self)
|
|
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
rect = QRectF(self.rect()).adjusted(0.75, 0.75, -0.75, -0.75)
|
|
painter.setBrush(QColor(PALETTE["accent_soft"] if self.underMouse() else PALETTE["surface"]))
|
|
painter.setPen(QPen(QColor(PALETTE["focus"] if self.hasFocus() else PALETTE["line_strong"]), 1))
|
|
painter.drawRoundedRect(rect, 12, 12)
|
|
color = QColor("#1A1C1F" if self.isEnabled() else "#8E8F90")
|
|
painter.setPen(_round_pen("#6A6B6D", 1.8))
|
|
center = QPointF(29, self.height() / 2)
|
|
painter.drawEllipse(center, 8, 8)
|
|
painter.drawEllipse(center, 2.8, 2.8)
|
|
for dx, dy in (
|
|
(0, -12),
|
|
(0, 12),
|
|
(-12, 0),
|
|
(12, 0),
|
|
(-8.5, -8.5),
|
|
(8.5, -8.5),
|
|
(-8.5, 8.5),
|
|
(8.5, 8.5),
|
|
):
|
|
painter.drawLine(
|
|
center + QPointF(dx * 0.65, dy * 0.65), center + QPointF(dx, dy)
|
|
)
|
|
painter.setFont(_font(17, QFont.Weight.Medium))
|
|
painter.setPen(color)
|
|
painter.drawText(
|
|
QRectF(51, 0, self.width() - 95, self.height()),
|
|
Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignLeft,
|
|
"服务器设置",
|
|
)
|
|
painter.setPen(_round_pen("#8E8F90", 2))
|
|
x, y = self.width() - 28, self.height() / 2
|
|
if self.isChecked():
|
|
painter.drawLine(QPointF(x - 5, y + 3), QPointF(x, y - 3))
|
|
painter.drawLine(QPointF(x, y - 3), QPointF(x + 5, y + 3))
|
|
else:
|
|
painter.drawLine(QPointF(x - 3, y - 5), QPointF(x + 3, y))
|
|
painter.drawLine(QPointF(x + 3, y), QPointF(x - 3, y + 5))
|
|
|
|
|
|
class LoginWindow(QMainWindow):
|
|
"""A responsive login surface with optional demo-repository switching.
|
|
|
|
``login_succeeded`` emits a dictionary containing ``user``, ``session``,
|
|
``repository`` and ``demo_mode``. Keeping the selected repository in the
|
|
payload lets the composition root construct the shell without guessing.
|
|
The remember-password choice is captured before the worker starts. The
|
|
repository receives the corresponding account-metadata flag, while this
|
|
window stores the password only after authentication succeeds.
|
|
"""
|
|
|
|
login_succeeded = Signal(object)
|
|
authenticated = Signal(object)
|
|
login_failed = Signal(str)
|
|
server_settings_changed = Signal(dict)
|
|
config_changed = Signal(object)
|
|
demo_mode_changed = Signal(bool)
|
|
|
|
def __init__(
|
|
self,
|
|
repository: Any,
|
|
config: Any | None = None,
|
|
demo_repository: Any | None = None,
|
|
settings: QSettings | None = None,
|
|
credential_store: Any | None = None,
|
|
parent: QWidget | None = None,
|
|
) -> None:
|
|
super().__init__(parent)
|
|
self.repository = repository
|
|
self.config = config
|
|
self.debug_mode = bool(getattr(config, "debug_mode", False))
|
|
if demo_repository is None:
|
|
demo_repository = getattr(config, "demo_repository", None)
|
|
self.demo_repository = demo_repository
|
|
self.settings = settings or QSettings("ZhenYangTang", "DoctorWorkstation")
|
|
self.credential_store = credential_store
|
|
self.active_repository = repository
|
|
self.authenticated_user: Any = None
|
|
self._loading = False
|
|
self._restored_account = ""
|
|
self._restored_scope = ""
|
|
|
|
self.setWindowTitle("甄养堂 · 医生工作站 - 甄养堂医生工作站")
|
|
self.setWindowIcon(self._window_icon())
|
|
self.setMinimumSize(860, 590)
|
|
self.resize(1280, 800)
|
|
|
|
canvas = QWidget()
|
|
canvas.setObjectName("LoginCanvas")
|
|
canvas.setStyleSheet(
|
|
"""
|
|
QWidget#LoginCanvas {
|
|
color: #1A1C1F;
|
|
background-color: #F4F6FA;
|
|
font-size: 16px;
|
|
}
|
|
QWidget#LoginBrandPanel {
|
|
background-color: transparent;
|
|
border: 0;
|
|
}
|
|
QFrame#LoginCard {
|
|
background-color: #FFFFFF;
|
|
border: 1px solid #EDEDEE;
|
|
border-radius: 20px;
|
|
}
|
|
QFrame#LoginCard QFrame#SubtleCard {
|
|
background-color: #FFFFFF;
|
|
border: 1px solid #E4E4E5;
|
|
border-radius: 12px;
|
|
}
|
|
QFrame#LoginCard QLabel { color: #1A1C1F; background: transparent; }
|
|
QFrame#LoginCard QLabel[role="muted"] { color: #606163; }
|
|
QFrame#LoginCard QLabel[role="danger"] { color: #C43E55; }
|
|
QFrame#LoginCard QCheckBox#AllowSelfSignedCertificate { color: #9A6813; }
|
|
QFrame#LoginCard QLineEdit,
|
|
QFrame#LoginCard QSpinBox {
|
|
color: #1A1C1F;
|
|
background-color: #FFFFFF;
|
|
border: 1px solid #E4E4E5;
|
|
border-radius: 12px;
|
|
padding: 0 16px;
|
|
font-size: 17px;
|
|
selection-background-color: #EEF1FA;
|
|
selection-color: #1A1C1F;
|
|
}
|
|
QFrame#LoginCard QLineEdit#AccountEdit {
|
|
min-height: 52px;
|
|
max-height: 52px;
|
|
padding-left: 52px;
|
|
}
|
|
QFrame#LoginCard QLineEdit:hover,
|
|
QFrame#LoginCard QSpinBox:hover { border-color: #8B9AD9; }
|
|
QFrame#LoginCard QLineEdit:focus,
|
|
QFrame#LoginCard QSpinBox:focus { border: 1.5px solid #8B9AD9; }
|
|
QFrame#LoginCard QLineEdit#PasswordEdit {
|
|
border: 0;
|
|
border-radius: 0;
|
|
background: transparent;
|
|
padding: 0;
|
|
}
|
|
QFrame#LoginCard QCheckBox#DemoModeCheck { spacing: 10px; }
|
|
QFrame#PasswordField {
|
|
background-color: #FFFFFF;
|
|
border: 1px solid #E4E4E5;
|
|
border-radius: 12px;
|
|
}
|
|
QFrame#PasswordField[focused="true"] { border-color: #8B9AD9; }
|
|
QFrame#LoginCard QCheckBox {
|
|
color: #606163;
|
|
spacing: 13px;
|
|
font-size: 16px;
|
|
}
|
|
QFrame#LoginCard QCheckBox::indicator {
|
|
width: 22px;
|
|
height: 22px;
|
|
border: 1px solid #E4E4E5;
|
|
border-radius: 6px;
|
|
background-color: #FFFFFF;
|
|
}
|
|
QFrame#LoginCard QCheckBox::indicator:hover { border-color: #8B9AD9; }
|
|
QFrame#LoginCard QCheckBox::indicator:checked {
|
|
border-color: #4F63D9;
|
|
background-color: #4F63D9;
|
|
}
|
|
QFrame#LoginCard QToolButton#PasswordReveal {
|
|
min-width: 87px;
|
|
max-width: 87px;
|
|
color: #6A6B6D;
|
|
background: transparent;
|
|
border: 0;
|
|
padding: 0;
|
|
}
|
|
QFrame#LoginCard QPushButton[variant="primary"] {
|
|
min-height: 58px;
|
|
max-height: 58px;
|
|
color: #FFFFFF;
|
|
background-color: #4F63D9;
|
|
border: 0;
|
|
border-radius: 12px;
|
|
font-size: 18px;
|
|
font-weight: 500;
|
|
}
|
|
QFrame#LoginCard QPushButton#ServerSettingsToggle {
|
|
min-height: 56px;
|
|
max-height: 56px;
|
|
padding: 0;
|
|
}
|
|
QFrame#LoginCard QPushButton[variant="primary"]:hover {
|
|
background-color: #4156C4;
|
|
}
|
|
QFrame#LoginCard QPushButton[variant="secondary"] {
|
|
color: #1A1C1F;
|
|
background-color: #F0F0F0;
|
|
border: 1px solid #E4E4E5;
|
|
border-radius: 9px;
|
|
}
|
|
QFrame#LoginCard QPushButton[variant="secondary"]:hover {
|
|
background-color: #E4E4E5;
|
|
border-color: #8B9AD9;
|
|
}
|
|
QScrollArea#LoginAreaScroll,
|
|
QScrollArea#LoginAreaScroll > QWidget > QWidget {
|
|
border: 0;
|
|
background-color: transparent;
|
|
}
|
|
"""
|
|
)
|
|
self.setCentralWidget(canvas)
|
|
self.login_root = QHBoxLayout(canvas)
|
|
self.login_root.setContentsMargins(36, 34, 36, 36)
|
|
self.login_root.setSpacing(82)
|
|
|
|
self.brand_panel = self._build_brand_panel()
|
|
self.login_root.addWidget(self.brand_panel, 60)
|
|
self.login_root.addWidget(self._build_login_area(), 40)
|
|
self._restore_settings()
|
|
for widget in (canvas, *canvas.findChildren(QWidget)):
|
|
if widget.styleSheet():
|
|
widget.setStyleSheet(clinical_stylesheet(widget.styleSheet()))
|
|
|
|
def resizeEvent(self, event: QResizeEvent) -> None: # noqa: N802 - Qt API
|
|
"""Preserve the reference composition while remaining usable on small screens."""
|
|
|
|
width = event.size().width()
|
|
if width >= 1320:
|
|
margins = (36, 34, 36, 36)
|
|
spacing = 82
|
|
elif width >= 1040:
|
|
margins = (26, 26, 26, 26)
|
|
spacing = 40
|
|
else:
|
|
margins = (18, 18, 18, 18)
|
|
spacing = 20
|
|
self.login_root.setContentsMargins(*margins)
|
|
self.login_root.setSpacing(spacing)
|
|
# Keep the form fully visible when the 60/40 desktop split would
|
|
# otherwise crop its fixed-width card. Small windows focus on login.
|
|
self.brand_panel.setVisible(width >= 1120)
|
|
compact_height = event.size().height() < 720
|
|
self.card.setMinimumHeight(580 if compact_height else 620)
|
|
self.login_area_layout.setContentsMargins(
|
|
0, 12 if compact_height else min(104, max(24, (event.size().height() - 694) // 2)), 0, 12
|
|
)
|
|
super().resizeEvent(event)
|
|
|
|
def _build_brand_panel(self) -> QWidget:
|
|
panel = _BrandPanel()
|
|
return panel
|
|
|
|
def _build_login_area(self) -> QWidget:
|
|
area = QScrollArea()
|
|
area.setObjectName("LoginAreaScroll")
|
|
area.setWidgetResizable(True)
|
|
area.setFrameShape(QFrame.Shape.NoFrame)
|
|
area.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
|
area.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
|
area.setMinimumWidth(492)
|
|
content = QWidget()
|
|
content.setObjectName("LoginAreaContent")
|
|
area.setWidget(content)
|
|
self.login_scroll = area
|
|
outer = QVBoxLayout(content)
|
|
self.login_area_layout = outer
|
|
outer.setContentsMargins(0, 40, 0, 12)
|
|
|
|
self.card = QFrame()
|
|
self.card.setObjectName("LoginCard")
|
|
self.card.setFixedWidth(480)
|
|
self.card.setMinimumHeight(620)
|
|
self.card.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Minimum)
|
|
card_layout = QVBoxLayout(self.card)
|
|
card_layout.setSizeConstraint(QLayout.SizeConstraint.SetDefaultConstraint)
|
|
card_layout.setContentsMargins(47, 42, 47, 26)
|
|
card_layout.setSpacing(0)
|
|
card_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
|
|
|
title = QLabel("欢迎回来")
|
|
title.setObjectName("LoginTitle")
|
|
title.setStyleSheet("color:#1A1C1F; font-size:26px; font-weight:600;")
|
|
title.setContentsMargins(1, -3, 0, 3)
|
|
title.setFixedHeight(46)
|
|
card_layout.addWidget(title)
|
|
subtitle = QLabel("使用医生账号登录工作站")
|
|
subtitle.setProperty("role", "muted")
|
|
subtitle.setStyleSheet("color:#606163; font-size:15px;")
|
|
subtitle.setContentsMargins(1, 8, 0, 0)
|
|
subtitle.setFixedHeight(27)
|
|
card_layout.addWidget(subtitle)
|
|
card_layout.addSpacing(34)
|
|
|
|
self.error_banner = MessageBanner()
|
|
card_layout.addWidget(self.error_banner)
|
|
|
|
account_label = QLabel("账号")
|
|
account_label.setStyleSheet("color:#1A1C1F; font-size:16px; font-weight:500;")
|
|
account_label.setContentsMargins(0, -2, 0, 2)
|
|
account_label.setFixedHeight(24)
|
|
card_layout.addWidget(account_label)
|
|
card_layout.addSpacing(14)
|
|
self.account_edit = _AccountLineEdit()
|
|
self.account_edit.setObjectName("AccountEdit")
|
|
self.account_edit.setPlaceholderText("手机号或工作账号")
|
|
self.account_edit.setClearButtonEnabled(True)
|
|
self.account_edit.setAccessibleName("登录账号")
|
|
self.account_edit.setFixedHeight(54)
|
|
self.account_edit.setTextMargins(0, 0, 0, 0)
|
|
card_layout.addWidget(self.account_edit)
|
|
card_layout.addSpacing(21)
|
|
|
|
password_label = QLabel("密码")
|
|
password_label.setStyleSheet("color:#1A1C1F; font-size:16px; font-weight:500;")
|
|
password_label.setContentsMargins(0, -3, 0, 3)
|
|
password_label.setFixedHeight(24)
|
|
card_layout.addWidget(password_label)
|
|
card_layout.addSpacing(11)
|
|
password_field = _PasswordField()
|
|
password_field.setObjectName("PasswordField")
|
|
password_field.setFixedHeight(54)
|
|
password_row = QHBoxLayout(password_field)
|
|
password_row.setContentsMargins(16, 0, 8, 0)
|
|
password_row.setSpacing(0)
|
|
self.password_edit = QLineEdit()
|
|
self.password_edit.setObjectName("PasswordEdit")
|
|
self.password_edit.setEchoMode(QLineEdit.EchoMode.Password)
|
|
self.password_edit.setPlaceholderText("请输入密码")
|
|
self.password_edit.setAccessibleName("登录密码")
|
|
self.password_edit.installEventFilter(password_field)
|
|
self.password_edit.setTextMargins(0, -2, 0, 2)
|
|
self.password_edit.returnPressed.connect(self.submit)
|
|
password_row.addWidget(self.password_edit, 1)
|
|
self.reveal_button = _RevealButton()
|
|
self.reveal_button.setObjectName("PasswordReveal")
|
|
self.reveal_button.setText("显示")
|
|
self.reveal_button.setCheckable(True)
|
|
self.reveal_button.setFixedSize(87, 52)
|
|
self.reveal_button.setToolTip("显示或隐藏密码")
|
|
self.reveal_button.installEventFilter(password_field)
|
|
self.reveal_button.toggled.connect(self._toggle_password)
|
|
password_row.addWidget(self.reveal_button)
|
|
card_layout.addWidget(password_field)
|
|
card_layout.addSpacing(20)
|
|
|
|
choices = QHBoxLayout()
|
|
choices.setContentsMargins(0, 0, 0, 0)
|
|
self.remember_check = _VisibleCheckBox("记住密码")
|
|
self.remember_check.setToolTip(
|
|
"密码使用系统安全凭据或 Windows DPAPI 加密,不保存明文"
|
|
)
|
|
choices.addWidget(self.remember_check)
|
|
choices.addStretch(1)
|
|
self.demo_check = _DemoCheckBox("演示模式")
|
|
self.demo_check.setObjectName("DemoModeCheck")
|
|
self.demo_check.setFixedWidth(133)
|
|
self.demo_check.setEnabled(self.demo_repository is not None)
|
|
if self.demo_repository is None:
|
|
self.demo_check.setToolTip("当前未配置演示数据")
|
|
self.demo_check.toggled.connect(self._on_demo_toggled)
|
|
self.demo_check.setVisible(self.debug_mode)
|
|
choices.addWidget(self.demo_check)
|
|
card_layout.addLayout(choices)
|
|
card_layout.addSpacing(26)
|
|
|
|
self.login_button = QPushButton("登录工作站")
|
|
self.login_button.setProperty("variant", "primary")
|
|
self.login_button.setFixedHeight(58)
|
|
self.login_button.clicked.connect(self.submit)
|
|
card_layout.addWidget(self.login_button)
|
|
self.debug_settings_section = QWidget()
|
|
self.debug_settings_section.setObjectName("DebugSettingsSection")
|
|
debug_settings_layout = QVBoxLayout(self.debug_settings_section)
|
|
debug_settings_layout.setContentsMargins(0, 0, 0, 0)
|
|
debug_settings_layout.setSpacing(0)
|
|
debug_settings_layout.addSpacing(20)
|
|
divider = QHBoxLayout()
|
|
divider.setSpacing(18)
|
|
line_left = QFrame()
|
|
line_left.setFrameShape(QFrame.Shape.HLine)
|
|
line_left.setStyleSheet("color:#EDEDEE; background:#EDEDEE; max-height:1px;")
|
|
divider.addWidget(line_left, 1)
|
|
divider_text = QLabel("或")
|
|
divider_text.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
divider_text.setStyleSheet("color:#6A6B6D; font-size:16px;")
|
|
divider_text.setFixedSize(38, 22)
|
|
divider.addWidget(divider_text)
|
|
line_right = QFrame()
|
|
line_right.setFrameShape(QFrame.Shape.HLine)
|
|
line_right.setStyleSheet("color:#EDEDEE; background:#EDEDEE; max-height:1px;")
|
|
divider.addWidget(line_right, 1)
|
|
debug_settings_layout.addLayout(divider)
|
|
debug_settings_layout.addSpacing(20)
|
|
|
|
self.server_toggle = _ServerButton("服务器设置 +")
|
|
self.server_toggle.setObjectName("ServerSettingsToggle")
|
|
self.server_toggle.setProperty("variant", "ghost")
|
|
self.server_toggle.setCheckable(True)
|
|
self.server_toggle.setFixedHeight(56)
|
|
self.server_toggle.clicked.connect(self._toggle_server_panel)
|
|
debug_settings_layout.addWidget(self.server_toggle)
|
|
|
|
self.server_panel = QFrame()
|
|
self.server_panel.setObjectName("SubtleCard")
|
|
self.server_panel.setSizePolicy(
|
|
QSizePolicy.Policy.Expanding,
|
|
QSizePolicy.Policy.Minimum,
|
|
)
|
|
server_layout = QVBoxLayout(self.server_panel)
|
|
server_layout.setSizeConstraint(QLayout.SizeConstraint.SetMinimumSize)
|
|
server_layout.setContentsMargins(14, 12, 14, 12)
|
|
server_layout.setSpacing(8)
|
|
self.server_url_label = QLabel("服务器地址")
|
|
self.server_url_label.setObjectName("ServerUrlLabel")
|
|
server_layout.addWidget(self.server_url_label)
|
|
self.server_url_edit = QLineEdit()
|
|
self.server_url_edit.setPlaceholderText("例如 https://api.example.com")
|
|
self.server_url_edit.setMinimumHeight(38)
|
|
self.server_url_edit.setAccessibleName("服务器地址")
|
|
server_layout.addWidget(self.server_url_edit)
|
|
timeout_row = QHBoxLayout()
|
|
timeout_row.setSpacing(10)
|
|
self.timeout_label = QLabel("读取超时")
|
|
timeout_row.addWidget(self.timeout_label)
|
|
self.timeout_spin = QSpinBox()
|
|
self.timeout_spin.setRange(10, 180)
|
|
self.timeout_spin.setSuffix(" 秒")
|
|
self.timeout_spin.setValue(60)
|
|
self.timeout_spin.setFixedWidth(128)
|
|
timeout_row.addWidget(self.timeout_spin)
|
|
timeout_row.addStretch(1)
|
|
self.save_server_button = QPushButton("保存设置")
|
|
self.save_server_button.setProperty("variant", "secondary")
|
|
self.save_server_button.setMinimumWidth(112)
|
|
self.save_server_button.clicked.connect(self._save_server_settings)
|
|
timeout_row.addWidget(self.save_server_button)
|
|
server_layout.addLayout(timeout_row)
|
|
self.allow_self_signed_check = _VisibleCheckBox("信任自签名证书(仅内网调试)")
|
|
self.allow_self_signed_check.setObjectName("AllowSelfSignedCertificate")
|
|
self.allow_self_signed_check.setToolTip(
|
|
"关闭 HTTPS 证书校验会降低连接安全性,仅用于可信内网的自签名服务器"
|
|
)
|
|
server_layout.addWidget(self.allow_self_signed_check)
|
|
self.ssl_warning = QLabel(
|
|
"启用后将不再验证服务器身份,请勿用于公网或正式生产环境。"
|
|
)
|
|
self.ssl_warning.setObjectName("SelfSignedCertificateWarning")
|
|
self.ssl_warning.setProperty("role", "danger")
|
|
self.ssl_warning.setWordWrap(True)
|
|
self.ssl_warning.setVisible(False)
|
|
self.allow_self_signed_check.toggled.connect(self.ssl_warning.setVisible)
|
|
server_layout.addWidget(self.ssl_warning)
|
|
self.server_hint = QLabel(
|
|
"填写管理员提供的 HTTPS 域名,程序会自动追加 /adminapi。"
|
|
)
|
|
self.server_hint.setProperty("role", "muted")
|
|
self.server_hint.setWordWrap(True)
|
|
server_layout.addWidget(self.server_hint)
|
|
self.server_panel.setVisible(False)
|
|
debug_settings_layout.addSpacing(9)
|
|
debug_settings_layout.addWidget(self.server_panel)
|
|
debug_settings_layout.addSpacing(12)
|
|
self.debug_settings_section.setVisible(self.debug_mode)
|
|
card_layout.addWidget(self.debug_settings_section)
|
|
|
|
footnote_row = QHBoxLayout()
|
|
footnote_row.setContentsMargins(0, 0, 0, 0)
|
|
footnote_row.setSpacing(10)
|
|
lock = QLabel()
|
|
lock.setPixmap(self._lock_icon().pixmap(19, 19))
|
|
lock.setFixedSize(19, 40)
|
|
lock.setAlignment(Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignHCenter)
|
|
lock.setContentsMargins(0, 7, 0, 0)
|
|
footnote_row.addWidget(lock)
|
|
footnote = QLabel("登录即表示你同意遵守机构的数据安全与隐私规范。")
|
|
footnote.setProperty("role", "muted")
|
|
footnote.setStyleSheet("color:#6A6B6D; font-size:15px;")
|
|
footnote.setContentsMargins(0, -4, 0, 4)
|
|
footnote.setWordWrap(True)
|
|
footnote.setFixedHeight(40)
|
|
footnote_row.addWidget(footnote, 1)
|
|
card_layout.addLayout(footnote_row)
|
|
self.version_label = QLabel(f"当前版本 {__version__}")
|
|
self.version_label.setObjectName("LoginVersionLabel")
|
|
self.version_label.setProperty("role", "muted")
|
|
self.version_label.setStyleSheet("color:#6A6B6D; font-size:13px;")
|
|
self.version_label.setContentsMargins(0, 8, 0, 0)
|
|
card_layout.addWidget(self.version_label, 0, Qt.AlignmentFlag.AlignRight)
|
|
|
|
outer.addWidget(
|
|
self.card, 0, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop
|
|
)
|
|
outer.addStretch(1)
|
|
self.busy_overlay = BusyOverlay(self.card, "正在验证账号…")
|
|
return area
|
|
|
|
@staticmethod
|
|
def _window_icon() -> QIcon:
|
|
return QIcon(str(app_icon_path()))
|
|
|
|
@staticmethod
|
|
def _account_icon() -> QIcon:
|
|
return icons.icon("user", "muted", 24)
|
|
|
|
@staticmethod
|
|
def _lock_icon() -> QIcon:
|
|
return icons.icon("lock", "muted", 20)
|
|
|
|
def _restore_settings(self) -> None:
|
|
configured_account = getattr(self.config, "remembered_account", "")
|
|
remembered = str(
|
|
self.settings.value("auth/remembered_account", configured_account) or ""
|
|
)
|
|
configured_url = getattr(self.config, "base_url", "") or getattr(
|
|
self.config, "api_base_url", ""
|
|
)
|
|
restored_url = (
|
|
self.settings.value("server/base_url", configured_url)
|
|
if self.debug_mode
|
|
else configured_url
|
|
)
|
|
self.server_url_edit.setText(
|
|
str(restored_url or "")
|
|
)
|
|
try:
|
|
configured_timeout = getattr(self.config, "request_timeout", 60)
|
|
timeout = int(
|
|
self.settings.value("server/read_timeout", configured_timeout)
|
|
or configured_timeout
|
|
)
|
|
except (TypeError, ValueError):
|
|
timeout = 60
|
|
self.timeout_spin.setValue(max(10, min(180, timeout)))
|
|
configured_verify_ssl = _setting_bool(
|
|
getattr(self.config, "verify_ssl", True), True
|
|
)
|
|
verify_ssl = (
|
|
_setting_bool(
|
|
self.settings.value("server/verify_ssl", configured_verify_ssl),
|
|
configured_verify_ssl,
|
|
)
|
|
if self.debug_mode
|
|
else configured_verify_ssl
|
|
)
|
|
self.allow_self_signed_check.setChecked(not verify_ssl)
|
|
if self.debug_mode and self.demo_repository is not None and bool(
|
|
getattr(self.config, "demo_mode", False)
|
|
):
|
|
self.demo_check.setChecked(True)
|
|
elif not self.debug_mode:
|
|
self.demo_check.setChecked(False)
|
|
self.active_repository = self.repository
|
|
self.account_edit.setText(remembered)
|
|
self.restore_remembered_credentials()
|
|
if remembered:
|
|
self.password_edit.setFocus()
|
|
else:
|
|
self.account_edit.setFocus()
|
|
|
|
def _credential_scope(self) -> str:
|
|
if not self.debug_mode:
|
|
return str(getattr(self.config, "api_base_url", "") or "").strip().rstrip("/")
|
|
if hasattr(self, "server_url_edit"):
|
|
scope = self.server_url_edit.text().strip()
|
|
if scope:
|
|
return scope.rstrip("/")
|
|
return (
|
|
str(
|
|
getattr(self.config, "base_url", "")
|
|
or getattr(self.config, "api_base_url", "")
|
|
or ""
|
|
)
|
|
.strip()
|
|
.rstrip("/")
|
|
)
|
|
|
|
def restore_remembered_credentials(self) -> None:
|
|
"""Restore a password from the OS keyring without touching config files."""
|
|
|
|
configured_account = getattr(self.config, "remembered_account", "")
|
|
account = str(
|
|
self.settings.value("auth/remembered_account", configured_account) or ""
|
|
).strip()
|
|
scope = self._credential_scope()
|
|
password = ""
|
|
should_restore = _setting_bool(
|
|
self.settings.value("auth/remember_password", False),
|
|
False,
|
|
)
|
|
loader = getattr(self.credential_store, "load_password", None)
|
|
if should_restore and account and scope and callable(loader):
|
|
try:
|
|
password = str(loader(account=account, scope=scope) or "")
|
|
except Exception:
|
|
password = ""
|
|
self.account_edit.setText(account)
|
|
self.password_edit.setText(password)
|
|
self.remember_check.setChecked(bool(password))
|
|
self._restored_account = account if password else ""
|
|
self._restored_scope = scope if password else ""
|
|
|
|
def _toggle_password(self, visible: bool) -> None:
|
|
self.password_edit.setEchoMode(
|
|
QLineEdit.EchoMode.Normal if visible else QLineEdit.EchoMode.Password
|
|
)
|
|
self.reveal_button.setText("隐藏" if visible else "显示")
|
|
|
|
def _on_demo_toggled(self, enabled: bool) -> None:
|
|
if enabled and not self.debug_mode:
|
|
self.demo_check.blockSignals(True)
|
|
self.demo_check.setChecked(False)
|
|
self.demo_check.blockSignals(False)
|
|
self.active_repository = self.repository
|
|
return
|
|
self.active_repository = self.demo_repository if enabled else self.repository
|
|
self.server_toggle.setEnabled(not enabled and not self._loading)
|
|
self.demo_mode_changed.emit(enabled)
|
|
self._emit_config_update(demo_mode=enabled)
|
|
self.error_banner.clear()
|
|
if enabled:
|
|
self.account_edit.setPlaceholderText("可留空,使用演示医生")
|
|
self.password_edit.setPlaceholderText("可留空")
|
|
else:
|
|
self.account_edit.setPlaceholderText("手机号或工作账号")
|
|
self.password_edit.setPlaceholderText("请输入密码")
|
|
|
|
def _toggle_server_panel(self, expanded: bool) -> None:
|
|
if not self.debug_mode:
|
|
self.server_toggle.setChecked(False)
|
|
self.server_panel.hide()
|
|
return
|
|
self.server_panel.setVisible(expanded)
|
|
self.server_toggle.setText("服务器设置 -" if expanded else "服务器设置 +")
|
|
self.server_panel.updateGeometry()
|
|
self.card.updateGeometry()
|
|
if expanded:
|
|
QTimer.singleShot(
|
|
0,
|
|
lambda: self.login_scroll.ensureWidgetVisible(self.server_panel, 0, 24),
|
|
)
|
|
|
|
def _save_server_settings(self) -> None:
|
|
self._apply_server_settings(announce=True)
|
|
|
|
def _apply_server_settings(self, *, announce: bool) -> bool:
|
|
if not self.debug_mode:
|
|
base_url = str(getattr(self.config, "api_base_url", "") or "").strip()
|
|
if base_url:
|
|
self.server_url_edit.setText(base_url)
|
|
return True
|
|
self.error_banner.show_message("线上服务器地址尚未配置,请联系管理员。", "warning")
|
|
return False
|
|
base_url = self.server_url_edit.text().strip().rstrip("/")
|
|
if base_url and not base_url.startswith(
|
|
("https://", "http://localhost", "http://127.0.0.1")
|
|
):
|
|
self.error_banner.show_message(
|
|
"服务地址需使用 HTTPS;本机调试可使用 localhost。", "warning"
|
|
)
|
|
return False
|
|
values = {
|
|
"base_url": base_url,
|
|
"read_timeout": self.timeout_spin.value(),
|
|
"api_base_url": base_url,
|
|
"request_timeout": self.timeout_spin.value(),
|
|
"verify_ssl": not self.allow_self_signed_check.isChecked(),
|
|
}
|
|
self.settings.setValue("server/base_url", base_url)
|
|
self.settings.setValue("server/read_timeout", self.timeout_spin.value())
|
|
self.settings.setValue("server/verify_ssl", values["verify_ssl"])
|
|
self.settings.sync()
|
|
self.server_settings_changed.emit(values)
|
|
self._emit_config_update(
|
|
api_base_url=base_url,
|
|
request_timeout=self.timeout_spin.value(),
|
|
verify_ssl=values["verify_ssl"],
|
|
)
|
|
if not announce:
|
|
return True
|
|
if values["verify_ssl"]:
|
|
self.error_banner.show_message(
|
|
"服务器设置已保存,将在连接时生效。", "success"
|
|
)
|
|
else:
|
|
self.error_banner.show_message(
|
|
"服务器设置已保存:证书校验已关闭,仅限可信内网调试。", "warning"
|
|
)
|
|
return True
|
|
|
|
def _emit_config_update(self, **changes: Any) -> None:
|
|
updater = getattr(self.config, "with_updates", None)
|
|
if callable(updater):
|
|
try:
|
|
self.config = updater(**changes)
|
|
except (TypeError, ValueError):
|
|
self.config_changed.emit(changes)
|
|
else:
|
|
self.config_changed.emit(self.config)
|
|
return
|
|
self.config_changed.emit(changes)
|
|
|
|
def submit(self) -> None:
|
|
if self._loading:
|
|
return
|
|
demo_mode = self.debug_mode and self.demo_check.isChecked()
|
|
remember_account = self.remember_check.isChecked()
|
|
account = self.account_edit.text().strip()
|
|
password = self.password_edit.text()
|
|
if demo_mode:
|
|
account = account or str(
|
|
getattr(self.active_repository, "DEMO_ACCOUNT", "doctor")
|
|
)
|
|
password = password or str(
|
|
getattr(self.active_repository, "DEMO_PASSWORD", "doctor123")
|
|
)
|
|
if not account:
|
|
self.error_banner.show_message("请输入登录账号。", "warning")
|
|
self.account_edit.setFocus()
|
|
return
|
|
if not password:
|
|
self.error_banner.show_message("请输入密码。", "warning")
|
|
self.password_edit.setFocus()
|
|
return
|
|
if not demo_mode and not self._apply_server_settings(announce=False):
|
|
return
|
|
repository = self.active_repository
|
|
if repository is None:
|
|
self.error_banner.show_message("演示服务尚未配置。", "warning")
|
|
return
|
|
|
|
self.error_banner.clear()
|
|
self._set_loading(True)
|
|
|
|
def authenticate() -> dict[str, Any]:
|
|
session = invoke(
|
|
repository,
|
|
"login",
|
|
account=account,
|
|
password=password,
|
|
remember_account=remember_account,
|
|
)
|
|
user = invoke(repository, "get_current_user")
|
|
return {
|
|
"session": session,
|
|
"user": user,
|
|
"repository": repository,
|
|
"demo_mode": demo_mode,
|
|
"remember_account": remember_account,
|
|
}
|
|
|
|
run_async(
|
|
authenticate,
|
|
on_success=lambda payload: self._on_login_success(
|
|
payload,
|
|
account,
|
|
remember_account,
|
|
password,
|
|
),
|
|
on_error=self._on_login_error,
|
|
on_finished=lambda: self._set_loading(False),
|
|
)
|
|
|
|
def _set_loading(
|
|
self,
|
|
loading: bool,
|
|
*,
|
|
button_text: str = "正在登录…",
|
|
overlay_text: str = "正在验证账号…",
|
|
) -> None:
|
|
self._loading = loading
|
|
self.login_button.setEnabled(not loading)
|
|
self.account_edit.setEnabled(not loading)
|
|
self.password_edit.setEnabled(not loading)
|
|
self.remember_check.setEnabled(not loading)
|
|
self.reveal_button.setEnabled(not loading)
|
|
self.demo_check.setEnabled(
|
|
self.debug_mode and not loading and self.demo_repository is not None
|
|
)
|
|
self.server_toggle.setEnabled(
|
|
self.debug_mode and not loading and not self.demo_check.isChecked()
|
|
)
|
|
self.server_panel.setEnabled(self.debug_mode and not loading)
|
|
self.server_url_edit.setEnabled(not loading)
|
|
self.timeout_spin.setEnabled(not loading)
|
|
self.allow_self_signed_check.setEnabled(not loading)
|
|
self.save_server_button.setEnabled(not loading)
|
|
self.login_button.setText(button_text if loading else "登录工作站")
|
|
self.busy_overlay.set_message(overlay_text)
|
|
self.busy_overlay.setVisible(loading)
|
|
if loading:
|
|
self.busy_overlay.raise_()
|
|
|
|
def set_session_restore_pending(self, pending: bool) -> None:
|
|
"""Block manual login controls while persisted-token validation runs."""
|
|
|
|
if pending:
|
|
self.error_banner.clear()
|
|
self._set_loading(
|
|
pending,
|
|
button_text="正在恢复登录…",
|
|
overlay_text="正在验证已保存的登录状态…",
|
|
)
|
|
|
|
def _on_login_success(
|
|
self,
|
|
payload: dict[str, Any],
|
|
account: str,
|
|
remember_account: bool | None = None,
|
|
password: str | None = None,
|
|
) -> None:
|
|
if remember_account is None:
|
|
remember_account = self.remember_check.isChecked()
|
|
scope = self._credential_scope()
|
|
is_demo = self.debug_mode and bool(payload.get("demo_mode"))
|
|
password_saved = False
|
|
clearer = getattr(self.credential_store, "clear_password", None)
|
|
if (
|
|
callable(clearer)
|
|
and self._restored_account
|
|
and (
|
|
not remember_account
|
|
or self._restored_account != account
|
|
or self._restored_scope != scope
|
|
)
|
|
):
|
|
with suppress(Exception):
|
|
clearer(account=self._restored_account, scope=self._restored_scope)
|
|
if remember_account:
|
|
self.settings.setValue("auth/remembered_account", account)
|
|
saver = getattr(self.credential_store, "save_password", None)
|
|
if not is_demo and password and scope and callable(saver):
|
|
try:
|
|
password_saved = bool(saver(password, account=account, scope=scope))
|
|
except Exception:
|
|
password_saved = False
|
|
else:
|
|
self.settings.remove("auth/remembered_account")
|
|
if callable(clearer):
|
|
with suppress(Exception):
|
|
clearer(account=account, scope=scope)
|
|
self.settings.setValue("auth/remember_password", password_saved)
|
|
self.settings.sync()
|
|
self._emit_config_update(remembered_account=account if remember_account else "")
|
|
self._restored_account = account if password_saved else ""
|
|
self._restored_scope = scope if password_saved else ""
|
|
self.password_edit.clear()
|
|
self.authenticated_user = payload.get("user")
|
|
self.login_succeeded.emit(payload)
|
|
self.authenticated.emit(payload.get("session"))
|
|
|
|
def _on_login_error(self, error: Exception) -> None:
|
|
error_text = str(error).lower()
|
|
certificate_error = (
|
|
"certificate_verify_failed" in error_text
|
|
or "self-signed certificate" in error_text
|
|
)
|
|
if certificate_error and self.debug_mode:
|
|
self.server_toggle.setChecked(True)
|
|
self._toggle_server_panel(True)
|
|
message = (
|
|
friendly_error(error)
|
|
if self.debug_mode or not certificate_error
|
|
else "服务器证书校验失败,请联系管理员检查线上域名和证书配置。"
|
|
)
|
|
self.error_banner.show_message(message, "danger")
|
|
self.login_failed.emit(message)
|
|
self.password_edit.selectAll()
|
|
self.password_edit.setFocus()
|
|
|
|
|
|
__all__ = ["LoginWindow"]
|