LoginCoverage.tsx 8.87 KB
/*
 * @Author: liimin 17653212@qq.com
 * @Date: 2026-11-13 10:00:00
 * @LastEditors: liimin 17653212@qq.com
 * @LastEditTime: 2026-11-15 12:25:00
 * @FilePath: \uj-store\src\pages\Login\components\LoginCoverage.tsx
 * @Description: 登录页左栏下半部分背景:门店覆盖点阵,纯装饰、无任何伪造数据。
 *   以「俯瞰 + 景深」呈现——画面是一张向远处地平线收敛的地面网络:
 *   - 透视投影:远点(深度 z→0)压向顶部地平线、横向收窄;近点( z→1)铺满底部、横向铺开;
 *   - 景深:近点更大/更亮/清晰,远点更小/更淡/带散景模糊(bokeh);
 *   - 叠加右深左淡(右侧原小方格处更聚焦),顶部渐隐融入墙面,并有两条极淡消失点引导线立住纵深。
 *   实现:固定 600×340 横向 viewBox,CSS 用 width:100%/height:auto 由浏览器按比例算高度,
 *   因此无论登录栏多宽多高都保持原始比例——不拉伸、不裁切、左右到边、贴底。
 */
import { useState } from 'react';

const W = 600;
const H = 340;
const HORIZON = 64; // 远处地平线 y(远点在此收敛)
const NEAR = H - 22; // 近处地面 y(近点铺到底部)
const Z_FAR = 0.12; // 最远深度
const VP = { x: W / 2, y: HORIZON - 14 }; // 消失点(略高于地平线)

// 固定种子伪随机:装饰用,保证网点分布一致(非真实门店数据)
function makeRand(seed: number) {
  let s = seed % 233280;
  return () => {
    s = (s * 9301 + 49297) % 233280;
    return s / 233280;
  };
}
const rand = makeRand(91);
const lerp = (a: number, b: number, t: number) => a + (b - a) * t;
const clamp = (v: number, lo: number, hi: number) => Math.max(lo, Math.min(hi, v));

// 世界坐标:z=深度(0远..1近),lx=横向(-1..1);投影到屏幕形成收敛透视
type WDot = { z: number; lx: number; hub: boolean; jx: number; jy: number };
const WDOTS: WDot[] = Array.from({ length: 92 }, (_, i) => ({
  z: Z_FAR + rand() * (1 - Z_FAR),
  lx: rand() * 2 - 1,
  hub: i % 8 === 0,
  jx: (rand() - 0.5) * 0.12,
  jy: (rand() - 0.5) * 0.06,
}));

// 投影:世界坐标 → 屏幕坐标,含透视收敛
function project(d: WDot) {
  const p = (d.z - Z_FAR) / (1 - Z_FAR); // 0 远 .. 1 近
  const pp = Math.pow(p, 0.82); // 近处更向下铺开
  const y = lerp(HORIZON, NEAR, pp) + d.jy * (NEAR - HORIZON);
  const halfSpread = lerp(34, 296, pp); // 远处横向收窄、近处铺开
  const x = W / 2 + (d.lx + d.jx) * halfSpread;
  return { x, y, p };
}

interface PNode {
  x: number;
  y: number;
  p: number;
  r: number;
  op: number;
  hub: boolean;
}
const NODES: PNode[] = WDOTS.map((d) => {
  const { x, y, p } = project(d);
  const r = lerp(0.7, 2.7, p) * (d.hub ? 1.5 : 1);
  const depthOp = lerp(0.14, 0.92, p); // 远处更淡
  const xOp = 0.5 + (x / W) * 0.75; // 左侧更淡(右深左淡)
  const op = clamp(depthOp * xOp + (d.hub ? 0.1 : 0), 0.07, 0.92);
  return { x, y, p, r, op, hub: d.hub };
});

// 枢纽连线:按屏幕 y 排序后相邻连成网(屏幕空间连线,端点各自带景深透明度)
const HUBS = NODES.filter((n) => n.hub).sort((a, b) => a.y - b.y);
const SEGMENTS = HUBS.slice(1).map((h, i) => {
  const a = HUBS[i];
  const midP = (a.p + h.p) / 2;
  return { a, b: h, op: clamp(0.06 + midP * 0.34, 0.05, 0.55) };
});

// 右上留白楔形区的点缀星点:只落在透视扇面右缘之外,填补空三角;极淡、静态为主、少数微闪
const srand = makeRand(47);
const STARS = Array.from({ length: 9 }, () => {
  const sy = lerp(HORIZON + 8, 220, srand());
  const pp = Math.pow(clamp((sy - HORIZON) / (NEAR - HORIZON), 0, 1), 1 / 0.82);
  const edge = W / 2 + lerp(34, 296, pp); // 扇面在该高度处的右缘 x
  const x = clamp(edge + srand() * (W - edge - 16), edge + 4, W - 8);
  const depthDim = lerp(0.5, 1, (sy - HORIZON) / (220 - HORIZON)); // 越靠地平线越淡
  const op = clamp((0.18 + (x / W) * 0.28) * depthDim, 0.14, 0.42);
  return { x, y: sy, r: 0.6 + srand() * 0.8, op, tw: srand() < 0.35 };
});

// 景深分层(远→近):越远模糊越强
const LAYER_BLUR = ['url(#covBlurFar)', 'url(#covBlurMid)', undefined as string | undefined];

