From bd0e5470014fb8cc236a1205d82a00e3bef91b0a Mon Sep 17 00:00:00 2001 From: Samson1990-09 Date: Tue, 25 Aug 2026 16:30:37 +0800 Subject: [PATCH 1/6] Add plugin.json --- plugins/loan-calculator/plugin.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 plugins/loan-calculator/plugin.json diff --git a/plugins/loan-calculator/plugin.json b/plugins/loan-calculator/plugin.json new file mode 100644 index 00000000..14a60463 --- /dev/null +++ b/plugins/loan-calculator/plugin.json @@ -0,0 +1,23 @@ +{ + "name": "loan-calculator", + "title": "贷款计算器", + "pluginName": "贷款计算器", + "description": "房贷、方案对比、提前还款、浮动利率多功能贷款计算器", + "author": "ztocwst", + "homepage": "https://github.com/ZToolsCenter/ZTools-plugins/tree/main/plugins/loan-calculator", + "version": "1.7.0", + "main": "index.html", + "logo": "logo.png", + "preload": "preload.js", + "features": [ + { + "code": "loan", + "explain": "贷款计算器", + "cmds": ["贷款计算器", "房贷", "loan"] + } + ], + "pluginSetting": { + "single": true, + "height": 640 + } +} From be77097879043145a3c2f10831a11ed5c5a9c548 Mon Sep 17 00:00:00 2001 From: Samson1990-09 Date: Tue, 25 Aug 2026 16:30:39 +0800 Subject: [PATCH 2/6] Add index.html --- plugins/loan-calculator/index.html | 2290 ++++++++++++++++++++++++++++ 1 file changed, 2290 insertions(+) create mode 100644 plugins/loan-calculator/index.html diff --git a/plugins/loan-calculator/index.html b/plugins/loan-calculator/index.html new file mode 100644 index 00000000..19f29c3f --- /dev/null +++ b/plugins/loan-calculator/index.html @@ -0,0 +1,2290 @@ + + + + + +贷款计算器 + + + +
+
+ +

贷款计算器

+ 房贷 · 方案对比 · 提前还款 · 浮动利率 · 历史记录 + v1.7.0 +
+ +
+ + + + + +
+ + +
+
+
+

贷款信息

+ + +
+ + +
首套:商业 LPR-20BP · 公积金 2.6%(5年内 2.1%)
+
+ +
+ +
+ + + +
+
+ +
+ +
+
+ + + +
+ +
+
+ +
+ + +
+ + 内置最新 · 商业 3.5% · 公积金 首套2.6%/二套3.075%(2026-08) +
+
+ +
+
+ +
%
+
+ 加点 + + + BP + + 实际 3.50% +
+
+ +
+ +
+ +
+ + +
+
+ + +
+ +
+
+ +
+ +
+ + +
+ + +
+ +
+
+
+
等额本息月供
+
+
+
+
+ + +
+
+ 月供收入比(DTI) + +
+
+
+
+ +
+
还款总额
+
贷款总额
+
支付利息
+
+ + +
+
+
本金 / 利息占比
+
+
+
+
剩余本金趋势
+
+
+
+ +
+
+

月供明细

+
+ + +
+
+ + + +
+
+ + 1 / 1 + +
+
+
+
+
+ + +
+
+
+

方案 A

+
+
+
%
+
+ 加点 + + + BP + + 实际 3.50% +
+
+
+
+
+
+
+

方案 B

+
+
+
%
+
+ 加点 + + + BP + + 实际 3.50% +
+
+
+
+
+
+
+
+ + + + + + +
+
+ + +
+
+
+
+

原贷款信息

+
+
+
%
+
+ 加点 + + + BP + + 实际 3.50% +
+
+
+
+
+
+
+ + +
+

提前还款计划

+
+ + +
+ +
%
+
用于对比"提前还款省利息" vs "同等金额理财收益"
+
+ + +
+
+ +
+ +
+

两种策略并排对比

+
+
+

缩短期限

+
点击"分析提前还款"查看结果
+
+
+

减少月供

+
点击"分析提前还款"查看结果
+
+
+
+ + +
+

提前还款 vs 理财投资

+
点击"分析提前还款"查看对比
+
+ +
+
+
+ + +
+
+
+
+

贷款信息

+
+
+
+
+
时间线节点可从中途切换还款方式
+
+
+ +
+ LPR + + % + 加点 + + BP + 实际 3.30% +
+
起始利率 = LPR + BP/100,后续按时间线变化
+
+
+ +
+

利率变化时间线

