WorkbenchBackdrop.tsx 6.74 KB
/**
 * 工作台右下角底图(纯装饰:aria-hidden + pointer-events:none,无状态)。
 *
 * 视觉语言与登录页 uj-login-coverage 同源——透视纵深点阵、链节点虚线、
 * 以基站为心的扫描弧与双层环、青绿脉冲核——配色从登录页的深空反转为
 * 浅底上的品牌蓝低透明度水印:贴合登录页主题,又不压过内容卡片,
 * 只在右侧与下部的空白处透出来。
 * 固定坐标 + 固定种子伪随机(分布一致、非真实数据);脉冲动画尊重
 * prefers-reduced-motion(见 design.css 的 .uj-wb-pulse)。
 */

const W = 640;
const H = 520;
const HORIZON = 74; // 远处地平线 y
const NEAR = 498; // 近处地面 y
const VP = { x: 300, y: HORIZON - 6 }; // 消失点
const BASE = { x: 462, y: 428 }; // 近景基站(右下,贴工作台空白区)
const AXIS_TOP = { x: 252, y: 106 }; // 链节点纵深起点

function makeRand(seed: number) {
  let s = seed % 233280;
  return () => {
    s = (s * 9301 + 49297) % 233280;
    return s / 233280;
  };
}
const rand = makeRand(73);
const lerp = (a: number, b: number, t: number) => a + (b - a) * t;

type Dot = { x: number; y: number; r: number; op: number };

// 透视点阵:4 排 × 8 列,约 55% 保留;越近越大越亮,整体压低做背景层
const DOTS: Dot[] = (() => {
  const out: Dot[] = [];
  const rows = [0.16, 0.4, 0.64, 0.88];
  const cols = [-0.8, -0.58, -0.36, -0.14, 0.1, 0.32, 0.54, 0.76];
  for (const t of rows) {
    const pp = Math.pow(t, 0.82);
    const y = lerp(HORIZON, NEAR, pp);
    const spread = lerp(60, 300, pp);
    for (const c of cols) {
      if (rand() < 0.55) {
        out.push({
          x: VP.x + c * spread + (rand() - 0.5) * 14,
          y: y + (rand() - 0.5) * 8,
          r: lerp(0.9, 2.6, t),
          op: lerp(0.07, 0.2, t),
        });
      }
    }
  }
  return out;
})();

// 链节点:沿纵深逐级放大/提亮,末端不重复(那里是基站)
const CHAIN = Array.from({ length: 4 }, (_, i) => {
  const pp = Math.pow((i + 1) / 5, 0.82);
  return {
    x: lerp(AXIS_TOP.x, BASE.x, pp),
    y: lerp(AXIS_TOP.y, BASE.y, pp),
    r: lerp(1.2, 4, pp),
    op: lerp(0.14, 0.4, pp),
  };
});
const CHAIN_DASH = [...CHAIN.slice(-2), { x: BASE.x, y: BASE.y }];

// 2 道扫描弧:以基站为心向上展开,两端渐隐由 stroke 渐变承担
const ARCS = [150, 224].map((r) => {
  const a0 = Math.PI * 1.05;
  const a1 = Math.PI * 1.95;
  return {
    r,
    d: `M ${BASE.x + r * Math.cos(a0)} ${BASE.y + r * Math.sin(a0)} A ${r} ${r} 0 0 1 ${BASE.x + r * Math.cos(a1)} ${BASE.y + r * Math.sin(a1)}`,
  };
});

// 2 条极淡经线:从近处地面两侧收向消失点
const MERIDIANS = [-0.62, 0.62].map((lx) => ({
  x1: VP.x + lx * 300,
  y1: NEAR,
  x2: VP.x,
  y2: VP.y,
}));

// 上方留白区 6 颗极淡星点
const STARS = Array.from({ length: 6 }, () => ({
  x: 40 + rand() * (W - 80),
  y: 14 + rand() * (HORIZON * 0.5),
  r: 0.7 + rand() * 0.9,
  op: 0.08 + rand() * 0.08,
}));

const CORE_R = 4.5; // 青绿脉冲/实心核半径

