Show Beijing time across admin UI and ntfy payloads.
Format ISO/unix stamps with Asia/Shanghai so join leads and alerts match China local clock. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
344886172d
commit
d830097b00
@ -126,9 +126,24 @@ export function fmtYuan(fen: number) {
|
|||||||
return `¥${(Number(fen || 0) / 100).toFixed(2)}`
|
return `¥${(Number(fen || 0) / 100).toFixed(2)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 管理后台统一北京时间(Asia/Shanghai)。 */
|
||||||
export function fmtTime(sec?: number | null) {
|
export function fmtTime(sec?: number | null) {
|
||||||
if (!sec) return '—'
|
if (!sec) return '—'
|
||||||
return new Date(sec * 1000).toLocaleString()
|
const ms = sec < 1e12 ? sec * 1000 : sec
|
||||||
|
try {
|
||||||
|
return new Intl.DateTimeFormat('zh-CN', {
|
||||||
|
timeZone: 'Asia/Shanghai',
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
}).format(new Date(ms))
|
||||||
|
} catch {
|
||||||
|
return new Date(ms).toISOString().slice(0, 19).replace('T', ' ')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shortId(id?: string | null, keep = 8) {
|
export function shortId(id?: string | null, keep = 8) {
|
||||||
|
|||||||
@ -2,7 +2,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
@ -11,6 +13,19 @@ from ebook_svc.config import settings
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_ICON = "https://nomadro.com/icon-192.png"
|
DEFAULT_ICON = "https://nomadro.com/icon-192.png"
|
||||||
|
_BEIJING = ZoneInfo("Asia/Shanghai")
|
||||||
|
|
||||||
|
|
||||||
|
def format_beijing_time(ts: float | int | None = None) -> str:
|
||||||
|
"""Admin / ntfy 统一北京时间。"""
|
||||||
|
try:
|
||||||
|
if ts is None:
|
||||||
|
d = datetime.now(_BEIJING)
|
||||||
|
else:
|
||||||
|
d = datetime.fromtimestamp(float(ts), tz=_BEIJING)
|
||||||
|
return d.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
except Exception:
|
||||||
|
return datetime.now(_BEIJING).strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
async def notify(
|
async def notify(
|
||||||
|
|||||||
@ -242,6 +242,7 @@ def format_event_message(ev: dict[str, Any], *, openid: str | None, client: str
|
|||||||
bullets: list[tuple[str, str]] = [
|
bullets: list[tuple[str, str]] = [
|
||||||
("用户", _short_openid(openid)),
|
("用户", _short_openid(openid)),
|
||||||
("渠道", _channel_label(client)),
|
("渠道", _channel_label(client)),
|
||||||
|
("时间", f"{ntfy_svc.format_beijing_time(ev.get('ts'))}(北京时间)"),
|
||||||
]
|
]
|
||||||
if ev.get("page"):
|
if ev.get("page"):
|
||||||
bullets.append(("页面", str(ev["page"])))
|
bullets.append(("页面", str(ev["page"])))
|
||||||
|
|||||||
38
apps/com/admin/src/lib/beijingTime.ts
Normal file
38
apps/com/admin/src/lib/beijingTime.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/** Admin UI clock: always Asia/Shanghai (北京时间). */
|
||||||
|
|
||||||
|
const BEIJING: Intl.DateTimeFormatOptions = {
|
||||||
|
timeZone: 'Asia/Shanghai',
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
function toDate(v: unknown): Date | null {
|
||||||
|
if (v == null || v === '') return null
|
||||||
|
if (typeof v === 'number' && Number.isFinite(v)) {
|
||||||
|
return new Date(v < 1e12 ? v * 1000 : v)
|
||||||
|
}
|
||||||
|
const s = String(v).trim()
|
||||||
|
if (!s) return null
|
||||||
|
if (/^\d+$/.test(s)) {
|
||||||
|
const n = Number(s)
|
||||||
|
return new Date(n < 1e12 ? n * 1000 : n)
|
||||||
|
}
|
||||||
|
const d = new Date(s)
|
||||||
|
return Number.isNaN(d.getTime()) ? null : d
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Format any ISO / unix / Date-like value as 北京时间. */
|
||||||
|
export function formatBeijingTime(v: unknown): string {
|
||||||
|
const d = toDate(v)
|
||||||
|
if (!d) return '—'
|
||||||
|
try {
|
||||||
|
return new Intl.DateTimeFormat('zh-CN', BEIJING).format(d)
|
||||||
|
} catch {
|
||||||
|
return d.toISOString().slice(0, 19).replace('T', ' ')
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { api } from '../api/client'
|
import { api } from '../api/client'
|
||||||
|
import { formatBeijingTime } from '../lib/beijingTime'
|
||||||
|
|
||||||
type TrackEvent = {
|
type TrackEvent = {
|
||||||
id: number
|
id: number
|
||||||
@ -54,9 +55,7 @@ function clientLabel(c: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fmtTime(ts: number) {
|
function fmtTime(ts: number) {
|
||||||
if (!ts) return '—'
|
return formatBeijingTime(ts)
|
||||||
const d = new Date(ts < 1e12 ? ts * 1000 : ts)
|
|
||||||
return d.toLocaleString('zh-CN', { hour12: false })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function shortId(id: string, n = 8) {
|
function shortId(id: string, n = 8) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import { api } from '../api/client'
|
import { api } from '../api/client'
|
||||||
|
import { formatBeijingTime } from '../lib/beijingTime'
|
||||||
|
|
||||||
type Usage = { totalBytes: number; usedBytes: number; usedPercent: number }
|
type Usage = { totalBytes: number; usedBytes: number; usedPercent: number }
|
||||||
type Health = {
|
type Health = {
|
||||||
@ -35,7 +36,7 @@ export default function Operations() {
|
|||||||
</header>
|
</header>
|
||||||
{error && <div className="com-toast com-toast-err" role="alert">{error} {data ? '下方保留上次检查结果。' : ''}</div>}
|
{error && <div className="com-toast com-toast-err" role="alert">{error} {data ? '下方保留上次检查结果。' : ''}</div>}
|
||||||
{data ? <>
|
{data ? <>
|
||||||
<section className={`com-health-banner ${data.ok && !error ? 'is-healthy' : 'is-degraded'}`} role="status"><span className="com-status-dot" /><div><strong>{error ? '状态更新失败' : data.ok ? '核心服务运行正常' : '部分服务需要检查'}</strong><p>上次检查:{new Date(data.checkedAt).toLocaleString('zh-CN', { hour12: false })}</p></div></section>
|
<section className={`com-health-banner ${data.ok && !error ? 'is-healthy' : 'is-degraded'}`} role="status"><span className="com-status-dot" /><div><strong>{error ? '状态更新失败' : data.ok ? '核心服务运行正常' : '部分服务需要检查'}</strong><p>上次检查:{formatBeijingTime(data.checkedAt)}(北京时间)</p></div></section>
|
||||||
<div className="com-health-grid">{data.checks.map(check => <article className="com-panel" key={check.name}><span className={`com-badge tone-${check.ok ? 'ok' : 'bad'}`}>{check.ok ? '可用' : '异常'}</span><h2>{check.name}</h2><strong className="com-health-value">{check.latencyMs}<small> ms</small></strong><p className="com-muted">{check.status ? `HTTP ${check.status}` : '连接失败或检查超时'}</p></article>)}</div>
|
<div className="com-health-grid">{data.checks.map(check => <article className="com-panel" key={check.name}><span className={`com-badge tone-${check.ok ? 'ok' : 'bad'}`}>{check.ok ? '可用' : '异常'}</span><h2>{check.name}</h2><strong className="com-health-value">{check.latencyMs}<small> ms</small></strong><p className="com-muted">{check.status ? `HTTP ${check.status}` : '连接失败或检查超时'}</p></article>)}</div>
|
||||||
<div className="com-health-grid">{(['memory', 'disk'] as const).map(key => {
|
<div className="com-health-grid">{(['memory', 'disk'] as const).map(key => {
|
||||||
const usage = data.resources[key]
|
const usage = data.resources[key]
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { api } from '../api/client'
|
import { api } from '../api/client'
|
||||||
|
import { formatBeijingTime } from '../lib/beijingTime'
|
||||||
import { orderState } from '../lib/orders'
|
import { orderState } from '../lib/orders'
|
||||||
import { downloadCsv } from '../lib/csv'
|
import { downloadCsv } from '../lib/csv'
|
||||||
|
|
||||||
@ -17,9 +18,7 @@ type Order = {
|
|||||||
type StatusTab = 'all' | 'paid' | 'pending' | 'other'
|
type StatusTab = 'all' | 'paid' | 'pending' | 'other'
|
||||||
|
|
||||||
function fmtTime(ts: number) {
|
function fmtTime(ts: number) {
|
||||||
if (!ts) return '—'
|
return formatBeijingTime(ts)
|
||||||
const d = new Date(ts < 1e12 ? ts * 1000 : ts)
|
|
||||||
return d.toLocaleString('zh-CN', { hour12: false })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fmtYuan(fen: number) {
|
function fmtYuan(fen: number) {
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { Link, useParams } from 'react-router-dom'
|
import { Link, useParams } from 'react-router-dom'
|
||||||
import { api } from '../api/client'
|
import { api } from '../api/client'
|
||||||
|
import { formatBeijingTime } from '../lib/beijingTime'
|
||||||
import { useConfigLive } from '../lib/useConfigLive'
|
import { useConfigLive } from '../lib/useConfigLive'
|
||||||
import { useDraft } from '../lib/useDraft'
|
import { useDraft } from '../lib/useDraft'
|
||||||
import UnsavedChanges from '../components/UnsavedChanges'
|
import UnsavedChanges from '../components/UnsavedChanges'
|
||||||
@ -205,7 +206,11 @@ export default function Pricing() {
|
|||||||
{cfg.flags?.payEnabled !== false ? '支付开' : '支付关'}
|
{cfg.flags?.payEnabled !== false ? '支付开' : '支付关'}
|
||||||
</span>
|
</span>
|
||||||
<span className="com-chip">v{cfg.version ?? '—'}</span>
|
<span className="com-chip">v{cfg.version ?? '—'}</span>
|
||||||
{cfg.updatedAt ? <span className="com-chip">{cfg.updatedAt}</span> : null}
|
{cfg.updatedAt ? (
|
||||||
|
<span className="com-chip" title="北京时间">
|
||||||
|
{formatBeijingTime(cfg.updatedAt)}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { Link, useParams } from 'react-router-dom'
|
import { Link, useParams } from 'react-router-dom'
|
||||||
import { api } from '../api/client'
|
import { api } from '../api/client'
|
||||||
|
import { formatBeijingTime } from '../lib/beijingTime'
|
||||||
import { useConfigLive } from '../lib/useConfigLive'
|
import { useConfigLive } from '../lib/useConfigLive'
|
||||||
import { useDraft } from '../lib/useDraft'
|
import { useDraft } from '../lib/useDraft'
|
||||||
import UnsavedChanges from '../components/UnsavedChanges'
|
import UnsavedChanges from '../components/UnsavedChanges'
|
||||||
@ -260,7 +261,11 @@ export default function Switches() {
|
|||||||
? '当前免费'
|
? '当前免费'
|
||||||
: `现价 ¥${((Number(cfg.copy?.vipPriceFen) || 0) / 100).toFixed((Number(cfg.copy?.vipPriceFen) || 0) % 100 === 0 ? 0 : 2)}`}
|
: `现价 ¥${((Number(cfg.copy?.vipPriceFen) || 0) / 100).toFixed((Number(cfg.copy?.vipPriceFen) || 0) % 100 === 0 ? 0 : 2)}`}
|
||||||
</span>
|
</span>
|
||||||
{cfg.updatedAt ? <span className="com-chip">{cfg.updatedAt}</span> : null}
|
{cfg.updatedAt ? (
|
||||||
|
<span className="com-chip" title="北京时间">
|
||||||
|
{formatBeijingTime(cfg.updatedAt)}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { api } from '../api/client'
|
import { api } from '../api/client'
|
||||||
|
import { formatBeijingTime } from '../lib/beijingTime'
|
||||||
|
|
||||||
type UnlockRow = { book_id: string; unlocked_at: number; source: string }
|
type UnlockRow = { book_id: string; unlocked_at: number; source: string }
|
||||||
|
|
||||||
@ -17,9 +18,7 @@ type UserRow = {
|
|||||||
type Tab = 'all' | 'unlocked' | 'vip' | 'locked' | 'blocked'
|
type Tab = 'all' | 'unlocked' | 'vip' | 'locked' | 'blocked'
|
||||||
|
|
||||||
function fmtTime(ts: number) {
|
function fmtTime(ts: number) {
|
||||||
if (!ts) return '—'
|
return formatBeijingTime(ts)
|
||||||
const d = new Date(ts < 1e12 ? ts * 1000 : ts)
|
|
||||||
return d.toLocaleString('zh-CN', { hour12: false })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function shortId(id: string, n = 10) {
|
function shortId(id: string, n = 10) {
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
/** 游民社区后台 · 分区与字段元数据 */
|
/** 游民社区后台 · 分区与字段元数据 */
|
||||||
|
|
||||||
|
import { formatBeijingTime } from '../lib/beijingTime'
|
||||||
|
|
||||||
export type SectionKey =
|
export type SectionKey =
|
||||||
| 'overview'
|
| 'overview'
|
||||||
| 'messages'
|
| 'messages'
|
||||||
@ -318,14 +320,9 @@ export function labelOf(key: string): string {
|
|||||||
return FIELD_LABEL[key] || key
|
return FIELD_LABEL[key] || key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 管理后台统一北京时间(Asia/Shanghai)。 */
|
||||||
export function fmtTime(v: unknown) {
|
export function fmtTime(v: unknown) {
|
||||||
if (v == null || v === '') return '—'
|
return formatBeijingTime(v)
|
||||||
const s = String(v)
|
|
||||||
if (/^\d+$/.test(s)) {
|
|
||||||
const n = Number(s)
|
|
||||||
return new Date(n < 1e12 ? n * 1000 : n).toLocaleString('zh-CN', { hour12: false })
|
|
||||||
}
|
|
||||||
return s.slice(0, 19).replace('T', ' ')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function short(v: unknown, n = 48) {
|
export function short(v: unknown, n = 48) {
|
||||||
|
|||||||
@ -61,7 +61,7 @@ function shortUid(uid: string | undefined): string {
|
|||||||
function fmtTime(ts?: number): string {
|
function fmtTime(ts?: number): string {
|
||||||
const d = ts && Number.isFinite(ts) ? new Date(ts) : new Date();
|
const d = ts && Number.isFinite(ts) ? new Date(ts) : new Date();
|
||||||
try {
|
try {
|
||||||
return new Intl.DateTimeFormat("zh-CN", {
|
const stamp = new Intl.DateTimeFormat("zh-CN", {
|
||||||
timeZone: "Asia/Shanghai",
|
timeZone: "Asia/Shanghai",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
month: "2-digit",
|
month: "2-digit",
|
||||||
@ -71,8 +71,9 @@ function fmtTime(ts?: number): string {
|
|||||||
second: "2-digit",
|
second: "2-digit",
|
||||||
hour12: false,
|
hour12: false,
|
||||||
}).format(d);
|
}).format(d);
|
||||||
|
return `${stamp}(北京时间)`;
|
||||||
} catch {
|
} catch {
|
||||||
return d.toISOString();
|
return `${d.toISOString()}(北京时间)`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user