export function LoginCoverage() {
  // 脉冲点:随机位置,每次挂载重新随机(刷新/重进登录页都变);偏向较深的右侧、且落在近-中景
  const [pulse] = useState(() => {
    const z = Z_FAR + (1 - Z_FAR) * (0.45 + Math.random() * 0.5);
    const lx = 0.15 + Math.random() * 0.8; // 偏右
    const { x, y } = project({ z, lx, hub: false, jx: 0, jy: 0 });
    return { x, y };
  });

  const renderDot = (n: PNode, i: number) => {
    const layer = n.p < 0.4 ? 0 : n.p < 0.72 ? 1 : 2;
    const fill = n.hub ? '#CFDDFF' : '#9DBBFF';
    if (n.hub) {
      return (
        <g key={i} filter={LAYER_BLUR[layer]}>
          <circle cx={n.x} cy={n.y} r={n.r * 2.8} fill="url(#ujCovGlow)" />
          <circle cx={n.x} cy={n.y} r={n.r} fill={fill} fillOpacity={Math.min(0.95, n.op + 0.15)} />
          <circle cx={n.x} cy={n.y} r={n.r + 1.8} fill="none" stroke="#5B8DEF" strokeOpacity={Math.min(0.6, n.op)} strokeWidth={0.7} />
        </g>
      );
    }
    return (
      <circle
        key={i}
        cx={n.x}
        cy={n.y}
        r={n.r}
        fill={fill}
        fillOpacity={n.op}
        filter={LAYER_BLUR[layer]}
      />
    );
  };

  return (
    <div className="uj-login-coverage" aria-hidden="true">
      <svg viewBox={`0 0 ${W} ${H}`} width="100%" height="auto" preserveAspectRatio="xMidYMax meet">
        <defs>
          {/* 右侧聚焦光晕:原小方格处的「更深」基调,品牌蓝向心渐隐 */}
          <radialGradient id="ujCovFocus" cx="50%" cy="50%" r="50%">
            <stop offset="0%" stopColor="#3A6BF0" stopOpacity="0.32" />
            <stop offset="100%" stopColor="#3A6BF0" stopOpacity="0" />
          </radialGradient>
          {/* 枢纽光晕 */}
          <radialGradient id="ujCovGlow" cx="50%" cy="50%" r="50%">
            <stop offset="0%" stopColor="#5B8DEF" stopOpacity="0.6" />
            <stop offset="100%" stopColor="#5B8DEF" stopOpacity="0" />
          </radialGradient>
          {/* 近处地面受光:底部(近)微亮,强化俯瞰纵深 */}
          <linearGradient id="ujCovGround" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="#0A1430" stopOpacity="0" />
            <stop offset="100%" stopColor="#2A4A9E" stopOpacity="0.22" />
          </linearGradient>
          {/* 景深散景模糊:极轻,仅作纵深暗示,避免发糊 */}
          <filter id="covBlurFar" x="-30%" y="-30%" width="160%" height="160%">
            <feGaussianBlur stdDeviation="1.3" />
          </filter>
          <filter id="covBlurMid" x="-30%" y="-30%" width="160%" height="160%">
            <feGaussianBlur stdDeviation="0.6" />
          </filter>
        </defs>

        {/* 近处地面受光(最底) */}
        <rect x={0} y={0} width={W} height={H} fill="url(#ujCovGround)" />
        {/* 右侧聚焦区:让原小方格处颜色稍深 */}
        <ellipse cx={W * 0.82} cy={H * 0.55} rx={W * 0.52} ry={H * 0.62} fill="url(#ujCovFocus)" />
        {/* 极淡消失点引导线:从底部两角收向地平线消失点,立住俯瞰纵深;近清晰、远虚 */}
        <g stroke="#7FA8F5" fill="none" strokeOpacity={0.1}>
          <line x1={W * 0.04} y1={NEAR} x2={VP.x} y2={VP.y} strokeWidth={0.8} />
          <line x1={W * 0.96} y1={NEAR} x2={VP.x} y2={VP.y} strokeWidth={0.8} />
          <line x1={W * 0.32} y1={NEAR} x2={VP.x} y2={VP.y} strokeWidth={0.5} strokeOpacity={0.06} />
          <line x1={W * 0.68} y1={NEAR} x2={VP.x} y2={VP.y} strokeWidth={0.5} strokeOpacity={0.06} />
        </g>

        {/* 枢纽连线(远处更虚,给一层中等模糊) */}
        <g fill="none" stroke="#5B8DEF" strokeWidth={0.8} strokeDasharray="2 3" filter="url(#covBlurMid)">
          {SEGMENTS.map((s, i) => (
            <line key={i} x1={s.a.x} y1={s.a.y} x2={s.b.x} y2={s.b.y} strokeOpacity={s.op} />
          ))}
        </g>

        {/* 网点:按景深分三层(远→近)渲染 */}
        {NODES.map((n, i) => renderDot(n, i))}

        {/* 右上空白楔形区的点缀星点:填补透视扇面右缘之外的留白,极淡、少数微闪 */}
        {STARS.map((s, i) => (
          <circle
            key={`star${i}`}
            cx={s.x}
            cy={s.y}
            r={s.r}
            fill="#AFC8FF"
            fillOpacity={s.op}
            className={s.tw ? 'uj-cov-star-tw' : undefined}
          />
        ))}

        {/* 单个活跃节点:光晕扩散(雷达 ping),鲜艳青绿突出于淡蓝网点;始终清晰不受景深模糊 */}
        <g>
          <circle cx={pulse.x} cy={pulse.y} r={2.8} fill="#1FE0C8" style={{ filter: 'drop-shadow(0 0 4px #1FE0C8)' }} />
          <circle className="uj-cov-pulse" cx={pulse.x} cy={pulse.y} r={3} fill="none" stroke="#2DE2C4" strokeWidth={1} style={{ animationDelay: '0s' }} />
        </g>
      </svg>
    </div>
  );
}