export function WorkbenchBackdrop() {
  return (
    <div className="uj-wb-backdrop" aria-hidden="true">
      <svg
        viewBox={`0 0 ${W} ${H}`}
        width="100%"
        height="auto"
        preserveAspectRatio="xMidYMax meet"
        focusable="false"
      >
        <defs>
          {/* 大光场:以基站为心,中心 0.12 → 边缘 0 */}
          <radialGradient id="ujWbFocus" cx="50%" cy="50%" r="50%">
            <stop offset="0%" stopColor="#2b5ce6" stopOpacity="0.12" />
            <stop offset="55%" stopColor="#2b5ce6" stopOpacity="0.05" />
            <stop offset="100%" stopColor="#2b5ce6" stopOpacity="0" />
          </radialGradient>
          {/* 基站中层辉光 */}
          <radialGradient id="ujWbGlow" cx="50%" cy="50%" r="50%">
            <stop offset="0%" stopColor="#5b8def" stopOpacity="0.18" />
            <stop offset="100%" stopColor="#5b8def" stopOpacity="0" />
          </radialGradient>
          {/* 经线垂直渐隐:远处化掉不形成硬线 */}
          <linearGradient id="ujWbMeridian" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="#2b5ce6" stopOpacity="0.1" />
            <stop offset="100%" stopColor="#2b5ce6" stopOpacity="0" />
          </linearGradient>
        </defs>

        {/* 明暗底层:以基站为心的大光场 */}
        <ellipse cx={BASE.x} cy={BASE.y - 30} rx={330} ry={250} fill="url(#ujWbFocus)" />

        {/* 2 道扫描弧(两端渐隐) */}
        <g fill="none" stroke="#2b5ce6" strokeWidth="1">
          {ARCS.map((arc) => (
            <path key={arc.r} d={arc.d} strokeOpacity="0.1" />
          ))}
        </g>

        {/* 2 条极淡经线收向消失点 */}
        <g fill="none" stroke="url(#ujWbMeridian)" strokeWidth="0.8">
          {MERIDIANS.map((m, i) => (
            <line key={i} x1={m.x1} y1={m.y1} x2={m.x2} y2={m.y2} />
          ))}
        </g>

        {/* 背景点阵:近大远小、近亮远淡 */}
        <g fill="#2b5ce6">
          {DOTS.map((dot, i) => (
            <circle key={i} cx={dot.x} cy={dot.y} r={dot.r} fillOpacity={dot.op} />
          ))}
        </g>

        {/* 链节点虚线:末段渐淡接入基站 */}
        <g fill="none" stroke="#5b8def" strokeWidth="1.1" strokeDasharray="4 5" strokeLinecap="round">
          {CHAIN_DASH.slice(1).map((c, i) => (
            <line
              key={i}
              x1={CHAIN_DASH[i].x}
              y1={CHAIN_DASH[i].y}
              x2={c.x}
              y2={c.y}
              strokeOpacity={i === 1 ? 0.12 : 0.2}
            />
          ))}
        </g>

        {/* 链节点 */}
        <g fill="#5b8def">
          {CHAIN.map((c, i) => (
            <circle key={i} cx={c.x} cy={c.y} r={c.r} fillOpacity={c.op} />
          ))}
        </g>

        {/* 基站:大光场 + 辉光 + 双层环 + 青绿脉冲 + 实心核 */}
        <g>
          <circle cx={BASE.x} cy={BASE.y} r={96} fill="url(#ujWbGlow)" />
          <circle cx={BASE.x} cy={BASE.y} r={44} fill="none" stroke="#2b5ce6" strokeOpacity="0.16" strokeWidth="1.1" />
          <circle cx={BASE.x} cy={BASE.y} r={25} fill="none" stroke="#2b5ce6" strokeOpacity="0.26" strokeWidth="1.2" />
          <circle
            className="uj-wb-pulse"
            cx={BASE.x}
            cy={BASE.y}
            r={CORE_R}
            fill="none"
            stroke="#2de2c4"
            strokeWidth="1.2"
            vectorEffect="non-scaling-stroke"
          />
          <circle cx={BASE.x} cy={BASE.y} r={CORE_R} fill="#1fe0c8" fillOpacity="0.8" />
        </g>

        {/* 上方 6 颗极淡星点 */}
        <g fill="#2b5ce6">
          {STARS.map((star, i) => (
            <circle key={i} cx={star.x} cy={star.y} r={star.r} fillOpacity={star.op} />
          ))}
        </g>
      </svg>
    </div>
  );
}