fix(weapp): 补齐 WXML 绑定字段,修复白屏

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
eric 2026-09-27 20:42:44 -05:00
parent 4e327282f5
commit 045d4306c8
6 changed files with 849 additions and 138 deletions

View File

@ -8,6 +8,5 @@
"backgroundTextStyle": "dark" "backgroundTextStyle": "dark"
}, },
"style": "v2", "style": "v2",
"sitemapLocation": "sitemap.json", "sitemapLocation": "sitemap.json"
"lazyCodeLoading": "requiredComponents"
} }

587
weapp/data/links.js Normal file
View File

@ -0,0 +1,587 @@
/* generated by scripts/sync_data.py — do not edit */
module.exports = {
"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"
}
]
}
]
}
],
"brandIcon": "/icons/_brand.webp"
};

View File

@ -1,18 +1,84 @@
const nav = require("../../data/links.json"); let nav = {
brand: "游民导航",
tagline: "",
footer: "",
brandIcon: "/icons/_brand.webp",
categories: [],
};
try {
nav = require("../../data/links.js");
} catch (e1) {
try {
nav = require("../../data/links.json");
} catch (e2) {
console.error("load links failed", e1, e2);
}
}
function countLinks(cat) { function countLinks(cat) {
let n = 0; var n = 0;
const groups = cat.groups || []; var groups = cat.groups || [];
for (let i = 0; i < groups.length; i++) { for (var i = 0; i < groups.length; i++) {
n += (groups[i].links || []).length; n += (groups[i].links || []).length;
} }
return n; return n;
} }
function withCounts(categories) { function buildCategories(categories, activeId) {
return (categories || []).map((c) => var list = categories || [];
Object.assign({}, c, { linkCount: countLinks(c) }) var out = [];
); for (var i = 0; i < list.length; i++) {
var c = list[i];
out.push({
id: c.id,
title: c.title,
emoji: c.emoji || "",
groups: c.groups || [],
linkCount: countLinks(c),
active: c.id === activeId,
});
}
return out;
}
function readWindowMetrics() {
var statusBarHeight = 20;
var navBarHeight = 44;
try {
var sys =
typeof wx.getWindowInfo === "function"
? wx.getWindowInfo()
: wx.getSystemInfoSync();
statusBarHeight = sys.statusBarHeight || 20;
} catch (e) {
console.warn("getWindowInfo failed", e);
}
try {
if (typeof wx.getMenuButtonBoundingClientRect === "function") {
var menu = wx.getMenuButtonBoundingClientRect();
if (menu && menu.height && menu.top) {
navBarHeight = (menu.top - statusBarHeight) * 2 + menu.height;
}
}
} catch (e) {
console.warn("getMenuButtonBoundingClientRect failed", e);
}
if (!navBarHeight || navBarHeight < 32) navBarHeight = 44;
return {
statusBarHeight: statusBarHeight,
navBarHeight: navBarHeight,
pagePadTop: statusBarHeight + navBarHeight,
};
}
function themeFields(theme) {
var dark = theme === "dark";
return {
theme: theme,
themeClass: dark ? "theme-dark" : "",
themeIcon: dark ? "☀" : "☾",
};
} }
Page({ Page({
@ -21,194 +87,247 @@ Page({
tagline: nav.tagline || "", tagline: nav.tagline || "",
footer: nav.footer || "", footer: nav.footer || "",
brandIcon: nav.brandIcon || "/icons/_brand.webp", brandIcon: nav.brandIcon || "/icons/_brand.webp",
categories: withCounts(nav.categories), categories: [],
activeId: (nav.categories && nav.categories[0] && nav.categories[0].id) || "", activeId: "",
activeTitle: activeTitle: "",
(nav.categories && nav.categories[0] && nav.categories[0].title) || "",
theme: "light", theme: "light",
themeClass: "",
themeIcon: "☾",
drawerOpen: false, drawerOpen: false,
showTop: false, showTop: false,
toast: "", toast: "",
statusBarHeight: 20, statusBarHeight: 20,
navBarHeight: 44, navBarHeight: 44,
pagePadTop: 64,
sheetOpen: false, sheetOpen: false,
sheetLink: null, sheetLink: {
icon: "",
title: "",
subtitle: "",
href: "",
},
loadError: "",
}, },
_jumping: false, _jumping: false,
_sectionTops: [], _sectionTops: [],
_toastTimer: null, _toastTimer: null,
onLoad() { onLoad: function () {
const sys = wx.getWindowInfo ? wx.getWindowInfo() : wx.getSystemInfoSync(); var first = (nav.categories && nav.categories[0]) || null;
const statusBarHeight = sys.statusBarHeight || 20; var activeId = first ? first.id : "";
const menu = wx.getMenuButtonBoundingClientRect var metrics = readWindowMetrics();
? wx.getMenuButtonBoundingClientRect() var app = getApp();
: null; var theme =
let navBarHeight = 44; (app && app.globalData && app.globalData.theme) || "light";
if (menu && menu.height) {
navBarHeight = (menu.top - statusBarHeight) * 2 + menu.height;
}
const app = getApp(); var patch = Object.assign(
const theme = (app && app.globalData && app.globalData.theme) || "light"; {},
metrics,
themeFields(theme),
{
categories: buildCategories(nav.categories, activeId),
activeId: activeId,
activeTitle: first ? first.title : "",
loadError:
!nav.categories || !nav.categories.length
? "导航数据未加载,请重新编译"
: "",
}
);
this.setData({ this.setData(patch);
statusBarHeight,
navBarHeight,
theme,
});
this._applyTheme(theme); this._applyTheme(theme);
}, },
onReady() { onReady: function () {
wx.nextTick(() => this._measureSections()); var self = this;
setTimeout(function () {
self._measureSections();
}, 50);
}, },
onShow() { onShow: function () {
this._applyTheme(this.data.theme); this._applyTheme(this.data.theme);
}, },
onPageScroll(e) { onPageScroll: function (e) {
const scrollTop = e.scrollTop || 0; var scrollTop = (e && e.scrollTop) || 0;
const showTop = scrollTop > 480; var showTop = scrollTop > 480;
if (showTop !== this.data.showTop) { if (showTop !== this.data.showTop) {
this.setData({ showTop }); this.setData({ showTop: showTop });
} }
if (this._jumping || !this._sectionTops.length) return; if (this._jumping || !this._sectionTops.length) return;
const marker = scrollTop + this.data.statusBarHeight + this.data.navBarHeight + 24; var marker =
let current = this._sectionTops[0].id; scrollTop + this.data.statusBarHeight + this.data.navBarHeight + 24;
for (let i = 0; i < this._sectionTops.length; i++) { var current = this._sectionTops[0].id;
for (var i = 0; i < this._sectionTops.length; i++) {
if (this._sectionTops[i].top <= marker) current = this._sectionTops[i].id; if (this._sectionTops[i].top <= marker) current = this._sectionTops[i].id;
else break; else break;
} }
if (current !== this.data.activeId) { if (current !== this.data.activeId) {
const cat = this.data.categories.find((c) => c.id === current); this._setActive(current);
this.setData({
activeId: current,
activeTitle: (cat && cat.title) || "",
});
} }
}, },
_measureSections() { _setActive: function (id) {
const query = wx.createSelectorQuery(); var cat = null;
var cats = this.data.categories || [];
for (var i = 0; i < cats.length; i++) {
if (cats[i].id === id) {
cat = cats[i];
break;
}
}
this.setData({
activeId: id,
activeTitle: (cat && cat.title) || "",
categories: buildCategories(nav.categories, id),
});
},
_measureSections: function () {
var self = this;
var query = wx.createSelectorQuery();
query.selectAll(".cat-panel").boundingClientRect(); query.selectAll(".cat-panel").boundingClientRect();
query.selectViewport().scrollOffset(); query.selectViewport().scrollOffset();
query.exec((res) => { query.exec(function (res) {
const rects = (res && res[0]) || []; var rects = (res && res[0]) || [];
const scroll = (res && res[1]) || { scrollTop: 0 }; var scroll = (res && res[1]) || { scrollTop: 0 };
this._sectionTops = rects.map((r) => ({ self._sectionTops = [];
id: (r.id || "").replace(/^cat-/, ""), for (var i = 0; i < rects.length; i++) {
top: (r.top || 0) + (scroll.scrollTop || 0), var r = rects[i];
})); self._sectionTops.push({
id: String(r.id || "").replace(/^cat-/, ""),
top: (r.top || 0) + (scroll.scrollTop || 0),
});
}
}); });
}, },
_applyTheme(theme) { _applyTheme: function (theme) {
const dark = theme === "dark"; var dark = theme === "dark";
wx.setNavigationBarColor({ try {
frontColor: dark ? "#ffffff" : "#000000", wx.setBackgroundColor({
backgroundColor: dark ? "#0a0f14" : "#e9eef4", backgroundColor: dark ? "#0a0f14" : "#e9eef4",
animation: { duration: 200, timingFunc: "easeIn" }, backgroundColorTop: dark ? "#0a0f14" : "#e9eef4",
}); backgroundColorBottom: dark ? "#0a0f14" : "#e9eef4",
wx.setBackgroundColor({ });
backgroundColor: dark ? "#0a0f14" : "#e9eef4", } catch (e) {
backgroundColorTop: dark ? "#0a0f14" : "#e9eef4", /* ignore */
backgroundColorBottom: dark ? "#0a0f14" : "#e9eef4", }
});
}, },
openDrawer() { openDrawer: function () {
this.setData({ drawerOpen: true }); this.setData({ drawerOpen: true });
}, },
closeDrawer() { closeDrawer: function () {
this.setData({ drawerOpen: false }); this.setData({ drawerOpen: false });
}, },
noop() {}, noop: function () {},
toggleTheme() { toggleTheme: function () {
const theme = this.data.theme === "dark" ? "light" : "dark"; var theme = this.data.theme === "dark" ? "light" : "dark";
this.setData({ theme }); this.setData(themeFields(theme));
try { try {
wx.setStorageSync("navmini-theme", theme); wx.setStorageSync("navmini-theme", theme);
} catch (e) { } catch (e) {
/* ignore */ /* ignore */
} }
const app = getApp(); var app = getApp();
if (app && app.globalData) app.globalData.theme = theme; if (app && app.globalData) app.globalData.theme = theme;
this._applyTheme(theme); this._applyTheme(theme);
}, },
onSelectCategory(e) { onSelectCategory: function (e) {
const id = e.currentTarget.dataset.id; var id = e.currentTarget.dataset.id;
if (!id) return; if (!id) return;
const cat = this.data.categories.find((c) => c.id === id); this._setActive(id);
this.setData({ this.setData({ drawerOpen: false });
drawerOpen: false,
activeId: id,
activeTitle: (cat && cat.title) || "",
});
this._jumping = true; this._jumping = true;
var self = this;
var offset = -(this.data.statusBarHeight + this.data.navBarHeight + 8);
wx.pageScrollTo({ wx.pageScrollTo({
selector: `#cat-${id}`, selector: "#cat-" + id,
duration: 320, duration: 320,
offsetTop: -(this.data.statusBarHeight + this.data.navBarHeight + 8), offsetTop: offset,
complete: () => { complete: function () {
setTimeout(() => { setTimeout(function () {
this._jumping = false; self._jumping = false;
this._measureSections(); self._measureSections();
}, 360); }, 360);
}, },
}); });
}, },
onTapLink(e) { onTapLink: function (e) {
const { id, catid, groupid } = e.currentTarget.dataset; var id = e.currentTarget.dataset.id;
let link = null; var catid = e.currentTarget.dataset.catid;
const cat = this.data.categories.find((c) => c.id === catid); var groupid = e.currentTarget.dataset.groupid;
if (cat) { var link = null;
const group = (cat.groups || []).find((g) => g.id === groupid); var cats = nav.categories || [];
if (group) link = (group.links || []).find((l) => l.id === id); for (var i = 0; i < cats.length; i++) {
if (cats[i].id !== catid) continue;
var groups = cats[i].groups || [];
for (var j = 0; j < groups.length; j++) {
if (groups[j].id !== groupid) continue;
var links = groups[j].links || [];
for (var k = 0; k < links.length; k++) {
if (links[k].id === id) {
link = links[k];
break;
}
}
}
} }
if (!link || !link.href) { if (!link || !link.href) {
this._showToast("无效链接"); this._showToast("无效链接");
return; return;
} }
this.setData({ sheetOpen: true, sheetLink: link }); this.setData({
}, sheetOpen: true,
sheetLink: {
closeSheet() { icon: link.icon || "/icons/_brand.webp",
this.setData({ sheetOpen: false, sheetLink: null }); title: link.title || "",
}, subtitle: link.subtitle || "",
href: link.href || "",
copySheetUrl() {
const link = this.data.sheetLink;
if (!link || !link.href) return;
wx.setClipboardData({
data: link.href,
success: () => {
this._showToast("已复制,请到浏览器打开");
},
fail: () => {
this._showToast("复制失败");
}, },
}); });
}, },
backTop() { closeSheet: function () {
this.setData({ sheetOpen: false });
},
copySheetUrl: function () {
var link = this.data.sheetLink;
if (!link || !link.href) return;
var self = this;
wx.setClipboardData({
data: link.href,
success: function () {
self._showToast("已复制,请到浏览器打开");
},
fail: function () {
self._showToast("复制失败");
},
});
},
backTop: function () {
wx.pageScrollTo({ scrollTop: 0, duration: 300 }); wx.pageScrollTo({ scrollTop: 0, duration: 300 });
}, },
_showToast(msg) { _showToast: function (msg) {
var self = this;
if (this._toastTimer) clearTimeout(this._toastTimer); if (this._toastTimer) clearTimeout(this._toastTimer);
this.setData({ toast: msg }); this.setData({ toast: msg });
this._toastTimer = setTimeout(() => { this._toastTimer = setTimeout(function () {
this.setData({ toast: "" }); self.setData({ toast: "" });
this._toastTimer = null; self._toastTimer = null;
}, 1800); }, 1800);
}, },
}); });

