feat: 管理端定时日扩到1至28号,学时顺带写回列表
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { apiFetch } from "../../shared/http";
|
||||
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: [] }>();
|
||||
|
||||
@@ -190,9 +190,8 @@ async function save() {
|
||||
<n-alert v-else-if="successText" class="admin-alert" type="success">{{ successText }}</n-alert>
|
||||
<div class="settings-stack">
|
||||
<p v-if="loading && !loaded" class="admin-status">正在获取</p>
|
||||
<template v-else-if="loaded">
|
||||
<section class="panel-card">
|
||||
<h3>登录验证</h3>
|
||||
<n-collapse v-else-if="loaded" class="settings-tree" :default-expanded-names="['login', 'hours', 'admin']" arrow-placement="left">
|
||||
<n-collapse-item title="登录验证" name="login">
|
||||
<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="定时刷新间隔">
|
||||
<div class="target-control">
|
||||
@@ -213,9 +212,8 @@ async function save() {
|
||||
</div>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</section>
|
||||
<section class="panel-card">
|
||||
<h3>学时达标</h3>
|
||||
</n-collapse-item>
|
||||
<n-collapse-item title="学时达标" name="hours">
|
||||
<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-radio-group v-model:value="hoursSource" size="small">
|
||||
@@ -225,9 +223,8 @@ async function save() {
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<p class="form-hint">首页、学时历史和达标判断使用同一来源</p>
|
||||
</section>
|
||||
<section class="panel-card">
|
||||
<h3>管理员</h3>
|
||||
</n-collapse-item>
|
||||
<n-collapse-item title="管理员" name="admin">
|
||||
<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-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-form-item>
|
||||
</n-form>
|
||||
</section>
|
||||
</template>
|
||||
</n-collapse-item>
|
||||
</n-collapse>
|
||||
</div>
|
||||
</div>
|
||||
</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 { EllipsisHorizontalOutline, EllipsisVerticalOutline, PauseOutline, PlayOutline, RefreshOutline, SettingsOutline } from "@vicons/ionicons5";
|
||||
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";
|
||||
|
||||
interface UserRow {
|
||||
@@ -659,8 +659,8 @@ async function saveSettings() {
|
||||
settingsError.value = "请填写完整的开始时刻";
|
||||
return;
|
||||
}
|
||||
if (scheduleTouched && !integerInRange(startDay.value, STUDY_DAY_MIN, STUDY_DAY_MAX)) {
|
||||
settingsError.value = "每月开始日须为 5 到 25 的整数";
|
||||
if (scheduleTouched && !integerInRange(startDay.value, ADMIN_DAY_MIN, ADMIN_DAY_MAX)) {
|
||||
settingsError.value = "每月开始日须为 1 到 28 的整数";
|
||||
return;
|
||||
}
|
||||
if (workersChanged && !integerInRange(workersValue.value, 1, 8)) {
|
||||
@@ -980,7 +980,7 @@ onMounted(() => {
|
||||
</n-form-item>
|
||||
<n-form-item label="开始时刻">
|
||||
<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" />
|
||||
</div>
|
||||
</n-form-item>
|
||||
|
||||
@@ -326,6 +326,19 @@ async function loadTarget() {
|
||||
const startLoaded = ref(false);
|
||||
const scheduleEnabled = ref(true);
|
||||
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 startMinute = ref<number | null>(0);
|
||||
const startSecond = ref<number | null>(0);
|
||||
@@ -350,6 +363,7 @@ async function loadStart() {
|
||||
if (!res.ok) return false;
|
||||
const data = await res.json();
|
||||
startDay.value = typeof data.day === "number" ? data.day : STUDY_DAY_DEFAULT;
|
||||
loadedStartDay.value = startDay.value;
|
||||
startHour.value = typeof data.hour === "number" ? data.hour : 0;
|
||||
startMinute.value = typeof data.minute === "number" ? data.minute : 0;
|
||||
startSecond.value = typeof data.second === "number" ? data.second : 0;
|
||||
@@ -412,7 +426,8 @@ function scheduleBody(): Record<string, unknown> | null {
|
||||
scheduleError.value = "请填写完整的开始时刻";
|
||||
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 的整数";
|
||||
return null;
|
||||
}
|
||||
@@ -1048,7 +1063,7 @@ onUnmounted(() => {
|
||||
<n-select
|
||||
v-model:value="startDay"
|
||||
size="small"
|
||||
:options="dayOptions"
|
||||
:options="userDayOptions"
|
||||
class="day-select"
|
||||
:disabled="!scheduleEnabled"
|
||||
aria-label="每月开始日"
|
||||
|
||||
@@ -12,8 +12,15 @@ export const workerOptions = [
|
||||
export const STUDY_DAY_MIN = 5;
|
||||
export const STUDY_DAY_MAX = 25;
|
||||
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) => {
|
||||
const day = STUDY_DAY_MIN + index;
|
||||
return { label: `每月 ${day} 日`, value: day };
|
||||
});
|
||||
export function dayOptionsBetween(min: number, max: number) {
|
||||
return Array.from({ length: max - min + 1 }, (_, index) => {
|
||||
const day = min + index;
|
||||
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 {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
|
||||
gap: 16px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.settings-stack > .panel-card {
|
||||
box-sizing: border-box;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: auto;
|
||||
.settings-tree .n-collapse-item:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.settings-tree .n-collapse-item__header {
|
||||
padding: 10px 14px !important;
|
||||
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 {
|
||||
@@ -795,8 +812,10 @@ select {
|
||||
max-width: 30rem;
|
||||
}
|
||||
|
||||
.study-config .compact-nform {
|
||||
.study-config .compact-nform,
|
||||
.study-config .compact-nform.n-form {
|
||||
max-width: none;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.study-live {
|
||||
@@ -1716,10 +1735,8 @@ body .n-base-select-menu .n-base-select-option__content {
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.settings-stack {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
grid-template-rows: none;
|
||||
grid-auto-rows: auto;
|
||||
.settings-tree {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user