feat(前端): TypeScript 重写版(esbuild IIFE 产物,暂不接管线上)
- 新增 src-ts/(22 个 .ts / 7792 行):按 core / map / card / order / nav / share / subscribe / ui / compat 分层,types 里有 BMapGL 与 API 响应声明 - compat/globals.ts 是唯一挂 window 的地方(292 个),覆盖模板 139 处内联事件 - esbuild 产出 static/dist/app.js(226.6 KiB,IIFE,es2019)+ README(构建/切换/回滚) - 构建可复现:node esbuild.config.mjs、node --check、npx tsc --noEmit 均通过 - .gitignore 增加 node_modules/ 与 static/dist/*.map(sourcemap 可重生成,不入库) - 暂不改 templates/map.html 与 MAP_ASSETS:等独立核对通过再切换,回滚=换回四个 script
This commit is contained in:
Vendored
+162
@@ -0,0 +1,162 @@
|
||||
/* 后端 JSON 契约类型(Flask 侧 routes/ + app.py 提供)。
|
||||
*
|
||||
* 这些类型**只用来标注与自检**,不改变运行时行为:搬过来的正文仍然按 any 处理,
|
||||
* 但接口路径 / 字段名在这里集中写清楚,后续改动有据可依。
|
||||
*
|
||||
* 约定(与后端一致):所有接口返回体顶层都有 rtn_code(0 = 成功)与 message。
|
||||
*/
|
||||
|
||||
declare global {
|
||||
/** 让 window.foo = foo 这类兼容层赋值无需逐个声明(内联事件用得到)。 */
|
||||
interface Window {
|
||||
[key: string]: any;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ApiEnvelope {
|
||||
/** 0 = 成功;401 = 未登录/凭证失效;其余见后端 message */
|
||||
rtn_code?: number;
|
||||
message?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/* ---------------- /api/map ---------------- */
|
||||
export interface BikeRecord {
|
||||
bike_code?: string;
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
electric_quantity?: number;
|
||||
electricQuantity?: number;
|
||||
/** 1 = 正常 2 = 损坏 4 = 欠压 10 = 低电量 */
|
||||
state?: number;
|
||||
/** 0 = 空闲 1 = 使用中 */
|
||||
status?: number;
|
||||
distance?: number;
|
||||
/** 扫码/搜索补点来源标记 */
|
||||
scan_type?: string;
|
||||
is_shared?: boolean;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface MapSnapshot {
|
||||
/** 快照生成时间(秒) */
|
||||
server_time?: number;
|
||||
/** 下次刷新间隔(秒) */
|
||||
refresh_seconds?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface MapApiResponse extends ApiEnvelope {
|
||||
/** 车辆列表(renderMap 逐条渲染) */
|
||||
results?: BikeRecord[];
|
||||
/** 地图初始中心(GCJ02,前端逐点转 BD09) */
|
||||
center_lat?: number;
|
||||
center_lng?: number;
|
||||
/** 校园边界 [[lat, lng], ...] */
|
||||
boundary?: number[][];
|
||||
/** 停车区 [{ boundary: [[lat,lng],...], name? }, ...] */
|
||||
parking_areas?: Array<{ boundary?: number[][]; name?: string; [key: string]: any }>;
|
||||
map_snapshot?: MapSnapshot;
|
||||
/** 失败时建议的重试间隔(秒) */
|
||||
retry_after?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/* ---------------- /api/order/status ---------------- */
|
||||
export interface OrderRecord {
|
||||
rental_id?: number;
|
||||
bike_code?: string;
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
/** 秒级时间戳 */
|
||||
start_time?: number;
|
||||
end_time?: number;
|
||||
duration_minutes?: number;
|
||||
total_rounds?: number;
|
||||
used_rounds?: number;
|
||||
/** 0 = 进行中 */
|
||||
status?: number;
|
||||
shared?: boolean;
|
||||
owner_email?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface OrderStatusResponse extends ApiEnvelope {
|
||||
has_order?: boolean;
|
||||
order?: OrderRecord;
|
||||
/** 骑行摘要(里程/时长等,展示在横幅上) */
|
||||
summary?: Record<string, any>;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/* ---------------- /api/nav_route ---------------- */
|
||||
export interface NavRouteResponse extends ApiEnvelope {
|
||||
/** 路线总长(米) */
|
||||
distance?: number;
|
||||
/** 预计耗时(秒) */
|
||||
duration?: number;
|
||||
/** 路径点(GCJ02 [lat, lng] 或 {lat,lng},按后端实现为准) */
|
||||
route?: any;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/* ---------------- /api/share/* ---------------- */
|
||||
export interface SharePartner {
|
||||
share_id?: number;
|
||||
email?: string;
|
||||
name?: string;
|
||||
/** 私密备注(我方给对方的昵称) */
|
||||
remark?: string;
|
||||
daily_limit?: number;
|
||||
require_card?: boolean;
|
||||
min_times?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface SharePendingItem {
|
||||
request_id?: number;
|
||||
from_email?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface ShareListResponse extends ApiEnvelope {
|
||||
usable?: SharePartner[];
|
||||
mine?: SharePartner[];
|
||||
pending?: SharePendingItem[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface SharePendingResponse extends ApiEnvelope {
|
||||
pending?: SharePendingItem[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface ShareActiveItem {
|
||||
order_id?: number;
|
||||
bike_code?: string;
|
||||
owner_email?: string;
|
||||
end_time?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface ShareActiveResponse extends ApiEnvelope {
|
||||
active?: ShareActiveItem[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/* ---------------- /api/admin/rentals ---------------- */
|
||||
export interface AdminRentalRecord {
|
||||
rental_id?: number;
|
||||
bike_code?: string;
|
||||
user_email?: string;
|
||||
start_time?: number;
|
||||
end_time?: number;
|
||||
status?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface AdminRentalsResponse extends ApiEnvelope {
|
||||
rentals?: AdminRentalRecord[];
|
||||
total?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
Vendored
+88
@@ -0,0 +1,88 @@
|
||||
/* BMapGL(百度地图 JS API GL 版)最小类型声明。
|
||||
*
|
||||
* 只声明 static/js 里**实际用到**的成员;其余一律靠索引签名放行,
|
||||
* 这样既不丢类型检查(构造函数/常用方法有签名),又不用为整个 SDK 写声明。
|
||||
*
|
||||
* 实际用到的:Map / Marker / Polyline / Polygon / Circle / Icon / Point / Size /
|
||||
* ViewAnimation / ScaleControl / WalkingRoute / Overlay / Convertor
|
||||
* 说明:bike-clusters.js 里还用了 BMapGL.Overlay(外部脚本自己声明,不进 bundle)。
|
||||
*/
|
||||
|
||||
declare namespace BMapGL {
|
||||
/** 构造选项一律宽松处理。 */
|
||||
type Opts = Record<string, any>;
|
||||
|
||||
class Point {
|
||||
constructor(lng: number, lat: number);
|
||||
lng: number;
|
||||
lat: number;
|
||||
equals(other: any): boolean;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
class Size {
|
||||
constructor(width: number, height: number);
|
||||
width: number;
|
||||
height: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
class Icon {
|
||||
constructor(imageUrl: string, size: Size, opts?: Size | Opts);
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
class Marker {
|
||||
constructor(point: Point, opts?: Opts);
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
class Polyline {
|
||||
constructor(points: Point[], opts?: Opts);
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
class Polygon {
|
||||
constructor(points: Point[], opts?: Opts);
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
class Circle {
|
||||
constructor(center: Point, radius: number, opts?: Opts);
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
class Overlay {
|
||||
constructor(opts?: Opts);
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
class ScaleControl {
|
||||
constructor(opts?: Opts);
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/** 视野动画(朝向/缩放过渡),navigation.js 用 new BMapGL.ViewAnimation([...], {duration}) */
|
||||
class ViewAnimation {
|
||||
constructor(opts: any, opts2?: any);
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/** 步行路线规划:navigation.js 用于精算步行距离 */
|
||||
class WalkingRoute {
|
||||
constructor(map: Map, opts?: Opts);
|
||||
search(start: any, end: any): void;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/** 在线坐标转换接口(本项目已改用 coordtransform.js,保留声明以免整库报错) */
|
||||
class Convertor {
|
||||
constructor(opts?: Opts);
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
class Map {
|
||||
constructor(container: string | HTMLElement, opts?: Opts);
|
||||
[key: string]: any;
|
||||
}
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
/* DOM 宽松化垫片。
|
||||
*
|
||||
* 原实现是原生 JS:`document.getElementById("x").value` / `.dataset` / 自定义标记
|
||||
* 属性(如 `el.__kind`)都直接拿来用,不做类型收窄。搬成 TS 后若逐个加 cast,
|
||||
* 会改动上百处正文、且和「逐函数等价」的目标冲突;这里改用**接口合并**给 DOM
|
||||
* 接口补一个宽松索引签名:已声明成员(addEventListener 等)保持原有类型,
|
||||
* 未声明成员一律 any。纯类型层面,零运行时开销、零行为变化。
|
||||
*/
|
||||
|
||||
interface Element {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface HTMLElement {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface HTMLInputElement {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface HTMLTextAreaElement {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface HTMLCanvasElement {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface SVGSVGElement {
|
||||
[key: string]: any;
|
||||
}
|
||||
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
/* 外部脚本提供的全局(**不打进 bundle**)。
|
||||
*
|
||||
* 这些库由 templates/map.html 的独立 <script> 提供,bundle 运行时按全局名访问:
|
||||
* coordtransform.js → coordtransform
|
||||
* qrcode.min.js → QRCode
|
||||
* settings-pages.js → SettingsPages
|
||||
* bike-clusters.js → BikeClusters
|
||||
* 运行时一律保留 `typeof X !== "undefined"` 的存在性检查(原实现就是这么写的)。
|
||||
*/
|
||||
|
||||
/** 坐标转换库(coordtransform.js,UMD 挂全局) */
|
||||
declare const coordtransform:
|
||||
| {
|
||||
gcj02tobd09(lng: number, lat: number): [number, number];
|
||||
bd09togcj02(lng: number, lat: number): [number, number];
|
||||
wgs84togcj02(lng: number, lat: number): [number, number];
|
||||
wgs84tobd09(lng: number, lat: number): [number, number];
|
||||
gcj02towgs84(lng: number, lat: number): [number, number];
|
||||
[key: string]: any;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
/** 二维码库(qrcode.min.js) */
|
||||
declare const QRCode: any;
|
||||
|
||||
/** 设置页栈(settings-pages.js):open/back/close/hide/restore/isOpen */
|
||||
declare const SettingsPages:
|
||||
| {
|
||||
open(id: string): void;
|
||||
back(): void;
|
||||
requestBack(): void;
|
||||
close(): void;
|
||||
hide(): void;
|
||||
restore(): void;
|
||||
isOpen(): boolean;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
/** 气泡聚合(bike-clusters.js) */
|
||||
declare const BikeClusters:
|
||||
| {
|
||||
PREFERENCE_KEY: string;
|
||||
readClusteringPreference(storage: Storage): boolean;
|
||||
writeClusteringPreference(storage: Storage, enabled: boolean): any;
|
||||
normalizeBikes(bikes: any[]): any[];
|
||||
bikeId(bike: any): string;
|
||||
clusterBikes(bikes: any[], project: any, getPoint: any, getState: any, radius?: number, selectedId?: string, zoom?: number, enabled?: boolean): any;
|
||||
createLayer(options: any): any;
|
||||
[key: string]: any;
|
||||
}
|
||||
| undefined;
|
||||
Reference in New Issue
Block a user