Add remote-controlled nav CRUD and fix weapp VIP/nav chrome.
Ship admin nav editor + navContent remote-config, custom nav bars for memo/store, and weapp icon copy/webp path so nav icons render in DevTools. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
3f7528f824
commit
4a7690c0b1
@ -16,7 +16,7 @@ scripts/ 本地开发 / 清理(dev-api · clean-artifacts)
|
||||
|
||||
| 产品 | 门户路由 | 源码 |
|
||||
|------|----------|------|
|
||||
| 导航 | `/nav` | `src/modules/nav` |
|
||||
| 导航 | `/nav` | `src/modules/nav` · 远程 `navContent`(后台 `/wechat/nav` 可 CRUD) |
|
||||
| 小册 | `/book` | `src/modules/ebook` + `src/modules/ebook-content` |
|
||||
| 社群 | `/community` | `src/modules/community` |
|
||||
| VIP | `/vip` | `src/modules/vip`(微信小程序原生页,见下) |
|
||||
@ -39,12 +39,13 @@ scripts/ 本地开发 / 清理(dev-api · clean-artifacts)
|
||||
| **设备商城** | `pages/vip-store*` | 虚拟卡 + 实物发货;微信 `chooseAddress` |
|
||||
|
||||
内容种子:`h5/src/data/vipEbooks.ts` · `vipLessonContent.ts` · `vipStoreCatalog.ts`(可由 `h5/scripts/extract-vip-*.py` 从 `src/modules/vip/app/data` 重生)。
|
||||
后台:`apps/admin` → VIP · **知识社群**(`/wechat/memo`)· **电商**(`/wechat/shop`)。
|
||||
下单:`POST /api/ebook/pay/vip-order` · 商城 ` /api/ebook/shop/*` · 社群 `/api/ebook/memo/*`。
|
||||
后台:`apps/admin` → VIP · **导航**(`/wechat/nav`)· **知识社群**(`/wechat/memo`)· **电商**(`/wechat/shop`)。
|
||||
下单:`POST /api/ebook/pay/vip-order` · 商城 `/api/ebook/shop/*` · 社群 `/api/ebook/memo/*` · 导航 `/api/admin/nav`。
|
||||
|
||||
部署脚本(本地构建 admin + 同步 API):
|
||||
|
||||
```bash
|
||||
python apps/admin/deploy/deploy_nav.py # 导航远程 CRUD
|
||||
python apps/admin/deploy/deploy_shop.py # 电商
|
||||
python apps/admin/deploy/deploy_memo.py # 知识社群
|
||||
```
|
||||
|
||||
@ -17,9 +17,18 @@ pnpm build:admin
|
||||
|
||||
| 入口 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| 微信小程序 | `/wechat/*` | 读者 · 订单 · 书籍 · VIP · **知识社群** · **电商** · 埋点 |
|
||||
| 微信小程序 | `/wechat/*` | 读者 · 订单 · 书籍 · **导航** · VIP · **知识社群** · **电商** · 埋点 |
|
||||
| 抖音小程序 | `/douyin/*` | 首页 A/B · 入口 · **加群弹窗** · 小册 · 验收 |
|
||||
|
||||
### 微信:导航(远程 CRUD)
|
||||
|
||||
路径 **`/wechat/nav`**:
|
||||
|
||||
- 分类 / 分组 / 链接:新增、编辑、隐藏、删除、排序
|
||||
- 写入 `remote-config.json` 的 `navContent`;门户 `/nav` 与小程序导航实时拉取,离线用包内 `links.json`
|
||||
- API:`GET/PUT /api/admin/nav`
|
||||
- 部署:`python apps/admin/deploy/deploy_nav.py`
|
||||
|
||||
### 微信:知识社群(对标知识星球)
|
||||
|
||||
路径 **`/wechat/memo`**:
|
||||
@ -56,6 +65,7 @@ API:`GET/PUT /api/admin/join-group`
|
||||
```bash
|
||||
pnpm build:admin
|
||||
python apps/admin/deploy/deploy_join_group.py # 前端 dist + 加群 API
|
||||
python apps/admin/deploy/deploy_nav.py # 导航远程 CRUD
|
||||
python apps/admin/deploy/deploy_memo.py # 知识社群
|
||||
python apps/admin/deploy/deploy_shop.py # 设备商城
|
||||
# 或仅前端:python apps/admin/deploy/_deploy_douyin_ui.py
|
||||
|
||||
221
apps/admin/deploy/deploy_nav.py
Normal file
221
apps/admin/deploy/deploy_nav.py
Normal file
@ -0,0 +1,221 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Deploy nav CRUD admin + API (navContent in remote-config)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import subprocess
|
||||
import tarfile
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import paramiko
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
REPO = ROOT.parents[1]
|
||||
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
|
||||
EBOOK = REPO / "apps" / "api" / "services" / "ebook_svc"
|
||||
SEED = REPO / "src" / "lib" / "nav-default-links.json"
|
||||
|
||||
|
||||
def to_app_pkg(text: str) -> str:
|
||||
return text.replace("ebook_svc.", "app.")
|
||||
|
||||
|
||||
REMOTE = r'''#!/bin/bash
|
||||
set -euo pipefail
|
||||
cd /tmp
|
||||
rm -rf nav-unpack && mkdir nav-unpack
|
||||
tar -xzf nav-release.tar.gz -C nav-unpack
|
||||
|
||||
if [ -d nav-unpack/admin-dist ]; then
|
||||
sudo rsync -a --delete nav-unpack/admin-dist/ /www/wwwroot/admin.nomadro.cn/
|
||||
sudo chown -R www:www /www/wwwroot/admin.nomadro.cn
|
||||
echo admin_dist_synced
|
||||
fi
|
||||
|
||||
API_ROOT=$(systemctl show nomadmini-api -p WorkingDirectory --value 2>/dev/null || true)
|
||||
if [ -z "$API_ROOT" ] || [ "$API_ROOT" = "/" ]; then
|
||||
API_ROOT=/opt/nomadmini/backend
|
||||
fi
|
||||
echo API_ROOT=$API_ROOT
|
||||
B=$API_ROOT/app
|
||||
if [ ! -d "$B" ]; then B=$API_ROOT/backend/app; fi
|
||||
sudo mkdir -p "$B/routers" "$B/services" "$API_ROOT/data"
|
||||
|
||||
sudo cp nav-unpack/backend/routers/nav_admin.py "$B/routers/"
|
||||
sudo cp nav-unpack/backend/services/nav_config.py "$B/services/"
|
||||
if [ -f nav-unpack/nav-default-links.json ]; then
|
||||
sudo cp nav-unpack/nav-default-links.json "$API_ROOT/data/"
|
||||
sudo cp nav-unpack/nav-default-links.json /var/www/nomadro.cn/data/nav-default-links.json 2>/dev/null || true
|
||||
fi
|
||||
|
||||
MAIN="$B/main.py"
|
||||
export MAIN
|
||||
sudo -E python3 <<'PY'
|
||||
from pathlib import Path
|
||||
import os, re
|
||||
p = Path(os.environ["MAIN"])
|
||||
t = p.read_text(encoding="utf-8")
|
||||
changed = False
|
||||
|
||||
m = re.search(r"from app\.routers import ([^\n]+)", t)
|
||||
if not m:
|
||||
raise SystemExit("no routers import")
|
||||
line = m.group(0)
|
||||
names = m.group(1)
|
||||
parts = [x.strip() for x in names.split(",")]
|
||||
if "nav_admin" not in parts:
|
||||
names = names.rstrip() + ", nav_admin"
|
||||
changed = True
|
||||
print("import + nav_admin")
|
||||
newt = f"from app.routers import {names}"
|
||||
if newt != line:
|
||||
t = t.replace(line, newt, 1)
|
||||
changed = True
|
||||
|
||||
if "include_router(nav_admin.router)" not in t:
|
||||
for a in (
|
||||
"app.include_router(memo_admin.router)",
|
||||
"app.include_router(shop_admin.router)",
|
||||
"app.include_router(vip_admin.router)",
|
||||
"app.include_router(public_config.router)",
|
||||
):
|
||||
if a in t:
|
||||
t = t.replace(a, a + "\napp.include_router(nav_admin.router)", 1)
|
||||
changed = True
|
||||
print("nav_admin after", a)
|
||||
break
|
||||
if "include_router(nav_admin.router)" not in t:
|
||||
raise SystemExit("failed nav_admin include")
|
||||
|
||||
if changed:
|
||||
p.write_text(t, encoding="utf-8")
|
||||
print("main.py patched")
|
||||
else:
|
||||
print("main.py already ok")
|
||||
PY
|
||||
|
||||
# seed navContent into remote-config if missing
|
||||
sudo python3 <<'PY'
|
||||
import json
|
||||
from pathlib import Path
|
||||
from datetime import datetime, timezone
|
||||
cands = [
|
||||
Path("/var/www/nomadro.cn/data/remote-config.json"),
|
||||
Path("/opt/nomadmini/backend/data/remote-config.json"),
|
||||
]
|
||||
seed_paths = [
|
||||
Path("/opt/nomadmini/backend/data/nav-default-links.json"),
|
||||
Path("/var/www/nomadro.cn/data/nav-default-links.json"),
|
||||
]
|
||||
seed = None
|
||||
for sp in seed_paths:
|
||||
if sp.is_file():
|
||||
seed = json.loads(sp.read_text(encoding="utf-8"))
|
||||
break
|
||||
if not seed:
|
||||
print("no seed, skip navContent inject")
|
||||
else:
|
||||
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
||||
for cfg in cands:
|
||||
if not cfg.is_file():
|
||||
continue
|
||||
raw = json.loads(cfg.read_text(encoding="utf-8"))
|
||||
nav = raw.get("navContent")
|
||||
if isinstance(nav, dict) and isinstance(nav.get("categories"), list) and nav["categories"]:
|
||||
print(cfg, "navContent already set", len(nav["categories"]))
|
||||
continue
|
||||
seed["updatedAt"] = now
|
||||
raw["navContent"] = seed
|
||||
raw["updatedAt"] = now
|
||||
raw["version"] = int(raw.get("version") or 0) + 1
|
||||
tmp = cfg.with_suffix(".json.tmp")
|
||||
tmp.write_text(json.dumps(raw, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
tmp.replace(cfg)
|
||||
print("seeded navContent into", cfg)
|
||||
PY
|
||||
|
||||
sudo systemctl restart nomadmini-api
|
||||
sleep 4
|
||||
systemctl is-active nomadmini-api
|
||||
echo "--- smoke ---"
|
||||
TOK=$(curl -sk -X POST https://api.nomadro.cn/api/admin/login \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"username":"admin","password":"Xiao4669805"}' | python3 -c "import sys,json; print(json.load(sys.stdin).get('token',''))" || true)
|
||||
echo "token_len=${#TOK}"
|
||||
if [ -n "$TOK" ]; then
|
||||
curl -sk -H "Authorization: Bearer $TOK" https://api.nomadro.cn/api/admin/nav | python3 -c "import sys,json; d=json.load(sys.stdin); n=d.get('nav') or {}; print('nav_ok', d.get('ok'), 'cats', len(n.get('categories') or []), d.get('stats'))"
|
||||
fi
|
||||
curl -sk https://api.nomadro.cn/api/config | python3 -c "import sys,json; d=json.load(sys.stdin); c=d.get('config') or {}; nc=c.get('navContent') or {}; print('public_nav', len(nc.get('categories') or []))"
|
||||
rm -rf nav-unpack nav-release.tar.gz
|
||||
echo DONE
|
||||
'''
|
||||
|
||||
|
||||
def main() -> int:
|
||||
print("building admin…", flush=True)
|
||||
r = subprocess.run(
|
||||
["pnpm", "exec", "vite", "build"],
|
||||
cwd=ROOT,
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
)
|
||||
print((r.stdout or "")[-500:], flush=True)
|
||||
if r.returncode != 0:
|
||||
print(r.stderr or "", flush=True)
|
||||
return r.returncode or 1
|
||||
|
||||
dist = ROOT / "dist"
|
||||
files = (
|
||||
("backend/routers/nav_admin.py", EBOOK / "routers" / "nav_admin.py"),
|
||||
("backend/services/nav_config.py", EBOOK / "services" / "nav_config.py"),
|
||||
)
|
||||
buf = io.BytesIO()
|
||||
with tarfile.open(fileobj=buf, mode="w:gz") as tar:
|
||||
for p in dist.rglob("*"):
|
||||
if p.is_file():
|
||||
tar.add(p, arcname="admin-dist/" + p.relative_to(dist).as_posix())
|
||||
for name, src in files:
|
||||
text = to_app_pkg(src.read_text(encoding="utf-8")).encode("utf-8")
|
||||
info = tarfile.TarInfo(name=name)
|
||||
info.size = len(text)
|
||||
tar.addfile(info, io.BytesIO(text))
|
||||
if SEED.is_file():
|
||||
data = SEED.read_bytes()
|
||||
info = tarfile.TarInfo(name="nav-default-links.json")
|
||||
info.size = len(data)
|
||||
tar.addfile(info, io.BytesIO(data))
|
||||
|
||||
payload = buf.getvalue()
|
||||
print(f"pack {len(payload)/1024:.1f} KB", flush=True)
|
||||
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect(HOST, username=USER, password=PASS, timeout=60, allow_agent=False, look_for_keys=False)
|
||||
sftp = c.open_sftp()
|
||||
with sftp.file("/tmp/nav-release.tar.gz", "wb") as rf:
|
||||
rf.write(payload)
|
||||
with sftp.file("/tmp/nav-deploy.sh", "w") as sf:
|
||||
sf.write(REMOTE.replace("\r\n", "\n"))
|
||||
sftp.chmod("/tmp/nav-deploy.sh", 0o755)
|
||||
sftp.close()
|
||||
print("uploaded", flush=True)
|
||||
|
||||
_, stdout, _ = c.exec_command("bash /tmp/nav-deploy.sh", timeout=300, get_pty=True)
|
||||
while not stdout.channel.exit_status_ready():
|
||||
if stdout.channel.recv_ready():
|
||||
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
|
||||
time.sleep(0.05)
|
||||
while stdout.channel.recv_ready():
|
||||
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
|
||||
code = stdout.channel.recv_exit_status()
|
||||
c.close()
|
||||
print(f"[exit {code}]", flush=True)
|
||||
return code
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@ -12,6 +12,7 @@ import Checklist from './pages/Checklist'
|
||||
import Vip from './pages/Vip'
|
||||
import Shop from './pages/Shop'
|
||||
import Memo from './pages/Memo'
|
||||
import Nav from './pages/Nav'
|
||||
import Layout from './components/Layout'
|
||||
import DouyinLayout from './pages/douyin/DouyinLayout'
|
||||
import DouyinOverview from './pages/douyin/DouyinOverview'
|
||||
@ -66,6 +67,7 @@ export default function App() {
|
||||
<Route index element={<Dashboard />} />
|
||||
<Route path="books/:id" element={<BookEdit />} />
|
||||
<Route path="vip" element={<Vip />} />
|
||||
<Route path="nav" element={<Nav />} />
|
||||
<Route path="shop" element={<Shop />} />
|
||||
<Route path="memo" element={<Memo />} />
|
||||
<Route path="orders" element={<Orders />} />
|
||||
@ -96,6 +98,7 @@ export default function App() {
|
||||
<Route path="/events" element={<WechatRedirect to="/wechat/events" />} />
|
||||
<Route path="/checklist" element={<WechatRedirect to="/wechat/checklist" />} />
|
||||
<Route path="/vip" element={<WechatRedirect to="/wechat/vip" />} />
|
||||
<Route path="/nav" element={<WechatRedirect to="/wechat/nav" />} />
|
||||
<Route path="/shop" element={<WechatRedirect to="/wechat/shop" />} />
|
||||
<Route path="/memo" element={<WechatRedirect to="/wechat/memo" />} />
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ export default function Layout() {
|
||||
概览
|
||||
</NavLink>
|
||||
<NavLink to="/wechat/books/default">书籍与试读%</NavLink>
|
||||
<NavLink to="/wechat/nav">导航</NavLink>
|
||||
<NavLink to="/wechat/vip">VIP</NavLink>
|
||||
<NavLink to="/wechat/shop">电商</NavLink>
|
||||
<NavLink to="/wechat/memo">知识社群</NavLink>
|
||||
|
||||
637
apps/admin/src/pages/Nav.tsx
Normal file
637
apps/admin/src/pages/Nav.tsx
Normal file
@ -0,0 +1,637 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { api } from '../api'
|
||||
import './BookEdit.css'
|
||||
|
||||
type NavLink = {
|
||||
id: string
|
||||
title: string
|
||||
subtitle: string
|
||||
href: string
|
||||
icon: string
|
||||
action?: 'open' | 'copy'
|
||||
hidden?: boolean
|
||||
}
|
||||
type NavGroup = { id: string; title: string; links: NavLink[]; hidden?: boolean }
|
||||
type NavCategory = {
|
||||
id: string
|
||||
title: string
|
||||
emoji: string
|
||||
groups: NavGroup[]
|
||||
hidden?: boolean
|
||||
}
|
||||
type NavContent = {
|
||||
brand: string
|
||||
tagline: string
|
||||
footer: string
|
||||
categories: NavCategory[]
|
||||
updatedAt?: string
|
||||
}
|
||||
|
||||
function uid(prefix: string) {
|
||||
return `${prefix}-${Math.random().toString(36).slice(2, 8)}`
|
||||
}
|
||||
|
||||
function emptyLink(): NavLink {
|
||||
return {
|
||||
id: uid('link'),
|
||||
title: '新链接',
|
||||
subtitle: '',
|
||||
href: 'https://',
|
||||
icon: '/icons/nomadro.webp',
|
||||
action: 'open',
|
||||
hidden: false,
|
||||
}
|
||||
}
|
||||
|
||||
function emptyGroup(): NavGroup {
|
||||
return { id: uid('group'), title: '新分组', links: [emptyLink()], hidden: false }
|
||||
}
|
||||
|
||||
function emptyCategory(): NavCategory {
|
||||
return {
|
||||
id: uid('cat'),
|
||||
title: '新分类',
|
||||
emoji: '✦',
|
||||
groups: [emptyGroup()],
|
||||
hidden: false,
|
||||
}
|
||||
}
|
||||
|
||||
export default function NavAdmin() {
|
||||
const [nav, setNav] = useState<NavContent | null>(null)
|
||||
const [catIdx, setCatIdx] = useState(0)
|
||||
const [groupIdx, setGroupIdx] = useState(0)
|
||||
const [err, setErr] = useState('')
|
||||
const [msg, setMsg] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [stats, setStats] = useState({ categories: 0, groups: 0, links: 0, hiddenCategories: 0 })
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setErr('')
|
||||
const data = await api<{ nav: NavContent; stats: typeof stats }>('/api/admin/nav')
|
||||
setNav(data.nav)
|
||||
setStats(data.stats || { categories: 0, groups: 0, links: 0, hiddenCategories: 0 })
|
||||
setCatIdx(0)
|
||||
setGroupIdx(0)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
load().catch((e) => setErr(e.message || '加载失败'))
|
||||
}, [load])
|
||||
|
||||
function patch(next: NavContent) {
|
||||
setNav(next)
|
||||
setMsg('')
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!nav) return
|
||||
setBusy(true)
|
||||
setErr('')
|
||||
setMsg('')
|
||||
try {
|
||||
const data = await api<{ nav: NavContent }>('/api/admin/nav', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(nav),
|
||||
})
|
||||
setNav(data.nav)
|
||||
setMsg(`已保存 · ${data.nav.updatedAt || 'OK'} · 前端会实时拉取`)
|
||||
await load()
|
||||
} catch (e) {
|
||||
setErr((e as Error).message || '保存失败')
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (!nav && !err) return <div className="page"><p>加载中…</p></div>
|
||||
if (!nav) {
|
||||
return (
|
||||
<div className="page">
|
||||
<div className="banner err">{err}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const cat = nav.categories[catIdx]
|
||||
const group = cat?.groups?.[groupIdx]
|
||||
|
||||
function moveCat(from: number, to: number) {
|
||||
if (to < 0 || to >= nav.categories.length) return
|
||||
const cats = [...nav.categories]
|
||||
const [item] = cats.splice(from, 1)
|
||||
cats.splice(to, 0, item)
|
||||
patch({ ...nav, categories: cats })
|
||||
setCatIdx(to)
|
||||
}
|
||||
|
||||
function moveGroup(from: number, to: number) {
|
||||
if (!cat || to < 0 || to >= cat.groups.length) return
|
||||
const groups = [...cat.groups]
|
||||
const [item] = groups.splice(from, 1)
|
||||
groups.splice(to, 0, item)
|
||||
const cats = nav.categories.map((c, i) => (i === catIdx ? { ...c, groups } : c))
|
||||
patch({ ...nav, categories: cats })
|
||||
setGroupIdx(to)
|
||||
}
|
||||
|
||||
function moveLink(from: number, to: number) {
|
||||
if (!cat || !group || to < 0 || to >= group.links.length) return
|
||||
const links = [...group.links]
|
||||
const [item] = links.splice(from, 1)
|
||||
links.splice(to, 0, item)
|
||||
const groups = cat.groups.map((g, i) => (i === groupIdx ? { ...g, links } : g))
|
||||
const cats = nav.categories.map((c, i) => (i === catIdx ? { ...c, groups } : c))
|
||||
patch({ ...nav, categories: cats })
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="page">
|
||||
<header className="page-head">
|
||||
<div>
|
||||
<h1>导航</h1>
|
||||
<p>
|
||||
远程控制门户 <code>/nav</code> 与小程序导航:新增 / 编辑 / 隐藏 / 删除 · 保存后客户端实时刷新
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" className="primary-btn" disabled={busy} onClick={() => void save()}>
|
||||
{busy ? '保存中…' : '保存并发布'}
|
||||
</button>
|
||||
</header>
|
||||
|
||||
{err ? <div className="banner err">{err}</div> : null}
|
||||
{msg ? <div className="banner ok">{msg}</div> : null}
|
||||
|
||||
<div className="panel" style={{ display: 'flex', gap: 16, flexWrap: 'wrap' }}>
|
||||
<span>
|
||||
分类 <strong>{stats.categories}</strong>
|
||||
</span>
|
||||
<span>
|
||||
分组 <strong>{stats.groups}</strong>
|
||||
</span>
|
||||
<span>
|
||||
链接 <strong>{stats.links}</strong>
|
||||
</span>
|
||||
<span>
|
||||
已隐藏分类 <strong>{stats.hiddenCategories}</strong>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="panel">
|
||||
<h2 style={{ marginTop: 0 }}>页头文案</h2>
|
||||
<div style={{ display: 'grid', gap: 10, gridTemplateColumns: '1fr 1fr' }}>
|
||||
<label>
|
||||
品牌
|
||||
<input
|
||||
value={nav.brand}
|
||||
onChange={(e) => patch({ ...nav, brand: e.target.value })}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
副标题
|
||||
<input
|
||||
value={nav.tagline}
|
||||
onChange={(e) => patch({ ...nav, tagline: e.target.value })}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<label style={{ display: 'block', marginTop: 10 }}>
|
||||
页脚
|
||||
<input
|
||||
value={nav.footer}
|
||||
onChange={(e) => patch({ ...nav, footer: e.target.value })}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '220px 1fr', gap: 16 }}>
|
||||
<div className="panel">
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<h2 style={{ margin: 0, fontSize: 15 }}>分类</h2>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => {
|
||||
const cats = [...nav.categories, emptyCategory()]
|
||||
patch({ ...nav, categories: cats })
|
||||
setCatIdx(cats.length - 1)
|
||||
setGroupIdx(0)
|
||||
}}
|
||||
>
|
||||
+ 新增
|
||||
</button>
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6, marginTop: 12 }}>
|
||||
{nav.categories.map((c, i) => (
|
||||
<button
|
||||
key={c.id}
|
||||
type="button"
|
||||
className={i === catIdx ? 'primary-btn' : 'ghost-btn'}
|
||||
style={{
|
||||
textAlign: 'left',
|
||||
opacity: c.hidden ? 0.5 : 1,
|
||||
textDecoration: c.hidden ? 'line-through' : 'none',
|
||||
}}
|
||||
onClick={() => {
|
||||
setCatIdx(i)
|
||||
setGroupIdx(0)
|
||||
}}
|
||||
>
|
||||
{c.emoji} {c.title}
|
||||
{c.hidden ? ' · 隐' : ''}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{cat ? (
|
||||
<>
|
||||
<div className="panel">
|
||||
<h2 style={{ marginTop: 0 }}>编辑分类</h2>
|
||||
<div style={{ display: 'grid', gap: 10, gridTemplateColumns: '80px 1fr 1fr' }}>
|
||||
<label>
|
||||
Emoji
|
||||
<input
|
||||
value={cat.emoji}
|
||||
onChange={(e) => {
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, emoji: e.target.value } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
标题
|
||||
<input
|
||||
value={cat.title}
|
||||
onChange={(e) => {
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, title: e.target.value } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
ID
|
||||
<input
|
||||
value={cat.id}
|
||||
onChange={(e) => {
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, id: e.target.value } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 8, marginTop: 12, flexWrap: 'wrap' }}>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => {
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, hidden: !c.hidden } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
>
|
||||
{cat.hidden ? '取消隐藏' : '隐藏分类'}
|
||||
</button>
|
||||
<button type="button" className="ghost-btn" onClick={() => moveCat(catIdx, catIdx - 1)}>
|
||||
↑ 上移
|
||||
</button>
|
||||
<button type="button" className="ghost-btn" onClick={() => moveCat(catIdx, catIdx + 1)}>
|
||||
↓ 下移
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => {
|
||||
if (!confirm('删除该分类?')) return
|
||||
const cats = nav.categories.filter((_, i) => i !== catIdx)
|
||||
patch({ ...nav, categories: cats })
|
||||
setCatIdx(Math.max(0, catIdx - 1))
|
||||
setGroupIdx(0)
|
||||
}}
|
||||
>
|
||||
删除分类
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel">
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<h2 style={{ margin: 0 }}>分组</h2>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => {
|
||||
const groups = [...cat.groups, emptyGroup()]
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
setGroupIdx(groups.length - 1)
|
||||
}}
|
||||
>
|
||||
+ 分组
|
||||
</button>
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', marginTop: 10 }}>
|
||||
{cat.groups.map((g, i) => (
|
||||
<button
|
||||
key={g.id}
|
||||
type="button"
|
||||
className={i === groupIdx ? 'primary-btn' : 'ghost-btn'}
|
||||
style={{ opacity: g.hidden ? 0.5 : 1 }}
|
||||
onClick={() => setGroupIdx(i)}
|
||||
>
|
||||
{g.title}
|
||||
{g.hidden ? ' · 隐' : ''}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{group ? (
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<div style={{ display: 'grid', gap: 10, gridTemplateColumns: '1fr 1fr' }}>
|
||||
<label>
|
||||
分组标题
|
||||
<input
|
||||
value={group.title}
|
||||
onChange={(e) => {
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, title: e.target.value } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
分组 ID
|
||||
<input
|
||||
value={group.id}
|
||||
onChange={(e) => {
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, id: e.target.value } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 8, marginTop: 10, flexWrap: 'wrap' }}>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => {
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, hidden: !g.hidden } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
>
|
||||
{group.hidden ? '取消隐藏分组' : '隐藏分组'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => moveGroup(groupIdx, groupIdx - 1)}
|
||||
>
|
||||
↑
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => moveGroup(groupIdx, groupIdx + 1)}
|
||||
>
|
||||
↓
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => {
|
||||
if (!confirm('删除该分组?')) return
|
||||
const groups = cat.groups.filter((_, i) => i !== groupIdx)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
setGroupIdx(Math.max(0, groupIdx - 1))
|
||||
}}
|
||||
>
|
||||
删除分组
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="primary-btn"
|
||||
onClick={() => {
|
||||
const links = [...group.links, emptyLink()]
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, links } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
>
|
||||
+ 链接
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="table-wrap" style={{ marginTop: 14 }}>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>标题</th>
|
||||
<th>副标题</th>
|
||||
<th>链接</th>
|
||||
<th>图标</th>
|
||||
<th>动作</th>
|
||||
<th>状态</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{group.links.map((link, li) => (
|
||||
<tr key={link.id} style={{ opacity: link.hidden ? 0.55 : 1 }}>
|
||||
<td>
|
||||
<input
|
||||
value={link.title}
|
||||
onChange={(e) => {
|
||||
const links = group.links.map((l, j) =>
|
||||
j === li ? { ...l, title: e.target.value } : l,
|
||||
)
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, links } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
value={link.subtitle}
|
||||
onChange={(e) => {
|
||||
const links = group.links.map((l, j) =>
|
||||
j === li ? { ...l, subtitle: e.target.value } : l,
|
||||
)
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, links } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
value={link.href}
|
||||
onChange={(e) => {
|
||||
const links = group.links.map((l, j) =>
|
||||
j === li ? { ...l, href: e.target.value } : l,
|
||||
)
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, links } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
value={link.icon}
|
||||
onChange={(e) => {
|
||||
const links = group.links.map((l, j) =>
|
||||
j === li ? { ...l, icon: e.target.value } : l,
|
||||
)
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, links } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<select
|
||||
value={link.action || 'open'}
|
||||
onChange={(e) => {
|
||||
const action = e.target.value === 'copy' ? 'copy' : 'open'
|
||||
const links = group.links.map((l, j) =>
|
||||
j === li ? { ...l, action } : l,
|
||||
)
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, links } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
>
|
||||
<option value="open">打开</option>
|
||||
<option value="copy">复制</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>{link.hidden ? '隐藏' : '显示'}</td>
|
||||
<td style={{ whiteSpace: 'nowrap' }}>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => {
|
||||
const links = group.links.map((l, j) =>
|
||||
j === li ? { ...l, hidden: !l.hidden } : l,
|
||||
)
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, links } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
>
|
||||
{link.hidden ? '显' : '隐'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => moveLink(li, li - 1)}
|
||||
>
|
||||
↑
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => moveLink(li, li + 1)}
|
||||
>
|
||||
↓
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-btn"
|
||||
onClick={() => {
|
||||
if (!confirm('删除链接?')) return
|
||||
const links = group.links.filter((_, j) => j !== li)
|
||||
const groups = cat.groups.map((g, i) =>
|
||||
i === groupIdx ? { ...g, links } : g,
|
||||
)
|
||||
const cats = nav.categories.map((c, i) =>
|
||||
i === catIdx ? { ...c, groups } : c,
|
||||
)
|
||||
patch({ ...nav, categories: cats })
|
||||
}}
|
||||
>
|
||||
删
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{!group.links.length ? (
|
||||
<tr>
|
||||
<td colSpan={7}>暂无链接,点「+ 链接」添加</td>
|
||||
</tr>
|
||||
) : null}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p className="vip-hint">请选择或新增分组</p>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="panel">
|
||||
<p>暂无分类,点左侧「+ 新增」</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@ -30,6 +30,7 @@ from ebook_svc.routers import ( # noqa: E402
|
||||
join_group_admin,
|
||||
memo,
|
||||
memo_admin,
|
||||
nav_admin,
|
||||
pay,
|
||||
public_config,
|
||||
shop,
|
||||
@ -115,6 +116,7 @@ app.include_router(join_group_admin.router)
|
||||
app.include_router(vip_admin.router)
|
||||
app.include_router(shop_admin.router)
|
||||
app.include_router(memo_admin.router)
|
||||
app.include_router(nav_admin.router)
|
||||
app.include_router(public_config.router)
|
||||
|
||||
# —— 社群 ——
|
||||
|
||||
@ -19,6 +19,7 @@ from ebook_svc.routers import (
|
||||
join_group_admin,
|
||||
memo,
|
||||
memo_admin,
|
||||
nav_admin,
|
||||
pay,
|
||||
public_config,
|
||||
shop,
|
||||
@ -71,6 +72,8 @@ app.include_router(vip_admin.router)
|
||||
app.include_router(shop_admin.router)
|
||||
# VIP 私密社群(类微博)
|
||||
app.include_router(memo_admin.router)
|
||||
# 导航远程 CRUD(navContent)
|
||||
app.include_router(nav_admin.router)
|
||||
# 公开远程配置(抖音真机:dyapi/api 合法域名 + 有效证书)
|
||||
app.include_router(public_config.router)
|
||||
|
||||
|
||||
83
apps/api/services/ebook_svc/routers/nav_admin.py
Normal file
83
apps/api/services/ebook_svc/routers/nav_admin.py
Normal file
@ -0,0 +1,83 @@
|
||||
"""导航管理:admin.nomadro.cn/wechat/nav — CRUD navContent。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ebook_svc.core.security import require_admin
|
||||
from ebook_svc.services.nav_config import read_nav_content, save_nav_content
|
||||
from ebook_svc.services.tt_platform_config import resolve_config_file
|
||||
|
||||
router = APIRouter(prefix="/api/admin/nav", tags=["nav-admin"])
|
||||
|
||||
|
||||
class NavLinkIn(BaseModel):
|
||||
id: str = ""
|
||||
title: str = ""
|
||||
subtitle: str = ""
|
||||
href: str = ""
|
||||
icon: str = "/icons/nomadro.webp"
|
||||
action: str = "open"
|
||||
hidden: bool = False
|
||||
|
||||
|
||||
class NavGroupIn(BaseModel):
|
||||
id: str = ""
|
||||
title: str = ""
|
||||
links: list[NavLinkIn] = Field(default_factory=list)
|
||||
hidden: bool = False
|
||||
|
||||
|
||||
class NavCategoryIn(BaseModel):
|
||||
id: str = ""
|
||||
title: str = ""
|
||||
emoji: str = "✦"
|
||||
groups: list[NavGroupIn] = Field(default_factory=list)
|
||||
hidden: bool = False
|
||||
|
||||
|
||||
class NavBody(BaseModel):
|
||||
brand: str | None = None
|
||||
tagline: str | None = None
|
||||
footer: str | None = None
|
||||
categories: list[NavCategoryIn] | None = None
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def get_nav(_: str = Depends(require_admin)) -> dict[str, Any]:
|
||||
nav = read_nav_content()
|
||||
path = resolve_config_file()
|
||||
return {
|
||||
"ok": True,
|
||||
"nav": nav,
|
||||
"configPath": str(path),
|
||||
"stats": {
|
||||
"categories": len(nav.get("categories") or []),
|
||||
"groups": sum(len(c.get("groups") or []) for c in nav.get("categories") or []),
|
||||
"links": sum(
|
||||
len(g.get("links") or [])
|
||||
for c in nav.get("categories") or []
|
||||
for g in c.get("groups") or []
|
||||
),
|
||||
"hiddenCategories": sum(
|
||||
1 for c in nav.get("categories") or [] if c.get("hidden")
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@router.put("")
|
||||
async def put_nav(body: NavBody, _: str = Depends(require_admin)) -> dict[str, Any]:
|
||||
patch: dict[str, Any] = {}
|
||||
if body.brand is not None:
|
||||
patch["brand"] = body.brand
|
||||
if body.tagline is not None:
|
||||
patch["tagline"] = body.tagline
|
||||
if body.footer is not None:
|
||||
patch["footer"] = body.footer
|
||||
if body.categories is not None:
|
||||
patch["categories"] = [c.model_dump() for c in body.categories]
|
||||
saved = save_nav_content(patch)
|
||||
return {"ok": True, "nav": saved}
|
||||
133
apps/api/services/ebook_svc/services/nav_config.py
Normal file
133
apps/api/services/ebook_svc/services/nav_config.py
Normal file
@ -0,0 +1,133 @@
|
||||
"""导航远程内容 — 读写 remote-config.json 的 navContent。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from ebook_svc.services.tt_platform_config import resolve_config_file
|
||||
|
||||
_SEED_CANDIDATES = [
|
||||
Path(__file__).resolve().parents[5] / "src" / "lib" / "nav-default-links.json",
|
||||
Path(__file__).resolve().parents[5] / "src" / "modules" / "nav" / "data" / "links.json",
|
||||
Path("/opt/nomadmini/backend/data/nav-default-links.json"),
|
||||
Path("/var/www/nomadro.cn/data/nav-default-links.json"),
|
||||
]
|
||||
|
||||
|
||||
def _read_raw() -> dict[str, Any]:
|
||||
path = resolve_config_file()
|
||||
if not path.is_file():
|
||||
return {}
|
||||
try:
|
||||
raw = json.loads(path.read_text(encoding="utf-8"))
|
||||
return raw if isinstance(raw, dict) else {}
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def _seed_nav() -> dict[str, Any]:
|
||||
for p in _SEED_CANDIDATES:
|
||||
if p.is_file():
|
||||
try:
|
||||
raw = json.loads(p.read_text(encoding="utf-8"))
|
||||
if isinstance(raw, dict) and isinstance(raw.get("categories"), list):
|
||||
return normalize_nav(raw)
|
||||
except Exception:
|
||||
continue
|
||||
return {
|
||||
"brand": "游民导航",
|
||||
"tagline": "数字游民工具与出海资源合集",
|
||||
"footer": "2026 游民导航",
|
||||
"categories": [],
|
||||
}
|
||||
|
||||
|
||||
def _norm_link(raw: Any, i: int) -> dict[str, Any]:
|
||||
r = raw if isinstance(raw, dict) else {}
|
||||
action = r.get("action")
|
||||
return {
|
||||
"id": str(r.get("id") or f"link-{i}"),
|
||||
"title": str(r.get("title") or "未命名"),
|
||||
"subtitle": str(r.get("subtitle") or ""),
|
||||
"href": str(r.get("href") or ""),
|
||||
"icon": str(r.get("icon") or "/icons/nomadro.webp"),
|
||||
"action": "copy" if action == "copy" else "open",
|
||||
"hidden": bool(r.get("hidden")),
|
||||
}
|
||||
|
||||
|
||||
def _norm_group(raw: Any, i: int) -> dict[str, Any]:
|
||||
r = raw if isinstance(raw, dict) else {}
|
||||
links = r.get("links") if isinstance(r.get("links"), list) else []
|
||||
return {
|
||||
"id": str(r.get("id") or f"group-{i}"),
|
||||
"title": str(r.get("title") or "未命名组"),
|
||||
"links": [_norm_link(x, j) for j, x in enumerate(links)],
|
||||
"hidden": bool(r.get("hidden")),
|
||||
}
|
||||
|
||||
|
||||
def _norm_cat(raw: Any, i: int) -> dict[str, Any]:
|
||||
r = raw if isinstance(raw, dict) else {}
|
||||
groups = r.get("groups") if isinstance(r.get("groups"), list) else []
|
||||
return {
|
||||
"id": str(r.get("id") or f"cat-{i}"),
|
||||
"title": str(r.get("title") or "未命名分类"),
|
||||
"emoji": str(r.get("emoji") or "✦"),
|
||||
"groups": [_norm_group(x, j) for j, x in enumerate(groups)],
|
||||
"hidden": bool(r.get("hidden")),
|
||||
}
|
||||
|
||||
|
||||
def normalize_nav(raw: Any) -> dict[str, Any]:
|
||||
r = raw if isinstance(raw, dict) else {}
|
||||
cats = r.get("categories") if isinstance(r.get("categories"), list) else []
|
||||
out = {
|
||||
"brand": str(r.get("brand") or "游民导航"),
|
||||
"tagline": str(r.get("tagline") or ""),
|
||||
"footer": str(r.get("footer") or ""),
|
||||
"categories": [_norm_cat(c, i) for i, c in enumerate(cats)],
|
||||
}
|
||||
if r.get("updatedAt"):
|
||||
out["updatedAt"] = str(r["updatedAt"])
|
||||
return out
|
||||
|
||||
|
||||
def read_nav_content() -> dict[str, Any]:
|
||||
raw = _read_raw()
|
||||
nav = raw.get("navContent")
|
||||
if isinstance(nav, dict) and isinstance(nav.get("categories"), list) and nav["categories"]:
|
||||
return normalize_nav(nav)
|
||||
return _seed_nav()
|
||||
|
||||
|
||||
def save_nav_content(patch: dict[str, Any]) -> dict[str, Any]:
|
||||
path = resolve_config_file()
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
raw = _read_raw()
|
||||
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
||||
current = read_nav_content()
|
||||
merged = normalize_nav(
|
||||
{
|
||||
"brand": patch.get("brand", current["brand"]),
|
||||
"tagline": patch.get("tagline", current["tagline"]),
|
||||
"footer": patch.get("footer", current["footer"]),
|
||||
"categories": patch["categories"]
|
||||
if isinstance(patch.get("categories"), list)
|
||||
else current["categories"],
|
||||
"updatedAt": now,
|
||||
}
|
||||
)
|
||||
raw["navContent"] = merged
|
||||
raw["updatedAt"] = now
|
||||
try:
|
||||
raw["version"] = int(raw.get("version") or 0) + 1
|
||||
except Exception:
|
||||
raw["version"] = 1
|
||||
# atomic write
|
||||
tmp = path.with_suffix(path.suffix + ".tmp")
|
||||
tmp.write_text(json.dumps(raw, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
tmp.replace(path)
|
||||
return merged
|
||||
@ -1,4 +1,6 @@
|
||||
/** Offline seed — keep in sync with lib/remote-config.ts DEFAULT */
|
||||
import linksSeed from './links.json'
|
||||
|
||||
export type ModuleToggle = {
|
||||
enabled: boolean
|
||||
title: string
|
||||
@ -6,6 +8,39 @@ export type ModuleToggle = {
|
||||
note?: string
|
||||
}
|
||||
|
||||
export type NavLinkItem = {
|
||||
id: string
|
||||
title: string
|
||||
subtitle: string
|
||||
href: string
|
||||
icon: string
|
||||
action?: 'open' | 'copy'
|
||||
hidden?: boolean
|
||||
}
|
||||
|
||||
export type NavGroupItem = {
|
||||
id: string
|
||||
title: string
|
||||
links: NavLinkItem[]
|
||||
hidden?: boolean
|
||||
}
|
||||
|
||||
export type NavCategoryItem = {
|
||||
id: string
|
||||
title: string
|
||||
emoji: string
|
||||
groups: NavGroupItem[]
|
||||
hidden?: boolean
|
||||
}
|
||||
|
||||
export type NavContent = {
|
||||
brand: string
|
||||
tagline: string
|
||||
footer: string
|
||||
categories: NavCategoryItem[]
|
||||
updatedAt?: string
|
||||
}
|
||||
|
||||
export type NomadroRemoteConfig = {
|
||||
version: number
|
||||
updatedAt: string
|
||||
@ -40,14 +75,49 @@ export type NomadroRemoteConfig = {
|
||||
joinGroupDouyinHint?: string
|
||||
joinGroupDouyinQr?: string
|
||||
}
|
||||
/** 导航分类/链接(后台 CRUD);离线用 links.json */
|
||||
navContent?: NavContent
|
||||
}
|
||||
|
||||
function normalizeNav(raw: unknown): NavContent {
|
||||
const r = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
const cats = Array.isArray(r.categories) ? r.categories : []
|
||||
return {
|
||||
brand: String(r.brand || '游民导航'),
|
||||
tagline: String(r.tagline || ''),
|
||||
footer: String(r.footer || ''),
|
||||
categories: cats.map((c: any, i: number) => ({
|
||||
id: String(c?.id || `cat-${i}`),
|
||||
title: String(c?.title || '未命名'),
|
||||
emoji: String(c?.emoji || '✦'),
|
||||
hidden: Boolean(c?.hidden),
|
||||
groups: (Array.isArray(c?.groups) ? c.groups : []).map((g: any, j: number) => ({
|
||||
id: String(g?.id || `group-${j}`),
|
||||
title: String(g?.title || '未命名组'),
|
||||
hidden: Boolean(g?.hidden),
|
||||
links: (Array.isArray(g?.links) ? g.links : []).map((l: any, k: number) => ({
|
||||
id: String(l?.id || `link-${k}`),
|
||||
title: String(l?.title || '未命名'),
|
||||
subtitle: String(l?.subtitle || ''),
|
||||
href: String(l?.href || ''),
|
||||
icon: String(l?.icon || '/icons/nomadro.webp'),
|
||||
action: l?.action === 'copy' ? ('copy' as const) : ('open' as const),
|
||||
hidden: Boolean(l?.hidden),
|
||||
})),
|
||||
})),
|
||||
})),
|
||||
updatedAt: r.updatedAt ? String(r.updatedAt) : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
export const DEFAULT_NAV_CONTENT: NavContent = normalizeNav(linksSeed)
|
||||
|
||||
export const DEFAULT_REMOTE_CONFIG: NomadroRemoteConfig = {
|
||||
version: 1,
|
||||
updatedAt: '2026-03-28T00:00:00.000Z',
|
||||
modules: {
|
||||
home: { enabled: true, title: '首页', tabLabel: '首页' },
|
||||
nav: { enabled: true, title: '出海导航', tabLabel: '导航' },
|
||||
nav: { enabled: true, title: '出海导航', tabLabel: '导航', note: 'navContent 远程可改' },
|
||||
book: { enabled: true, title: '数字游民小册', tabLabel: '小册' },
|
||||
community: { enabled: true, title: '旅居社群', tabLabel: '社群' },
|
||||
destinations: { enabled: true, title: '目的地' },
|
||||
@ -75,6 +145,44 @@ export const DEFAULT_REMOTE_CONFIG: NomadroRemoteConfig = {
|
||||
joinGroupDouyinHint: '打开抖音搜群「数字游民」或扫码进群',
|
||||
joinGroupDouyinQr: '',
|
||||
},
|
||||
navContent: JSON.parse(JSON.stringify(DEFAULT_NAV_CONTENT)) as NavContent,
|
||||
}
|
||||
|
||||
export function mergeNavContent(
|
||||
base: NavContent,
|
||||
patch?: Partial<NavContent> | null,
|
||||
): NavContent {
|
||||
if (!patch) return JSON.parse(JSON.stringify(base)) as NavContent
|
||||
if (Array.isArray(patch.categories)) {
|
||||
return normalizeNav({ ...base, ...patch, categories: patch.categories })
|
||||
}
|
||||
return normalizeNav({ ...base, ...patch, categories: base.categories })
|
||||
}
|
||||
|
||||
export function resolveNavContent(config: NomadroRemoteConfig): NavContent {
|
||||
const remote = config.navContent
|
||||
if (remote && Array.isArray(remote.categories) && remote.categories.length > 0) {
|
||||
return mergeNavContent(DEFAULT_NAV_CONTENT, remote)
|
||||
}
|
||||
return JSON.parse(JSON.stringify(DEFAULT_NAV_CONTENT)) as NavContent
|
||||
}
|
||||
|
||||
/** 展示用:过滤 hidden */
|
||||
export function visibleNavContent(nav: NavContent): NavContent {
|
||||
return {
|
||||
...nav,
|
||||
categories: (nav.categories || [])
|
||||
.filter((c) => !c.hidden)
|
||||
.map((c) => ({
|
||||
...c,
|
||||
groups: (c.groups || [])
|
||||
.filter((g) => !g.hidden)
|
||||
.map((g) => ({
|
||||
...g,
|
||||
links: (g.links || []).filter((l) => !l.hidden),
|
||||
})),
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
export function mergeRemoteConfig(
|
||||
@ -90,5 +198,9 @@ export function mergeRemoteConfig(
|
||||
modules: { ...base.modules, ...(partial.modules || {}) },
|
||||
flags: { ...base.flags, ...(partial.flags || {}) },
|
||||
copy: { ...base.copy, ...(partial.copy || {}) },
|
||||
navContent: mergeNavContent(
|
||||
base.navContent || DEFAULT_NAV_CONTENT,
|
||||
partial.navContent ?? base.navContent,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,23 @@
|
||||
/**
|
||||
* 对齐门户 app/nav → @navmini/App.tsx(结构 / 样式 / 双列卡片 / 侧栏)
|
||||
* 数据:src/data/links.json(与 navmini 同步)
|
||||
* 数据:远程 navContent(后台 CRUD)+ 包内 links.json 离线兜底
|
||||
*/
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, type CSSProperties } from 'react'
|
||||
import { Image, ScrollView } from '@tarojs/components'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { MiniModuleGate } from '@/components/MiniModuleGate'
|
||||
import { H5Box, H5Txt } from '@/components/H5Box'
|
||||
import config from '@/data/links.json'
|
||||
import seed from '@/data/links.json'
|
||||
import {
|
||||
getCachedRemoteConfig,
|
||||
loadRemoteConfig,
|
||||
subscribeRemoteConfig,
|
||||
} from '@/services/remoteConfig'
|
||||
import {
|
||||
resolveNavContent,
|
||||
visibleNavContent,
|
||||
type NavContent,
|
||||
} from '@/data/remoteConfig.defaults'
|
||||
import { applyH5Theme, useNomadroTheme } from '@/utils/h5Theme'
|
||||
import { goHome } from '@/utils/nav'
|
||||
import { usePageShare, markPageShare } from '@/utils/pageShare'
|
||||
@ -22,8 +32,9 @@ type NavLink = {
|
||||
href: string
|
||||
icon: string
|
||||
action?: LinkAction
|
||||
hidden?: boolean
|
||||
}
|
||||
type NavGroup = { id: string; title: string; links: NavLink[] }
|
||||
type NavGroup = { id: string; title: string; links: NavLink[]; hidden?: boolean }
|
||||
type NavCategory = { id: string; title: string; emoji: string; groups: NavGroup[]; hidden?: boolean }
|
||||
type NavConfig = {
|
||||
brand: string
|
||||
@ -32,11 +43,27 @@ type NavConfig = {
|
||||
categories: NavCategory[]
|
||||
}
|
||||
|
||||
const nav = config as NavConfig
|
||||
/** 隐藏分类仍保留在 links.json,仅不展示(如 books) */
|
||||
const visibleCategories = nav.categories.filter((c) => !c.hidden)
|
||||
const seedNav = seed as NavConfig
|
||||
const isH5 = process.env.TARO_ENV === 'h5'
|
||||
|
||||
function toVisible(nav: NavContent | NavConfig): NavConfig {
|
||||
const v = visibleNavContent(nav as NavContent)
|
||||
return {
|
||||
brand: v.brand,
|
||||
tagline: v.tagline,
|
||||
footer: v.footer,
|
||||
categories: v.categories as NavCategory[],
|
||||
}
|
||||
}
|
||||
|
||||
function bootNav(): NavConfig {
|
||||
try {
|
||||
return toVisible(resolveNavContent(getCachedRemoteConfig()))
|
||||
} catch {
|
||||
return toVisible(seedNav)
|
||||
}
|
||||
}
|
||||
|
||||
function countLinks(cat: NavCategory) {
|
||||
return cat.groups.reduce((s, g) => s + g.links.length, 0)
|
||||
}
|
||||
@ -44,13 +71,17 @@ function countLinks(cat: NavCategory) {
|
||||
function iconSrc(icon: string) {
|
||||
if (!icon) return ''
|
||||
// 真机调试:绝对路径 /icons 偶发解析失败;相对 pages/nav → ../../icons
|
||||
// 真机对本地 webp 常空白 → 统一 png(copy-weapp-static 已从 webp 导出)
|
||||
// 资源以 webp 为主;dev 可能未跑 webp→png,优先 webp,避免空白
|
||||
const cleaned = icon.replace(/^\//, '').replace(/^icons\//, '')
|
||||
const base = cleaned.replace(/\.(webp|png|jpe?g)$/i, '')
|
||||
if (process.env.TARO_ENV === 'h5') return `/icons/${base}.png`
|
||||
return `../../icons/${base}.png`
|
||||
if (process.env.TARO_ENV === 'h5') {
|
||||
// H5 public 多为 webp;有 png 时亦可
|
||||
return `/icons/${base}.webp`
|
||||
}
|
||||
return `../../icons/${base}.webp`
|
||||
}
|
||||
|
||||
|
||||
const MENU_SVG = (open: boolean) =>
|
||||
`<svg class="menu-icon${open ? ' open' : ''}" viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
||||
<path class="menu-line top" d="M4 7h16" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
|
||||
@ -74,6 +105,8 @@ const CLOSE_SVG = `<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
||||
|
||||
function NavPageInner() {
|
||||
const theme = useNomadroTheme()
|
||||
const [nav, setNav] = useState<NavConfig>(() => bootNav())
|
||||
const visibleCategories = nav.categories
|
||||
const [activeId, setActiveId] = useState(visibleCategories[0]?.id ?? '')
|
||||
const [drawerOpen, setDrawerOpen] = useState(false)
|
||||
const [toast, setToast] = useState('')
|
||||
@ -93,6 +126,20 @@ function NavPageInner() {
|
||||
[safe],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
const apply = (cfg = getCachedRemoteConfig()) => {
|
||||
const next = toVisible(resolveNavContent(cfg))
|
||||
setNav(next)
|
||||
setActiveId((prev) =>
|
||||
next.categories.some((c) => c.id === prev) ? prev : next.categories[0]?.id ?? '',
|
||||
)
|
||||
}
|
||||
apply()
|
||||
const unsub = subscribeRemoteConfig((r) => apply(r.config))
|
||||
void loadRemoteConfig(true).then((r) => apply(r.config))
|
||||
return unsub
|
||||
}, [])
|
||||
|
||||
// rem 锁定(H5);主题由 useNomadroTheme + 根节点 data-theme 承接
|
||||
useEffect(() => {
|
||||
applyH5Theme(theme)
|
||||
@ -140,11 +187,11 @@ function NavPageInner() {
|
||||
onScroll()
|
||||
window.addEventListener('scroll', onScroll, { passive: true })
|
||||
return () => window.removeEventListener('scroll', onScroll)
|
||||
}, [])
|
||||
}, [visibleCategories])
|
||||
|
||||
const activeCategory = useMemo(
|
||||
() => visibleCategories.find((c) => c.id === activeId) ?? visibleCategories[0],
|
||||
[activeId],
|
||||
[activeId, visibleCategories],
|
||||
)
|
||||
|
||||
const onOpen = useCallback((link: NavLink) => {
|
||||
@ -210,7 +257,7 @@ function NavPageInner() {
|
||||
<H5Box className="desktop-rail-nav">
|
||||
{visibleCategories.map((cat) => {
|
||||
const count = countLinks(cat)
|
||||
const active = cat.id === activeCategory.id
|
||||
const active = cat.id === activeCategory?.id
|
||||
return (
|
||||
<H5Box
|
||||
key={cat.id}
|
||||
@ -264,7 +311,7 @@ function NavPageInner() {
|
||||
</H5Box>
|
||||
|
||||
<H5Txt key={`pc-${pillKey}`} className="pc-section-label">
|
||||
{activeCategory.title}
|
||||
{activeCategory?.title || nav.brand}
|
||||
</H5Txt>
|
||||
</H5Box>
|
||||
</H5Box>
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
export default definePageConfig({
|
||||
navigationStyle: 'custom',
|
||||
navigationBarTitleText: '阅读',
|
||||
navigationBarBackgroundColor: '#0c0c0f',
|
||||
navigationBarTextStyle: 'white',
|
||||
backgroundColor: '#0c0c0f',
|
||||
})
|
||||
@ -55,8 +55,10 @@
|
||||
.zd-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 44px;
|
||||
height: 44px;
|
||||
padding-left: 4px;
|
||||
box-sizing: border-box;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
|
||||
}
|
||||
.zd-back {
|
||||
|
||||
@ -134,8 +134,14 @@ export default function VipMemoDetailPage() {
|
||||
|
||||
if (!memo) {
|
||||
return (
|
||||
<View className="zd" style={{ paddingTop: safe.statusBarHeight }}>
|
||||
<View className="zd-nav" style={{ paddingRight: safe.menuRightPad }}>
|
||||
<View className="zd" style={{ paddingTop: `${safe.statusBarHeight}px` }}>
|
||||
<View
|
||||
className="zd-nav"
|
||||
style={{
|
||||
height: `${safe.navBarHeight}px`,
|
||||
paddingRight: `${safe.menuRightPad}px`,
|
||||
}}
|
||||
>
|
||||
<View className="zd-back" onClick={() => goPage('/pages/vip-memo/index')}>
|
||||
<Text>←</Text>
|
||||
</View>
|
||||
@ -156,8 +162,14 @@ export default function VipMemoDetailPage() {
|
||||
const imgs = (memo.resources || []).map((r) => r.url).filter(Boolean)
|
||||
|
||||
return (
|
||||
<View className="zd" style={{ paddingTop: safe.statusBarHeight }}>
|
||||
<View className="zd-nav" style={{ paddingRight: safe.menuRightPad }}>
|
||||
<View className="zd" style={{ paddingTop: `${safe.statusBarHeight}px` }}>
|
||||
<View
|
||||
className="zd-nav"
|
||||
style={{
|
||||
height: `${safe.navBarHeight}px`,
|
||||
paddingRight: `${safe.menuRightPad}px`,
|
||||
}}
|
||||
>
|
||||
<View className="zd-back" onClick={() => goPage('/pages/vip-memo/index')}>
|
||||
<Text>←</Text>
|
||||
</View>
|
||||
|
||||
7
apps/miniprogram/h5/src/pages/vip-memo/index.config.ts
Normal file
7
apps/miniprogram/h5/src/pages/vip-memo/index.config.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export default definePageConfig({
|
||||
navigationStyle: 'custom',
|
||||
navigationBarTitleText: '知识社群',
|
||||
navigationBarBackgroundColor: '#0c0c0f',
|
||||
navigationBarTextStyle: 'white',
|
||||
backgroundColor: '#0c0c0f',
|
||||
})
|
||||
@ -11,8 +11,10 @@
|
||||
.zk-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 44px;
|
||||
height: 44px;
|
||||
padding-left: 4px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.zk-back,
|
||||
.zk-nav-btn {
|
||||
|
||||
@ -213,8 +213,14 @@ export default function VipMemoPage() {
|
||||
const showBootSpin = refreshing && !items.length
|
||||
|
||||
return (
|
||||
<View className="zk" style={{ paddingTop: safe.statusBarHeight }}>
|
||||
<View className="zk-nav" style={{ paddingRight: safe.menuRightPad }}>
|
||||
<View className="zk" style={{ paddingTop: `${safe.statusBarHeight}px` }}>
|
||||
<View
|
||||
className="zk-nav"
|
||||
style={{
|
||||
height: `${safe.navBarHeight}px`,
|
||||
paddingRight: `${safe.menuRightPad}px`,
|
||||
}}
|
||||
>
|
||||
<View className="zk-back" onClick={() => goPage('/pages/vip/index')}>
|
||||
<Text>←</Text>
|
||||
</View>
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
export default definePageConfig({
|
||||
navigationStyle: 'custom',
|
||||
navigationBarTitleText: '商品',
|
||||
navigationBarBackgroundColor: '#0c0c0f',
|
||||
navigationBarTextStyle: 'white',
|
||||
backgroundColor: '#0c0c0f',
|
||||
})
|
||||
@ -129,14 +129,14 @@ export default function VipStoreDetailPage() {
|
||||
|
||||
if (!product) {
|
||||
return (
|
||||
<View className="vsd" style={{ paddingTop: safe.safeTop }}>
|
||||
<View className="vsd" style={{ paddingTop: `${safe.statusBarHeight}px` }}>
|
||||
<Text className="vsd-loading">加载中…</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="vsd" style={{ paddingTop: safe.safeTop }}>
|
||||
<View className="vsd" style={{ paddingTop: `${safe.statusBarHeight}px` }}>
|
||||
<View className="vsd-head">
|
||||
<View className="vsd-back" onClick={() => goPage('/pages/vip-store/index')}>
|
||||
<Text>←</Text>
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
export default definePageConfig({
|
||||
navigationStyle: 'custom',
|
||||
navigationBarTitleText: '我的订单',
|
||||
navigationBarBackgroundColor: '#0c0c0f',
|
||||
navigationBarTextStyle: 'white',
|
||||
backgroundColor: '#0c0c0f',
|
||||
})
|
||||
@ -40,7 +40,7 @@ export default function VipStoreOrdersPage() {
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="vso" style={{ paddingTop: safe.safeTop }}>
|
||||
<View className="vso" style={{ paddingTop: `${safe.statusBarHeight}px` }}>
|
||||
<View className="vso-head">
|
||||
<View className="vso-back" onClick={() => goPage('/pages/vip-store/index')}>
|
||||
<Text>←</Text>
|
||||
|
||||
7
apps/miniprogram/h5/src/pages/vip-store/index.config.ts
Normal file
7
apps/miniprogram/h5/src/pages/vip-store/index.config.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export default definePageConfig({
|
||||
navigationStyle: 'custom',
|
||||
navigationBarTitleText: '设备商城',
|
||||
navigationBarBackgroundColor: '#0c0c0f',
|
||||
navigationBarTextStyle: 'white',
|
||||
backgroundColor: '#0c0c0f',
|
||||
})
|
||||
@ -64,7 +64,7 @@ export default function VipStorePage() {
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="vs" style={{ paddingTop: safe.safeTop }}>
|
||||
<View className="vs" style={{ paddingTop: `${safe.statusBarHeight}px` }}>
|
||||
<View className="vs-head">
|
||||
<View className="vs-back" onClick={() => goPage('/pages/vip/index')}>
|
||||
<Text>←</Text>
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
"private": true,
|
||||
"description": "Nomadro 微信小程序(独立目录,与 h5 / tt / xhs 互不影响)",
|
||||
"scripts": {
|
||||
"dev": "cross-env TARO_APP_TARGET=weapp node ./node_modules/@tarojs/cli/bin/taro build --type weapp --watch",
|
||||
"dev": "node ./scripts/copy-weapp-static.mjs && cross-env TARO_APP_TARGET=weapp node ./node_modules/@tarojs/cli/bin/taro build --type weapp --watch",
|
||||
"build": "cross-env TARO_APP_TARGET=weapp node ./node_modules/@tarojs/cli/bin/taro build --type weapp && node ./scripts/copy-weapp-static.mjs",
|
||||
"dev:weapp": "pnpm dev",
|
||||
"build:weapp": "pnpm build",
|
||||
|
||||
@ -36,6 +36,7 @@ export async function PUT(request: Request) {
|
||||
modules: { ...current.modules, ...(body.config.modules || {}) },
|
||||
flags: { ...current.flags, ...(body.config.flags || {}) },
|
||||
copy: { ...current.copy, ...(body.config.copy || {}) },
|
||||
navContent: body.config.navContent ?? current.navContent,
|
||||
platforms: {
|
||||
tt: body.config.platforms?.tt ?? current.platforms?.tt,
|
||||
},
|
||||
|
||||
585
src/lib/nav-default-links.json
Normal file
585
src/lib/nav-default-links.json
Normal file
@ -0,0 +1,585 @@
|
||||
{
|
||||
"brand": "游民导航",
|
||||
"tagline": "数字游民工具与出海资源合集",
|
||||
"footer": "2026 游民导航",
|
||||
"categories": [
|
||||
{
|
||||
"id": "nomad",
|
||||
"title": "数字游民",
|
||||
"emoji": "✦",
|
||||
"groups": [
|
||||
{
|
||||
"id": "community",
|
||||
"title": "游民社区",
|
||||
"links": [
|
||||
{
|
||||
"id": "nomadro",
|
||||
"title": "nomadro",
|
||||
"subtitle": "出海导航",
|
||||
"href": "https://nomadro.com",
|
||||
"icon": "/icons/nomadro.webp"
|
||||
},
|
||||
{
|
||||
"id": "nomadlist",
|
||||
"title": "nomadlist",
|
||||
"subtitle": "海外最大的数字游民社区",
|
||||
"href": "https://nomads.com?ref=https://nomadro.com",
|
||||
"icon": "/icons/nomadlist.webp"
|
||||
},
|
||||
{
|
||||
"id": "nomadcna",
|
||||
"title": "nomadcna",
|
||||
"subtitle": "国内数字游民社区",
|
||||
"href": "https://meetup.hackrobot.cn",
|
||||
"icon": "/icons/nomadcna.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "toolbox",
|
||||
"title": "工具箱",
|
||||
"links": [
|
||||
{
|
||||
"id": "chatgpt",
|
||||
"title": "ChatGPT",
|
||||
"subtitle": "OpenAI 开发的人工智能聊天机器人",
|
||||
"href": "https://chat.openai.com/",
|
||||
"icon": "/icons/chatgpt.webp"
|
||||
},
|
||||
{
|
||||
"id": "grok",
|
||||
"title": "Grok",
|
||||
"subtitle": "xAI 免费 AI 助手,追求真实与客观",
|
||||
"href": "https://grok.com/",
|
||||
"icon": "/icons/grok.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "us-phone",
|
||||
"title": "美国手机号",
|
||||
"links": [
|
||||
{
|
||||
"id": "1psim",
|
||||
"title": "1psim",
|
||||
"subtitle": "低成本 2.5$/m,支持 eSIM 和实体卡(邮寄中国)",
|
||||
"href": "https://1psim.com/7GARRL",
|
||||
"icon": "/icons/1psim.webp"
|
||||
},
|
||||
{
|
||||
"id": "yesim",
|
||||
"title": "yesim",
|
||||
"subtitle": "美国手机号,3$/m",
|
||||
"href": "https://yesim.app/?partner_id=1948",
|
||||
"icon": "/icons/yesim.webp"
|
||||
},
|
||||
{
|
||||
"id": "tello",
|
||||
"title": "tello",
|
||||
"subtitle": "最低 5$/m,支持 eSIM",
|
||||
"href": "https://tello.com/",
|
||||
"icon": "/icons/tello.webp"
|
||||
},
|
||||
{
|
||||
"id": "9esim",
|
||||
"title": "9esim",
|
||||
"subtitle": "让任何手机支持 eSIM,可写数据的 SIM 实体卡",
|
||||
"href": "https://www.9esim.com/?coupon=XIAOSHUANGERIC2",
|
||||
"icon": "/icons/9esim.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "finance",
|
||||
"title": "金融收款",
|
||||
"links": [
|
||||
{
|
||||
"id": "wise",
|
||||
"title": "wise",
|
||||
"subtitle": "线上开通境外银行账户(身份证即可)",
|
||||
"href": "https://wise.com/invite/amc/xiaoshuangh",
|
||||
"icon": "/icons/wise.webp"
|
||||
},
|
||||
{
|
||||
"id": "okx",
|
||||
"title": "OKX 交易所",
|
||||
"subtitle": "加密货币交易所",
|
||||
"href": "https://okx.com/join/84999861",
|
||||
"icon": "/icons/okx.webp"
|
||||
},
|
||||
{
|
||||
"id": "safepal",
|
||||
"title": "safepal (U卡)",
|
||||
"subtitle": "邀请码 104809,出海神卡,加密货币与法币转换",
|
||||
"href": "https://www.safepal.com/zh-cn/",
|
||||
"icon": "/icons/safepal.webp"
|
||||
},
|
||||
{
|
||||
"id": "paypal",
|
||||
"title": "paypal",
|
||||
"subtitle": "出海收款必备,TikTok 提现、佣金提现",
|
||||
"href": "https://py.pl/1tyAwY",
|
||||
"icon": "/icons/paypal.webp"
|
||||
},
|
||||
{
|
||||
"id": "bmc",
|
||||
"title": "buy me coffee",
|
||||
"subtitle": "赞助收款平台",
|
||||
"href": "https://www.buymeacoffee.com/invite/xiaoshuangi",
|
||||
"icon": "/icons/bmc.webp"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "studio",
|
||||
"title": "工作室",
|
||||
"emoji": "☕",
|
||||
"groups": [
|
||||
{
|
||||
"id": "proxy",
|
||||
"title": "科学上网",
|
||||
"links": [
|
||||
{
|
||||
"id": "jms",
|
||||
"title": "just my socks",
|
||||
"subtitle": "老牌网络代理服务",
|
||||
"href": "https://justmysocks.net/members/aff.php?aff=12475",
|
||||
"icon": "/icons/jms.webp"
|
||||
},
|
||||
{
|
||||
"id": "ykk",
|
||||
"title": "Ykk Cloud",
|
||||
"subtitle": "性价比高的网络加速服务",
|
||||
"href": "https://panel.ykkk.best/#/register?code=xYQebIgT",
|
||||
"icon": "/icons/ykk.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "vps",
|
||||
"title": "VPS 服务器",
|
||||
"links": [
|
||||
{
|
||||
"id": "vultr",
|
||||
"title": "vultr",
|
||||
"subtitle": "可按分钟计费的服务器(可支付宝)",
|
||||
"href": "https://www.vultr.com/?ref=8985003",
|
||||
"icon": "/icons/vultr.webp"
|
||||
},
|
||||
{
|
||||
"id": "bwh",
|
||||
"title": "bandwagonhost",
|
||||
"subtitle": "针对中国线路优化的高质量 VPS",
|
||||
"href": "https://bandwagonhost.com/aff.php?aff=25463",
|
||||
"icon": "/icons/bwh.webp"
|
||||
},
|
||||
{
|
||||
"id": "racknerd",
|
||||
"title": "RackNerd",
|
||||
"subtitle": "最便宜的美国 VPS 服务器",
|
||||
"href": "https://my.racknerd.com/aff.php?aff=15630",
|
||||
"icon": "/icons/racknerd.webp"
|
||||
},
|
||||
{
|
||||
"id": "qcloud",
|
||||
"title": "腾讯云",
|
||||
"subtitle": "腾讯服务器,国内速度快",
|
||||
"href": "https://curl.qcloud.com/BZZ2MBTN",
|
||||
"icon": "/icons/qcloud.webp"
|
||||
},
|
||||
{
|
||||
"id": "aliyun",
|
||||
"title": "阿里云",
|
||||
"subtitle": "阿里巴巴旗下 VPS 服务器",
|
||||
"href": "https://www.aliyun.com/minisite/goods?userCode=dii0ofzg",
|
||||
"icon": "/icons/aliyun.webp"
|
||||
},
|
||||
{
|
||||
"id": "colocrossing",
|
||||
"title": "colocrossing",
|
||||
"subtitle": "美国 VPS 服务商",
|
||||
"href": "https://cloud.colocrossing.com/aff.php?aff=1846",
|
||||
"icon": "/icons/colocrossing.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "resi-ip",
|
||||
"title": "静态住宅 IP",
|
||||
"links": [
|
||||
{
|
||||
"id": "iproyal",
|
||||
"title": "iproyal",
|
||||
"subtitle": "静态住宅 IP,出海必备",
|
||||
"href": "https://iproyal.cn/?r=nomadro",
|
||||
"icon": "/icons/iproyal.webp"
|
||||
},
|
||||
{
|
||||
"id": "proxy-cheap",
|
||||
"title": "proxy-cheap",
|
||||
"subtitle": "便宜的住宅 IP",
|
||||
"href": "https://app.proxy-cheap.com/r/bmcMoY",
|
||||
"icon": "/icons/proxy-cheap.webp"
|
||||
},
|
||||
{
|
||||
"id": "smartproxy",
|
||||
"title": "smartproxy",
|
||||
"subtitle": "静态住宅 IP 服务商",
|
||||
"href": "https://www.smartproxy.org/register/?invitation_code=7RXPLM",
|
||||
"icon": "/icons/smartproxy.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "resi-vps",
|
||||
"title": "住宅 VPS 服务器",
|
||||
"links": [
|
||||
{
|
||||
"id": "lisa",
|
||||
"title": "lisa",
|
||||
"subtitle": "住宅 IP 服务器,TikTok 必备",
|
||||
"href": "https://lisahost.com/aff.php?aff=7566",
|
||||
"icon": "/icons/lisa.webp"
|
||||
},
|
||||
{
|
||||
"id": "voyracloud",
|
||||
"title": "voyracloud",
|
||||
"subtitle": "静态住宅 IP 服务器",
|
||||
"href": "https://www.voyracloud.com/?ref_code=2LJPRTE5",
|
||||
"icon": "/icons/voyracloud.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "hardware",
|
||||
"title": "硬件",
|
||||
"links": [
|
||||
{
|
||||
"id": "rpi",
|
||||
"title": "树莓派",
|
||||
"subtitle": "无与伦比的 ARM 开发板",
|
||||
"href": "https://uland.taobao.com/coupon/edetail?e=5hkWkiThOmClhHvvyUNXZfh8CuWt5YH5OVuOuRD5gLJMmdsrkidbOWBzzpT26idJPSbzO0ArF68ertbZl9wqRUbeJevxT02sHgNIxyFsmaMOsi2OxhyQb%2BhYUTTNN7GRRSHvQe2jOLZ9pbNCYX0I%2BPP%2BWUTgK%2F%2B0I%2BtaUgbudUxA%2B536asYsLWVfKa%2BhVnND4NyB1fwjO3bJLf667Yy8Q5jB6TX2HR3Qrq8LCw4Dujjqyaqc1rGLUwdQHHM8iY%2BUDMxLRSiIntldeBz90au3REAmOgZ0RtdnfeSBK3KXa0%2FA9snq37kKL6zL4bZ3EAS%2F2oYsLHTsIOxroXBFP6oz%2BA%3D%3D&traceId=213e032e17650447230113327e0c4f&union_lens=lensId%3APUB%401765044691%400b521400_0da4_19af4dca231_da77%400290EZjuZ2xbgOlH3NTYAyI%40eyJmbG9vcklkIjoyMDg3MTcxMDEwLCJzcG1CIjoiiX3BvcnRhbF92Ml90b29sX3NlbGVjdGlvbmxpc3RfZGV0YWlsX2luZGV4X2h0bSIsInNyY0Zsb29ySWQiiOiiI4MDY2NCJ9",
|
||||
"icon": "/icons/rpi.webp"
|
||||
},
|
||||
{
|
||||
"id": "mini-pc",
|
||||
"title": "迷你主机",
|
||||
"subtitle": "具有性价比的 X86 小主机",
|
||||
"href": "https://s.click.taobao.com/t?e=m%3D2%26s%3DCb1Quo%2F0Wb5w4vFB6t2Z2ueEDrYVVa64YUrQeSeIhnK53hKxp7mNFuhCZFSw9yq2woqx0EHqItb0JlhLk0Jl4eVWmNyHytKdTKJ80yOOA0Mtd0e5Ku7CIDk5ffgV5fRI1qrpxiwMoCNxc1AtbZGVS936JshS%2F%2FIdwgQgG5hIzyLNEPXytV9ALtCLThlbPuuZLb93Df8fOziGg7JVKZos%2BjLJJgRsfWlWtajntMnDLEHhuApO%2F8klJ62RdK%2B6%2FP7Z6k6s3rDgsC6jO9AJYjY8CXJ%2BwEVkOqHFPSJJXArlDuzso5nyPLY4NPiLqets6lIJ",
|
||||
"icon": "/icons/mini-pc.webp"
|
||||
},
|
||||
{
|
||||
"id": "gpu",
|
||||
"title": "GPU 显卡",
|
||||
"subtitle": "AI 时代的算力基础设施",
|
||||
"href": "https://union-click.jd.com/jdc?e=618%7Cpc%7C&p=JF8BATUJK1olXwEDUFZVCkkRC18IGloWWwALV19aAUonRzBQRQQlBENHFRxWFlVPRjtUBABAQlRcCEBdCUoUBWkBGFoSVAcdDRsBVXsQB29pbiZRKGMHKlclCEgVWghcGV91UQoyVW5dCUoWAmYPHl4RbTYCU24fZp-esLulkIK0yd6n5V1eOEonA2kPH1oQWQUFV19VCnsQA2Y4El0dWQ4LU1hBC00SCmcJK2slXjYFVFdJDjlWUXsOaWslXTYBZF5cCEoQAGoLH1kRQQYHV1lbAFcXBWgMGl4RXgUKUllYOEkWAmsBK2vL05J3IB9Uajl8UStqSz4dFQ9jitDJGTlnA2sPH0olImF5ECFaSU0VVAdNQDxuW09KFiw8SyljbW1jcih3JWNxNlwaS0hqWBhoX2sQbQEEVW4",
|
||||
"icon": "/icons/gpu.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "software",
|
||||
"title": "软件",
|
||||
"links": [
|
||||
{
|
||||
"id": "3x-ui",
|
||||
"title": "3X-UI",
|
||||
"subtitle": "科学上网仪表盘",
|
||||
"href": "https://github.com/MHSanaei/3x-ui",
|
||||
"icon": "/icons/3x-ui.webp"
|
||||
},
|
||||
{
|
||||
"id": "mihomo",
|
||||
"title": "虚空终端 mihomo",
|
||||
"subtitle": "代理软件以及配置 wiki",
|
||||
"href": "https://wiki.metacubex.one/config/",
|
||||
"icon": "/icons/mihomo.webp"
|
||||
},
|
||||
{
|
||||
"id": "frp",
|
||||
"title": "frp",
|
||||
"subtitle": "高性能内网穿透",
|
||||
"href": "https://gofrp.org/zh-cn/docs/",
|
||||
"icon": "/icons/frp.webp"
|
||||
},
|
||||
{
|
||||
"id": "wireguard",
|
||||
"title": "wireguard",
|
||||
"subtitle": "P2P 打洞组网",
|
||||
"href": "https://github.com/WireGuard/wireguard-go",
|
||||
"icon": "/icons/wireguard.webp"
|
||||
},
|
||||
{
|
||||
"id": "lineageos",
|
||||
"title": "lineageos (pi5)",
|
||||
"subtitle": "树莓派的安卓 LineageOS",
|
||||
"href": "https://konstakang.com/devices/rpi5/",
|
||||
"icon": "/icons/lineageos.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "gear",
|
||||
"title": "数码装备",
|
||||
"links": [
|
||||
{
|
||||
"id": "ai-glasses",
|
||||
"title": "AI 眼镜",
|
||||
"subtitle": "第一视角拍摄",
|
||||
"href": "https://union-click.jd.com/jdc?e=618%7Cpc%7C&p=JF8BATkJK1olXw8AXVxfCU8UA18IGloVWwcKXFlZDUgnRzBQRQQlBENHFRxWFlVPRjtUBABAQlRcCEBdCUoXBW4AE1wRWAUdDRsBVXtwXw1pZzNKAmZgFFwlYUh8UzVBZyZlUQoyVW5dCUoWAmYPHl4RbTYCU24fZpO9hbeBtYKjxt-jwInikZ-fjV8JK1sTWgIDUVtVAEkVA2w4HFscbQ8EXFpVAUwRH2wOHlIdXDYyZF1tD0seF2l6WgkBW3QyZF5tC3sXAm8AGFsVXAEBXEJdDUMVB24UG10SWQcHUVZbAE8fCl8KGloRVDYyitPtY0JrQAYIYj0dXGZKMVc5T5Was35jYlMVXQUTZAQOch9SZTMNbC9gIGdQJi5VCzkRSCpfWDUXVAJlDQoCbw1gcG9qRwYdHnYyUW5aDEgn",
|
||||
"icon": "/icons/ai-glasses.webp"
|
||||
},
|
||||
{
|
||||
"id": "action-cam",
|
||||
"title": "运动相机",
|
||||
"subtitle": "骑行记录仪",
|
||||
"href": "https://union-click.jd.com/jdc?e=618%7Cpc%7C&p=JF8BASgJK1olXDYCVV9eCE0UB28ME1slGVlaCgFtUQ5SQi0DBUVNGFJeSwUIFxlJX3EIGloWXQABUF5ZAEsIWipURmt3CFhXIQkpbChuRy8JGDpRJUJQDwkbBEcnAl8IGloUXA8FUVtZOHsXBF9edVsUXAcDVV1fDEonAl8IHVwRXAMGVVpaDEsUM2gIEmscWw4GXFdaDlcUBWoBE1olbTYBZFldAV8RcS5aD11nbTYCZF1tCEoXAmsNHl8UXQQeVF1ZDE0UH28OHF8UWAIDUVddCkgnAW4JH1IlbdiMwDxcaAJfBTlNTRpCBHpHLhyDht8GcR8BHFIUTDZ6NSMpYRJweWtBfAUXC2JyXBkpfTNRWi1mGV4UAlgENFpeDA13cRRcTAJLbQMyU1peOA",
|
||||
"icon": "/icons/action-cam.webp"
|
||||
},
|
||||
{
|
||||
"id": "drone",
|
||||
"title": "无人机",
|
||||
"subtitle": "天空视角",
|
||||
"href": "https://union-click.jd.com/jdc?e=618%7Cpc%7C&p=JF8BASgJK1olXDYCVV9eAUIeB2YMH14lGVlaCgFtUQ5SQi0DBUVNGFJeSwUIFxlJX3EIGloWVA8LUFdZDE4IWipURmtCHHVEABsFVChPYRJAbVhlGRhbFRgLBEcnAl8IGloUXA8FUVtZOHsXBF9edVsUXAcDVV1fDEonAl8IHVwRXAMGVVdbC04VM2gIEmscWw4GXFdaDlcUBWoBE1olbTYBZFldAV8RcS5aD11nbTYCZF1tCEoXAmgLHlgRXgIeVFpfDU0UH28OHF8UWAIDUlteAUwnAW4JH1IlbdiMwCQvcipMBxJhfV9HGgF3FVaDht8GfxgBGVkRTDZUCjsVbzBTYRJbeRkWGG9WAx02D0JcUy5mGRNRFEJiUwgldStzfx1wTj1GbQMyU1peOA",
|
||||
"icon": "/icons/drone.webp"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "overseas",
|
||||
"title": "出海掘金",
|
||||
"emoji": "◎",
|
||||
"groups": [
|
||||
{
|
||||
"id": "tiktok",
|
||||
"title": "TikTok",
|
||||
"links": [
|
||||
{
|
||||
"id": "tiktok",
|
||||
"title": "TikTok",
|
||||
"subtitle": "全球直播平台",
|
||||
"href": "https://www.tiktok.com/",
|
||||
"icon": "/icons/tiktok.webp"
|
||||
},
|
||||
{
|
||||
"id": "cloud-phone",
|
||||
"title": "云手机",
|
||||
"subtitle": "用开源硬件打造云手机",
|
||||
"href": "https://www.hackrobot.cn/",
|
||||
"icon": "/icons/cloud-phone.webp"
|
||||
},
|
||||
{
|
||||
"id": "vcam",
|
||||
"title": "vcam 虚拟摄像头",
|
||||
"subtitle": "Xposed 模块,替换摄像头视频流",
|
||||
"href": "https://pan.baidu.com/s/1NW4GMGA3cxfUQNWZPD9vOg?pwd=live",
|
||||
"icon": "/icons/vcam.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "youtube",
|
||||
"title": "YouTube",
|
||||
"links": [
|
||||
{
|
||||
"id": "youtube",
|
||||
"title": "YouTube",
|
||||
"subtitle": "全球最大的视频网站",
|
||||
"href": "https://www.youtube.com/",
|
||||
"icon": "/icons/youtube.webp"
|
||||
},
|
||||
{
|
||||
"id": "smmfollows",
|
||||
"title": "smmfollows",
|
||||
"subtitle": "刷粉刷量平台",
|
||||
"href": "https://smmfollows.com/ref/dfugq",
|
||||
"icon": "/icons/smmfollows.webp"
|
||||
},
|
||||
{
|
||||
"id": "yt-auto-dismiss",
|
||||
"title": "YouTube Studio Auto Dismiss",
|
||||
"subtitle": "油猴脚本,无人直播辅助",
|
||||
"href": "https://greasyfork.org/zh-CN/scripts/557378-youtube-studio-auto-dismiss",
|
||||
"icon": "/icons/yt-auto-dismiss.webp"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "web",
|
||||
"title": "Web 网站",
|
||||
"links": [
|
||||
{
|
||||
"id": "namesilo",
|
||||
"title": "namesilo",
|
||||
"subtitle": "注册域名",
|
||||
"href": "https://www.namesilo.com/?rid=3bd4047mc",
|
||||
"icon": "/icons/namesilo.webp"
|
||||
},
|
||||
{
|
||||
"id": "aapanel",
|
||||
"title": "aapanel",
|
||||
"subtitle": "宝塔面板",
|
||||
"href": "https://www.aapanel.com?referral_code=wcn04vez",
|
||||
"icon": "/icons/aapanel.webp"
|
||||
},
|
||||
{
|
||||
"id": "cloudflare",
|
||||
"title": "Cloudflare",
|
||||
"subtitle": "互联网基础节点",
|
||||
"href": "https://www.cloudflare.com/",
|
||||
"icon": "/icons/cloudflare.webp"
|
||||
},
|
||||
{
|
||||
"id": "ga",
|
||||
"title": "Google Analytics",
|
||||
"subtitle": "网站流量统计服务",
|
||||
"href": "https://analytics.google.com/",
|
||||
"icon": "/icons/ga.webp"
|
||||
},
|
||||
{
|
||||
"id": "adsense",
|
||||
"title": "Google AdSense",
|
||||
"subtitle": "Google 广告服务",
|
||||
"href": "https://www.google.com/adsense/",
|
||||
"icon": "/icons/adsense.webp"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "live",
|
||||
"title": "无人直播",
|
||||
"emoji": "▷",
|
||||
"groups": [
|
||||
{
|
||||
"id": "live-soft",
|
||||
"title": "软件",
|
||||
"links": [
|
||||
{
|
||||
"id": "obs",
|
||||
"title": "OBS",
|
||||
"subtitle": "免费开源:录屏 / 推流直播",
|
||||
"href": "https://pan.quark.cn/s/03e89f1bbc9b",
|
||||
"icon": "/icons/obs.webp"
|
||||
},
|
||||
{
|
||||
"id": "ffmpeg",
|
||||
"title": "ffmpeg",
|
||||
"subtitle": "命令行视频处理 / 推流,Python 自动化",
|
||||
"href": "https://www.ffmpeg.org/download.html",
|
||||
"icon": "/icons/ffmpeg.webp"
|
||||
},
|
||||
{
|
||||
"id": "srs",
|
||||
"title": "SRS",
|
||||
"subtitle": "开源直播服务器,拉流推流中转",
|
||||
"href": "https://ossrs.io/",
|
||||
"icon": "/icons/srs.webp"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pay",
|
||||
"title": "支付网关",
|
||||
"emoji": "◇",
|
||||
"groups": [
|
||||
{
|
||||
"id": "merchant",
|
||||
"title": "小微商户",
|
||||
"links": [
|
||||
{
|
||||
"id": "nowpayments",
|
||||
"title": "NOWPayments",
|
||||
"subtitle": "加密货币收款",
|
||||
"href": "https://account.nowpayments.io/create-account?link_id=3680795921",
|
||||
"icon": "/icons/nowpayments.webp"
|
||||
},
|
||||
{
|
||||
"id": "creem",
|
||||
"title": "Creem",
|
||||
"subtitle": "软件出海收款,税务合规",
|
||||
"href": "https://www.creem.io/",
|
||||
"icon": "/icons/creem.webp"
|
||||
},
|
||||
{
|
||||
"id": "stripe",
|
||||
"title": "Stripe",
|
||||
"subtitle": "全球在线支付",
|
||||
"href": "https://stripe.com/",
|
||||
"icon": "/icons/stripe.webp"
|
||||
},
|
||||
{
|
||||
"id": "zpay",
|
||||
"title": "z-pay",
|
||||
"subtitle": "支持独角数卡 · 易支付",
|
||||
"href": "https://z-pay.cn/?uid=22119",
|
||||
"icon": "/icons/zpay.webp"
|
||||
},
|
||||
{
|
||||
"id": "xorpay",
|
||||
"title": "xorpay",
|
||||
"subtitle": "支持收银台支付",
|
||||
"href": "https://xorpay.com?r=nomadro",
|
||||
"icon": "/icons/xorpay.webp"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "books",
|
||||
"title": "书籍",
|
||||
"emoji": "◈",
|
||||
"groups": [
|
||||
{
|
||||
"id": "handbook",
|
||||
"title": "手册",
|
||||
"links": [
|
||||
{
|
||||
"id": "nomad-book",
|
||||
"title": "数字游民手册",
|
||||
"subtitle": "复制链接后在小红书打开",
|
||||
"href": "https://www.xiaohongshu.com/s/poster?bgimg=https%3A%2F%2Fsns-redskillhub-s1.xhscdn.com%2Fred_app_image%2F1040g4m8325ke1q36l0404a4druqrlvd5valvb80%3Fsign%3Dbc0c41c2e219f6ca904f52176bd17f54%26t%3D6c9a7a85&xhsshare=&appuid=5acc75ba4eacab15c751fda5&apptime=1790527237&deeplink=xhsdiscover%3A%2F%2FminiTool%2F6ab8984da1e3af0015584e92%3Fsource%3Dh5%26page_key%3D28%26xhsMpScreenMode%3Dfull%26share_id%3D5e90e5979b054c8baf8b3db4c8993d79%26share_channel%3Dcopy_link",
|
||||
"icon": "/icons/nomad-book.webp",
|
||||
"action": "copy"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "forum",
|
||||
"title": "论坛社区",
|
||||
"emoji": "◉",
|
||||
"groups": [
|
||||
{
|
||||
"id": "blog",
|
||||
"title": "博客",
|
||||
"links": [
|
||||
{
|
||||
"id": "yidu",
|
||||
"title": "异度世界",
|
||||
"subtitle": "独立博客,Hugo 搭建",
|
||||
"href": "https://blog.hackrobot.cn",
|
||||
"icon": "/icons/yidu.webp"
|
||||
},
|
||||
{
|
||||
"id": "dsx",
|
||||
"title": "大师兄",
|
||||
"subtitle": "AI 实践",
|
||||
"href": "https://dsx2016.com",
|
||||
"icon": "/icons/dsx.webp"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import ttDefaultBook from "./tt-default-book.json";
|
||||
import navDefaultLinks from "./nav-default-links.json";
|
||||
|
||||
export type ModuleToggle = {
|
||||
enabled: boolean;
|
||||
@ -12,6 +13,42 @@ export type ModuleToggle = {
|
||||
note?: string;
|
||||
};
|
||||
|
||||
|
||||
/** 导航链接(远程可 CRUD;hidden=软隐藏) */
|
||||
export type NavLinkItem = {
|
||||
id: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
href: string;
|
||||
icon: string;
|
||||
action?: "open" | "copy";
|
||||
hidden?: boolean;
|
||||
};
|
||||
|
||||
export type NavGroupItem = {
|
||||
id: string;
|
||||
title: string;
|
||||
links: NavLinkItem[];
|
||||
hidden?: boolean;
|
||||
};
|
||||
|
||||
export type NavCategoryItem = {
|
||||
id: string;
|
||||
title: string;
|
||||
emoji: string;
|
||||
groups: NavGroupItem[];
|
||||
hidden?: boolean;
|
||||
};
|
||||
|
||||
/** 门户 / 小程序导航页内容(对标 links.json) */
|
||||
export type NavContent = {
|
||||
brand: string;
|
||||
tagline: string;
|
||||
footer: string;
|
||||
categories: NavCategoryItem[];
|
||||
updatedAt?: string;
|
||||
};
|
||||
|
||||
/** 抖音小程序远程小册章节(markdown 正文) */
|
||||
export type TtBookChapter = {
|
||||
id: string;
|
||||
@ -90,12 +127,113 @@ export type NomadroRemoteConfig = {
|
||||
joinGroupDouyinHint?: string;
|
||||
joinGroupDouyinQr?: string;
|
||||
};
|
||||
/** 导航页分类 / 链接(后台可增删改隐) */
|
||||
navContent?: NavContent;
|
||||
/** 分端配置;仅抖音等使用。门户 / 微信仍只读顶层 modules,互不影响 */
|
||||
platforms?: {
|
||||
tt?: TtPlatformConfig;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
function normalizeNavLink(raw: unknown, i: number): NavLinkItem {
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
||||
const action = r.action === "copy" ? "copy" : "open";
|
||||
return {
|
||||
id: String(r.id || `link-${i}`),
|
||||
title: String(r.title || "未命名"),
|
||||
subtitle: String(r.subtitle || ""),
|
||||
href: String(r.href || ""),
|
||||
icon: String(r.icon || "/icons/nomadro.webp"),
|
||||
action,
|
||||
hidden: Boolean(r.hidden),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeNavGroup(raw: unknown, i: number): NavGroupItem {
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
||||
const links = Array.isArray(r.links) ? r.links.map(normalizeNavLink) : [];
|
||||
return {
|
||||
id: String(r.id || `group-${i}`),
|
||||
title: String(r.title || "未命名组"),
|
||||
links,
|
||||
hidden: Boolean(r.hidden),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeNavCategory(raw: unknown, i: number): NavCategoryItem {
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
||||
const groups = Array.isArray(r.groups) ? r.groups.map(normalizeNavGroup) : [];
|
||||
return {
|
||||
id: String(r.id || `cat-${i}`),
|
||||
title: String(r.title || "未命名分类"),
|
||||
emoji: String(r.emoji || "✦"),
|
||||
groups,
|
||||
hidden: Boolean(r.hidden),
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeNavContent(raw: unknown): NavContent {
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
||||
const categories = Array.isArray(r.categories)
|
||||
? r.categories.map(normalizeNavCategory)
|
||||
: [];
|
||||
return {
|
||||
brand: String(r.brand || "游民导航"),
|
||||
tagline: String(r.tagline || ""),
|
||||
footer: String(r.footer || ""),
|
||||
categories,
|
||||
updatedAt: r.updatedAt ? String(r.updatedAt) : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export const DEFAULT_NAV_CONTENT: NavContent = normalizeNavContent(navDefaultLinks);
|
||||
|
||||
/** 后台完整提交 categories 时整表替换;否则保留 base */
|
||||
export function mergeNavContent(
|
||||
base: NavContent,
|
||||
patch?: Partial<NavContent> | null,
|
||||
): NavContent {
|
||||
if (!patch) return structuredClone(base);
|
||||
const hasCats = Array.isArray(patch.categories);
|
||||
return {
|
||||
brand: patch.brand ?? base.brand,
|
||||
tagline: patch.tagline ?? base.tagline,
|
||||
footer: patch.footer ?? base.footer,
|
||||
categories: hasCats
|
||||
? patch.categories!.map(normalizeNavCategory)
|
||||
: structuredClone(base.categories),
|
||||
updatedAt: patch.updatedAt || base.updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
/** 导航内容:远程有分类则用远程,否则包内 seed */
|
||||
export function resolveNavContent(config: NomadroRemoteConfig): NavContent {
|
||||
const remote = config.navContent;
|
||||
if (remote && Array.isArray(remote.categories) && remote.categories.length > 0) {
|
||||
return mergeNavContent(DEFAULT_NAV_CONTENT, remote);
|
||||
}
|
||||
return structuredClone(DEFAULT_NAV_CONTENT);
|
||||
}
|
||||
|
||||
/** 展示用:去掉 hidden */
|
||||
export function visibleNavContent(nav: NavContent): NavContent {
|
||||
return {
|
||||
...nav,
|
||||
categories: (nav.categories || [])
|
||||
.filter((c) => !c.hidden)
|
||||
.map((c) => ({
|
||||
...c,
|
||||
groups: (c.groups || [])
|
||||
.filter((g) => !g.hidden)
|
||||
.map((g) => ({
|
||||
...g,
|
||||
links: (g.links || []).filter((l) => !l.hidden),
|
||||
})),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export const DEFAULT_TT_BOOK_CONTENT: TtBookContent = {
|
||||
title: String(ttDefaultBook.title || "数字游民"),
|
||||
subtitle: String(ttDefaultBook.subtitle || ""),
|
||||
@ -148,7 +286,7 @@ export const DEFAULT_REMOTE_CONFIG: NomadroRemoteConfig = {
|
||||
enabled: true,
|
||||
title: "出海导航",
|
||||
tabLabel: "导航",
|
||||
note: "modules/nav links",
|
||||
note: "navContent 远程可改",
|
||||
},
|
||||
book: {
|
||||
enabled: true,
|
||||
@ -187,6 +325,7 @@ export const DEFAULT_REMOTE_CONFIG: NomadroRemoteConfig = {
|
||||
joinGroupDouyinHint: "打开抖音搜群「数字游民」或扫码进群",
|
||||
joinGroupDouyinQr: "",
|
||||
},
|
||||
navContent: structuredClone(DEFAULT_NAV_CONTENT),
|
||||
platforms: {
|
||||
tt: structuredClone(DEFAULT_TT_PLATFORM),
|
||||
},
|
||||
@ -309,6 +448,10 @@ export function mergeRemoteConfig(
|
||||
offlineBadge: asBool(pf.offlineBadge, base.flags.offlineBadge),
|
||||
},
|
||||
copy: { ...base.copy, ...(partial.copy || {}) },
|
||||
navContent: mergeNavContent(
|
||||
base.navContent || DEFAULT_NAV_CONTENT,
|
||||
partial.navContent ?? base.navContent,
|
||||
),
|
||||
platforms: {
|
||||
// 未传 platforms.tt 时保留已有/默认,避免后台保存门户配置时冲掉抖音小册
|
||||
tt: mergeTtPlatform(partial.platforms?.tt ?? base.platforms?.tt),
|
||||
|
||||
@ -1,10 +1,27 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { CategoryPanel } from './components/CategoryPanel'
|
||||
import { SideDrawer } from './components/SideDrawer'
|
||||
import config from './data/links.json'
|
||||
import seed from './data/links.json'
|
||||
import type { NavCategory, NavConfig, NavLink } from './types'
|
||||
import { visibleNavConfig } from './types'
|
||||
import { useRemoteConfig } from '~/lib/use-remote-config'
|
||||
import {
|
||||
resolveNavContent,
|
||||
visibleNavContent,
|
||||
type NavContent,
|
||||
} from '~/lib/remote-config'
|
||||
|
||||
const nav = config as NavConfig
|
||||
const seedNav = seed as NavConfig
|
||||
|
||||
function toNavConfig(content: NavContent): NavConfig {
|
||||
return {
|
||||
brand: content.brand,
|
||||
tagline: content.tagline,
|
||||
footer: content.footer,
|
||||
categories: content.categories as NavCategory[],
|
||||
updatedAt: content.updatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
type Theme = 'light' | 'dark'
|
||||
|
||||
@ -99,6 +116,14 @@ function IconUp() {
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const { config } = useRemoteConfig()
|
||||
const nav = useMemo(() => {
|
||||
const remote = resolveNavContent(config)
|
||||
const visible = visibleNavContent(remote)
|
||||
if (visible.categories.length) return toNavConfig(visible)
|
||||
return visibleNavConfig(seedNav)
|
||||
}, [config])
|
||||
|
||||
const [theme, setTheme] = useState<Theme>('dark')
|
||||
const [activeId, setActiveId] = useState(nav.categories[0]?.id ?? '')
|
||||
const [drawerOpen, setDrawerOpen] = useState(false)
|
||||
@ -108,6 +133,12 @@ export default function App() {
|
||||
const jumpingRef = useRef(false)
|
||||
const themeBtnRef = useRef<HTMLButtonElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!nav.categories.some((c) => c.id === activeId)) {
|
||||
setActiveId(nav.categories[0]?.id ?? '')
|
||||
}
|
||||
}, [nav, activeId])
|
||||
|
||||
useEffect(() => {
|
||||
setTheme(readTheme())
|
||||
}, [])
|
||||
@ -164,13 +195,23 @@ export default function App() {
|
||||
onScroll()
|
||||
window.addEventListener('scroll', onScroll, { passive: true })
|
||||
return () => window.removeEventListener('scroll', onScroll)
|
||||
}, [])
|
||||
}, [nav.categories])
|
||||
|
||||
const activeCategory = useMemo(
|
||||
() => nav.categories.find((c) => c.id === activeId) ?? nav.categories[0],
|
||||
[activeId],
|
||||
[activeId, nav.categories],
|
||||
)
|
||||
|
||||
if (!activeCategory) {
|
||||
return (
|
||||
<div className="app-shell">
|
||||
<main className="page" style={{ padding: 48, textAlign: 'center' }}>
|
||||
暂无导航分类,请在后台添加
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const onOpen = useCallback((link: NavLink) => {
|
||||
const action = link.action ?? 'open'
|
||||
if (action === 'copy') {
|
||||
|
||||
@ -7,12 +7,15 @@ export interface NavLink {
|
||||
href: string
|
||||
icon: string
|
||||
action?: LinkAction
|
||||
/** 隐藏后前端不展示,数据仍保留便于恢复 */
|
||||
hidden?: boolean
|
||||
}
|
||||
|
||||
export interface NavGroup {
|
||||
id: string
|
||||
title: string
|
||||
links: NavLink[]
|
||||
hidden?: boolean
|
||||
}
|
||||
|
||||
export interface NavCategory {
|
||||
@ -20,6 +23,7 @@ export interface NavCategory {
|
||||
title: string
|
||||
emoji: string
|
||||
groups: NavGroup[]
|
||||
hidden?: boolean
|
||||
}
|
||||
|
||||
export interface NavConfig {
|
||||
@ -27,4 +31,25 @@ export interface NavConfig {
|
||||
tagline: string
|
||||
footer: string
|
||||
categories: NavCategory[]
|
||||
updatedAt?: string
|
||||
}
|
||||
|
||||
/** 过滤 hidden,供前端展示 */
|
||||
export function visibleNavConfig(nav: NavConfig): NavConfig {
|
||||
return {
|
||||
...nav,
|
||||
categories: (nav.categories || [])
|
||||
.filter((c) => !c.hidden)
|
||||
.map((c) => ({
|
||||
...c,
|
||||
groups: (c.groups || [])
|
||||
.filter((g) => !g.hidden)
|
||||
.map((g) => ({
|
||||
...g,
|
||||
links: (g.links || []).filter((l) => !l.hidden),
|
||||
}))
|
||||
.filter((g) => g.links.length > 0 || !g.hidden),
|
||||
}))
|
||||
.filter((c) => c.groups.length > 0 || !c.hidden),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user