feat: 每月定时开始学习并改为本地计算心跳摘要
This commit is contained in:
@@ -12,6 +12,11 @@ interface UserRow {
|
||||
month_hours: string;
|
||||
has_proxy: boolean;
|
||||
proxy: string;
|
||||
study_start: string;
|
||||
study_start_day: number;
|
||||
study_start_hour: number;
|
||||
study_start_minute: number;
|
||||
study_start_second: number;
|
||||
}
|
||||
|
||||
interface SecretField {
|
||||
@@ -49,6 +54,14 @@ const proxyOptions = [
|
||||
{ label: "SOCKS4", value: "socks4" },
|
||||
{ label: "SOCKS5", value: "socks5" },
|
||||
];
|
||||
const startOpen = ref(false);
|
||||
const startSaving = ref(false);
|
||||
const startError = ref("");
|
||||
const startIds = ref<string[]>([]);
|
||||
const startDay = ref<number | null>(1);
|
||||
const startHour = ref<number | null>(0);
|
||||
const startMinute = ref<number | null>(0);
|
||||
const startSecond = ref<number | null>(0);
|
||||
|
||||
const pickedIds = computed(() => users.value.filter((row) => picked.value[row.employee_id]).map((row) => row.employee_id));
|
||||
const allPicked = computed(() => users.value.length > 0 && pickedIds.value.length === users.value.length);
|
||||
@@ -93,6 +106,11 @@ function asUser(value: unknown): UserRow | null {
|
||||
month_hours: textOf(value.month_hours),
|
||||
has_proxy: value.has_proxy === true,
|
||||
proxy: textOf(value.proxy),
|
||||
study_start: textOf(value.study_start),
|
||||
study_start_day: typeof value.study_start_day === "number" ? value.study_start_day : 1,
|
||||
study_start_hour: typeof value.study_start_hour === "number" ? value.study_start_hour : 0,
|
||||
study_start_minute: typeof value.study_start_minute === "number" ? value.study_start_minute : 0,
|
||||
study_start_second: typeof value.study_start_second === "number" ? value.study_start_second : 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -428,6 +446,69 @@ function confirmClearProxy(ids: string[]) {
|
||||
});
|
||||
}
|
||||
|
||||
function resetStartForm() {
|
||||
startDay.value = 1;
|
||||
startHour.value = 0;
|
||||
startMinute.value = 0;
|
||||
startSecond.value = 0;
|
||||
startError.value = "";
|
||||
}
|
||||
|
||||
function openStart(ids: string[]) {
|
||||
if (!ids.length) return;
|
||||
startIds.value = ids;
|
||||
resetStartForm();
|
||||
if (ids.length === 1) {
|
||||
const row = users.value.find((item) => item.employee_id === ids[0]);
|
||||
if (row) {
|
||||
startDay.value = row.study_start_day;
|
||||
startHour.value = row.study_start_hour;
|
||||
startMinute.value = row.study_start_minute;
|
||||
startSecond.value = row.study_start_second;
|
||||
}
|
||||
}
|
||||
startOpen.value = true;
|
||||
}
|
||||
|
||||
async function saveStart() {
|
||||
if (startSaving.value || !startIds.value.length) return;
|
||||
startError.value = "";
|
||||
if (
|
||||
startDay.value == null || startHour.value == null
|
||||
|| startMinute.value == null || startSecond.value == null
|
||||
|| !Number.isInteger(startDay.value) || !Number.isInteger(startHour.value)
|
||||
|| !Number.isInteger(startMinute.value) || !Number.isInteger(startSecond.value)
|
||||
) {
|
||||
startError.value = "请填写完整的开始时刻";
|
||||
return;
|
||||
}
|
||||
startSaving.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/admin/users/study-start", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
employee_ids: startIds.value,
|
||||
day: startDay.value,
|
||||
hour: startHour.value,
|
||||
minute: startMinute.value,
|
||||
second: startSecond.value,
|
||||
}),
|
||||
});
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
startError.value = detailOf(payload, "没有保存。");
|
||||
return;
|
||||
}
|
||||
startOpen.value = false;
|
||||
await load();
|
||||
} catch {
|
||||
startError.value = "没有保存。";
|
||||
} finally {
|
||||
startSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function rowActions(row: UserRow): DropdownOption[] {
|
||||
const busy = checkingAll.value || checkingId.value !== "";
|
||||
return [
|
||||
@@ -435,6 +516,7 @@ function rowActions(row: UserRow): DropdownOption[] {
|
||||
{ label: "查看凭据", key: "credentials" },
|
||||
{ label: "设置代理", key: "proxy" },
|
||||
{ label: "清除代理", key: "proxy-clear" },
|
||||
{ label: "开始时刻", key: "start" },
|
||||
{ label: row.refresh_paused ? "恢复自动刷新" : "停止自动刷新", key: "refresh" },
|
||||
{ label: "删除", key: "delete", props: { style: { color: "var(--danger)" } } },
|
||||
];
|
||||
@@ -445,6 +527,7 @@ function onRowAction(row: UserRow, key: string | number) {
|
||||
else if (key === "credentials") void openCredentials(row);
|
||||
else if (key === "proxy") void openProxy([row.employee_id]);
|
||||
else if (key === "proxy-clear") confirmClearProxy([row.employee_id]);
|
||||
else if (key === "start") openStart([row.employee_id]);
|
||||
else if (key === "refresh") confirmRefresh(row);
|
||||
else if (key === "delete") confirmDelete(row);
|
||||
}
|
||||
@@ -461,6 +544,7 @@ onMounted(() => {
|
||||
<div class="page-head-actions">
|
||||
<n-button :disabled="!pickedIds.length" @click="openProxy(pickedIds)">设置代理</n-button>
|
||||
<n-button :disabled="!pickedIds.length" @click="confirmClearProxy(pickedIds)">清除代理</n-button>
|
||||
<n-button :disabled="!pickedIds.length" @click="openStart(pickedIds)">开始时刻</n-button>
|
||||
<n-button :loading="checkingAll" :disabled="checkingAll || checkingId !== '' || !users.length" @click="checkAll">检查全部</n-button>
|
||||
</div>
|
||||
</header>
|
||||
@@ -477,6 +561,7 @@ onMounted(() => {
|
||||
<th>凭证</th>
|
||||
<th>凭据是否有效</th>
|
||||
<th>本月学时</th>
|
||||
<th>开始时刻</th>
|
||||
<th>代理</th>
|
||||
<th>上次刷新时间</th>
|
||||
<th>自动刷新</th>
|
||||
@@ -492,6 +577,7 @@ onMounted(() => {
|
||||
<td>{{ row.has_credential ? "已保存凭证" : "未保存凭证" }}</td>
|
||||
<td :class="validityClass(validityText(row))">{{ validityText(row) }}</td>
|
||||
<td class="when">{{ row.month_hours || "—" }}</td>
|
||||
<td class="when">{{ row.study_start || "—" }}</td>
|
||||
<td class="when">{{ row.proxy || "—" }}</td>
|
||||
<td class="when">{{ formatRefreshTime(row.last_refresh_at) }}</td>
|
||||
<td>{{ row.refresh_paused ? "已停止" : "开启" }}</td>
|
||||
@@ -574,5 +660,38 @@ onMounted(() => {
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
<n-modal
|
||||
:show="startOpen"
|
||||
preset="card"
|
||||
:title="startIds.length === 1 ? `工号 ${startIds[0]} 的开始时刻` : `已选 ${startIds.length} 个账号的开始时刻`"
|
||||
:style="{ width: 'min(520px, calc(100vw - 32px))' }"
|
||||
@update:show="(show) => (startOpen = show)"
|
||||
>
|
||||
<n-alert v-if="startError" class="admin-alert" type="error">{{ startError }}</n-alert>
|
||||
<form class="settings-form" @submit.prevent="saveStart">
|
||||
<div class="form-row">
|
||||
<label for="admin-start-day">每月</label>
|
||||
<n-input-number id="admin-start-day" v-model:value="startDay" button-placement="both" :min="1" :max="31" :precision="0" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-start-hour">时</label>
|
||||
<n-input-number id="admin-start-hour" v-model:value="startHour" button-placement="both" :min="0" :max="23" :precision="0" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-start-minute">分</label>
|
||||
<n-input-number id="admin-start-minute" v-model:value="startMinute" button-placement="both" :min="0" :max="59" :precision="0" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-start-second">秒</label>
|
||||
<n-input-number id="admin-start-second" v-model:value="startSecond" button-placement="both" :min="0" :max="59" :precision="0" />
|
||||
</div>
|
||||
</form>
|
||||
<template #footer>
|
||||
<div class="modal-actions">
|
||||
<n-button @click="startOpen = false">取消</n-button>
|
||||
<n-button type="primary" :loading="startSaving" @click="saveStart">保存</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -136,6 +136,50 @@ function saveTarget(value: number | null) {
|
||||
|
||||
watch(monthlyTarget, (v) => { if (targetLoaded.value) saveTarget(v); });
|
||||
|
||||
const startLoaded = ref(false);
|
||||
const startDay = ref<number | null>(1);
|
||||
const startHour = ref<number | null>(0);
|
||||
const startMinute = ref<number | null>(0);
|
||||
const startSecond = ref<number | null>(0);
|
||||
let startSaveTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
async function loadStart() {
|
||||
try {
|
||||
const res = await fetch("/api/settings/study-start");
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
startDay.value = typeof data.day === "number" ? data.day : 1;
|
||||
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;
|
||||
startLoaded.value = true;
|
||||
}
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
function saveStart() {
|
||||
const day = startDay.value;
|
||||
const hour = startHour.value;
|
||||
const minute = startMinute.value;
|
||||
const second = startSecond.value;
|
||||
if (
|
||||
day == null || hour == null || minute == null || second == null
|
||||
|| !Number.isInteger(day) || !Number.isInteger(hour) || !Number.isInteger(minute) || !Number.isInteger(second)
|
||||
) return;
|
||||
clearTimeout(startSaveTimer);
|
||||
startSaveTimer = setTimeout(async () => {
|
||||
try {
|
||||
await fetch("/api/settings/study-start", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ day, hour, minute, second }),
|
||||
});
|
||||
} catch { /* 静默 */ }
|
||||
}, 600);
|
||||
}
|
||||
|
||||
watch([startDay, startHour, startMinute, startSecond], () => { if (startLoaded.value) saveStart(); });
|
||||
|
||||
const proxyLoaded = ref(false);
|
||||
const proxySaving = ref(false);
|
||||
const proxyError = ref("");
|
||||
@@ -242,7 +286,7 @@ async function loadStudyStatus() {
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
onMounted(() => { refresh(); loadTarget(); loadProxy(); loadStudyStatus(); });
|
||||
onMounted(() => { refresh(); loadTarget(); loadStart(); loadProxy(); loadStudyStatus(); });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -313,6 +357,18 @@ onMounted(() => { refresh(); loadTarget(); loadProxy(); loadStudyStatus(); });
|
||||
<span class="target-unit">分钟</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="startLoaded" class="home-target home-start">
|
||||
<label for="study-start-day">每月开始学习</label>
|
||||
<div class="target-control start-control">
|
||||
<n-input-number id="study-start-day" v-model:value="startDay" button-placement="both" :min="1" :max="31" :precision="0" size="small" />
|
||||
<span class="target-unit">日</span>
|
||||
<n-input-number v-model:value="startHour" button-placement="both" :min="0" :max="23" :precision="0" size="small" />
|
||||
<span class="target-unit">:</span>
|
||||
<n-input-number v-model:value="startMinute" button-placement="both" :min="0" :max="59" :precision="0" size="small" />
|
||||
<span class="target-unit">:</span>
|
||||
<n-input-number v-model:value="startSecond" button-placement="both" :min="0" :max="59" :precision="0" size="small" />
|
||||
</div>
|
||||
</div>
|
||||
<form v-if="proxyLoaded" class="home-proxy" @submit.prevent="saveProxy">
|
||||
<n-alert v-if="proxyError" class="summary-error" type="error">{{ proxyError }}</n-alert>
|
||||
<div class="form-row">
|
||||
|
||||
@@ -429,6 +429,10 @@ select {
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.start-control .n-input-number {
|
||||
width: 88px;
|
||||
}
|
||||
|
||||
.target-unit {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
|
||||
Reference in New Issue
Block a user