diff --git a/weapp/app.json b/weapp/app.json index 30d28b6..71a1988 100644 --- a/weapp/app.json +++ b/weapp/app.json @@ -8,6 +8,5 @@ "backgroundTextStyle": "dark" }, "style": "v2", - "sitemapLocation": "sitemap.json", - "lazyCodeLoading": "requiredComponents" + "sitemapLocation": "sitemap.json" } diff --git a/weapp/data/links.js b/weapp/data/links.js new file mode 100644 index 0000000..adcb441 --- /dev/null +++ b/weapp/data/links.js @@ -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" +}; diff --git a/weapp/pages/index/index.js b/weapp/pages/index/index.js index f29402c..2d10c77 100644 --- a/weapp/pages/index/index.js +++ b/weapp/pages/index/index.js @@ -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) { - let n = 0; - const groups = cat.groups || []; - for (let i = 0; i < groups.length; i++) { + var n = 0; + var groups = cat.groups || []; + for (var i = 0; i < groups.length; i++) { n += (groups[i].links || []).length; } return n; } -function withCounts(categories) { - return (categories || []).map((c) => - Object.assign({}, c, { linkCount: countLinks(c) }) - ); +function buildCategories(categories, activeId) { + var list = categories || []; + 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({ @@ -21,194 +87,247 @@ Page({ tagline: nav.tagline || "", footer: nav.footer || "", brandIcon: nav.brandIcon || "/icons/_brand.webp", - categories: withCounts(nav.categories), - activeId: (nav.categories && nav.categories[0] && nav.categories[0].id) || "", - activeTitle: - (nav.categories && nav.categories[0] && nav.categories[0].title) || "", + categories: [], + activeId: "", + activeTitle: "", theme: "light", + themeClass: "", + themeIcon: "☾", drawerOpen: false, showTop: false, toast: "", statusBarHeight: 20, navBarHeight: 44, + pagePadTop: 64, sheetOpen: false, - sheetLink: null, + sheetLink: { + icon: "", + title: "", + subtitle: "", + href: "", + }, + loadError: "", }, _jumping: false, _sectionTops: [], _toastTimer: null, - onLoad() { - const sys = wx.getWindowInfo ? wx.getWindowInfo() : wx.getSystemInfoSync(); - const statusBarHeight = sys.statusBarHeight || 20; - const menu = wx.getMenuButtonBoundingClientRect - ? wx.getMenuButtonBoundingClientRect() - : null; - let navBarHeight = 44; - if (menu && menu.height) { - navBarHeight = (menu.top - statusBarHeight) * 2 + menu.height; - } + onLoad: function () { + var first = (nav.categories && nav.categories[0]) || null; + var activeId = first ? first.id : ""; + var metrics = readWindowMetrics(); + var app = getApp(); + var theme = + (app && app.globalData && app.globalData.theme) || "light"; - const app = getApp(); - const theme = (app && app.globalData && app.globalData.theme) || "light"; + var patch = Object.assign( + {}, + metrics, + themeFields(theme), + { + categories: buildCategories(nav.categories, activeId), + activeId: activeId, + activeTitle: first ? first.title : "", + loadError: + !nav.categories || !nav.categories.length + ? "导航数据未加载,请重新编译" + : "", + } + ); - this.setData({ - statusBarHeight, - navBarHeight, - theme, - }); + this.setData(patch); this._applyTheme(theme); }, - onReady() { - wx.nextTick(() => this._measureSections()); + onReady: function () { + var self = this; + setTimeout(function () { + self._measureSections(); + }, 50); }, - onShow() { + onShow: function () { this._applyTheme(this.data.theme); }, - onPageScroll(e) { - const scrollTop = e.scrollTop || 0; - const showTop = scrollTop > 480; + onPageScroll: function (e) { + var scrollTop = (e && e.scrollTop) || 0; + var showTop = scrollTop > 480; if (showTop !== this.data.showTop) { - this.setData({ showTop }); + this.setData({ showTop: showTop }); } if (this._jumping || !this._sectionTops.length) return; - const marker = scrollTop + this.data.statusBarHeight + this.data.navBarHeight + 24; - let current = this._sectionTops[0].id; - for (let i = 0; i < this._sectionTops.length; i++) { + var marker = + scrollTop + this.data.statusBarHeight + this.data.navBarHeight + 24; + 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; else break; } if (current !== this.data.activeId) { - const cat = this.data.categories.find((c) => c.id === current); - this.setData({ - activeId: current, - activeTitle: (cat && cat.title) || "", - }); + this._setActive(current); } }, - _measureSections() { - const query = wx.createSelectorQuery(); + _setActive: function (id) { + 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.selectViewport().scrollOffset(); - query.exec((res) => { - const rects = (res && res[0]) || []; - const scroll = (res && res[1]) || { scrollTop: 0 }; - this._sectionTops = rects.map((r) => ({ - id: (r.id || "").replace(/^cat-/, ""), - top: (r.top || 0) + (scroll.scrollTop || 0), - })); + query.exec(function (res) { + var rects = (res && res[0]) || []; + var scroll = (res && res[1]) || { scrollTop: 0 }; + self._sectionTops = []; + for (var i = 0; i < rects.length; i++) { + var r = rects[i]; + self._sectionTops.push({ + id: String(r.id || "").replace(/^cat-/, ""), + top: (r.top || 0) + (scroll.scrollTop || 0), + }); + } }); }, - _applyTheme(theme) { - const dark = theme === "dark"; - wx.setNavigationBarColor({ - frontColor: dark ? "#ffffff" : "#000000", - backgroundColor: dark ? "#0a0f14" : "#e9eef4", - animation: { duration: 200, timingFunc: "easeIn" }, - }); - wx.setBackgroundColor({ - backgroundColor: dark ? "#0a0f14" : "#e9eef4", - backgroundColorTop: dark ? "#0a0f14" : "#e9eef4", - backgroundColorBottom: dark ? "#0a0f14" : "#e9eef4", - }); + _applyTheme: function (theme) { + var dark = theme === "dark"; + try { + wx.setBackgroundColor({ + backgroundColor: dark ? "#0a0f14" : "#e9eef4", + backgroundColorTop: dark ? "#0a0f14" : "#e9eef4", + backgroundColorBottom: dark ? "#0a0f14" : "#e9eef4", + }); + } catch (e) { + /* ignore */ + } }, - openDrawer() { + openDrawer: function () { this.setData({ drawerOpen: true }); }, - closeDrawer() { + closeDrawer: function () { this.setData({ drawerOpen: false }); }, - noop() {}, + noop: function () {}, - toggleTheme() { - const theme = this.data.theme === "dark" ? "light" : "dark"; - this.setData({ theme }); + toggleTheme: function () { + var theme = this.data.theme === "dark" ? "light" : "dark"; + this.setData(themeFields(theme)); try { wx.setStorageSync("navmini-theme", theme); } catch (e) { /* ignore */ } - const app = getApp(); + var app = getApp(); if (app && app.globalData) app.globalData.theme = theme; this._applyTheme(theme); }, - onSelectCategory(e) { - const id = e.currentTarget.dataset.id; + onSelectCategory: function (e) { + var id = e.currentTarget.dataset.id; if (!id) return; - const cat = this.data.categories.find((c) => c.id === id); - this.setData({ - drawerOpen: false, - activeId: id, - activeTitle: (cat && cat.title) || "", - }); + this._setActive(id); + this.setData({ drawerOpen: false }); this._jumping = true; + var self = this; + var offset = -(this.data.statusBarHeight + this.data.navBarHeight + 8); wx.pageScrollTo({ - selector: `#cat-${id}`, + selector: "#cat-" + id, duration: 320, - offsetTop: -(this.data.statusBarHeight + this.data.navBarHeight + 8), - complete: () => { - setTimeout(() => { - this._jumping = false; - this._measureSections(); + offsetTop: offset, + complete: function () { + setTimeout(function () { + self._jumping = false; + self._measureSections(); }, 360); }, }); }, - onTapLink(e) { - const { id, catid, groupid } = e.currentTarget.dataset; - let link = null; - const cat = this.data.categories.find((c) => c.id === catid); - if (cat) { - const group = (cat.groups || []).find((g) => g.id === groupid); - if (group) link = (group.links || []).find((l) => l.id === id); + onTapLink: function (e) { + var id = e.currentTarget.dataset.id; + var catid = e.currentTarget.dataset.catid; + var groupid = e.currentTarget.dataset.groupid; + var link = null; + var cats = nav.categories || []; + 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) { this._showToast("无效链接"); return; } - this.setData({ sheetOpen: true, sheetLink: link }); - }, - - closeSheet() { - this.setData({ sheetOpen: false, sheetLink: null }); - }, - - copySheetUrl() { - const link = this.data.sheetLink; - if (!link || !link.href) return; - wx.setClipboardData({ - data: link.href, - success: () => { - this._showToast("已复制,请到浏览器打开"); - }, - fail: () => { - this._showToast("复制失败"); + this.setData({ + sheetOpen: true, + sheetLink: { + icon: link.icon || "/icons/_brand.webp", + title: link.title || "", + subtitle: link.subtitle || "", + href: link.href || "", }, }); }, - 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 }); }, - _showToast(msg) { + _showToast: function (msg) { + var self = this; if (this._toastTimer) clearTimeout(this._toastTimer); this.setData({ toast: msg }); - this._toastTimer = setTimeout(() => { - this.setData({ toast: "" }); - this._toastTimer = null; + this._toastTimer = setTimeout(function () { + self.setData({ toast: "" }); + self._toastTimer = null; }, 1800); }, }); diff --git a/weapp/pages/index/index.wxml b/weapp/pages/index/index.wxml index e2a3ab5..120f219 100644 --- a/weapp/pages/index/index.wxml +++ b/weapp/pages/index/index.wxml @@ -1,9 +1,5 @@ - - - + + @@ -22,15 +18,13 @@ - {{theme === 'dark' ? '☀' : '☾'}} + {{themeIcon}} - + + {{loadError}} @@ -75,8 +69,7 @@ {{footer}} - - + @@ -91,11 +84,11 @@ × - + - - + diff --git a/weapp/pages/index/index.wxss b/weapp/pages/index/index.wxss index 07c55dc..254587c 100644 --- a/weapp/pages/index/index.wxss +++ b/weapp/pages/index/index.wxss @@ -111,6 +111,16 @@ 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 { margin-top: 8rpx; padding-top: 20rpx; diff --git a/weapp/scripts/sync_data.py b/weapp/scripts/sync_data.py index 401cb82..e4c7301 100644 --- a/weapp/scripts/sync_data.py +++ b/weapp/scripts/sync_data.py @@ -12,6 +12,7 @@ PROJ = ROOT.parent # navmini/ SRC_JSON = PROJ / "src" / "data" / "links.json" SRC_ICONS = PROJ / "public" / "icons" OUT_JSON = ROOT / "data" / "links.json" +OUT_JS = ROOT / "data" / "links.js" OUT_ICONS = ROOT / "icons" @@ -51,13 +52,16 @@ def main() -> int: data["brandIcon"] = "/icons/_brand.webp" - OUT_JSON.write_text( - json.dumps(data, ensure_ascii=False, indent=2) + "\n", + payload = json.dumps(data, ensure_ascii=False, indent=2) + 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", ) 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