feat: 管理端定时日扩到1至28号,学时顺带写回列表
This commit is contained in:
@@ -19,7 +19,7 @@ from euniv.proxy import ProxyError, apply, clear, enabled, summary_of, url_of, v
|
|||||||
from euniv.study_control import start_now, stop_now
|
from euniv.study_control import start_now, stop_now
|
||||||
from euniv.study_control import view_of as study_view
|
from euniv.study_control import view_of as study_view
|
||||||
from euniv.study_window import StudyWindowError
|
from euniv.study_window import StudyWindowError
|
||||||
from euniv.study_window import apply as apply_start
|
from euniv.study_window import apply_admin as apply_start
|
||||||
from euniv.study_window import label_of as start_label
|
from euniv.study_window import label_of as start_label
|
||||||
|
|
||||||
_TOKEN_KEYS = (
|
_TOKEN_KEYS = (
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class ProxyBody(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class StudyStartBody(BaseModel):
|
class StudyStartBody(BaseModel):
|
||||||
day: int = Field(strict=True, ge=5, le=25)
|
day: int = Field(strict=True, ge=1, le=28)
|
||||||
hour: int = Field(strict=True, ge=0, le=23)
|
hour: int = Field(strict=True, ge=0, le=23)
|
||||||
minute: int = Field(strict=True, ge=0, le=59)
|
minute: int = Field(strict=True, ge=0, le=59)
|
||||||
second: int = Field(strict=True, ge=0, le=59)
|
second: int = Field(strict=True, ge=0, le=59)
|
||||||
@@ -74,7 +74,7 @@ class CourseWorkersBody(BaseModel):
|
|||||||
|
|
||||||
class StudyBundleBody(BaseModel):
|
class StudyBundleBody(BaseModel):
|
||||||
monthly_target: int = Field(strict=True, ge=0, le=9999)
|
monthly_target: int = Field(strict=True, ge=0, le=9999)
|
||||||
day: int = Field(strict=True, ge=5, le=25)
|
day: int = Field(strict=True, ge=1, le=28)
|
||||||
hour: int = Field(strict=True, ge=0, le=23)
|
hour: int = Field(strict=True, ge=0, le=23)
|
||||||
minute: int = Field(strict=True, ge=0, le=59)
|
minute: int = Field(strict=True, ge=0, le=59)
|
||||||
second: int = Field(strict=True, ge=0, le=59)
|
second: int = Field(strict=True, ge=0, le=59)
|
||||||
@@ -394,13 +394,13 @@ def get_study_start(request: Request, db: Session = Depends(get_db)) -> dict:
|
|||||||
|
|
||||||
@app.put("/api/settings/study-start")
|
@app.put("/api/settings/study-start")
|
||||||
def put_study_start(body: StudyStartBody, request: Request, db: Session = Depends(get_db)) -> dict:
|
def put_study_start(body: StudyStartBody, request: Request, db: Session = Depends(get_db)) -> dict:
|
||||||
from euniv.study_window import StudyWindowError, apply, view_of
|
from euniv.study_window import StudyWindowError, apply_user, view_of
|
||||||
|
|
||||||
account = db.get(Account, _signed_in(request, db))
|
account = db.get(Account, _signed_in(request, db))
|
||||||
if account is None:
|
if account is None:
|
||||||
raise HTTPException(status_code=401, detail="未登录")
|
raise HTTPException(status_code=401, detail="未登录")
|
||||||
try:
|
try:
|
||||||
apply(account, body.day, body.hour, body.minute, body.second)
|
apply_user(account, body.day, body.hour, body.minute, body.second)
|
||||||
except StudyWindowError as exc:
|
except StudyWindowError as exc:
|
||||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||||
if body.enabled is not None:
|
if body.enabled is not None:
|
||||||
@@ -426,7 +426,7 @@ def _apply_study_bundle(account: Account, body: StudyBundleBody) -> None:
|
|||||||
"""把首页这一组学习配置写到账号上。不符合要求时抛 400,由调用方回滚。"""
|
"""把首页这一组学习配置写到账号上。不符合要求时抛 400,由调用方回滚。"""
|
||||||
from euniv.course_workers import CourseWorkersError, apply as apply_workers
|
from euniv.course_workers import CourseWorkersError, apply as apply_workers
|
||||||
from euniv.heartbeat import HeartbeatError, apply as apply_heartbeat
|
from euniv.heartbeat import HeartbeatError, apply as apply_heartbeat
|
||||||
from euniv.study_window import StudyWindowError, apply as apply_start
|
from euniv.study_window import StudyWindowError, apply_user as apply_start
|
||||||
|
|
||||||
try:
|
try:
|
||||||
account.monthly_target = body.monthly_target
|
account.monthly_target = body.monthly_target
|
||||||
|
|||||||
@@ -367,7 +367,9 @@ def poll_qr_login(db: Session, attempt_id: str) -> dict:
|
|||||||
|
|
||||||
|
|
||||||
def fetch_home_summary(db: Session, employee_id: str, client_factory=EunivClient) -> dict:
|
def fetch_home_summary(db: Session, employee_id: str, client_factory=EunivClient) -> dict:
|
||||||
return _live(db, employee_id, client_factory, lambda client: _apply_hours_source(client, client.home_summary()))
|
data = _live(db, employee_id, client_factory, lambda client: _apply_hours_source(client, client.home_summary()))
|
||||||
|
_remember_month_hours(db, employee_id, data)
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def fetch_home_exams(db: Session, employee_id: str, client_factory=EunivClient) -> dict:
|
def fetch_home_exams(db: Session, employee_id: str, client_factory=EunivClient) -> dict:
|
||||||
@@ -402,7 +404,9 @@ def fetch_study_history(db: Session, employee_id: str, client_factory=EunivClien
|
|||||||
hours = _hour_fields(_apply_hours_source(client, _api_hour_fields(client), items))
|
hours = _hour_fields(_apply_hours_source(client, _api_hour_fields(client), items))
|
||||||
return {"items": items, "total": len(items), **hours}
|
return {"items": items, "total": len(items), **hours}
|
||||||
|
|
||||||
return _live(db, employee_id, client_factory, read)
|
data = _live(db, employee_id, client_factory, read)
|
||||||
|
_remember_month_hours(db, employee_id, data)
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def _apply_hours_source(client, summary: dict, items: list | None = None) -> dict:
|
def _apply_hours_source(client, summary: dict, items: list | None = None) -> dict:
|
||||||
@@ -447,6 +451,25 @@ def _api_hour_fields(client) -> dict:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _remember_month_hours(db: Session, employee_id: str, payload: dict) -> None:
|
||||||
|
"""首页、学时历史这些已经取到本月学时的地方,顺手写回用户列表。"""
|
||||||
|
if not isinstance(payload, dict):
|
||||||
|
return
|
||||||
|
raw = payload.get("month_hours")
|
||||||
|
if raw is None or isinstance(raw, bool):
|
||||||
|
return
|
||||||
|
text = str(raw).strip()
|
||||||
|
if not text:
|
||||||
|
return
|
||||||
|
account = db.get(Account, employee_id)
|
||||||
|
if account is None:
|
||||||
|
return
|
||||||
|
from euniv.study_control import stamp_hours
|
||||||
|
|
||||||
|
stamp_hours(account, text)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
def _hour_fields(data: dict) -> dict:
|
def _hour_fields(data: dict) -> dict:
|
||||||
fields = {
|
fields = {
|
||||||
"hours_source": data.get("hours_source") or "api",
|
"hours_source": data.get("hours_source") or "api",
|
||||||
|
|||||||
@@ -9,15 +9,25 @@ CN_TZ = timezone(timedelta(hours=8))
|
|||||||
DAY_MIN = 5
|
DAY_MIN = 5
|
||||||
DAY_MAX = 25
|
DAY_MAX = 25
|
||||||
DAY_DEFAULT = 8
|
DAY_DEFAULT = 8
|
||||||
|
ADMIN_DAY_MIN = 1
|
||||||
|
ADMIN_DAY_MAX = 28
|
||||||
|
|
||||||
|
|
||||||
class StudyWindowError(ValueError):
|
class StudyWindowError(ValueError):
|
||||||
"""开始时刻不符合要求。"""
|
"""开始时刻不符合要求。"""
|
||||||
|
|
||||||
|
|
||||||
def validate_start(day: object, hour: object, minute: object, second: object) -> tuple[int, int, int, int]:
|
def validate_start(
|
||||||
|
day: object,
|
||||||
|
hour: object,
|
||||||
|
minute: object,
|
||||||
|
second: object,
|
||||||
|
*,
|
||||||
|
day_min: int = DAY_MIN,
|
||||||
|
day_max: int = DAY_MAX,
|
||||||
|
) -> tuple[int, int, int, int]:
|
||||||
for name, value, low, high in (
|
for name, value, low, high in (
|
||||||
("日", day, DAY_MIN, DAY_MAX),
|
("日", day, day_min, day_max),
|
||||||
("时", hour, 0, 23),
|
("时", hour, 0, 23),
|
||||||
("分", minute, 0, 59),
|
("分", minute, 0, 59),
|
||||||
("秒", second, 0, 59),
|
("秒", second, 0, 59),
|
||||||
@@ -44,7 +54,7 @@ def _stored_day(value: object) -> int:
|
|||||||
number = int(value) # type: ignore[arg-type]
|
number = int(value) # type: ignore[arg-type]
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
return DAY_DEFAULT
|
return DAY_DEFAULT
|
||||||
if DAY_MIN <= number <= DAY_MAX:
|
if ADMIN_DAY_MIN <= number <= ADMIN_DAY_MAX:
|
||||||
return number
|
return number
|
||||||
return DAY_DEFAULT
|
return DAY_DEFAULT
|
||||||
|
|
||||||
@@ -59,14 +69,42 @@ def stored_start(account) -> tuple[int, int, int, int]:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def apply(account, day: object, hour: object, minute: object, second: object) -> None:
|
def apply(
|
||||||
d, h, m, s = validate_start(day, hour, minute, second)
|
account,
|
||||||
|
day: object,
|
||||||
|
hour: object,
|
||||||
|
minute: object,
|
||||||
|
second: object,
|
||||||
|
*,
|
||||||
|
day_min: int = DAY_MIN,
|
||||||
|
day_max: int = DAY_MAX,
|
||||||
|
) -> None:
|
||||||
|
d, h, m, s = validate_start(day, hour, minute, second, day_min=day_min, day_max=day_max)
|
||||||
account.study_start_day = d
|
account.study_start_day = d
|
||||||
account.study_start_hour = h
|
account.study_start_hour = h
|
||||||
account.study_start_minute = m
|
account.study_start_minute = m
|
||||||
account.study_start_second = s
|
account.study_start_second = s
|
||||||
|
|
||||||
|
|
||||||
|
def apply_admin(account, day: object, hour: object, minute: object, second: object) -> None:
|
||||||
|
"""管理端可以把开始日设成 1 到 28 号,用户端仍只能改到 5 到 25 号。"""
|
||||||
|
apply(account, day, hour, minute, second, day_min=ADMIN_DAY_MIN, day_max=ADMIN_DAY_MAX)
|
||||||
|
|
||||||
|
|
||||||
|
def apply_user(account, day: object, hour: object, minute: object, second: object) -> None:
|
||||||
|
"""用户改时刻时仍限制 5 到 25 号。已经由管理端设好的 1 到 28 号,原样保存时保留。"""
|
||||||
|
stored = stored_start(account)[0]
|
||||||
|
if (
|
||||||
|
isinstance(day, int)
|
||||||
|
and not isinstance(day, bool)
|
||||||
|
and day == stored
|
||||||
|
and not DAY_MIN <= day <= DAY_MAX
|
||||||
|
):
|
||||||
|
apply(account, day, hour, minute, second, day_min=ADMIN_DAY_MIN, day_max=ADMIN_DAY_MAX)
|
||||||
|
return
|
||||||
|
apply(account, day, hour, minute, second)
|
||||||
|
|
||||||
|
|
||||||
def label_of(account) -> str:
|
def label_of(account) -> str:
|
||||||
day, hour, minute, second = stored_start(account)
|
day, hour, minute, second = stored_start(account)
|
||||||
return f"每月{day}日 {hour:02d}:{minute:02d}:{second:02d}"
|
return f"每月{day}日 {hour:02d}:{minute:02d}:{second:02d}"
|
||||||
|
|||||||
@@ -804,6 +804,24 @@ def test_admin_can_set_study_start_for_selected_users() -> None:
|
|||||||
assert one["study_start"] == "每月20日 00:00:00"
|
assert one["study_start"] == "每月20日 00:00:00"
|
||||||
assert two["study_start"] == "每月5日 16:08:09"
|
assert two["study_start"] == "每月5日 16:08:09"
|
||||||
assert one["study_start_day"] == 20
|
assert one["study_start_day"] == 20
|
||||||
|
edges = client.put(
|
||||||
|
"/api/admin/users/study-settings",
|
||||||
|
json={"employee_ids": ["s1-user"], "day": 1, "hour": 0, "minute": 0, "second": 0},
|
||||||
|
)
|
||||||
|
assert edges.status_code == 200
|
||||||
|
late = client.put(
|
||||||
|
"/api/admin/users/study-settings",
|
||||||
|
json={"employee_ids": ["s1-user"], "day": 28, "hour": 23, "minute": 59, "second": 59},
|
||||||
|
)
|
||||||
|
assert late.status_code == 200
|
||||||
|
listed = client.get("/api/admin/users").json()
|
||||||
|
one = next(item for item in listed if item["employee_id"] == "s1-user")
|
||||||
|
assert one["study_start"] == "每月28日 23:59:59"
|
||||||
|
rejected = client.put(
|
||||||
|
"/api/admin/users/study-settings",
|
||||||
|
json={"employee_ids": ["s1-user"], "day": 29, "hour": 0, "minute": 0, "second": 0},
|
||||||
|
)
|
||||||
|
assert rejected.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
def test_admin_can_set_course_workers_for_selected_users() -> None:
|
def test_admin_can_set_course_workers_for_selected_users() -> None:
|
||||||
|
|||||||
@@ -743,6 +743,16 @@ def test_user_can_set_monthly_study_start(monkeypatch) -> None:
|
|||||||
assert bad.status_code == 400
|
assert bad.status_code == 400
|
||||||
too_late = client.put("/api/settings/study-start", json={"day": 26, "hour": 16, "minute": 0, "second": 0})
|
too_late = client.put("/api/settings/study-start", json={"day": 26, "hour": 16, "minute": 0, "second": 0})
|
||||||
assert too_late.status_code == 400
|
assert too_late.status_code == 400
|
||||||
|
with SessionLocal() as db:
|
||||||
|
account = db.get(Account, "6650000146")
|
||||||
|
assert account is not None
|
||||||
|
account.study_start_day = 1
|
||||||
|
db.commit()
|
||||||
|
kept = client.put("/api/settings/study-start", json={"day": 1, "hour": 7, "minute": 0, "second": 0, "enabled": True})
|
||||||
|
assert kept.status_code == 200
|
||||||
|
assert kept.json()["label"] == "每月1日 07:00:00"
|
||||||
|
changed = client.put("/api/settings/study-start", json={"day": 2, "hour": 7, "minute": 0, "second": 0})
|
||||||
|
assert changed.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
def _freeze_beijing(monkeypatch, year: int, month: int, day: int) -> None:
|
def _freeze_beijing(monkeypatch, year: int, month: int, day: int) -> None:
|
||||||
@@ -1051,6 +1061,10 @@ def test_user_can_read_study_history(monkeypatch) -> None:
|
|||||||
assert body["items"][0]["minutes"] == 2
|
assert body["items"][0]["minutes"] == 2
|
||||||
assert body["hours_source"] == "api"
|
assert body["hours_source"] == "api"
|
||||||
assert body["month_hours"] == "60"
|
assert body["month_hours"] == "60"
|
||||||
|
with SessionLocal() as db:
|
||||||
|
account = db.get(Account, "6650000146")
|
||||||
|
assert account is not None
|
||||||
|
assert account.month_hours == "60"
|
||||||
assert body["year_hours"] == "100"
|
assert body["year_hours"] == "100"
|
||||||
assert body["today_hours"] == 1
|
assert body["today_hours"] == 1
|
||||||
assert body["total_hours"] == "10"
|
assert body["total_hours"] == "10"
|
||||||
|
|||||||
@@ -606,8 +606,9 @@ def test_study_window_clamps_day_into_allowed_range() -> None:
|
|||||||
assert window_open(account, datetime(2026, 2, 8, 15, 59, 59, tzinfo=CN_TZ)) is False
|
assert window_open(account, datetime(2026, 2, 8, 15, 59, 59, tzinfo=CN_TZ)) is False
|
||||||
assert window_open(account, datetime(2026, 2, 8, 16, 0, 0, tzinfo=CN_TZ)) is True
|
assert window_open(account, datetime(2026, 2, 8, 16, 0, 0, tzinfo=CN_TZ)) is True
|
||||||
early = _Start(1, 16, 0, 0)
|
early = _Start(1, 16, 0, 0)
|
||||||
assert window_open(early, datetime(2026, 11, 8, 15, 59, 59, tzinfo=CN_TZ)) is False
|
assert window_open(early, datetime(2026, 11, 1, 15, 59, 59, tzinfo=CN_TZ)) is False
|
||||||
assert window_open(early, datetime(2026, 11, 8, 16, 0, 0, tzinfo=CN_TZ)) is True
|
assert window_open(early, datetime(2026, 11, 1, 16, 0, 0, tzinfo=CN_TZ)) is True
|
||||||
|
assert window_open(early, datetime(2026, 11, 8, 15, 59, 59, tzinfo=CN_TZ)) is True
|
||||||
|
|
||||||
|
|
||||||
def test_immediate_start_skips_monthly_window() -> None:
|
def test_immediate_start_skips_monthly_window() -> None:
|
||||||
@@ -899,6 +900,19 @@ def test_study_window_rejects_invalid_parts() -> None:
|
|||||||
validate_start(8, 24, 0, 0)
|
validate_start(8, 24, 0, 0)
|
||||||
assert validate_start(5, 0, 0, 0) == (5, 0, 0, 0)
|
assert validate_start(5, 0, 0, 0) == (5, 0, 0, 0)
|
||||||
assert validate_start(25, 23, 59, 59) == (25, 23, 59, 59)
|
assert validate_start(25, 23, 59, 59) == (25, 23, 59, 59)
|
||||||
|
assert validate_start(1, 0, 0, 0, day_min=1, day_max=28) == (1, 0, 0, 0)
|
||||||
|
assert validate_start(28, 8, 0, 0, day_min=1, day_max=28) == (28, 8, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_stored_start_keeps_admin_days_outside_the_user_range() -> None:
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
from euniv.study_window import stored_start
|
||||||
|
|
||||||
|
early = SimpleNamespace(study_start_day=1, study_start_hour=6, study_start_minute=0, study_start_second=0)
|
||||||
|
late = SimpleNamespace(study_start_day=28, study_start_hour=0, study_start_minute=0, study_start_second=0)
|
||||||
|
assert stored_start(early) == (1, 6, 0, 0)
|
||||||
|
assert stored_start(late) == (28, 0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
def test_course_workers_default_and_range() -> None:
|
def test_course_workers_default_and_range() -> None:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { apiFetch } from "../../shared/http";
|
import { apiFetch } from "../../shared/http";
|
||||||
import { onMounted, onUnmounted, ref } from "vue";
|
import { onMounted, onUnmounted, ref } from "vue";
|
||||||
import { NAlert, NButton, NForm, NFormItem, NInput, NInputNumber, NRadioButton, NRadioGroup, NSwitch } from "naive-ui";
|
import { NAlert, NButton, NCollapse, NCollapseItem, NForm, NFormItem, NInput, NInputNumber, NRadioButton, NRadioGroup, NSwitch } from "naive-ui";
|
||||||
|
|
||||||
const emit = defineEmits<{ saved: [] }>();
|
const emit = defineEmits<{ saved: [] }>();
|
||||||
|
|
||||||
@@ -190,9 +190,8 @@ async function save() {
|
|||||||
<n-alert v-else-if="successText" class="admin-alert" type="success">{{ successText }}</n-alert>
|
<n-alert v-else-if="successText" class="admin-alert" type="success">{{ successText }}</n-alert>
|
||||||
<div class="settings-stack">
|
<div class="settings-stack">
|
||||||
<p v-if="loading && !loaded" class="admin-status">正在获取</p>
|
<p v-if="loading && !loaded" class="admin-status">正在获取</p>
|
||||||
<template v-else-if="loaded">
|
<n-collapse v-else-if="loaded" class="settings-tree" :default-expanded-names="['login', 'hours', 'admin']" arrow-placement="left">
|
||||||
<section class="panel-card">
|
<n-collapse-item title="登录验证" name="login">
|
||||||
<h3>登录验证</h3>
|
|
||||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small" @submit.prevent="save">
|
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small" @submit.prevent="save">
|
||||||
<n-form-item label="定时刷新间隔">
|
<n-form-item label="定时刷新间隔">
|
||||||
<div class="target-control">
|
<div class="target-control">
|
||||||
@@ -213,9 +212,8 @@ async function save() {
|
|||||||
</div>
|
</div>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
</n-form>
|
</n-form>
|
||||||
</section>
|
</n-collapse-item>
|
||||||
<section class="panel-card">
|
<n-collapse-item title="学时达标" name="hours">
|
||||||
<h3>学时达标</h3>
|
|
||||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small" @submit.prevent="save">
|
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small" @submit.prevent="save">
|
||||||
<n-form-item label="判断依据">
|
<n-form-item label="判断依据">
|
||||||
<n-radio-group v-model:value="hoursSource" size="small">
|
<n-radio-group v-model:value="hoursSource" size="small">
|
||||||
@@ -225,9 +223,8 @@ async function save() {
|
|||||||
</n-form-item>
|
</n-form-item>
|
||||||
</n-form>
|
</n-form>
|
||||||
<p class="form-hint">首页、学时历史和达标判断使用同一来源</p>
|
<p class="form-hint">首页、学时历史和达标判断使用同一来源</p>
|
||||||
</section>
|
</n-collapse-item>
|
||||||
<section class="panel-card">
|
<n-collapse-item title="管理员" name="admin">
|
||||||
<h3>管理员</h3>
|
|
||||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small" @submit.prevent="save">
|
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small" @submit.prevent="save">
|
||||||
<n-form-item label="用户名">
|
<n-form-item label="用户名">
|
||||||
<n-input v-model:value="username" :input-props="{ autocomplete: 'username', name: 'username' }" />
|
<n-input v-model:value="username" :input-props="{ autocomplete: 'username', name: 'username' }" />
|
||||||
@@ -242,8 +239,8 @@ async function save() {
|
|||||||
<n-input v-model:value="confirmPassword" type="password" show-password-on="click" placeholder="请输入" :input-props="{ autocomplete: 'new-password', name: 'confirm-password' }" />
|
<n-input v-model:value="confirmPassword" type="password" show-password-on="click" placeholder="请输入" :input-props="{ autocomplete: 'new-password', name: 'confirm-password' }" />
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
</n-form>
|
</n-form>
|
||||||
</section>
|
</n-collapse-item>
|
||||||
</template>
|
</n-collapse>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { computed, onMounted, ref } from "vue";
|
|||||||
import { NAlert, NButton, NCheckbox, NDropdown, NForm, NFormItem, NIcon, NInputNumber, NModal, NRadioButton, NRadioGroup, NSelect, NTimePicker, NTooltip, useDialog, type DropdownOption } from "naive-ui";
|
import { NAlert, NButton, NCheckbox, NDropdown, NForm, NFormItem, NIcon, NInputNumber, NModal, NRadioButton, NRadioGroup, NSelect, NTimePicker, NTooltip, useDialog, type DropdownOption } from "naive-ui";
|
||||||
import { EllipsisHorizontalOutline, EllipsisVerticalOutline, PauseOutline, PlayOutline, RefreshOutline, SettingsOutline } from "@vicons/ionicons5";
|
import { EllipsisHorizontalOutline, EllipsisVerticalOutline, PauseOutline, PlayOutline, RefreshOutline, SettingsOutline } from "@vicons/ionicons5";
|
||||||
import ProxyFields from "../../shared/ProxyFields.vue";
|
import ProxyFields from "../../shared/ProxyFields.vue";
|
||||||
import { STUDY_DAY_DEFAULT, STUDY_DAY_MAX, STUDY_DAY_MIN, dayOptions, workerOptions } from "../../shared/studyFields";
|
import { ADMIN_DAY_MAX, ADMIN_DAY_MIN, STUDY_DAY_DEFAULT, adminDayOptions, workerOptions } from "../../shared/studyFields";
|
||||||
import { isRecord, textOf } from "../../shared/text";
|
import { isRecord, textOf } from "../../shared/text";
|
||||||
|
|
||||||
interface UserRow {
|
interface UserRow {
|
||||||
@@ -659,8 +659,8 @@ async function saveSettings() {
|
|||||||
settingsError.value = "请填写完整的开始时刻";
|
settingsError.value = "请填写完整的开始时刻";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (scheduleTouched && !integerInRange(startDay.value, STUDY_DAY_MIN, STUDY_DAY_MAX)) {
|
if (scheduleTouched && !integerInRange(startDay.value, ADMIN_DAY_MIN, ADMIN_DAY_MAX)) {
|
||||||
settingsError.value = "每月开始日须为 5 到 25 的整数";
|
settingsError.value = "每月开始日须为 1 到 28 的整数";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (workersChanged && !integerInRange(workersValue.value, 1, 8)) {
|
if (workersChanged && !integerInRange(workersValue.value, 1, 8)) {
|
||||||
@@ -980,7 +980,7 @@ onMounted(() => {
|
|||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item label="开始时刻">
|
<n-form-item label="开始时刻">
|
||||||
<div class="target-control start-control">
|
<div class="target-control start-control">
|
||||||
<n-select v-model:value="startDay" :options="dayOptions" class="day-select" placeholder="保持不变" :disabled="scheduleTimeDisabled" />
|
<n-select v-model:value="startDay" :options="adminDayOptions" class="day-select" placeholder="保持不变" :disabled="scheduleTimeDisabled" />
|
||||||
<n-time-picker v-model:formatted-value="startTime" value-format="HH:mm:ss" :actions="null" placeholder="保持不变" :disabled="scheduleTimeDisabled" />
|
<n-time-picker v-model:formatted-value="startTime" value-format="HH:mm:ss" :actions="null" placeholder="保持不变" :disabled="scheduleTimeDisabled" />
|
||||||
</div>
|
</div>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
|
|||||||
@@ -326,6 +326,19 @@ async function loadTarget() {
|
|||||||
const startLoaded = ref(false);
|
const startLoaded = ref(false);
|
||||||
const scheduleEnabled = ref(true);
|
const scheduleEnabled = ref(true);
|
||||||
const startDay = ref<number | null>(STUDY_DAY_DEFAULT);
|
const startDay = ref<number | null>(STUDY_DAY_DEFAULT);
|
||||||
|
const loadedStartDay = ref<number | null>(null);
|
||||||
|
const userDayOptions = computed(() => {
|
||||||
|
const current = loadedStartDay.value;
|
||||||
|
if (
|
||||||
|
current != null
|
||||||
|
&& (current < STUDY_DAY_MIN || current > STUDY_DAY_MAX)
|
||||||
|
&& current >= 1
|
||||||
|
&& current <= 28
|
||||||
|
) {
|
||||||
|
return [...dayOptions, { label: `每月 ${current} 日`, value: current }].sort((left, right) => left.value - right.value);
|
||||||
|
}
|
||||||
|
return dayOptions;
|
||||||
|
});
|
||||||
const startHour = ref<number | null>(0);
|
const startHour = ref<number | null>(0);
|
||||||
const startMinute = ref<number | null>(0);
|
const startMinute = ref<number | null>(0);
|
||||||
const startSecond = ref<number | null>(0);
|
const startSecond = ref<number | null>(0);
|
||||||
@@ -350,6 +363,7 @@ async function loadStart() {
|
|||||||
if (!res.ok) return false;
|
if (!res.ok) return false;
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
startDay.value = typeof data.day === "number" ? data.day : STUDY_DAY_DEFAULT;
|
startDay.value = typeof data.day === "number" ? data.day : STUDY_DAY_DEFAULT;
|
||||||
|
loadedStartDay.value = startDay.value;
|
||||||
startHour.value = typeof data.hour === "number" ? data.hour : 0;
|
startHour.value = typeof data.hour === "number" ? data.hour : 0;
|
||||||
startMinute.value = typeof data.minute === "number" ? data.minute : 0;
|
startMinute.value = typeof data.minute === "number" ? data.minute : 0;
|
||||||
startSecond.value = typeof data.second === "number" ? data.second : 0;
|
startSecond.value = typeof data.second === "number" ? data.second : 0;
|
||||||
@@ -412,7 +426,8 @@ function scheduleBody(): Record<string, unknown> | null {
|
|||||||
scheduleError.value = "请填写完整的开始时刻";
|
scheduleError.value = "请填写完整的开始时刻";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (day < STUDY_DAY_MIN || day > STUDY_DAY_MAX) {
|
const keptByAdmin = loadedStartDay.value != null && day === loadedStartDay.value && (day < STUDY_DAY_MIN || day > STUDY_DAY_MAX);
|
||||||
|
if (!keptByAdmin && (day < STUDY_DAY_MIN || day > STUDY_DAY_MAX)) {
|
||||||
scheduleError.value = "每月开始日须为 5 到 25 的整数";
|
scheduleError.value = "每月开始日须为 5 到 25 的整数";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -1048,7 +1063,7 @@ onUnmounted(() => {
|
|||||||
<n-select
|
<n-select
|
||||||
v-model:value="startDay"
|
v-model:value="startDay"
|
||||||
size="small"
|
size="small"
|
||||||
:options="dayOptions"
|
:options="userDayOptions"
|
||||||
class="day-select"
|
class="day-select"
|
||||||
:disabled="!scheduleEnabled"
|
:disabled="!scheduleEnabled"
|
||||||
aria-label="每月开始日"
|
aria-label="每月开始日"
|
||||||
|
|||||||
@@ -12,8 +12,15 @@ export const workerOptions = [
|
|||||||
export const STUDY_DAY_MIN = 5;
|
export const STUDY_DAY_MIN = 5;
|
||||||
export const STUDY_DAY_MAX = 25;
|
export const STUDY_DAY_MAX = 25;
|
||||||
export const STUDY_DAY_DEFAULT = 8;
|
export const STUDY_DAY_DEFAULT = 8;
|
||||||
|
export const ADMIN_DAY_MIN = 1;
|
||||||
|
export const ADMIN_DAY_MAX = 28;
|
||||||
|
|
||||||
export const dayOptions = Array.from({ length: STUDY_DAY_MAX - STUDY_DAY_MIN + 1 }, (_, index) => {
|
export function dayOptionsBetween(min: number, max: number) {
|
||||||
const day = STUDY_DAY_MIN + index;
|
return Array.from({ length: max - min + 1 }, (_, index) => {
|
||||||
|
const day = min + index;
|
||||||
return { label: `每月 ${day} 日`, value: day };
|
return { label: `每月 ${day} 日`, value: day };
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const dayOptions = dayOptionsBetween(STUDY_DAY_MIN, STUDY_DAY_MAX);
|
||||||
|
export const adminDayOptions = dayOptionsBetween(ADMIN_DAY_MIN, ADMIN_DAY_MAX);
|
||||||
|
|||||||
+33
-16
@@ -525,20 +525,37 @@ select {
|
|||||||
.settings-stack {
|
.settings-stack {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
display: grid;
|
overflow: auto;
|
||||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
}
|
||||||
grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
|
|
||||||
gap: 16px;
|
.settings-tree {
|
||||||
|
width: min(720px, 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-tree .n-collapse-item {
|
||||||
|
margin-top: 8px;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 4px;
|
||||||
|
background: var(--panel);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-stack > .panel-card {
|
.settings-tree .n-collapse-item:first-child {
|
||||||
box-sizing: border-box;
|
margin-top: 0;
|
||||||
min-width: 0;
|
}
|
||||||
min-height: 0;
|
|
||||||
display: flex;
|
.settings-tree .n-collapse-item__header {
|
||||||
flex-direction: column;
|
padding: 10px 14px !important;
|
||||||
overflow: auto;
|
font-size: 13px;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-tree .n-collapse-item__content-inner {
|
||||||
|
padding: 0 14px 12px 36px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-tree .n-collapse-item__header-main {
|
||||||
|
color: var(--ink);
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-stack .compact-nform {
|
.settings-stack .compact-nform {
|
||||||
@@ -795,8 +812,10 @@ select {
|
|||||||
max-width: 30rem;
|
max-width: 30rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.study-config .compact-nform {
|
.study-config .compact-nform,
|
||||||
|
.study-config .compact-nform.n-form {
|
||||||
max-width: none;
|
max-width: none;
|
||||||
|
gap: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.study-live {
|
.study-live {
|
||||||
@@ -1716,10 +1735,8 @@ body .n-base-select-menu .n-base-select-option__content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 1100px) {
|
@media (max-width: 1100px) {
|
||||||
.settings-stack {
|
.settings-tree {
|
||||||
grid-template-columns: minmax(0, 1fr);
|
width: 100%;
|
||||||
grid-template-rows: none;
|
|
||||||
grid-auto-rows: auto;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user