diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index 48a0361..b5292c6 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -1,11 +1,15 @@ /** - * 接口客户端:统一带上 `Authorization: Bearer `,统一处理 `{ ok, data, message }` 结构 + * 接口客户端:统一带上 `Authorization: Bearer ` + `X-Subject-Id`, + * 统一处理 `{ ok, data, message }` 结构 * * 后端约定(见 backend/README): * - 成功 `{ ok: true, data }`;失败 `{ ok: false, message, status? }` * - 401 = 令牌缺失/过期/无效 → 清掉本地令牌并跳登录页 + * - 400 `status='subject_required'` = 没选主体;403 `status='subject_expired'` = 主体到期 + * (这两种由页面自己提示,不清令牌) */ import { clearToken, getToken } from '@/composables/useAuth'; +import { getStoredSubjectId } from '@/composables/subjectStorage'; /** 开发时走 Vite 代理(同源 /api),生产时后端同源托管,所以默认空字符串即可 */ const BASE = (import.meta.env.VITE_API_BASE as string | undefined) || ''; @@ -42,6 +46,9 @@ async function request(path: string, options: RequestOptions = {}): Promise(path: string, timeoutMs: number, method: 'GET' | 'POST' = 'GET'): Promise { +async function request(path: string, timeoutMs: number, method: 'GET' | 'POST' | 'DELETE' = 'GET', requestBody?: unknown): Promise { const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), timeoutMs); try { - const res = await fetch(`${LOCAL_BASE}${path}`, { - method, - headers: { Accept: 'application/json' }, - signal: controller.signal, - }); + let res: Response; + try { + res = await fetch(`${LOCAL_BASE}${path}`, { + method, + headers: { + Accept: 'application/json', + ...(requestBody === undefined ? {} : { 'Content-Type': 'application/json' }), + }, + body: requestBody === undefined ? undefined : JSON.stringify(requestBody), + signal: controller.signal, + }); + } catch (err) { + // 连不上本机软件(没启动 / 没安装 / 被拦):统一成 status=0,调用方据此提示唤起或下载 + const aborted = err instanceof DOMException && err.name === 'AbortError'; + throw new LocalServiceError(aborted ? '连接本机软件超时' : '无法连接本机软件', 0); + } const text = await res.text(); let body: unknown = null; @@ -177,3 +188,300 @@ export async function waitForQuery( return { result: last, offline: false }; } + +// ---------------- 按运单下载录像(本机软件 POST /api/playback/download) ---------------- + +/** 下载录像的结果 */ +export interface LocalPlaybackDownloadResult { + ok: boolean; + state?: 'ok' | 'need-login' | 'bad-request' | 'unsupported' | 'error'; + code?: string; + /** 最终存放目录(本机软件里设置的录像根目录 + 年/月/日) */ + folder?: string; + /** 合并后的成片路径(单路时就是那一路) */ + merged?: string | null; + /** 各路段文件(合并失败时会有多个) */ + segments?: string[]; + /** 非致命提示(某路没下到 / 合并失败等) */ + warnings?: string[]; + elapsedMs?: number; + message?: string; +} + +/** + * 让本机软件按运单号下载这段时间的录像(多路自动合并) + * + * 走的是 `POST /api/playback/download { code }`: + * - 录像存到**这台电脑自己设置的目录**(默认 `~/packVideo/年/月/日/`), + * 跟「是不是设备服务器」无关 —— 任何装了本机软件的电脑都能下; + * - 下载 + 合并可能要几十秒,所以超时给到 **180 秒**。 + */ +export function downloadPlayback(code: string): Promise { + return request('/api/playback/download', 180000, 'POST', { code }); +} + +// ---------------- 海康设备通道(本机软件 POST /api/hik/channels) ---------------- + +/** 本机软件返回的单个通道 */ +export interface HikChannelItem { + channel: number; + type: 'analog' | 'digital'; + enabled: boolean; + /** 设备上的通道名(来自 ISAPI,可能为空) */ + name?: string | null; + ip?: string | null; + port?: number | null; + user?: string | null; +} + +/** 本机软件拉通道的返回体(失败时 state=hik-error,并带 lastError) */ +export interface HikChannelsPayload { + ok: boolean; + state?: string; + lastError?: number; + message?: string; + data?: { + endpoint: string; + serialNumber: string; + diskCount: number; + analogChannelCount: number; + digitalChannelCount: number; + startChannel: number; + startDigitalChannel: number; + channels: HikChannelItem[]; + warning?: string | null; + userId: number; + sessionReused: boolean; + elapsedMs: number; + }; +} + +/** + * 通过**本机软件**登录海康 NVR(8000 私有协议)并拉取通道列表 + * + * 连不上本机软件(没启动 / 版本过旧 / 跨域被拦)→ 抛 {@link LocalServiceError}; + * 设备侧失败(密码错 / 端口不通)→ 正常返回,看 `ok === false` 与 `lastError`。 + */ +export function fetchHikChannels(params: { + host: string; + port?: number; + webPort?: number; + user: string; + password: string; +}): Promise { + return request('/api/hik/channels', 30000, 'POST', { + host: params.host, + port: params.port || 8000, + webPort: params.webPort || 80, + user: params.user, + password: params.password, + }); +} + +// ---------------- 海康实时预览(本机软件 /api/hik/preview) ---------------- + +/** 预览会话(密码不会出现在 URL 里,只用 sid) */ +export interface HikPreviewData { + sid: string; + host: string; + port: number; + /** 海康通道号(数字通道从 33 起) */ + channel: number; + /** ISAPI/RTSP 的 1 起序号 */ + logicalChannel: number; + /** RTSP 码流 id(主码流 = 通道号*100+1) */ + streamId: string; + fps: number; + /** stream = 码流本地解码(可到 25fps);capture = 设备抓帧(约 5fps);ffmpeg = ffmpeg 转码 */ + mode?: 'stream' | 'capture' | 'ffmpeg' | string; + /** 0-主码流 1-子码流 */ + streamType?: number; + maxFps?: number; + /** 降级提示(例如取流失败已退回抓帧) */ + warning?: string | null; + name?: string | null; + rtspUrl: string; + /** 相对路径,用 {@link localUrl} 拼成可给 `` 的地址 */ + mjpegUrl: string; + snapshotUrl: string; + expireAt: string; +} + +/** 本机软件建预览会话的返回体 */ +export interface HikPreviewPayload { + ok: boolean; + state?: string; + lastError?: number; + message?: string; + data?: HikPreviewData; +} + +/** 把本机服务返回的相对路径拼成完整地址(给 `` / `` 用) */ +export function localUrl(path: string): string { + return path.startsWith('http') ? path : `${LOCAL_BASE}${path}`; +} + +/** + * 建预览会话(本机软件 → 设备 8000 端口登录 + 抓帧) + * + * 设备侧失败(密码错 / 通道号错 / 不通)→ 正常返回,看 `ok === false` 与 `lastError`。 + */ +export function createHikPreview(params: { + host: string; + port?: number; + user: string; + password: string; + channel: number; + fps?: number; + logicalChannel?: number; + name?: string; + /** 0-主码流(默认) 1-子码流 */ + streamType?: number; + /** capture = 设备抓帧(低带宽,约 5fps);stream = SDK 取流解码;ffmpeg = ffmpeg 转码(主码流) */ + mode?: 'stream' | 'capture' | 'ffmpeg'; +}): Promise { + return request('/api/hik/preview', 20000, 'POST', { + host: params.host, + port: params.port || 8000, + user: params.user, + password: params.password, + channel: params.channel, + fps: params.fps || 25, + logicalChannel: params.logicalChannel, + name: params.name, + streamType: params.streamType ?? 0, + mode: params.mode, + }); +} + +/** 关闭预览(释放本机侧会话,设备侧连接留给连接池) */ +export function closeHikPreview(sid: string): Promise<{ ok?: boolean; removed?: boolean }> { + return request(`/api/hik/preview?sid=${encodeURIComponent(sid)}`, 4000, 'DELETE'); +} + +/** + * 页面卸载时释放预览(`navigator.sendBeacon` 只能发 POST,而且不能被 abort) + * + * 不释放的话:本机软件会一直拉设备码流,下次再开同一通道可能拿不到帧。 + */ +export function closeHikPreviewBeacon(sid: string): void { + if (!sid) return; + try { + navigator.sendBeacon(`${LOCAL_BASE}/api/hik/preview/close?sid=${encodeURIComponent(sid)}`); + } catch { + // 失败就算了:会话 30 分钟自动过期 + } +} + +/** + * 打开**满帧率**预览窗口(PlayM4 直接画到窗口,不经过 JPEG 编码 → 可跑满设备帧率 25fps) + * + * 浏览器无法直接承载 25fps 画面:内嵌只能逐帧转 JPEG(1080p 约 7fps 上限)。 + */ +export function openHikWindow(params: { + host: string; + port?: number; + user: string; + password: string; + channel: number; + streamType?: number; + name?: string; +}): Promise<{ + ok: boolean; + state?: string; + lastError?: number; + message?: string; + data?: { wid: string; host: string; channel: number; streamType: number; mode: string; fps: number; message: string }; +}> { + return request('/api/hik/preview/window', 20000, 'POST', { + host: params.host, + port: params.port || 8000, + user: params.user, + password: params.password, + channel: params.channel, + streamType: params.streamType ?? 0, + name: params.name, + }); +} + +/** 关窗口(用户直接关窗口时本机侧会自动释放,这里只是显式关) */ +export function closeHikWindow(wid: string): Promise<{ ok?: boolean; closed?: boolean }> { + return request(`/api/hik/preview/window?wid=${encodeURIComponent(wid)}`, 4000, 'DELETE'); +} + +/** 页面卸载时关满帧率窗口(同 {@link closeHikPreviewBeacon},sendBeacon 只能 POST) */ +export function closeHikWindowBeacon(wid: string): void { + if (!wid) return; + try { + navigator.sendBeacon(`${LOCAL_BASE}/api/hik/preview/window/close?wid=${encodeURIComponent(wid)}`); + } catch { + // 忽略 + } +} + +// ---------------- 海康云台(PTZ,本机软件 /api/hik/ptz) ---------------- + +/** 云台连续动作(方向 / 变倍 / 聚焦 / 光圈 / 自动扫描) */ +export type HikPtzCommand = + | 'up' | 'down' | 'left' | 'right' + | 'up-left' | 'up-right' | 'down-left' | 'down-right' + | 'zoom-in' | 'zoom-out' + | 'focus-near' | 'focus-far' + | 'iris-open' | 'iris-close' + | 'auto'; + +export interface HikPtzPayload { + ok: boolean; + state?: string; + lastError?: number; + message?: string; + data?: { channel: number; command?: string | null; action?: string | null; preset?: number; stop?: boolean }; +} + +/** + * 云台连续动作:stop=false 开始、stop=true 停止(必须成对) + * + * 走设备 8000 私有协议,不需要开预览;不是云台的通道会回 `state=hik-error`(设备不支持)。 + */ +export function ptzControl(params: { + host: string; + port?: number; + user: string; + password: string; + channel: number; + command: HikPtzCommand | string; + stop?: boolean; + speed?: number; +}): Promise { + return request('/api/hik/ptz', 8000, 'POST', { + host: params.host, + port: params.port || 8000, + user: params.user, + password: params.password, + channel: params.channel, + command: params.command, + stop: params.stop === true, + speed: params.speed || 4, + }); +} + +/** 预置点:set 设置当前位置 / goto 调用 / clear 删除 */ +export function ptzPreset(params: { + host: string; + port?: number; + user: string; + password: string; + channel: number; + action: 'set' | 'goto' | 'clear'; + preset: number; +}): Promise { + return request('/api/hik/ptz/preset', 8000, 'POST', { + host: params.host, + port: params.port || 8000, + user: params.user, + password: params.password, + channel: params.channel, + action: params.action, + preset: params.preset, + }); +} diff --git a/frontend/src/api/subjectApi.ts b/frontend/src/api/subjectApi.ts new file mode 100644 index 0000000..aa6d0bb --- /dev/null +++ b/frontend/src/api/subjectApi.ts @@ -0,0 +1,77 @@ +/** 主体(租户)相关接口 */ +import { api } from '@/api/client'; +import type { SubjectItem, SubjectMemberItem } from '@/composables/useSubject'; + +/** 我的主体列表 */ +export function fetchSubjects(): Promise<{ list: SubjectItem[]; trialDays: number }> { + return api.get<{ list: SubjectItem[]; trialDays: number }>('/api/web/subjects'); +} + +/** 创建主体(默认赠送 trialDays 天) */ +export function createSubject(body: { name: string; days?: number; remark?: string }): Promise { + return api.post('/api/web/subjects', body); +} + +/** 修改主体(管理员):改名 / 备注 / 续期 */ +export function updateSubject( + id: number, + body: { name?: string; remark?: string; extendDays?: number }, +): Promise { + return api.put(`/api/web/subjects/${id}`, body); +} + +/** 成员列表 */ +export function fetchSubjectMembers(id: number): Promise<{ subjectId: number; list: SubjectMemberItem[] }> { + return api.get<{ subjectId: number; list: SubjectMemberItem[] }>(`/api/web/subjects/${id}/members`); +} + +/** 按姓名快速添加成员 */ +export function addSubjectMember(id: number, body: { name: string; role?: number }): Promise { + return api.post(`/api/web/subjects/${id}/members`, body); +} + +/** 移除成员 */ +export function removeSubjectMember(id: number, memberId: number): Promise<{ id: number }> { + return api.del<{ id: number }>(`/api/web/subjects/${id}/members/${memberId}`); +} + +export interface MemberBindCode { + code: string; + memberId: number; + memberName: string; + bindUrl: string; + qrUrl: string; + expiresIn: number; +} + +/** 生成成员绑定码(手机扫码后绑定成员) */ +export function createMemberBindCode(id: number, memberId: number): Promise { + return api.post(`/api/web/subjects/${id}/members/${memberId}/bind-code`, {}); +} + +export interface MemberBindStatus { + status: 'pending' | 'confirmed' | 'expired' | 'bad_format' | string; + code?: string; + subjectId?: number; + subjectName?: string; + memberId?: number; + memberName?: string; + boundName?: string; +} + +/** 绑定码状态(公开接口,手机扫码页轮询) */ +export function fetchMemberBindStatus(code: string): Promise { + return api.get(`/api/subject/member-bind?code=${encodeURIComponent(code)}`, { auth: false }); +} + +/** 确认绑定:把当前登录账号绑到该成员(需登录) */ +export function confirmMemberBind(code: string): Promise<{ + status: string; + subjectId: number; + subjectName: string; + memberId: number; + memberName: string; + boundName: string; +}> { + return api.post('/api/subject/member-bind/confirm', { code }); +} diff --git a/frontend/src/api/video.ts b/frontend/src/api/video.ts new file mode 100644 index 0000000..4eff205 --- /dev/null +++ b/frontend/src/api/video.ts @@ -0,0 +1,128 @@ +/** + * 视频接入:NVR / 摄像头 / 工作台 —— 类型定义 + * + * 后端返回的字段名同时存在驼峰与下划线(Sequelize 的 toJSON 习惯), + * 页面只用驼峰字段,下划线字段忽略即可。 + */ + +/** NVR 录像机 */ +export interface Nvr { + id: number; + userId?: number | null; + name: string; + host: string; + port: number; + username: string; + serialNumber?: string | null; + deviceModel?: string | null; + channelCount: number; + lastSyncAt?: string | null; + lastError?: string | null; + status: number; + remark?: string | null; + createdAt?: string; + updatedAt?: string; +} + +/** 摄像头(NVR 通道) */ +export interface Camera { + id: number; + nvrId: number; + channelNo: number; + name: string; + /** 设备上的通道名(可能为空) */ + channelName?: string | null; + type: 'analog' | 'digital' | string; + ip?: string | null; + port?: number | null; + enabled: number; + /** 是否支持云台(PTZ),由用户勾选 */ + hasPtz?: boolean | number | null; + status: number; + remark?: string | null; + nvr?: { + id: number; + name: string; + host: string; + port: number; + serialNumber?: string | null; + userId?: number | null; + } | null; + /** 已被哪个工作台绑定(null = 可绑);来自 /cameras/options */ + boundWorkstation?: { id: number; code?: string; name?: string } | null; +} + +/** 工作台 */ +export interface Workstation { + id: number; + userId?: number | null; + code: string; + name: string; + /** 1 散单工作台 2 团购工作台 */ + wsType?: number; + /** 录制范围:触发点之前秒数(团购=扫码前,散单=任务结束前) */ + recordBeforeSec?: number; + /** 录制范围:触发点之后秒数 */ + recordAfterSec?: number; + /** 最大录制时长(秒),默认 240 */ + recordMaxSec?: number; + status: number; + remark?: string | null; + /** 合成画布(默认 1920×1080) */ + canvasWidth?: number; + canvasHeight?: number; + cameraCount?: number; + scanChannelCount?: number; + createdAt?: string; + updatedAt?: string; + /** Sequelize 实际输出的下划线时间字段 */ + created_at?: string; + updated_at?: string; +} + +/** 工作台-摄像头绑定 */ +export interface WorkstationCameraLink { + id: number; + workstationId: number; + cameraId: number; + sortNo: number; + remark?: string | null; + /** 合成画面里的矩形(像素,相对画布) */ + x?: number; + y?: number; + width?: number; + height?: number; + /** 0 主码流 1 子码流 */ + streamType?: number; + zIndex?: number; + camera?: (Camera & { displayName?: string }) | null; +} + +/** 工作台-扫码通道绑定 */ +export interface WorkstationScanChannelLink { + id: number; + workstationId: number; + scannerId: number; + channelId: string; + channelName?: string | null; + sortNo: number; + remark?: string | null; + scanner?: { id: number; sn: string; name?: string | null; status?: number } | null; +} + +/** 工作台详情 */ +export interface WorkstationDetail extends Workstation { + cameras: WorkstationCameraLink[]; + scanChannels: WorkstationScanChannelLink[]; +} + +/** 可绑定的扫码通道(来自中控上报) */ +export interface AvailableScanChannel { + id: number; + scannerId: number; + channelId: string; + channelName?: string | null; + scanner?: { id: number; sn: string; name?: string | null; status?: number } | null; + /** 已被哪个工作台绑定(null = 可绑) */ + boundWorkstation?: { id: number; code?: string; name?: string } | null; +} diff --git a/frontend/src/api/videoApi.ts b/frontend/src/api/videoApi.ts new file mode 100644 index 0000000..4c514a4 --- /dev/null +++ b/frontend/src/api/videoApi.ts @@ -0,0 +1,250 @@ +/** + * 视频接入接口(`/api/web/nvrs|cameras|workstations`) + * + * 全部只碰「自己的」数据:后端按令牌里的 user 过滤,别人的资源一律 404。 + */ +import { api } from '@/api/client'; +import type { Paged } from '@/api/types'; +import type { + AvailableScanChannel, + Camera, + Nvr, + Workstation, + WorkstationDetail, +} from '@/api/video'; + +// ---------------- NVR ---------------- + +export function fetchNvrs(params: { + page?: number; + pageSize?: number; + keyword?: string; + status?: number | ''; +} = {}): Promise> { + const query = new URLSearchParams(); + if (params.page) query.set('page', String(params.page)); + if (params.pageSize) query.set('pageSize', String(params.pageSize)); + if (params.keyword) query.set('keyword', params.keyword); + if (params.status !== undefined && params.status !== '') query.set('status', String(params.status)); + const qs = query.toString(); + return api.get>(`/api/web/nvrs${qs ? `?${qs}` : ''}`); +} + +/** 新增 NVR(同 host+port+username 已存在时后端会更新) */ +export function createNvr(body: { + name?: string; + host: string; + port?: number; + username?: string; + password: string; + serialNumber?: string; + deviceModel?: string; + remark?: string; +}): Promise { + return api.post('/api/web/nvrs', body); +} + +/** 更新 NVR(password 不传 = 保持原密码) */ +export function updateNvr(id: number, body: { + name?: string; + host?: string; + port?: number; + username?: string; + password?: string; + remark?: string; + status?: number; +}): Promise { + return api.put(`/api/web/nvrs/${id}`, body); +} + +/** 删除 NVR(连带删除其下摄像头并解除工作台绑定) */ +export function deleteNvr(id: number): Promise<{ id: number; removedCameras: number }> { + return api.del<{ id: number; removedCameras: number }>(`/api/web/nvrs/${id}`); +} + +/** 某 NVR 下已导入的摄像头 */ +export function fetchNvrCameras(id: number): Promise<{ nvrId: number; list: Camera[] }> { + return api.get<{ nvrId: number; list: Camera[] }>(`/api/web/nvrs/${id}/channels`); +} + +/** + * 拉取通道用的登录凭据(含库里解密出来的密码) + * + * 仅当密码存在时可取;返回后直接转给本机软件,不要长期缓存。 + */ +export function fetchNvrCredential(id: number): Promise<{ + id: number; + name: string; + host: string; + port: number; + username: string; + password: string; + hasPassword: boolean; +}> { + return api.get(`/api/web/nvrs/${id}/credential`); +} + +/** + * 导入(勾选)通道为摄像头 + * + * 通道数据来自本机软件 `POST /api/hik/channels`,这里只把结果落库。 + */ +export function importNvrChannels(id: number, body: { + serialNumber?: string; + deviceModel?: string; + channels: Array<{ + channel: number; + type: string; + name?: string; + ip?: string | null; + port?: number | null; + enabled?: boolean | number; + }>; +}): Promise<{ created: number; updated: number; list: Camera[]; nvr: Nvr }> { + return api.post<{ created: number; updated: number; list: Camera[]; nvr: Nvr }>( + `/api/web/nvrs/${id}/channels`, + body, + ); +} + +// ---------------- 摄像头 ---------------- + +export function fetchCameras(params: { + page?: number; + pageSize?: number; + nvrId?: number | ''; + keyword?: string; + status?: number | ''; +} = {}): Promise> { + const query = new URLSearchParams(); + if (params.page) query.set('page', String(params.page)); + if (params.pageSize) query.set('pageSize', String(params.pageSize)); + if (params.nvrId !== undefined && params.nvrId !== '') query.set('nvrId', String(params.nvrId)); + if (params.keyword) query.set('keyword', params.keyword); + if (params.status !== undefined && params.status !== '') query.set('status', String(params.status)); + const qs = query.toString(); + return api.get>(`/api/web/cameras${qs ? `?${qs}` : ''}`); +} + +/** 我的全部可用摄像头(工作台绑定选择器) */ +export function fetchCameraOptions(): Promise<{ list: Camera[] }> { + return api.get<{ list: Camera[] }>('/api/web/cameras/options'); +} + +export function updateCamera(id: number, body: { + name?: string; + status?: number; + remark?: string; + /** 1/0:是否支持云台(PTZ) */ + hasPtz?: number | boolean; +}): Promise { + return api.put(`/api/web/cameras/${id}`, body); +} + +export function deleteCamera(id: number): Promise<{ id: number }> { + return api.del<{ id: number }>(`/api/web/cameras/${id}`); +} + +/** 批量删除摄像头 */ +export function batchDeleteCameras(ids: number[]): Promise<{ removed: number; skipped: number }> { + return api.post<{ removed: number; skipped: number }>('/api/web/cameras/batch-delete', { ids }); +} + +// ---------------- 工作台 ---------------- + +export function fetchWorkstations(params: { + page?: number; + pageSize?: number; + keyword?: string; + status?: number | ''; + /** 1 散单 2 团购;不传 = 全部 */ + wsType?: number | ''; +} = {}): Promise> { + const query = new URLSearchParams(); + if (params.page) query.set('page', String(params.page)); + if (params.pageSize) query.set('pageSize', String(params.pageSize)); + if (params.keyword) query.set('keyword', params.keyword); + if (params.status !== undefined && params.status !== '') query.set('status', String(params.status)); + if (params.wsType !== undefined && params.wsType !== '') query.set('wsType', String(params.wsType)); + const qs = query.toString(); + return api.get>(`/api/web/workstations${qs ? `?${qs}` : ''}`); +} + +/** 工作台详情(含已绑摄像头 / 扫码通道) */ +export function fetchWorkstation(id: number): Promise { + return api.get(`/api/web/workstations/${id}`); +} + +export function createWorkstation(body: { + /** 不传则由后端自动生成 */ + code?: string; + name?: string; + /** 1 散单 2 团购 */ + wsType?: number; + recordBeforeSec?: number; + recordAfterSec?: number; + recordMaxSec?: number; + remark?: string; +}): Promise { + return api.post('/api/web/workstations', body); +} + +export function updateWorkstation(id: number, body: { + code?: string; + name?: string; + wsType?: number; + recordBeforeSec?: number; + recordAfterSec?: number; + recordMaxSec?: number; + remark?: string; + status?: number; +}): Promise { + return api.put(`/api/web/workstations/${id}`, body); +} + +export function deleteWorkstation(id: number): Promise<{ id: number }> { + return api.del<{ id: number }>(`/api/web/workstations/${id}`); +} + +/** 追加绑定摄像头 */ +export function bindWorkstationCameras(id: number, cameraIds: number[]): Promise { + return api.post(`/api/web/workstations/${id}/cameras`, { cameraIds }); +} + +export function unbindWorkstationCamera(id: number, cameraId: number): Promise { + return api.del(`/api/web/workstations/${id}/cameras/${cameraId}`); +} + +/** + * 保存某块摄像头在合成画面里的位置 / 大小 / 码流 + * + * 坐标是相对画布(默认 1920×1080)的像素;后端会按画布范围夹住。 + */ +export function updateWorkstationCameraLayout(id: number, cameraId: number, patch: { + x?: number; + y?: number; + width?: number; + height?: number; + streamType?: number; + zIndex?: number; +}): Promise { + return api.put(`/api/web/workstations/${id}/cameras/${cameraId}/layout`, patch); +} + +/** 追加绑定扫码通道 */ +export function bindWorkstationScanChannels( + id: number, + items: Array<{ scannerId: number; channelId: string; channelName?: string }>, +): Promise { + return api.post(`/api/web/workstations/${id}/scan-channels`, { items }); +} + +export function unbindWorkstationScanChannel(id: number, linkId: number): Promise { + return api.del(`/api/web/workstations/${id}/scan-channels/${linkId}`); +} + +/** 当前用户可绑定的扫码通道(自己的中控上报的通道) */ +export function fetchAvailableScanChannels(keyword = ''): Promise<{ list: AvailableScanChannel[] }> { + const qs = keyword ? `?keyword=${encodeURIComponent(keyword)}` : ''; + return api.get<{ list: AvailableScanChannel[] }>(`/api/web/workstation-scan-channels${qs}`); +} diff --git a/frontend/src/components/AppLayout.vue b/frontend/src/components/AppLayout.vue index 0952cad..426c233 100644 --- a/frontend/src/components/AppLayout.vue +++ b/frontend/src/components/AppLayout.vue @@ -1,7 +1,16 @@ + + diff --git a/frontend/src/components/CameraLayoutCanvas.vue b/frontend/src/components/CameraLayoutCanvas.vue new file mode 100644 index 0000000..9cac08d --- /dev/null +++ b/frontend/src/components/CameraLayoutCanvas.vue @@ -0,0 +1,546 @@ + + + + + diff --git a/frontend/src/components/DataPager.vue b/frontend/src/components/DataPager.vue new file mode 100644 index 0000000..27b9a23 --- /dev/null +++ b/frontend/src/components/DataPager.vue @@ -0,0 +1,79 @@ + + + diff --git a/frontend/src/components/ModalBox.vue b/frontend/src/components/ModalBox.vue new file mode 100644 index 0000000..bf426cd --- /dev/null +++ b/frontend/src/components/ModalBox.vue @@ -0,0 +1,92 @@ + + + + + diff --git a/frontend/src/composables/subjectStorage.ts b/frontend/src/composables/subjectStorage.ts new file mode 100644 index 0000000..1330912 --- /dev/null +++ b/frontend/src/composables/subjectStorage.ts @@ -0,0 +1,26 @@ +/** + * 主体选择的本地存储(**只做 localStorage**,不引接口,避免和 api/client.ts 形成循环依赖) + * + * `client.ts` 每次请求都会调 `getStoredSubjectId()` 决定要不要带 `X-Subject-Id`。 + */ +const SUBJECT_KEY = 'packs_subject_id'; + +/** 上次使用的主体 id(没有/非法返回 null) */ +export function getStoredSubjectId(): number | null { + try { + const raw = Number(localStorage.getItem(SUBJECT_KEY)); + return Number.isInteger(raw) && raw > 0 ? raw : null; + } catch { + return null; + } +} + +/** 记住/清除当前主体 */ +export function setStoredSubjectId(id: number | null): void { + try { + if (id) localStorage.setItem(SUBJECT_KEY, String(id)); + else localStorage.removeItem(SUBJECT_KEY); + } catch { + /* localStorage 不可用时忽略(隐私模式) */ + } +} diff --git a/frontend/src/composables/useAuth.ts b/frontend/src/composables/useAuth.ts index de548ba..abb6dd0 100644 --- a/frontend/src/composables/useAuth.ts +++ b/frontend/src/composables/useAuth.ts @@ -1,4 +1,5 @@ import { ref } from 'vue'; +import { setStoredSubjectId } from '@/composables/subjectStorage'; /** 本地令牌与当前用户的存放(SPA 用 header 令牌,不依赖 cookie/session) */ const TOKEN_KEY = 'packs_token'; @@ -43,6 +44,8 @@ export function setUser(user: CurrentUser): void { export function clearToken(): void { localStorage.removeItem(TOKEN_KEY); localStorage.removeItem(USER_KEY); + // 主体选择也要清:换账号后不能带着上一个账号的主体 id + setStoredSubjectId(null); currentUser.value = null; } diff --git a/frontend/src/composables/useSubject.ts b/frontend/src/composables/useSubject.ts new file mode 100644 index 0000000..125d2eb --- /dev/null +++ b/frontend/src/composables/useSubject.ts @@ -0,0 +1,126 @@ +/** + * 主体(租户)状态:当前主体 + 主体列表 + * + * - 上次使用的主题存在 `localStorage.packs_subject_id`,登录后如果还在列表里就继续用它 + * - 所有业务接口都要带 `X-Subject-Id`(见 `api/client.ts`) + * - 没有可用主体时,菜单里只留「主体」入口,先创建主体才能看到设备/录像机/摄像头/工作台/扫码记录 + */ +import { computed, ref } from 'vue'; +import { api } from '@/api/client'; +import { getToken } from '@/composables/useAuth'; +import { getStoredSubjectId, setStoredSubjectId } from '@/composables/subjectStorage'; + +export interface SubjectItem { + id: number; + name: string; + adminUserId: number; + expireAt: string; + status: number; + remark?: string | null; + /** 1 管理员 2 成员 */ + role: number; + memberName?: string | null; + memberCount?: number; + expired: boolean; +} + +export interface SubjectMemberItem { + id: number; + name: string; + role: number; + status: number; + userId: number | null; + boundAt?: string | null; + wechatBound: boolean; + user?: { id: number; username?: string | null; nickname?: string | null; avatar?: string | null } | null; + createdAt?: string; +} + +function readId(): number | null { + return getStoredSubjectId(); +} + +/** 主体列表(响应式) */ +export const subjects = ref([]); +/** 新建主体默认赠送天数(后端下发) */ +export const trialDays = ref(7); +/** 当前主体 id(响应式) */ +export const currentSubjectId = ref(readId()); +/** 是否已经拉过主体列表 */ +export const subjectsLoaded = ref(false); +/** 这份列表是用哪个令牌拉下来的(换账号/退出后自动重拉,避免脏数据) */ +let loadedForToken = ''; + +/** 当前主体对象 */ +export const currentSubject = computed( + () => subjects.value.find(item => item.id === currentSubjectId.value) || null, +); + +/** 是否有可用主体(存在且在有效期内) */ +export const hasSubject = computed(() => Boolean(currentSubject.value && !currentSubject.value.expired)); + +/** 当前账号是不是当前主体的管理员 */ +export const isSubjectAdmin = computed(() => Number(currentSubject.value?.role) === 1); + +export function getSubjectId(): number | null { + const id = currentSubjectId.value; + return id && subjects.value.some(item => item.id === id) ? id : null; +} + +/** 切换主体(只改本地;接口靠 header 带上) */ +export function setSubjectId(id: number | null): void { + setStoredSubjectId(id); + currentSubjectId.value = id; + if (!id) return; +} + +/** 清掉主体选择(退出登录 / 换账号时) */ +export function clearSubjectCache(): void { + subjects.value = []; + subjectsLoaded.value = false; + loadedForToken = ''; + currentSubjectId.value = null; + setStoredSubjectId(null); +} + +/** 用后端下发的列表刷新(登录接口里也带了一份) */ +export function applySubjects(list: SubjectItem[], days?: number): void { + subjects.value = Array.isArray(list) ? list : []; + subjectsLoaded.value = true; + loadedForToken = getToken(); + if (typeof days === 'number' && days > 0) trialDays.value = days; + + // 上次用的主体还在 → 继续用;否则挑第一个可用的(没过期),都没有就选第一个 + const stored = readId(); + const keep = stored && subjects.value.some(item => item.id === stored) ? stored : null; + if (keep) { + currentSubjectId.value = keep; + return; + } + const usable = subjects.value.find(item => !item.expired && Number(item.status) === 1) || subjects.value[0]; + setSubjectId(usable ? usable.id : null); +} + +/** 拉取主体列表(`GET /api/web/subjects`) */ +export async function loadSubjects(): Promise { + const data = await api.get<{ list: SubjectItem[]; trialDays: number }>('/api/web/subjects'); + applySubjects(data.list, data.trialDays); + return subjects.value; +} + +/** 没拉过(或换了账号)就拉一次(路由守卫里用) */ +export async function ensureSubjects(): Promise { + if (subjectsLoaded.value && loadedForToken === getToken() && getToken()) return; + await loadSubjects(); +} + +/** 本地更新某个主体(改完名字/续期后不用整表重拉) */ +export function patchSubject(id: number, patch: Partial): void { + const index = subjects.value.findIndex(item => item.id === id); + if (index >= 0) subjects.value[index] = Object.assign({}, subjects.value[index], patch); +} + +/** 使用期限是否已过(前端也判一次,用于提示色) */ +export function isExpired(item: SubjectItem): boolean { + return Boolean(item.expired) || new Date(item.expireAt).getTime() <= Date.now(); +} diff --git a/frontend/src/main.ts b/frontend/src/main.ts index a2d45ef..4481f9d 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -1,6 +1,32 @@ import { createApp } from 'vue'; import App from './App.vue'; import { router } from './router'; +import { api } from './api/client'; +import { getToken, setUser, type CurrentUser } from './composables/useAuth'; +import { loadSubjects } from './composables/useSubject'; import './styles/main.css'; createApp(App).use(router).mount('#app'); + +/** + * 启动后补拉一下当前用户与主体。 + * + * 桌面端「工具 → 打开配置页」带 `?token=` 直接打开时,本地只有令牌没有用户信息; + * 令牌由路由守卫先落地(并把 URL 里的 token 去掉),这里只管把用户/主体补全。 + */ +async function refreshSession(): Promise { + if (!getToken()) return; + + try { + const me = await api.get('/api/web/me'); + setUser(me); + } catch { + // 令牌无效:路由守卫会把人送回登录页 + return; + } + + await loadSubjects().catch(() => undefined); +} + +// 等首屏路由(含 SSO 令牌落地)完成后再补拉用户信息 +void router.isReady().then(refreshSession); diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 7259bf6..ab5ef9b 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -1,5 +1,6 @@ import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'; import { getToken } from '@/composables/useAuth'; +import { ensureSubjects, hasSubject } from '@/composables/useSubject'; /** * 路由表(meta.public = 不需要登录) @@ -23,10 +24,16 @@ const routes: RouteRecordRaw[] = [ meta: { public: true, bare: true }, }, - { path: '/', name: 'home', component: () => import('@/views/HomeView.vue') }, + { path: '/', name: 'home', component: () => import('@/views/HomeView.vue'), meta: { allowNoSubject: true } }, + // 主体 / 成员:没有主体时只有这个入口(创建主体、切换主体、绑成员) + { path: '/subjects', name: 'subjects', component: () => import('@/views/SubjectsView.vue'), meta: { allowNoSubject: true } }, { path: '/devices', name: 'devices', component: () => import('@/views/DevicesView.vue') }, + // 视频接入:NVR → 摄像头 → 工作台 + { path: '/nvrs', name: 'nvrs', component: () => import('@/views/NvrsView.vue') }, + { path: '/cameras', name: 'cameras', component: () => import('@/views/CamerasView.vue') }, + { path: '/workstations', name: 'workstations', component: () => import('@/views/WorkstationsView.vue') }, { path: '/records', name: 'records', component: () => import('@/views/RecordsView.vue') }, - { path: '/profile', name: 'profile', component: () => import('@/views/ProfileView.vue') }, + { path: '/profile', name: 'profile', component: () => import('@/views/ProfileView.vue'), meta: { allowNoSubject: true } }, { path: '/test', name: 'test', component: () => import('@/views/TestView.vue') }, { path: '/:pathMatch(.*)*', redirect: '/' }, @@ -37,7 +44,17 @@ export const router = createRouter({ routes, }); -router.beforeEach((to) => { +router.beforeEach(async (to) => { + // 桌面端「工具 → 打开配置页」:`?token=<用户 JWT>` 直接登录,并把 token 从地址栏去掉 + const ssoToken = typeof to.query.token === 'string' ? to.query.token : (typeof to.query.sso === 'string' ? to.query.sso : ''); + if (ssoToken) { + localStorage.setItem('packs_token', ssoToken); + const query = { ...to.query }; + delete query.token; + delete query.sso; + return { path: to.path, query, replace: true }; + } + const logged = Boolean(getToken()); if (!to.meta.public && !logged) { return { name: 'login', query: { redirect: to.fullPath } }; @@ -48,5 +65,17 @@ router.beforeEach((to) => { if (to.meta.public && logged && !alwaysShow) { return { name: 'home' }; } + + // 业务页都要主体:没拉过列表先拉一次,没有可用主体就去「主体 / 成员」页创建 + if (logged && !to.meta.public) { + try { + await ensureSubjects(); + } catch { + // 后端不可用时不拦路由,让页面自己报错 + } + if (to.meta.allowNoSubject !== true && !hasSubject.value) { + return { name: 'subjects', query: { need: '1' } }; + } + } return true; }); diff --git a/frontend/src/styles/main.css b/frontend/src/styles/main.css index 43317ff..0f57f64 100644 --- a/frontend/src/styles/main.css +++ b/frontend/src/styles/main.css @@ -134,29 +134,26 @@ select:focus { } .bare-card { + position: relative; /* 登录页的右上角三角就以卡片为定位父级 */ width: 360px; max-width: 100%; margin: auto; + overflow: hidden; /* 让三角的直角被卡片圆角裁掉 */ } /* ---------------- 登录页的面板切换(账号密码 ↔ 微信扫码) ---------------- · 面板都放在同一个 .panel-switch 容器里,靠 is-login / is-register / is-wechat 决定显示哪个; - · 登录与扫码用 padding-top + min-height 定成同高 → 切换时卡片高度/位置不变; - · 右上角的三角形 .corner-toggle 挂在容器上,和输入框右边缘对齐(不是页面右上角)。 */ + · 登录与扫码用 min-height 定成同高 → 切换时卡片高度/位置不变; + · 右上角三角形 .corner-toggle 挂在**卡片**(.card.bare-card)上,不是在面板里: + 它从卡片顶边算 38px 高,卡片自身 padding 20px,所以面板再留 18px(20+18=38)就不会被三角压住。 */ .panel-switch { position: relative; } -/* 登录(含注册)与扫码面板都要给右上角三角形留出 38px,登录/扫码再定成同高 */ -.panel-switch.is-login, -.panel-switch.is-register, -.panel-switch.is-wechat { - padding-top: 38px; -} - .panel-switch.is-login, .panel-switch.is-wechat { - min-height: 300px; + padding-top: 18px; + min-height: 282px; } .pane { @@ -176,6 +173,7 @@ select:focus { position: absolute; top: 0; right: 0; + z-index: 1; width: 38px; height: 38px; padding: 0; @@ -399,6 +397,30 @@ th { justify-content: flex-end; gap: 10px; margin-top: 14px; + flex-wrap: wrap; +} + +.pager-pos { + min-width: 54px; + text-align: center; +} + +.pager-select { + height: 30px; + padding: 0 6px; + border: 1px solid var(--border); + border-radius: 6px; + background: #fff; + font-size: 13px; +} + +.pager-jump { + width: 72px; + height: 30px; + padding: 0 8px; + border: 1px solid var(--border); + border-radius: 6px; + font-size: 13px; } .btn-sm { @@ -427,6 +449,19 @@ th { border-color: #fecaca; } +/* 工作台类型:散单(蓝)/ 团购(橙) */ +.badge-single { + color: #1d4ed8; + background: #eff6ff; + border-color: #bfdbfe; +} + +.badge-group { + color: #b45309; + background: #fff7ed; + border-color: #fed7aa; +} + /* ---------------- 列表页:占满高度,滚动只在表格内部(整页不滚动) ---------------- AppLayout 传 fill 时给内容区加 .content-fill: 卡片撑满剩余高度(只有一两条数据也撑满)→ 表头吸顶、分页固定在卡片底部。 */ diff --git a/frontend/src/utils/localSoftware.ts b/frontend/src/utils/localSoftware.ts new file mode 100644 index 0000000..191fc4a --- /dev/null +++ b/frontend/src/utils/localSoftware.ts @@ -0,0 +1,74 @@ +/** + * 「本机软件」的启动 / 安装辅助 + * + * 网页**没法直接判断**软件是「没装」还是「装了没启动」(浏览器的沙箱看不到注册表)。 + * 所以统一用「先叫一次,唤不起来就当没装」这套流程(与 `/local` 公共页一致): + * + * 1. 用自定义协议 `yuncang://open` 叫醒 → 能起来就是「装了没启动」; + * 2. 等不到就提示「可能未安装」,给出安装包下载地址。 + * + * 下载地址来自后端 `GET /download/version.json`(打包脚本自动生成,带版本号), + * 取不到时退回 `VITE_SOFTWARE_DOWNLOAD_URL`。 + */ +import { LOCAL_BASE, launchApp } from '@/api/local'; + +/** `/download/version.json` 的内容(打包脚本写入) */ +export interface SoftwareRelease { + version?: string; + downloadUrl?: string; + size?: number; + md5?: string; + publishedAt?: string; + releaseNotes?: string; +} + +/** 兜底下载地址(后端没放 version.json 时用) */ +const FALLBACK_DOWNLOAD_URL = (import.meta.env.VITE_SOFTWARE_DOWNLOAD_URL as string | undefined) || ''; + +/** 探测本机软件是否在线:**任何 HTTP 响应都算在线**(连不上才算离线) */ +export async function isLocalServiceAlive(timeoutMs = 1500): Promise { + const controller = new AbortController(); + const timer = setTimeout(() => controller.abort(), timeoutMs); + + try { + await fetch(`${LOCAL_BASE}/`, { signal: controller.signal, cache: 'no-store' }); + return true; + } catch { + return false; + } finally { + clearTimeout(timer); + } +} + +/** 轮询等本机软件起来(用户点了「启动」之后) */ +export async function waitForLocalService(timeoutMs = 15000, intervalMs = 800): Promise { + const deadline = Date.now() + timeoutMs; + + while (Date.now() < deadline) { + if (await isLocalServiceAlive()) return true; + await new Promise(resolve => setTimeout(resolve, intervalMs)); + } + + return false; +} + +/** 用自定义协议唤起本机软件(必须在用户手势里调用) */ +export function launchLocalSoftware(): void { + launchApp(); +} + +/** 取最新安装包信息(后端静态文件,失败就返回 null) */ +export async function fetchSoftwareRelease(): Promise { + try { + const res = await fetch('/download/version.json', { cache: 'no-store' }); + if (!res.ok) return null; + return (await res.json()) as SoftwareRelease; + } catch { + return null; + } +} + +/** 安装包下载地址(release 里优先,其次环境变量兜底) */ +export function softwareDownloadUrl(release: SoftwareRelease | null): string { + return release?.downloadUrl || FALLBACK_DOWNLOAD_URL; +} diff --git a/frontend/src/views/CamerasView.vue b/frontend/src/views/CamerasView.vue new file mode 100644 index 0000000..1af4aee --- /dev/null +++ b/frontend/src/views/CamerasView.vue @@ -0,0 +1,1024 @@ + + + + + diff --git a/frontend/src/views/DevicesView.vue b/frontend/src/views/DevicesView.vue index 52ee10b..0c08ad2 100644 --- a/frontend/src/views/DevicesView.vue +++ b/frontend/src/views/DevicesView.vue @@ -6,6 +6,7 @@ */ import { onMounted, ref } from 'vue'; import AppLayout from '@/components/AppLayout.vue'; +import DataPager from '@/components/DataPager.vue'; import { ApiError } from '@/api/client'; import { deleteDevice, fetchDeviceChannels, fetchDevices, unbindDevice } from '@/api/web'; import type { Channel, Device } from '@/api/types'; @@ -14,7 +15,7 @@ import { formatTime, fromNow } from '@/utils/format'; const list = ref([]); const total = ref(0); const page = ref(1); -const pageSize = 10; +const pageSize = ref(10); const keyword = ref(''); const loading = ref(false); const error = ref(''); @@ -24,13 +25,11 @@ const ok = ref(''); const channels = ref>({}); const expanding = ref(0); -const totalPages = () => Math.max(Math.ceil(total.value / pageSize), 1); - async function load(targetPage = page.value) { loading.value = true; error.value = ''; try { - const data = await fetchDevices({ page: targetPage, pageSize, keyword: keyword.value.trim() }); + const data = await fetchDevices({ page: targetPage, pageSize: pageSize.value, keyword: keyword.value.trim() }); list.value = data.list; total.value = data.total; page.value = data.page; @@ -41,6 +40,11 @@ async function load(targetPage = page.value) { } } +/** 分页组件换页 / 改每页条数 */ +function changePageSize(size: number) { + pageSize.value = size; +} + function search() { load(1); } @@ -105,7 +109,6 @@ onMounted(() => load(1));
- 共 {{ total }} 台
@@ -171,11 +174,8 @@ onMounted(() => load(1));
-
- - {{ page }} / {{ totalPages() }} - -
+ diff --git a/frontend/src/views/HomeView.vue b/frontend/src/views/HomeView.vue index abd2be8..b050473 100644 --- a/frontend/src/views/HomeView.vue +++ b/frontend/src/views/HomeView.vue @@ -1,18 +1,24 @@ @@ -269,6 +318,18 @@ onMounted(load);

本机软件没有返回内容。

+ +
+ +

+ 录像存到这台电脑的录像目录(默认 用户目录\packVideo\年\月\日,可在软件「设置 → 录像存储路径」改) +

+

{{ downloadMsg }}

+
{{ downloadError }}
+
+
原始返回(JSON)
{{ raw }}
@@ -348,6 +409,23 @@ onMounted(load); word-break: break-all; } +/* 下载录像区块 */ +.download-box { + margin-top: 14px; + padding-top: 12px; + border-top: 1px dashed var(--border); + text-align: center; +} + +.download-box .hint { + margin: 8px 0 0; +} + +.download-ok { + color: #15803d; + word-break: break-all; +} + .raw { margin-top: 12px; font-size: 13px; diff --git a/frontend/src/views/LoginView.vue b/frontend/src/views/LoginView.vue index a6b479b..c1316eb 100644 --- a/frontend/src/views/LoginView.vue +++ b/frontend/src/views/LoginView.vue @@ -14,6 +14,15 @@ import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import { api, ApiError } from '@/api/client'; import { setSession, type CurrentUser } from '@/composables/useAuth'; +import { applySubjects, type SubjectItem } from '@/composables/useSubject'; + +/** 登录/注册接口返回:令牌 + 用户 + 可进入的主体列表 */ +type LoginResult = { + token: string; + user: CurrentUser; + subjects?: SubjectItem[]; + expiresIn?: number | string; +}; const route = useRoute(); const router = useRouter(); @@ -43,12 +52,14 @@ async function doLogin() { error.value = ''; busy.value = true; try { - const data = await api.post<{ token: string; user: CurrentUser }>( + const data = await api.post( '/api/web/auth/login', { account: loginForm.account, password: loginForm.password }, { auth: false }, ); setSession(data.token, data.user); + // 登录接口直接下发主体列表:先落地,路由守卫就不用再请求一次 + if (Array.isArray(data.subjects)) applySubjects(data.subjects); go(); } catch (err) { error.value = err instanceof ApiError ? err.message : '登录失败,请稍后再试'; @@ -89,7 +100,7 @@ async function doRegister() { } busy.value = true; try { - const data = await api.post<{ token: string; user: CurrentUser }>( + const data = await api.post( '/api/web/auth/register', { username: registerForm.username, @@ -100,6 +111,7 @@ async function doRegister() { { auth: false }, ); setSession(data.token, data.user); + if (Array.isArray(data.subjects)) applySubjects(data.subjects); go(); } catch (err) { error.value = err instanceof ApiError ? err.message : '注册失败,请稍后再试'; @@ -187,6 +199,8 @@ function switchTab(next: Tab) { onMounted(() => { window.addEventListener('pagehide', stopWechat); + // 从「改密 / 重置密码」跳回来时的提示(旧令牌已失效,需要重新登录) + if (typeof route.query.ok === 'string' && route.query.ok) ok.value = route.query.ok; if (route.query.mode === 'wechat') switchTab('wechat'); else if (route.query.mode === 'register') tab.value = 'register'; }); @@ -202,36 +216,31 @@ onBeforeUnmount(() => {
@@ -305,28 +316,6 @@ onBeforeUnmount(() => { text-align: center; } -.tabs { - display: flex; - gap: 6px; - margin-bottom: 14px; -} - -.tab { - flex: 1; - border: 1px solid var(--border); - background: #fff; - border-radius: 8px; - padding: 7px 0; - cursor: pointer; - color: var(--text-muted); -} - -.tab.active { - border-color: var(--brand); - color: var(--brand); - font-weight: 600; -} - .btn-block { width: 100%; } @@ -339,6 +328,11 @@ onBeforeUnmount(() => { margin: 12px 0 0; } +.hint.center .sep { + margin: 0 6px; + color: var(--border); +} + .pane-wechat { text-align: center; } diff --git a/frontend/src/views/NvrsView.vue b/frontend/src/views/NvrsView.vue new file mode 100644 index 0000000..821716d --- /dev/null +++ b/frontend/src/views/NvrsView.vue @@ -0,0 +1,523 @@ + + + + + diff --git a/frontend/src/views/ProfileView.vue b/frontend/src/views/ProfileView.vue index 04fd344..b74fcb3 100644 --- a/frontend/src/views/ProfileView.vue +++ b/frontend/src/views/ProfileView.vue @@ -1,9 +1,12 @@ + + + + diff --git a/frontend/src/views/WechatConfirmView.vue b/frontend/src/views/WechatConfirmView.vue index 9f1e005..0b198ce 100644 --- a/frontend/src/views/WechatConfirmView.vue +++ b/frontend/src/views/WechatConfirmView.vue @@ -1,27 +1,86 @@