+
+ + + +
+
+ +
每个节点设定从该月起生效的新 LPR 和 BP;留空则保持原值
+ + +
+
+ +
+
+
初始月供
+
最终月供
+
利息总额
+
+ + + + + +
+

利率变化节点

+ + + +
+
+ +
+
+
月供变化趋势
+
+
+
+
利率变化曲线
+
+
+
+ +
+
+

月供明细

+
+
+ + + +
+
+ + 1 / 1 + +
+
+
+
+
+ + +
+
+
+

历史记录

+
+ +
+
+
+
+
+
+ + + + From a0a1d210e78a90a3f89c09da99acb4c819302908 Mon Sep 17 00:00:00 2001 From: Samson1990-09 Date: Tue, 25 Aug 2026 16:30:40 +0800 Subject: [PATCH 3/6] Add preload.js --- plugins/loan-calculator/preload.js | 72 ++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 plugins/loan-calculator/preload.js diff --git a/plugins/loan-calculator/preload.js b/plugins/loan-calculator/preload.js new file mode 100644 index 00000000..c573210d --- /dev/null +++ b/plugins/loan-calculator/preload.js @@ -0,0 +1,72 @@ +/** + * ZTools 贷款计算器插件 preload + * 规范:不压缩、不混淆,保持清晰可读 + * + * 存储说明: + * ZTools 的 ztools.db 为「文档型」存储(put(doc) 会自动写 doc._id), + * 且写入走 IPC 到主进程,签名用错会直接在主进程抛 Uncaught Exception(try/catch 拦截不到)。 + * 为避免该不稳定路径,历史记录统一用插件页面自带的 localStorage 持久化, + * 渲染进程与 preload 均可访问,且不会触发主进程崩溃。 + */ + +(function () { + const storageKey = 'loan-calculator-history' + + function read () { + try { + const raw = window.localStorage.getItem(storageKey) + return raw ? JSON.parse(raw) : [] + } catch (e) { + return [] + } + } + + function write (data) { + try { + window.localStorage.setItem(storageKey, JSON.stringify(data)) + } catch (e) { + // 存储不可用,静默忽略 + } + } + + const api = { + read, + write, + // 添加一条记录,最多保留 10 条 + add: (item) => { + const list = read() + list.unshift(item) + if (list.length > 10) list.length = 10 + write(list) + }, + // 读取全部历史(供「历史记录」界面使用) + list: () => read(), + // 删除指定时间戳的记录 + remove: (ts) => { + const list = read().filter((it) => it.ts !== ts) + write(list) + return list + }, + // 清空历史 + clear: () => write([]) + } + + // 暴露给渲染进程:优先 contextBridge(隔离开启时),否则直接挂 window + try { + if ( + typeof window !== 'undefined' && + window.contextBridge && + typeof window.contextBridge.exposeInMainWorld === 'function' + ) { + window.contextBridge.exposeInMainWorld('loanApi', api) + return + } + } catch (e) { + // 忽略,走下方兜底 + } + try { + window.loanApi = api + } catch (e) { + // 极端情况下 window 不可写,放弃暴露 + } +})() From e1e9b57329ff5a3fa75de273d7abe45f19f7708b Mon Sep 17 00:00:00 2001 From: Samson1990-09 Date: Tue, 25 Aug 2026 16:30:42 +0800 Subject: [PATCH 4/6] Add logo.png --- plugins/loan-calculator/logo.png | Bin 0 -> 917 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 plugins/loan-calculator/logo.png diff --git a/plugins/loan-calculator/logo.png b/plugins/loan-calculator/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..8884a8633d25d57dc54fed0e91d3b5b9e552fae2 GIT binary patch literal 917 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1SEZ8zRh7^V2<&0aSW-r_4e*}KhZ#uqlx!U z+^c@S_j}w+*=qMdmp~C$!TTk<&;RH*6bsw*Zmvtc_G`{_(H7C9uJ(W|xX4S4Lg=;D7$+=fc zotM7OKhpN*?2U-h%WE&4-Ja}yb#1xV_Pf1rZ&q(y{Oa8ArMu;hyjxW*H|Q=y?z1+uG5@h-FcEvOo^e4S!)6`^Ud9=<3Ef|-4&^f`Q(Ar+; z$DnD$YYLPq+#>A2^`7|*!>yN}osMxRw3;WSF=+0YRKn!(aP9_42QK}ma~XnuXdU8N zFwc&`j6t(TJcaFo-+cbfJwRcjb3oJlg+VIJt^k?+#UQ5DEtujv{2=R_+JJVLr<`F3 z+Og;f%Y;L+hQleli zj2?*vtAQSw404-9Y!2ImLvJ!bO3P=%lz#jQ^z$430w#~d#%7>WX_Gk&K@o{bK&4#5 zK&4?bX26t+ssWX*F(?EoZS4dq)%JlZ1%`>NksCVKc699^jgMiyAEC}FTP{Fi8mcl^V{ik?gwo-x)iH(yHn?cKNT6-d(4)z4*} HQ$iB}n2>e2 literal 0 HcmV?d00001 From abb001ca43eb80df5a715687fde116d7d0e96e76 Mon Sep 17 00:00:00 2001 From: Samson1990-09 Date: Tue, 25 Aug 2026 16:30:43 +0800 Subject: [PATCH 5/6] Add README.md --- plugins/loan-calculator/README.md | 155 ++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 plugins/loan-calculator/README.md diff --git a/plugins/loan-calculator/README.md b/plugins/loan-calculator/README.md new file mode 100644 index 00000000..0c6f768a --- /dev/null +++ b/plugins/loan-calculator/README.md @@ -0,0 +1,155 @@ +# 贷款计算器(loan-calculator) + +> 一个面向房贷场景的多功能 ZTools 插件:房贷计算、方案对比、提前还款、浮动利率模拟、历史记录。 + +本插件为**单文件 HTML 插件**(无需构建),以 `index.html` 为主入口,`preload.js` 提供历史记录的本地持久化能力,所有计算与界面均在渲染进程内完成,开箱即用。 + +--- + +## ✨ 功能特性 + +### 🏠 贷款计算器(房贷) + +- 支持三种贷款类型:**商业贷款 / 公积金 / 组合贷** +- 支持两种还款方式:**等额本息 / 等额本金** +- 利率模式:**最新利率(自动回填)** 与 **自定义** + - 商业贷款利率基于最新 LPR(5 年以上 3.5%)+ BP 加点 + - 公积金利率为政策固定值,按首套/二套 × 5 年内/5 年以上四档自动回填 +- 输入校验:金额、年限、利率、加点实时校验并提示 +- 结果展示:月供、利息总额、还款总额;饼图(本金/利息占比)+ 月供趋势图 +- 一键**导出 CSV**、**复制结果** + +### ⚖️ 方案对比 + +- 方案 A / 方案 B 双栏**等宽**并排对比 +- 自动计算差额(月供差、利息差、总额差)与百分比 +- 支持商业/公积金利率与 BP 加点分别配置 +- 当前房贷结果可**一键加入方案 A**(原 A 自动移至 B),组合贷自动换算等效固定利率 +- 一键**导出对比 CSV** + +### 💰 提前还款 + +- 支持**一次提前还款**与**多次时间线提前还款** +- 双策略对比:月供不变缩短期限 / 期限不变减少月供 +- 对比**不提前还款**方案,量化节省利息 +- 可选对接理财收益率(vs 投资),评估提前还款是否划算 +- 一键**复制 / 导出**完整报表 + +### 📈 浮动利率模拟 + +- 基于历史 LPR 变化 + BP 加点变化逐月模拟还款计划 +- 时间线支持多个节点(月份、LPR、BP),每个节点可独立切换还款方式 +- 内置预设:「近 3 年 LPR 走势」「每年降 10BP」 +- 固定 vs 浮动对比卡片、月供变化曲线、利率变化节点表 +- 360 期逐月明细,**导出 CSV** + +### 🕘 历史记录 + +- 自动保存最近 10 条计算方案(localStorage 持久化,跨会话保留) +- 支持回填、删除、清空 +- 浮动利率方案可完整回填至浮动利率 Tab + +### 🔄 跨页签缓存 + +- 所有页签输入/配置自动缓存,切换或重载不丢失 +- 仅对「已计算」的页签在初始化时自动重算,避免未配置出乱数 + +--- + +## 📁 项目结构 + +``` +loan-calculator/ +├── publish/ # 发布根目录(与中心仓库 plugins/loan-calculator/ 一一对应,独立 git 仓库) +│ ├── plugin.json # 插件配置(ZTools 识别入口) +│ ├── index.html # 主入口(UI + 全部计算逻辑,单文件无构建) +│ ├── preload.js # 预加载脚本(历史记录本地持久化桥接) +│ ├── logo.png # 插件图标(128×128 PNG) +│ ├── README.md # 项目说明(本文件) +│ ├── LICENSE # MIT 开源协议 +│ └── .gitignore +├── tests/ # 端到端测试(jsdom,本地开发用,不参与发布) +│ ├── test-export-csv.js +│ ├── test-variable-rate.js +│ └── test-method-switch.js +└── releases/ # 历史构建产物 .zpx / .zip(本地归档,不参与发布) +``` + +> 发布时 `ztools publish` 在 `publish/` 目录下执行,仅该目录内的 7 个文件进入中心仓库 `plugins/loan-calculator/`;`tests/` 与 `releases/` 始终留在本地,不会发布。 + +--- + +## 🚀 安装与使用 + +1. 下载构建产物 `loan-calculator-1.7.0.zpx`(见 `releases/`,或 PR 附件)。 +2. 在 ZTools 中「导入插件 / 安装本地插件」,选择该 `.zpx` 文件。 +3. 通过指令 `贷款计算器` / `房贷` / `loan` 唤起,或在插件列表点击打开。 + +### 配置说明(plugin.json 关键字段) + +| 字段 | 含义 | +|---|---| +| `name` | 插件唯一标识 `loan-calculator`(对应中心仓库目录 `plugins/loan-calculator/`) | +| `title` / `pluginName` | 展示名称「贷款计算器」 | +| `main` | 主入口 `index.html` | +| `logo` | 图标 `logo.png` | +| `preload` | 预加载脚本 `preload.js` | +| `features[].code` | 功能标识 | +| `features[].cmds` | 触发指令 | +| `pluginSetting.single` | `true`(单实例) | +| `pluginSetting.height` | 内嵌窗口高度 `640` | + +--- + +## 🧪 本地开发 / 测试 + +插件为纯前端单文件,无需 `npm install` 即可运行;测试基于 `jsdom`(需安装): + +```bash +# 安装测试依赖(仅需一次) +npm install jsdom --workspace=../node_modules # 或放入本地 node_modules + +# 运行端到端测试 +NODE_PATH= node tests/test-export-csv.js +node tests/test-variable-rate.js +node tests/test-method-switch.js +``` + +当前测试覆盖:浮动利率核心计算(32)、中途切换还款方式(12)、导出 CSV / 跨页签交互修复(100),共 **144 条断言全部通过**。 + +--- + +## 📋 版本历史 + +| 版本 | 要点 | +|---|---| +| v1.1.0 | 基础房贷计算 + 历史记录 + 图表 + CSV 导出 | +| v1.2.0 | 浮动利率模拟(逐月可变利率) | +| v1.3.0 | 浮动利率支持按节点切换还款方式 | +| v1.4.0 | 11 项交互优化(输入校验 / tooltip / 复制 / 恢复默认 / 多 Tab 导出) | +| v1.5.0 | 公积金四档利率 + 切换自动回填(联网核实 2026-08 最新 LPR) | +| v1.6.0 | 交互界面现代化重设计(设计令牌 / sticky 导航 / 精致化控件) | +| v1.7.0 | 四项交互修复:①切公积金隐藏商业利率区 ②房贷结果一键加入方案对比(A,原 A→B) ③方案对比 A/B 等宽 ④跨页签自动缓存 | + +--- + +## 📸 截图 + +> 请在此处补充插件运行截图 / 演示 GIF(在 PR 描述中直接拖入图片,GitHub 会自动上传)。 +> 建议包含:房贷计算主界面、方案对比、提前还款、浮动利率模拟、历史记录。 + +--- + +## ✅ 发布自检清单 + +- [ ] `plugin.json` 字段完整(`name` / `title` / `description` / `version` / `main` / `logo` / `features` 齐全且格式正确) +- [ ] 插件可正常加载运行,无控制台报错 +- [ ] 已提供功能截图 / 演示 GIF +- [ ] 已阅读并遵守 ZTools 插件规范(无恶意代码、不收集用户隐私、不请求无关权限) +- [ ] `README.md` 文档完整(功能、结构、使用、版本历史、自检清单) + +--- + +## 📄 开源协议 + +[MIT License](./LICENSE) © 2026 ztocwst From 95d059623fdbfe5a50b37217eb8b805abb0e24e1 Mon Sep 17 00:00:00 2001 From: Samson1990-09 Date: Tue, 25 Aug 2026 16:30:45 +0800 Subject: [PATCH 6/6] Add LICENSE --- plugins/loan-calculator/LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 plugins/loan-calculator/LICENSE diff --git a/plugins/loan-calculator/LICENSE b/plugins/loan-calculator/LICENSE new file mode 100644 index 00000000..98437d8e --- /dev/null +++ b/plugins/loan-calculator/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 ztocwst + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.