View File

@ -1,9 +1,5 @@
<view class="app-shell {{theme === 'dark' ? 'theme-dark' : ''}}"> <view class="app-shell {{themeClass}}">
<!-- 自定义顶栏 --> <view class="topbar" style="padding-top: {{statusBarHeight}}px;">
<view
class="topbar"
style="padding-top: {{statusBarHeight}}px;"
>
<view class="topbar-inner" style="height: {{navBarHeight}}px;"> <view class="topbar-inner" style="height: {{navBarHeight}}px;">
<view class="icon-btn" bindtap="openDrawer" hover-class="icon-btn-hover"> <view class="icon-btn" bindtap="openDrawer" hover-class="icon-btn-hover">
<view class="menu-bars"> <view class="menu-bars">
@ -22,15 +18,13 @@
</view> </view>
<view class="icon-btn" bindtap="toggleTheme" hover-class="icon-btn-hover"> <view class="icon-btn" bindtap="toggleTheme" hover-class="icon-btn-hover">
<text class="theme-ico">{{theme === 'dark' ? '☀' : '☾'}}</text> <text class="theme-ico">{{themeIcon}}</text>
</view> </view>
</view> </view>
</view> </view>
<view <view class="page" style="padding-top: {{pagePadTop}}px;">
class="page" <view wx:if="{{loadError}}" class="load-error">{{loadError}}</view>
style="padding-top: {{statusBarHeight + navBarHeight}}px;"
>
<block wx:for="{{categories}}" wx:key="id"> <block wx:for="{{categories}}" wx:key="id">
<view class="cat-panel" id="cat-{{item.id}}"> <view class="cat-panel" id="cat-{{item.id}}">
<view class="cat-heading"> <view class="cat-heading">
@ -75,8 +69,7 @@
<view class="footer">{{footer}}</view> <view class="footer">{{footer}}</view>
</view> </view>
<!-- 抽屉 --> <view class="drawer-root {{drawerOpen ? 'open' : ''}}">
<view class="drawer-root {{drawerOpen ? 'open' : ''}}" aria-hidden="{{!drawerOpen}}">
<view class="drawer-mask" bindtap="closeDrawer"></view> <view class="drawer-mask" bindtap="closeDrawer"></view>
<view class="drawer-panel" catchtap="noop"> <view class="drawer-panel" catchtap="noop">
<view class="drawer-head" style="padding-top: {{statusBarHeight}}px;"> <view class="drawer-head" style="padding-top: {{statusBarHeight}}px;">
@ -91,11 +84,11 @@
<text class="close-ico">×</text> <text class="close-ico">×</text>
</view> </view>
</view> </view>
<scroll-view scroll-y class="drawer-nav" enhanced show-scrollbar="{{false}}"> <scroll-view scroll-y class="drawer-nav" show-scrollbar="{{false}}">
<view <view
wx:for="{{categories}}" wx:for="{{categories}}"
wx:key="id" wx:key="id"
class="drawer-item {{activeId === item.id ? 'active' : ''}}" class="drawer-item {{item.active ? 'active' : ''}}"
data-id="{{item.id}}" data-id="{{item.id}}"
bindtap="onSelectCategory" bindtap="onSelectCategory"
hover-class="drawer-item-hover" hover-class="drawer-item-hover"
@ -110,8 +103,7 @@
</view> </view>
</view> </view>
<!-- 链接详情 + 复制 --> <view class="sheet-root" wx:if="{{sheetOpen}}">
<view class="sheet-root {{sheetOpen ? 'open' : ''}}" wx:if="{{sheetLink}}">
<view class="sheet-mask" bindtap="closeSheet"></view> <view class="sheet-mask" bindtap="closeSheet"></view>
<view class="sheet-panel" catchtap="noop"> <view class="sheet-panel" catchtap="noop">
<view class="sheet-head"> <view class="sheet-head">

