更新
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import suppress
|
||||
from typing import Any
|
||||
|
||||
from PySide6.QtCore import QPoint, QSettings, Qt, QTimer, Signal
|
||||
@@ -70,8 +71,9 @@ class LoginWindow(QMainWindow):
|
||||
``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.
|
||||
``remember_account`` is captured before the worker starts and is forwarded
|
||||
to the repository so every account metadata store follows the same choice.
|
||||
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)
|
||||
@@ -87,6 +89,7 @@ class LoginWindow(QMainWindow):
|
||||
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)
|
||||
@@ -96,9 +99,12 @@ class LoginWindow(QMainWindow):
|
||||
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.setMinimumSize(860, 590)
|
||||
@@ -214,7 +220,7 @@ class LoginWindow(QMainWindow):
|
||||
layout.addLayout(brand_row)
|
||||
layout.addStretch(2)
|
||||
|
||||
eyebrow = QLabel("DOCTOR WORKSTATION")
|
||||
eyebrow = QLabel("医生工作站")
|
||||
eyebrow.setStyleSheet(
|
||||
"color:#4F63D9; font-size:11px; font-weight:700; letter-spacing:1px;"
|
||||
)
|
||||
@@ -300,8 +306,8 @@ class LoginWindow(QMainWindow):
|
||||
card_layout.addLayout(password_row)
|
||||
|
||||
choices = QHBoxLayout()
|
||||
self.remember_check = _VisibleCheckBox("记住账号")
|
||||
self.remember_check.setToolTip("仅保存账号,不保存密码")
|
||||
self.remember_check = _VisibleCheckBox("记住密码")
|
||||
self.remember_check.setToolTip("密码使用系统安全凭据或 Windows DPAPI 加密,不保存明文")
|
||||
choices.addWidget(self.remember_check)
|
||||
choices.addStretch(1)
|
||||
self.demo_check = _VisibleCheckBox("演示模式")
|
||||
@@ -394,8 +400,6 @@ class LoginWindow(QMainWindow):
|
||||
def _restore_settings(self) -> None:
|
||||
configured_account = getattr(self.config, "remembered_account", "")
|
||||
remembered = str(self.settings.value("auth/remembered_account", configured_account) or "")
|
||||
self.account_edit.setText(remembered)
|
||||
self.remember_check.setChecked(bool(remembered))
|
||||
configured_url = getattr(self.config, "base_url", "") or getattr(
|
||||
self.config, "api_base_url", ""
|
||||
)
|
||||
@@ -418,11 +422,49 @@ class LoginWindow(QMainWindow):
|
||||
self.allow_self_signed_check.setChecked(not verify_ssl)
|
||||
if self.demo_repository is not None and bool(getattr(self.config, "demo_mode", False)):
|
||||
self.demo_check.setChecked(True)
|
||||
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 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
|
||||
@@ -557,6 +599,7 @@ class LoginWindow(QMainWindow):
|
||||
payload,
|
||||
account,
|
||||
remember_account,
|
||||
password,
|
||||
),
|
||||
on_error=self._on_login_error,
|
||||
on_finished=lambda: self._set_loading(False),
|
||||
@@ -604,15 +647,39 @@ class LoginWindow(QMainWindow):
|
||||
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 = 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)
|
||||
|
||||
@@ -843,6 +843,7 @@ class AppointmentsPage(QWidget):
|
||||
"patient_id": patient_id,
|
||||
"diagnosis_id": diagnosis_id,
|
||||
"patient_name": first_value(row, "patient_name", default="患者"),
|
||||
"mode": "im",
|
||||
"record": row,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -8,9 +8,10 @@ from datetime import date, timedelta
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from PySide6.QtCore import Qt, QTimer, Signal
|
||||
from PySide6.QtGui import QTextCursor
|
||||
from PySide6.QtCore import Qt, QTimer, QUrl, Signal
|
||||
from PySide6.QtGui import QDesktopServices, QPixmap, QTextCursor
|
||||
from PySide6.QtWidgets import (
|
||||
QDialog,
|
||||
QFileDialog,
|
||||
QFrame,
|
||||
QGridLayout,
|
||||
@@ -22,6 +23,7 @@ from PySide6.QtWidgets import (
|
||||
QMessageBox,
|
||||
QPushButton,
|
||||
QScrollArea,
|
||||
QSizePolicy,
|
||||
QSplitter,
|
||||
QStackedWidget,
|
||||
QTabBar,
|
||||
@@ -118,6 +120,13 @@ def _attachment_name(value: object) -> str:
|
||||
return name or text
|
||||
|
||||
|
||||
def _is_image_attachment(value: object) -> bool:
|
||||
"""Return whether a server attachment can be previewed as an image."""
|
||||
|
||||
path = str(value or "").split("?", 1)[0].split("#", 1)[0].lower()
|
||||
return path.endswith((".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp"))
|
||||
|
||||
|
||||
def _is_local_material_reference(value: str) -> bool:
|
||||
"""Reject local filesystem references before a note JSON is constructed."""
|
||||
|
||||
@@ -139,12 +148,14 @@ class QueueRow(QWidget):
|
||||
layout.setContentsMargins(12, 9, 12, 9)
|
||||
layout.setSpacing(5)
|
||||
top = QHBoxLayout()
|
||||
top.setSpacing(8)
|
||||
name = QLabel(
|
||||
display_text(first_value(record, "patient_name", "name", default="未命名患者"))
|
||||
)
|
||||
name.setStyleSheet("font-size:14px; font-weight:700; color:#172033;")
|
||||
top.addWidget(name)
|
||||
top.addStretch(1)
|
||||
name.setMinimumWidth(0)
|
||||
name.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
|
||||
top.addWidget(name, 1)
|
||||
status_number = _as_int(first_value(record, "status", default=1), 1) or 1
|
||||
badge = StatusBadge(
|
||||
display_text(
|
||||
@@ -157,7 +168,12 @@ class QueueRow(QWidget):
|
||||
),
|
||||
STATUS_KIND.get(status_number, "neutral"),
|
||||
)
|
||||
top.addWidget(badge)
|
||||
badge.setMinimumWidth(max(54, badge.sizeHint().width()))
|
||||
top.addWidget(
|
||||
badge,
|
||||
0,
|
||||
Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTop,
|
||||
)
|
||||
layout.addLayout(top)
|
||||
time = first_value(
|
||||
record, "appointment_time_text", "appointment_time", "time", default="时间待确认"
|
||||
@@ -168,6 +184,10 @@ class QueueRow(QWidget):
|
||||
f"{display_text(first_value(record, 'age'))}岁"
|
||||
)
|
||||
meta.setProperty("role", "muted")
|
||||
# Long timestamps must not dictate the minimum width of the whole
|
||||
# queue row and push the status badge underneath the viewport edge.
|
||||
meta.setMinimumWidth(0)
|
||||
meta.setSizePolicy(QSizePolicy.Policy.Ignored, QSizePolicy.Policy.Preferred)
|
||||
layout.addWidget(meta)
|
||||
assistant = first_value(record, "assistant_name", default=None)
|
||||
if assistant:
|
||||
@@ -211,6 +231,7 @@ class ReceptionPage(QWidget):
|
||||
self._pending_tongue_images: list[str] = []
|
||||
self._pending_report_files: list[str] = []
|
||||
self._note_busy = False
|
||||
self._attachment_preview_generation = 0
|
||||
|
||||
self._can_complete = has_permission(self.permissions, "doctor.appointment/complete")
|
||||
self._can_note = has_permission(self.permissions, "doctor.appointment/addDoctorNote")
|
||||
@@ -335,7 +356,8 @@ class ReceptionPage(QWidget):
|
||||
self.notify_button = QPushButton("通知医助")
|
||||
self.notify_button.clicked.connect(self._notify_assistant)
|
||||
action_row.addWidget(self.notify_button)
|
||||
self.video_button = QPushButton("发起视频")
|
||||
self.video_button = QPushButton("IM 问诊")
|
||||
self.video_button.setToolTip("打开患者 IM,可发送消息并从会话中发起视频")
|
||||
self.video_button.setProperty("variant", "secondary")
|
||||
self.video_button.clicked.connect(self._request_video)
|
||||
action_row.addWidget(self.video_button)
|
||||
@@ -1245,13 +1267,25 @@ class ReceptionPage(QWidget):
|
||||
("report_files", "检查报告"),
|
||||
):
|
||||
for path in _sequence(first_value(note, image_type, default=[])):
|
||||
path_text = str(path).strip()
|
||||
attachment = QWidget()
|
||||
attachment_layout = QHBoxLayout(attachment)
|
||||
attachment_layout.setContentsMargins(0, 0, 0, 0)
|
||||
label = QLabel(f"{caption}:{_attachment_name(path)}")
|
||||
label.setToolTip(str(path))
|
||||
label = QLabel(f"{caption}:{_attachment_name(path_text)}")
|
||||
label.setToolTip(path_text)
|
||||
label.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse)
|
||||
attachment_layout.addWidget(label, 1)
|
||||
preview_button = QPushButton(
|
||||
"预览" if _is_image_attachment(path_text) else "打开"
|
||||
)
|
||||
preview_button.setProperty("variant", "secondary")
|
||||
preview_button.setEnabled(bool(path_text))
|
||||
preview_button.clicked.connect(
|
||||
lambda _checked=False, current_path=path_text, button=preview_button: (
|
||||
self._preview_note_attachment(current_path, button)
|
||||
)
|
||||
)
|
||||
attachment_layout.addWidget(preview_button)
|
||||
if self._can_note and note_id is not None:
|
||||
delete_button = QPushButton("删除")
|
||||
delete_button.setProperty("variant", "secondary")
|
||||
@@ -1266,6 +1300,97 @@ class ReceptionPage(QWidget):
|
||||
layout.addWidget(attachment)
|
||||
self.notes_layout.addWidget(card)
|
||||
|
||||
def _preview_note_attachment(self, path: str, button: QPushButton) -> None:
|
||||
"""Preview note images in-app and open non-image reports safely."""
|
||||
|
||||
target = str(path or "").strip()
|
||||
if not target:
|
||||
return
|
||||
if not _is_image_attachment(target):
|
||||
url = QUrl(target)
|
||||
if (
|
||||
not url.isValid()
|
||||
or url.scheme().lower() not in {"https", "http"}
|
||||
or not url.host()
|
||||
):
|
||||
show_toast(self, "附件地址无效,无法打开。", "warning", 4200)
|
||||
return
|
||||
if not QDesktopServices.openUrl(url):
|
||||
show_toast(self, "系统未能打开该附件。", "danger", 4200)
|
||||
return
|
||||
|
||||
download = getattr(self.repository, "download_public_image", None)
|
||||
if not callable(download):
|
||||
show_toast(self, "当前数据源不支持图片预览。", "warning", 4200)
|
||||
return
|
||||
self._attachment_preview_generation += 1
|
||||
generation = self._attachment_preview_generation
|
||||
button.setEnabled(False)
|
||||
button.setText("加载中…")
|
||||
run_async(
|
||||
lambda: invoke(self.repository, "download_public_image", url=target),
|
||||
on_success=lambda payload: self._show_note_image_preview(
|
||||
target, payload, button, generation
|
||||
),
|
||||
on_error=lambda error: self._note_image_preview_failed(
|
||||
error, button, generation
|
||||
),
|
||||
)
|
||||
|
||||
def _show_note_image_preview(
|
||||
self,
|
||||
path: str,
|
||||
payload: Any,
|
||||
button: QPushButton,
|
||||
generation: int,
|
||||
) -> None:
|
||||
if generation != self._attachment_preview_generation:
|
||||
return
|
||||
button.setEnabled(True)
|
||||
button.setText("预览")
|
||||
content = bytes(payload or b"")
|
||||
pixmap = QPixmap()
|
||||
if not content or len(content) > 10 * 1024 * 1024 or not pixmap.loadFromData(content):
|
||||
show_toast(self, "服务器返回的图片无法预览。", "danger", 4600)
|
||||
return
|
||||
dialog = QDialog(self)
|
||||
dialog.setWindowTitle(f"预览 · {_attachment_name(path)}")
|
||||
dialog.setModal(True)
|
||||
dialog.resize(920, 680)
|
||||
layout = QVBoxLayout(dialog)
|
||||
layout.setContentsMargins(14, 14, 14, 14)
|
||||
scroll = QScrollArea(dialog)
|
||||
scroll.setWidgetResizable(True)
|
||||
image = QLabel()
|
||||
image.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
image.setPixmap(
|
||||
pixmap.scaled(
|
||||
880,
|
||||
620,
|
||||
Qt.AspectRatioMode.KeepAspectRatio,
|
||||
Qt.TransformationMode.SmoothTransformation,
|
||||
)
|
||||
)
|
||||
scroll.setWidget(image)
|
||||
layout.addWidget(scroll, 1)
|
||||
close_button = QPushButton("关闭")
|
||||
close_button.setProperty("variant", "primary")
|
||||
close_button.clicked.connect(dialog.accept)
|
||||
layout.addWidget(close_button, 0, Qt.AlignmentFlag.AlignRight)
|
||||
dialog.exec()
|
||||
|
||||
def _note_image_preview_failed(
|
||||
self,
|
||||
error: Exception,
|
||||
button: QPushButton,
|
||||
generation: int,
|
||||
) -> None:
|
||||
if generation != self._attachment_preview_generation:
|
||||
return
|
||||
button.setEnabled(True)
|
||||
button.setText("预览")
|
||||
show_toast(self, f"图片预览失败:{friendly_error(error)}", "danger", 5200)
|
||||
|
||||
def _reset_detail_content(self, seed: Any = None) -> None:
|
||||
self.patient_name_label.setText(
|
||||
display_text(first_value(seed, "patient_name", "name", default="—"))
|
||||
@@ -1753,6 +1878,7 @@ class ReceptionPage(QWidget):
|
||||
"patient_name",
|
||||
default=first_value(diagnosis, "patient_name", default="患者"),
|
||||
),
|
||||
"mode": "im",
|
||||
"record": self._selected_record,
|
||||
}
|
||||
self.video_requested.emit(payload)
|
||||
|
||||
@@ -25,7 +25,13 @@ from PySide6.QtWidgets import (
|
||||
QWidget,
|
||||
)
|
||||
|
||||
from doctor_workstation.core.errors import AuthenticationExpiredError
|
||||
from doctor_workstation.core.errors import (
|
||||
ApiHttpError,
|
||||
ApiProtocolError,
|
||||
ApiTimeoutError,
|
||||
ApiTransportError,
|
||||
AuthenticationExpiredError,
|
||||
)
|
||||
|
||||
AuthenticationExpiredHandler = Callable[[AuthenticationExpiredError], bool]
|
||||
_AUTHENTICATION_EXPIRED_HANDLER: AuthenticationExpiredHandler | None = None
|
||||
@@ -331,7 +337,45 @@ def friendly_error(error: Any) -> str:
|
||||
"服务器证书不受系统信任。若这是可信内网的自签名服务器,请展开“服务器设置”,"
|
||||
"勾选“信任自签名证书(仅内网调试)”后重新登录,设置会自动应用。"
|
||||
)
|
||||
return text or "操作未完成,请稍后重试。"
|
||||
if isinstance(error, AuthenticationExpiredError):
|
||||
return "登录状态已失效,请重新登录。"
|
||||
if isinstance(error, ApiTimeoutError) or "timed out" in lowered or "timeout" in lowered:
|
||||
return "连接服务器超时,请检查网络后重试。"
|
||||
if isinstance(error, ApiProtocolError) or any(
|
||||
marker in lowered
|
||||
for marker in (
|
||||
"api response envelope",
|
||||
"api response is not valid json",
|
||||
"invalid json",
|
||||
)
|
||||
):
|
||||
return "服务器返回的数据格式不正确,请联系管理员检查接口。"
|
||||
if isinstance(error, ApiHttpError):
|
||||
status_code = getattr(error, "status_code", None)
|
||||
suffix = f"(状态码 {status_code})" if status_code else ""
|
||||
return f"服务器请求失败{suffix},请稍后重试。"
|
||||
if isinstance(error, ApiTransportError) or any(
|
||||
marker in lowered
|
||||
for marker in (
|
||||
"connection refused",
|
||||
"connecterror",
|
||||
"connection error",
|
||||
"failed to connect",
|
||||
"getaddrinfo failed",
|
||||
"name or service not known",
|
||||
"network is unreachable",
|
||||
)
|
||||
):
|
||||
return "无法连接服务器,请检查服务器地址与网络。"
|
||||
if any(marker in lowered for marker in ("unauthorized", "forbidden", "permission denied")):
|
||||
return "当前账号无权执行此操作。"
|
||||
if "not found" in lowered:
|
||||
return "未找到所需数据。"
|
||||
if any("\u4e00" <= character <= "\u9fff" for character in text):
|
||||
return text
|
||||
if isinstance(error, TypeError):
|
||||
return "程序执行失败,请重试;若问题持续出现,请联系管理员。"
|
||||
return "操作未完成,请稍后重试。"
|
||||
|
||||
|
||||
class PageHeader(QWidget):
|
||||
@@ -379,6 +423,10 @@ class StatusBadge(QLabel):
|
||||
self.setObjectName("StatusBadge")
|
||||
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
self.setSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Fixed)
|
||||
# QSS padding alone is not a reliable minimum on every Windows DPI
|
||||
# scale. Keep enough physical row height so badge text is never
|
||||
# squeezed into the thin coloured strip seen in list item widgets.
|
||||
self.setMinimumHeight(24)
|
||||
self.set_kind(kind)
|
||||
|
||||
def set_kind(self, kind: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user