View File

@ -111,6 +111,16 @@
margin: 0 auto; margin: 0 auto;
} }
.load-error {
margin: 24rpx 4rpx;
padding: 20rpx;
border-radius: 16rpx;
background: #ffe8e6;
color: #c23;
font-size: 26rpx;
line-height: 1.4;
}
.cat-panel { .cat-panel {
margin-top: 8rpx; margin-top: 8rpx;
padding-top: 20rpx; padding-top: 20rpx;

View File

@ -12,6 +12,7 @@ PROJ = ROOT.parent # navmini/
SRC_JSON = PROJ / "src" / "data" / "links.json" SRC_JSON = PROJ / "src" / "data" / "links.json"
SRC_ICONS = PROJ / "public" / "icons" SRC_ICONS = PROJ / "public" / "icons"
OUT_JSON = ROOT / "data" / "links.json" OUT_JSON = ROOT / "data" / "links.json"
OUT_JS = ROOT / "data" / "links.js"
OUT_ICONS = ROOT / "icons" OUT_ICONS = ROOT / "icons"
@ -51,13 +52,16 @@ def main() -> int:
data["brandIcon"] = "/icons/_brand.webp" data["brandIcon"] = "/icons/_brand.webp"
OUT_JSON.write_text( payload = json.dumps(data, ensure_ascii=False, indent=2)
json.dumps(data, ensure_ascii=False, indent=2) + "\n", OUT_JSON.write_text(payload + "\n", encoding="utf-8")
OUT_JS.write_text(
"/* generated by scripts/sync_data.py — do not edit */\n"
f"module.exports = {payload};\n",
encoding="utf-8", encoding="utf-8",
) )
icon_count = len(list(OUT_ICONS.glob("*.webp"))) icon_count = len(list(OUT_ICONS.glob("*.webp")))
print(f"synced data/links.json + {icon_count} icons -> {ROOT}") print(f"synced data/links.json + links.js + {icon_count} icons -> {ROOT}")
return 0 return 0