feat: 优化统一规则逻辑

This commit is contained in:
2026-03-12 10:04:29 +08:00
parent d0f68e07b7
commit bf15918136
17 changed files with 859 additions and 600 deletions

View File

@@ -1,5 +1,24 @@
# Vue 3 + Vite # Echo
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more. Local-first personal finance app built with Vue 3, Vite, Capacitor, and SQLite.
Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support). ## Commands
```bash
npm run rules:sync
npm run dev
npm run build
npm run rule:smoke
```
## Structure
- `src/`: web app, stores, services, views, and SQLite bridge
- `android/`: Capacitor Android shell and notification listener implementation
- `scripts/`: release and local verification scripts
- `src/config/notificationRules.js`: single source of truth for notification rules
## Notes
- Transaction data is stored locally.
- After editing notification rules, run `npm run rules:sync` to regenerate the Android rule file.

View File

@@ -0,0 +1,91 @@
package com.echo.app.notification
// Generated from src/config/notificationRules.js by scripts/sync-notification-rules.mjs.
internal object NotificationRuleData {
val fallbackRules: List<NotificationRuleDefinition> = listOf(
NotificationRuleDefinition(
id = "alipay-expense",
label = "支付宝消费",
channels = listOf("支付宝", "Alipay"),
keywords = listOf("支付", "扣款", "支出", "消费", "成功支付"),
requiredTextPatterns = emptyList(),
direction = NotificationRuleDirection.EXPENSE,
defaultCategory = "Food",
autoCapture = false,
merchantPattern = Regex("(?:向|收款方|商户)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)", setOf(RegexOption.IGNORE_CASE)),
defaultMerchant = null,
),
NotificationRuleDefinition(
id = "alipay-income",
label = "支付宝收款",
channels = listOf("支付宝", "Alipay"),
keywords = listOf("到账", "收入", "收款", "入账"),
requiredTextPatterns = emptyList(),
direction = NotificationRuleDirection.INCOME,
defaultCategory = "Income",
autoCapture = true,
merchantPattern = Regex("(?:来自|收款方|付款方|来源)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)", setOf(RegexOption.IGNORE_CASE)),
defaultMerchant = null,
),
NotificationRuleDefinition(
id = "wechat-expense",
label = "微信消费",
channels = listOf("微信支付", "微信", "WeChat"),
keywords = listOf("支付", "支出", "扣款", "消费成功"),
requiredTextPatterns = emptyList(),
direction = NotificationRuleDirection.EXPENSE,
defaultCategory = "Groceries",
autoCapture = false,
merchantPattern = Regex("(?:向|收款方|商户)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)"),
defaultMerchant = null,
),
NotificationRuleDefinition(
id = "wechat-income",
label = "微信收款",
channels = listOf("微信支付", "微信", "WeChat"),
keywords = listOf("收款", "到账", "入账", "转入"),
requiredTextPatterns = emptyList(),
direction = NotificationRuleDirection.INCOME,
defaultCategory = "Income",
autoCapture = true,
merchantPattern = Regex("(?:来自|收款方|付款方|来源)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)"),
defaultMerchant = null,
),
NotificationRuleDefinition(
id = "bank-income",
label = "银行入账",
channels = listOf("招商银行", "中国银行", "建设银行", "工商银行", "农业银行", "交通银行", "浦发银行", "兴业银行", "光大银行", "中信银行", "广发银行", "平安银行"),
keywords = listOf("工资", "薪资", "代发", "到账", "入账", "收入"),
requiredTextPatterns = emptyList(),
direction = NotificationRuleDirection.INCOME,
defaultCategory = "Income",
autoCapture = true,
merchantPattern = Regex("(?:来自|付款方|来源)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)"),
defaultMerchant = null,
),
NotificationRuleDefinition(
id = "bank-expense",
label = "银行卡支出",
channels = listOf("招商银行", "中国银行", "建设银行", "工商银行", "农业银行", "交通银行", "浦发银行", "兴业银行", "光大银行", "中信银行", "广发银行", "平安银行", "借记卡", "信用卡"),
keywords = listOf("支出", "消费", "扣款", "刷卡消费", "银联消费"),
requiredTextPatterns = emptyList(),
direction = NotificationRuleDirection.EXPENSE,
defaultCategory = "Expense",
autoCapture = false,
merchantPattern = Regex("(?:商户|商家|消费商户)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)"),
defaultMerchant = null,
),
NotificationRuleDefinition(
id = "transit-card-expense",
label = "公交出行",
channels = listOf("杭州通互联互通卡", "杭州通", "北京一卡通", "上海公共交通卡", "深圳通", "苏州公交卡", "交通联合", "乘车码", "地铁", "公交", "Mi Pay", "Huawei Pay", "华为钱包", "小米钱包", "OPPO 钱包"),
keywords = emptyList(),
requiredTextPatterns = listOf("扣费", "扣款", "支付", "乘车码", "车费", "票价", "本次乘车", "实付", "优惠后"),
direction = NotificationRuleDirection.EXPENSE,
defaultCategory = "Transport",
autoCapture = true,
merchantPattern = Regex("([\\u4e00-\\u9fa5]{2,}\\s*(?:-|->|→|至|到)\\s*[\\u4e00-\\u9fa5]{2,})"),
defaultMerchant = "公交/地铁出行",
)
)
}

View File

@@ -2,149 +2,28 @@ package com.echo.app.notification
import kotlin.math.abs import kotlin.math.abs
// 原生通知解析引擎:将 JS 侧的 fallbackRules & 提取逻辑完整搬到 Kotlin internal enum class NotificationRuleDirection {
// 在后台直接把通知转成交易草稿。 INCOME,
EXPENSE,
}
internal data class NotificationRuleDefinition(
val id: String,
val label: String,
val channels: List<String> = emptyList(),
val keywords: List<String> = emptyList(),
val requiredTextPatterns: List<String> = emptyList(),
val direction: NotificationRuleDirection,
val defaultCategory: String,
val autoCapture: Boolean,
val merchantPattern: Regex? = null,
val defaultMerchant: String? = null,
val enabled: Boolean = true,
)
object NotificationRuleEngine { object NotificationRuleEngine {
private val fallbackRules: List<NotificationRuleDefinition> = NotificationRuleData.fallbackRules
// JS 侧规则模型的 Kotlin 版本
private data class Rule(
val id: String,
val label: String,
val channels: List<String> = emptyList(),
val keywords: List<String> = emptyList(),
val direction: Direction,
val defaultCategory: String,
val autoCapture: Boolean,
val merchantPattern: Regex? = null,
val defaultMerchant: String? = null,
val enabled: Boolean = true,
)
private enum class Direction {
INCOME,
EXPENSE,
}
// 与 src/services/notificationRuleService.js 中的 fallbackRules 一一对应
private val fallbackRules: List<Rule> = listOf(
Rule(
id = "alipay-expense",
label = "支付宝消费",
channels = listOf("支付宝", "Alipay"),
keywords = listOf("支付", "扣款", "支出", "消费", "成功支付"),
direction = Direction.EXPENSE,
defaultCategory = "Food",
autoCapture = false,
merchantPattern = Regex("""向\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)""", RegexOption.IGNORE_CASE),
),
Rule(
id = "alipay-income",
label = "支付宝收款",
channels = listOf("支付宝", "Alipay"),
keywords = listOf("到账", "收入", "收款", "入账"),
direction = Direction.INCOME,
defaultCategory = "Income",
autoCapture = true,
merchantPattern = Regex("""(?:来自|收款方)\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)""", RegexOption.IGNORE_CASE),
),
Rule(
id = "wechat-expense",
label = "微信消费",
channels = listOf("微信支付", "微信", "WeChat"),
keywords = listOf("支付", "支出", "扣款", "消费成功"),
direction = Direction.EXPENSE,
defaultCategory = "Groceries",
autoCapture = false,
merchantPattern = Regex("""向\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)"""),
),
Rule(
id = "wechat-income",
label = "微信收款",
channels = listOf("微信支付", "微信", "WeChat"),
keywords = listOf("收款", "到账", "入账", "转入"),
direction = Direction.INCOME,
defaultCategory = "Income",
autoCapture = true,
merchantPattern = Regex("""(?:来自|收款方)\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)"""),
),
Rule(
id = "bank-income",
label = "工资到账",
channels = listOf(
"招商银行",
"中国银行",
"建设银行",
"工商银行",
"农业银行",
"交通银行",
"浦发银行",
"兴业银行",
"光大银行",
"中信银行",
"广发银行",
"平安银行",
),
keywords = listOf("工资", "薪资", "代发", "到账", "入账", "收入"),
direction = Direction.INCOME,
defaultCategory = "Income",
autoCapture = true,
merchantPattern = Regex("""(?:来自|付款方|来源)\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)"""),
),
Rule(
id = "bank-expense",
label = "银行卡支出",
channels = listOf(
"招商银行",
"中国银行",
"建设银行",
"工商银行",
"农业银行",
"交通银行",
"浦发银行",
"兴业银行",
"光大银行",
"中信银行",
"广发银行",
"平安银行",
"借记卡",
"信用卡",
),
keywords = listOf("支出", "消费", "扣款", "刷卡消费", "银联消费"),
direction = Direction.EXPENSE,
defaultCategory = "Expense",
autoCapture = false,
merchantPattern = Regex("""(?:商户|商家|消费商户)\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)"""),
),
Rule(
id = "transit-card-expense",
label = "公交出行",
channels = listOf(
"杭州通互联互通卡",
"杭州通",
"北京一卡通",
"上海公共交通卡",
"深圳通",
"苏州公交卡",
"交通联合",
"乘车码",
"地铁",
"公交",
"Mi Pay",
"Huawei Pay",
"华为钱包",
"小米钱包",
"OPPO 钱包",
),
keywords = emptyList(), // 只看来源,不强制正文关键字
direction = Direction.EXPENSE,
defaultCategory = "Transport",
autoCapture = true,
merchantPattern = Regex("""([\u4e00-\u9fa5]{2,}\s*(?:-|—|>|→|至|到)\s*[\u4e00-\u9fa5]{2,})"""),
defaultMerchant = "公交/地铁出行",
),
)
// 解析后的交易结果,与 JS transformNotificationToTransaction 对齐
data class ParsedTransaction( data class ParsedTransaction(
val ruleId: String, val ruleId: String,
val merchant: String, val merchant: String,
@@ -155,12 +34,6 @@ object NotificationRuleEngine {
val autoCapture: Boolean, val autoCapture: Boolean,
) )
/**
* 尝试从原始通知中解析出一条交易记录。
*
* 返回 null 表示未命中任何规则或无法解析金额,
* 此时应在前端视图中展示为 unmatched供用户手动处理。
*/
fun parse(raw: NotificationDb.RawNotification): ParsedTransaction? { fun parse(raw: NotificationDb.RawNotification): ParsedTransaction? {
val content = buildString { val content = buildString {
if (!raw.title.isNullOrBlank()) { if (!raw.title.isNullOrBlank()) {
@@ -181,72 +54,77 @@ object NotificationRuleEngine {
merchant = rule.defaultMerchant merchant = rule.defaultMerchant
} }
val isExpense = rule.direction == Direction.EXPENSE
val category = rule.defaultCategory.ifBlank { "Uncategorized" }
return ParsedTransaction( return ParsedTransaction(
ruleId = rule.id, ruleId = rule.id,
merchant = merchant.ifBlank { "Unknown" }, merchant = merchant.ifBlank { "Unknown" },
category = category, category = rule.defaultCategory.ifBlank { "Uncategorized" },
amount = amount, amount = amount,
isExpense = isExpense, isExpense = rule.direction == NotificationRuleDirection.EXPENSE,
note = content.take(200), note = content.take(200),
autoCapture = rule.autoCapture, autoCapture = rule.autoCapture,
) )
} }
// ===== 内部辅助函数:匹配规则 & 提取金额 / 商户 ===== private fun matchRule(
raw: NotificationDb.RawNotification,
private fun matchRule(raw: NotificationDb.RawNotification, text: String, rule: Rule): Boolean { text: String,
rule: NotificationRuleDefinition
): Boolean {
if (!rule.enabled) return false if (!rule.enabled) return false
val channel = raw.channel ?: "" val channel = raw.channel ?: ""
// 频道命中:优先用通知来源/标题匹配,必要时回退到正文匹配(兼容 adb shell / 部分厂商改名)
val channelHit = val channelHit =
rule.channels.isEmpty() || rule.channels.any { channel.contains(it) || text.contains(it) } rule.channels.isEmpty() ||
val keywordHit = rule.keywords.isEmpty() || rule.keywords.any { text.contains(it) } rule.channels.any { channel.contains(it) } ||
return channelHit && keywordHit (channel.isBlank() && rule.channels.any { text.contains(it) })
val keywordHit =
rule.keywords.isEmpty() || rule.keywords.any { text.contains(it) }
val requiredTextHit =
rule.requiredTextPatterns.isEmpty() || rule.requiredTextPatterns.any { text.contains(it) }
return channelHit && keywordHit && requiredTextHit
} }
// 从通知文本中提取交易金额,兼容「¥」「¥」「元」「人民币」等常见形式
private fun extractAmount(text: String): Double { private fun extractAmount(text: String): Double {
val primaryRegex = val normalized = text.replace(",", "").trim()
Regex("""(?:[¥¥]|人民币)\s*(-?\d+(?:\.\d{1,2})?)|(-?\d+(?:\.\d{1,2})?)\s*元""") val patterns = listOf(
val primary = primaryRegex.find(text) Regex("""(?:¥|¥|RMB|CNY|人民币)\s*(-?\d+(?:\.\d{1,2})?)""", RegexOption.IGNORE_CASE),
val v1 = primary?.groups?.get(1)?.value Regex("""(-?\d+(?:\.\d{1,2})?)\s*(?:元|块|块钱)"""),
val v2 = primary?.groups?.get(2)?.value Regex("""(?:金额|实付|扣费|扣款|消费|支出|收入|收款|到账|入账|转入|转出|支付|票价|车费|本次乘车)\D{0,8}?(-?\d+(?:\.\d{1,2})?)"""),
val value = v1 ?: v2 Regex("""(-?\d+(?:\.\d{1,2})?)\s*(?:元|块|块钱)?\s*(?:已支付|已收款|到账|入账)"""),
if (!value.isNullOrBlank()) { )
return abs(value.toDoubleOrNull() ?: 0.0)
for (pattern in patterns) {
val match = pattern.find(normalized)
val value = match?.groups?.get(1)?.value ?: continue
val parsed = abs(value.toDoubleOrNull() ?: 0.0)
if (parsed > 0.0) {
return parsed
}
} }
val looseRegex = Regex("""(-?\d+(?:\.\d{1,2})?)""") return 0.0
val loose = looseRegex.find(text)
val looseVal = loose?.groups?.get(1)?.value
return if (!looseVal.isNullOrBlank()) abs(looseVal.toDoubleOrNull() ?: 0.0) else 0.0
} }
// 判断字符串是否更像是「金额」而不是商户名
private fun looksLikeAmount(raw: String?): Boolean { private fun looksLikeAmount(raw: String?): Boolean {
val value = raw?.trim().orEmpty() val value = raw?.trim().orEmpty()
if (value.isEmpty()) return false if (value.isEmpty()) return false
val pattern = Regex("""^[-\d.,]+\s*(?:元|块钱|¥|¥|人民币)?$""") return Regex("""^[-\d.,]+\s*(?:元|块|块钱|¥|¥|人民币)?$""", RegexOption.IGNORE_CASE)
return pattern.matches(value) .matches(value)
} }
private fun extractMerchant(text: String, rule: Rule): String { private fun extractMerchant(text: String, rule: NotificationRuleDefinition): String {
val content = text.ifBlank { "" } val content = text.ifBlank { "" }
rule.merchantPattern?.let { regex -> rule.merchantPattern?.let { regex ->
val m = regex.find(content) val match = regex.find(content)
if (m != null && m.groupValues.size > 1) { if (match != null && match.groupValues.size > 1) {
val candidate = m.groupValues[1].trim() val candidate = match.groupValues[1].trim()
if (candidate.isNotEmpty()) return candidate if (candidate.isNotEmpty()) return candidate
} }
} }
// 通用的「站点 A -> 站点 B」线路模式公交/地铁通知) val routeRegex = Regex("""([\u4e00-\u9fa5]{2,}\s*(?:-|->|→|至|到)\s*[\u4e00-\u9fa5]{2,})""")
val routeRegex =
Regex("""([\u4e00-\u9fa5]{2,}\s*(?:-|—|>|→|至|到|->)\s*[\u4e00-\u9fa5]{2,})""")
val routeMatch = routeRegex.find(content) val routeMatch = routeRegex.find(content)
if (routeMatch != null && routeMatch.groupValues.size > 1) { if (routeMatch != null && routeMatch.groupValues.size > 1) {
return routeMatch.groupValues[1].trim() return routeMatch.groupValues[1].trim()
@@ -258,18 +136,17 @@ object NotificationRuleEngine {
) )
for (pattern in genericPatterns) { for (pattern in genericPatterns) {
val m = pattern.find(content) val match = pattern.find(content)
if (m != null && m.groupValues.size > 1) { if (match != null && match.groupValues.size > 1) {
val candidate = m.groupValues[1].trim() val candidate = match.groupValues[1].trim()
if (candidate.isNotEmpty()) return candidate if (candidate.isNotEmpty()) return candidate
} }
} }
// 处理「……支出(消费支付宝-上海拉扎斯信息科技有限公司)3.23元」这类银行通知
val parenMatch = Regex("""\(([^)]+)\)""").find(content) val parenMatch = Regex("""\(([^)]+)\)""").find(content)
if (parenMatch != null && parenMatch.groupValues.size > 1) { if (parenMatch != null && parenMatch.groupValues.size > 1) {
val inner = parenMatch.groupValues[1] val inner = parenMatch.groupValues[1]
val payMatch = Regex("""(?:支付宝|微信支付|微信)[-\s]*([^\d元¥¥]+)$""").find(inner) val payMatch = Regex("""(?:支付宝|微信支付|微信)[-\s]*([^\d元¥¥]+)$""").find(inner)
if (payMatch != null && payMatch.groupValues.size > 1) { if (payMatch != null && payMatch.groupValues.size > 1) {
val candidate = payMatch.groupValues[1].trim() val candidate = payMatch.groupValues[1].trim()
if (candidate.isNotEmpty() && !looksLikeAmount(candidate)) { if (candidate.isNotEmpty() && !looksLikeAmount(candidate)) {

272
package-lock.json generated
View File

@@ -22,7 +22,7 @@
"vue-router": "^4.6.3" "vue-router": "^4.6.3"
}, },
"devDependencies": { "devDependencies": {
"@capacitor/cli": "^7.4.4", "@capacitor/cli": "^5.7.8",
"@vitejs/plugin-vue": "^6.0.1", "@vitejs/plugin-vue": "^6.0.1",
"autoprefixer": "^10.4.17", "autoprefixer": "^10.4.17",
"postcss": "^8.4.35", "postcss": "^8.4.35",
@@ -124,46 +124,46 @@
} }
}, },
"node_modules/@capacitor/cli": { "node_modules/@capacitor/cli": {
"version": "7.4.4", "version": "5.7.8",
"resolved": "https://registry.npmmirror.com/@capacitor/cli/-/cli-7.4.4.tgz", "resolved": "https://registry.npmmirror.com/@capacitor/cli/-/cli-5.7.8.tgz",
"integrity": "sha512-J7ciBE7GlJ70sr2s8oz1+H4ZdNk4MGG41fsakUlDHWva5UWgFIZYMiEdDvGbYazAYTaxN3lVZpH9zil9FfZj+Q==", "integrity": "sha512-qN8LDlREMhrYhOvVXahoJVNkP8LP55/YPRJrzTAFrMqlNJC18L3CzgWYIblFPnuwfbH/RxbfoZT/ydkwgVpMrw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@ionic/cli-framework-output": "^2.2.8", "@ionic/cli-framework-output": "^2.2.5",
"@ionic/utils-subprocess": "^3.0.1", "@ionic/utils-fs": "^3.1.6",
"@ionic/utils-terminal": "^2.3.5", "@ionic/utils-subprocess": "^2.1.11",
"commander": "^12.1.0", "@ionic/utils-terminal": "^2.3.3",
"debug": "^4.4.0", "commander": "^9.3.0",
"debug": "^4.3.4",
"env-paths": "^2.2.0", "env-paths": "^2.2.0",
"fs-extra": "^11.2.0", "kleur": "^4.1.4",
"kleur": "^4.1.5", "native-run": "^2.0.0",
"native-run": "^2.0.1",
"open": "^8.4.0", "open": "^8.4.0",
"plist": "^3.1.0", "plist": "^3.0.5",
"prompts": "^2.4.2", "prompts": "^2.4.2",
"rimraf": "^6.0.1", "rimraf": "^4.4.1",
"semver": "^7.6.3", "semver": "^7.3.7",
"tar": "^6.1.11", "tar": "^6.1.11",
"tslib": "^2.8.1", "tslib": "^2.4.0",
"xml2js": "^0.6.2" "xml2js": "^0.5.0"
}, },
"bin": { "bin": {
"cap": "bin/capacitor", "cap": "bin/capacitor",
"capacitor": "bin/capacitor" "capacitor": "bin/capacitor"
}, },
"engines": { "engines": {
"node": ">=20.0.0" "node": ">=16.0.0"
} }
}, },
"node_modules/@capacitor/cli/node_modules/commander": { "node_modules/@capacitor/cli/node_modules/commander": {
"version": "12.1.0", "version": "9.5.0",
"resolved": "https://registry.npmmirror.com/commander/-/commander-12.1.0.tgz", "resolved": "https://registry.npmmirror.com/commander/-/commander-9.5.0.tgz",
"integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">=18" "node": "^12.20.0 || >=14"
} }
}, },
"node_modules/@capacitor/core": { "node_modules/@capacitor/core": {
@@ -693,14 +693,14 @@
} }
}, },
"node_modules/@ionic/utils-process": { "node_modules/@ionic/utils-process": {
"version": "2.1.12", "version": "2.1.11",
"resolved": "https://registry.npmmirror.com/@ionic/utils-process/-/utils-process-2.1.12.tgz", "resolved": "https://registry.npmmirror.com/@ionic/utils-process/-/utils-process-2.1.11.tgz",
"integrity": "sha512-Jqkgyq7zBs/v/J3YvKtQQiIcxfJyplPgECMWgdO0E1fKrrH8EF0QGHNJ9mJCn6PYe2UtHNS8JJf5G21e09DfYg==", "integrity": "sha512-Uavxn+x8j3rDlZEk1X7YnaN6wCgbCwYQOeIjv/m94i1dzslqWhqIHEqxEyeE8HsT5Negboagg7GtQiABy+BLbA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@ionic/utils-object": "2.1.6", "@ionic/utils-object": "2.1.6",
"@ionic/utils-terminal": "2.3.5", "@ionic/utils-terminal": "2.3.4",
"debug": "^4.0.0", "debug": "^4.0.0",
"signal-exit": "^3.0.3", "signal-exit": "^3.0.3",
"tree-kill": "^1.2.2", "tree-kill": "^1.2.2",
@@ -710,10 +710,31 @@
"node": ">=16.0.0" "node": ">=16.0.0"
} }
}, },
"node_modules/@ionic/utils-process/node_modules/@ionic/utils-terminal": {
"version": "2.3.4",
"resolved": "https://registry.npmmirror.com/@ionic/utils-terminal/-/utils-terminal-2.3.4.tgz",
"integrity": "sha512-cEiMFl3jklE0sW60r8JHH3ijFTwh/jkdEKWbylSyExQwZ8pPuwoXz7gpkWoJRLuoRHHSvg+wzNYyPJazIHfoJA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/slice-ansi": "^4.0.0",
"debug": "^4.0.0",
"signal-exit": "^3.0.3",
"slice-ansi": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0",
"tslib": "^2.0.1",
"untildify": "^4.0.0",
"wrap-ansi": "^7.0.0"
},
"engines": {
"node": ">=16.0.0"
}
},
"node_modules/@ionic/utils-stream": { "node_modules/@ionic/utils-stream": {
"version": "3.1.7", "version": "3.1.6",
"resolved": "https://registry.npmmirror.com/@ionic/utils-stream/-/utils-stream-3.1.7.tgz", "resolved": "https://registry.npmmirror.com/@ionic/utils-stream/-/utils-stream-3.1.6.tgz",
"integrity": "sha512-eSELBE7NWNFIHTbTC2jiMvh1ABKGIpGdUIvARsNPMNQhxJB3wpwdiVnoBoTYp+5a6UUIww4Kpg7v6S7iTctH1w==", "integrity": "sha512-4+Kitey1lTA1yGtnigeYNhV/0tggI3lWBMjC7tBs1K9GXa/q7q4CtOISppdh8QgtOhrhAXS2Igp8rbko/Cj+lA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@@ -725,17 +746,17 @@
} }
}, },
"node_modules/@ionic/utils-subprocess": { "node_modules/@ionic/utils-subprocess": {
"version": "3.0.1", "version": "2.1.14",
"resolved": "https://registry.npmmirror.com/@ionic/utils-subprocess/-/utils-subprocess-3.0.1.tgz", "resolved": "https://registry.npmmirror.com/@ionic/utils-subprocess/-/utils-subprocess-2.1.14.tgz",
"integrity": "sha512-cT4te3AQQPeIM9WCwIg8ohroJ8TjsYaMb2G4ZEgv9YzeDqHZ4JpeIKqG2SoaA3GmVQ3sOfhPM6Ox9sxphV/d1A==", "integrity": "sha512-nGYvyGVjU0kjPUcSRFr4ROTraT3w/7r502f5QJEsMRKTqa4eEzCshtwRk+/mpASm0kgBN5rrjYA5A/OZg8ahqg==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@ionic/utils-array": "2.1.6", "@ionic/utils-array": "2.1.6",
"@ionic/utils-fs": "3.1.7", "@ionic/utils-fs": "3.1.7",
"@ionic/utils-process": "2.1.12", "@ionic/utils-process": "2.1.11",
"@ionic/utils-stream": "3.1.7", "@ionic/utils-stream": "3.1.6",
"@ionic/utils-terminal": "2.3.5", "@ionic/utils-terminal": "2.3.4",
"cross-spawn": "^7.0.3", "cross-spawn": "^7.0.3",
"debug": "^4.0.0", "debug": "^4.0.0",
"tslib": "^2.0.1" "tslib": "^2.0.1"
@@ -744,6 +765,27 @@
"node": ">=16.0.0" "node": ">=16.0.0"
} }
}, },
"node_modules/@ionic/utils-subprocess/node_modules/@ionic/utils-terminal": {
"version": "2.3.4",
"resolved": "https://registry.npmmirror.com/@ionic/utils-terminal/-/utils-terminal-2.3.4.tgz",
"integrity": "sha512-cEiMFl3jklE0sW60r8JHH3ijFTwh/jkdEKWbylSyExQwZ8pPuwoXz7gpkWoJRLuoRHHSvg+wzNYyPJazIHfoJA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/slice-ansi": "^4.0.0",
"debug": "^4.0.0",
"signal-exit": "^3.0.3",
"slice-ansi": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0",
"tslib": "^2.0.1",
"untildify": "^4.0.0",
"wrap-ansi": "^7.0.0"
},
"engines": {
"node": ">=16.0.0"
}
},
"node_modules/@ionic/utils-terminal": { "node_modules/@ionic/utils-terminal": {
"version": "2.3.5", "version": "2.3.5",
"resolved": "https://registry.npmmirror.com/@ionic/utils-terminal/-/utils-terminal-2.3.5.tgz", "resolved": "https://registry.npmmirror.com/@ionic/utils-terminal/-/utils-terminal-2.3.5.tgz",
@@ -765,29 +807,6 @@
"node": ">=16.0.0" "node": ">=16.0.0"
} }
}, },
"node_modules/@isaacs/balanced-match": {
"version": "4.0.1",
"resolved": "https://registry.npmmirror.com/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz",
"integrity": "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": "20 || >=22"
}
},
"node_modules/@isaacs/brace-expansion": {
"version": "5.0.0",
"resolved": "https://registry.npmmirror.com/@isaacs/brace-expansion/-/brace-expansion-5.0.0.tgz",
"integrity": "sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@isaacs/balanced-match": "^4.0.1"
},
"engines": {
"node": "20 || >=22"
}
},
"node_modules/@jridgewell/gen-mapping": { "node_modules/@jridgewell/gen-mapping": {
"version": "0.3.13", "version": "0.3.13",
"resolved": "https://registry.npmmirror.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", "resolved": "https://registry.npmmirror.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
@@ -1479,6 +1498,13 @@
"postcss": "^8.1.0" "postcss": "^8.1.0"
} }
}, },
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true,
"license": "MIT"
},
"node_modules/base64-js": { "node_modules/base64-js": {
"version": "1.5.1", "version": "1.5.1",
"resolved": "https://registry.npmmirror.com/base64-js/-/base64-js-1.5.1.tgz", "resolved": "https://registry.npmmirror.com/base64-js/-/base64-js-1.5.1.tgz",
@@ -1546,6 +1572,16 @@
"node": ">= 5.10.0" "node": ">= 5.10.0"
} }
}, },
"node_modules/brace-expansion": {
"version": "2.0.2",
"resolved": "https://registry.npmmirror.com/brace-expansion/-/brace-expansion-2.0.2.tgz",
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"balanced-match": "^1.0.0"
}
},
"node_modules/braces": { "node_modules/braces": {
"version": "3.0.3", "version": "3.0.3",
"resolved": "https://registry.npmmirror.com/braces/-/braces-3.0.3.tgz", "resolved": "https://registry.npmmirror.com/braces/-/braces-3.0.3.tgz",
@@ -1984,21 +2020,6 @@
"url": "https://github.com/sponsors/rawify" "url": "https://github.com/sponsors/rawify"
} }
}, },
"node_modules/fs-extra": {
"version": "11.3.2",
"resolved": "https://registry.npmmirror.com/fs-extra/-/fs-extra-11.3.2.tgz",
"integrity": "sha512-Xr9F6z6up6Ws+NjzMCZc6WXg2YFRlrLP9NQDO3VQrWrfiojdhS56TzueT88ze0uBdCTwEIhQ3ptnmKeWGFAe0A==",
"dev": true,
"license": "MIT",
"dependencies": {
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=14.14"
}
},
"node_modules/fs-minipass": { "node_modules/fs-minipass": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmmirror.com/fs-minipass/-/fs-minipass-2.1.0.tgz", "resolved": "https://registry.npmmirror.com/fs-minipass/-/fs-minipass-2.1.0.tgz",
@@ -2025,6 +2046,13 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
"dev": true,
"license": "ISC"
},
"node_modules/fsevents": { "node_modules/fsevents": {
"version": "2.3.3", "version": "2.3.3",
"resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz", "resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz",
@@ -2051,18 +2079,19 @@
} }
}, },
"node_modules/glob": { "node_modules/glob": {
"version": "13.0.0", "version": "9.3.4",
"resolved": "https://registry.npmmirror.com/glob/-/glob-13.0.0.tgz", "resolved": "https://registry.npmmirror.com/glob/-/glob-9.3.4.tgz",
"integrity": "sha512-tvZgpqk6fz4BaNZ66ZsRaZnbHvP/jG3uKJvAZOwEVUL4RTA5nJeeLYfyN9/VA8NX/V3IBG+hkeuGpKjvELkVhA==", "integrity": "sha512-qaSc49hojMOv1EPM4EuyITjDSgSKI0rthoHnvE81tcOi1SCVndHko7auqxdQ14eiQG2NDBJBE86+2xIrbIvrbA==",
"dev": true, "dev": true,
"license": "BlueOak-1.0.0", "license": "ISC",
"dependencies": { "dependencies": {
"minimatch": "^10.1.1", "fs.realpath": "^1.0.0",
"minipass": "^7.1.2", "minimatch": "^8.0.2",
"path-scurry": "^2.0.0" "minipass": "^4.2.4",
"path-scurry": "^1.6.1"
}, },
"engines": { "engines": {
"node": "20 || >=22" "node": ">=16 || 14 >=14.17"
}, },
"funding": { "funding": {
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
@@ -2343,14 +2372,11 @@
} }
}, },
"node_modules/lru-cache": { "node_modules/lru-cache": {
"version": "11.2.2", "version": "10.4.3",
"resolved": "https://registry.npmmirror.com/lru-cache/-/lru-cache-11.2.2.tgz", "resolved": "https://registry.npmmirror.com/lru-cache/-/lru-cache-10.4.3.tgz",
"integrity": "sha512-F9ODfyqML2coTIsQpSkRHnLSZMtkU8Q+mSfcaIyKwy58u+8k5nvAYeiNhsyMARvzNcXJ9QfWVrcPsC9e9rAxtg==", "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
"dev": true, "dev": true,
"license": "ISC", "license": "ISC"
"engines": {
"node": "20 || >=22"
}
}, },
"node_modules/magic-string": { "node_modules/magic-string": {
"version": "0.30.21", "version": "0.30.21",
@@ -2386,29 +2412,29 @@
} }
}, },
"node_modules/minimatch": { "node_modules/minimatch": {
"version": "10.1.1", "version": "8.0.7",
"resolved": "https://registry.npmmirror.com/minimatch/-/minimatch-10.1.1.tgz", "resolved": "https://registry.npmmirror.com/minimatch/-/minimatch-8.0.7.tgz",
"integrity": "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ==", "integrity": "sha512-V+1uQNdzybxa14e/p00HZnQNNcTjnRJjDxg2V8wtkjFctq4M7hXFws4oekyTP0Jebeq7QYtpFyOeBAjc88zvYg==",
"dev": true, "dev": true,
"license": "BlueOak-1.0.0", "license": "ISC",
"dependencies": { "dependencies": {
"@isaacs/brace-expansion": "^5.0.0" "brace-expansion": "^2.0.1"
}, },
"engines": { "engines": {
"node": "20 || >=22" "node": ">=16 || 14 >=14.17"
}, },
"funding": { "funding": {
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/minipass": { "node_modules/minipass": {
"version": "7.1.2", "version": "4.2.8",
"resolved": "https://registry.npmmirror.com/minipass/-/minipass-7.1.2.tgz", "resolved": "https://registry.npmmirror.com/minipass/-/minipass-4.2.8.tgz",
"integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", "integrity": "sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ==",
"dev": true, "dev": true,
"license": "ISC", "license": "ISC",
"engines": { "engines": {
"node": ">=16 || 14 >=14.17" "node": ">=8"
} }
}, },
"node_modules/minizlib": { "node_modules/minizlib": {
@@ -2579,13 +2605,6 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/package-json-from-dist": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz",
"integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==",
"dev": true,
"license": "BlueOak-1.0.0"
},
"node_modules/pako": { "node_modules/pako": {
"version": "1.0.11", "version": "1.0.11",
"resolved": "https://registry.npmmirror.com/pako/-/pako-1.0.11.tgz", "resolved": "https://registry.npmmirror.com/pako/-/pako-1.0.11.tgz",
@@ -2610,22 +2629,32 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/path-scurry": { "node_modules/path-scurry": {
"version": "2.0.1", "version": "1.11.1",
"resolved": "https://registry.npmmirror.com/path-scurry/-/path-scurry-2.0.1.tgz", "resolved": "https://registry.npmmirror.com/path-scurry/-/path-scurry-1.11.1.tgz",
"integrity": "sha512-oWyT4gICAu+kaA7QWk/jvCHWarMKNs6pXOGWKDTr7cw4IGcUbW+PeTfbaQiLGheFRpjo6O9J0PmyMfQPjH71oA==", "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==",
"dev": true, "dev": true,
"license": "BlueOak-1.0.0", "license": "BlueOak-1.0.0",
"dependencies": { "dependencies": {
"lru-cache": "^11.0.0", "lru-cache": "^10.2.0",
"minipass": "^7.1.2" "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0"
}, },
"engines": { "engines": {
"node": "20 || >=22" "node": ">=16 || 14 >=14.18"
}, },
"funding": { "funding": {
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/path-scurry/node_modules/minipass": {
"version": "7.1.3",
"resolved": "https://registry.npmmirror.com/minipass/-/minipass-7.1.3.tgz",
"integrity": "sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A==",
"dev": true,
"license": "BlueOak-1.0.0",
"engines": {
"node": ">=16 || 14 >=14.17"
}
},
"node_modules/pend": { "node_modules/pend": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmmirror.com/pend/-/pend-1.2.0.tgz", "resolved": "https://registry.npmmirror.com/pend/-/pend-1.2.0.tgz",
@@ -3002,20 +3031,19 @@
} }
}, },
"node_modules/rimraf": { "node_modules/rimraf": {
"version": "6.1.2", "version": "4.4.1",
"resolved": "https://registry.npmmirror.com/rimraf/-/rimraf-6.1.2.tgz", "resolved": "https://registry.npmmirror.com/rimraf/-/rimraf-4.4.1.tgz",
"integrity": "sha512-cFCkPslJv7BAXJsYlK1dZsbP8/ZNLkCAQ0bi1hf5EKX2QHegmDFEFA6QhuYJlk7UDdc+02JjO80YSOrWPpw06g==", "integrity": "sha512-Gk8NlF062+T9CqNGn6h4tls3k6T1+/nXdOcSZVikNVtlRdYpA7wRJJMoXmuvOnLW844rPjdQ7JgXCYM6PPC/og==",
"dev": true, "dev": true,
"license": "BlueOak-1.0.0", "license": "ISC",
"dependencies": { "dependencies": {
"glob": "^13.0.0", "glob": "^9.2.0"
"package-json-from-dist": "^1.0.1"
}, },
"bin": { "bin": {
"rimraf": "dist/esm/bin.mjs" "rimraf": "dist/cjs/src/bin.js"
}, },
"engines": { "engines": {
"node": "20 || >=22" "node": ">=14"
}, },
"funding": { "funding": {
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
@@ -3876,9 +3904,9 @@
} }
}, },
"node_modules/xml2js": { "node_modules/xml2js": {
"version": "0.6.2", "version": "0.5.0",
"resolved": "https://registry.npmmirror.com/xml2js/-/xml2js-0.6.2.tgz", "resolved": "https://registry.npmmirror.com/xml2js/-/xml2js-0.5.0.tgz",
"integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==", "integrity": "sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

@@ -7,6 +7,8 @@
"dev": "vite --host 0.0.0.0", "dev": "vite --host 0.0.0.0",
"build": "vite build", "build": "vite build",
"preview": "vite preview", "preview": "vite preview",
"rules:sync": "node scripts/sync-notification-rules.mjs",
"rule:smoke": "node scripts/rule-smoke.mjs",
"version:sync": "node scripts/sync-version.cjs", "version:sync": "node scripts/sync-version.cjs",
"release": "node scripts/release.cjs", "release": "node scripts/release.cjs",
"release:patch": "node scripts/release.cjs patch", "release:patch": "node scripts/release.cjs patch",
@@ -14,9 +16,9 @@
"release:major": "node scripts/release.cjs major" "release:major": "node scripts/release.cjs major"
}, },
"dependencies": { "dependencies": {
"@capacitor-community/sqlite": "^5.7.2", "@capacitor-community/sqlite": "^5.7.4",
"@capacitor/android": "^5.7.8", "@capacitor/android": "^5.7.8",
"@capacitor/app": "^5.0.0", "@capacitor/app": "^5.0.8",
"@capacitor/core": "^5.7.8", "@capacitor/core": "^5.7.8",
"@phosphor-icons/web": "^2.1.2", "@phosphor-icons/web": "^2.1.2",
"jeep-sqlite": "^2.7.1", "jeep-sqlite": "^2.7.1",
@@ -28,7 +30,7 @@
"vue-router": "^4.6.3" "vue-router": "^4.6.3"
}, },
"devDependencies": { "devDependencies": {
"@capacitor/cli": "^7.4.4", "@capacitor/cli": "^5.7.8",
"@vitejs/plugin-vue": "^6.0.1", "@vitejs/plugin-vue": "^6.0.1",
"autoprefixer": "^10.4.17", "autoprefixer": "^10.4.17",
"postcss": "^8.4.35", "postcss": "^8.4.35",

63
scripts/rule-smoke.mjs Normal file
View File

@@ -0,0 +1,63 @@
import assert from 'node:assert/strict'
import { transformNotificationToTransaction } from '../src/services/notificationRuleService.js'
const cases = [
{
name: 'ignore transit operation notice',
notification: {
id: 'n1',
channel: '绍兴公交',
text: '黄酒小镇专线绍兴北站出站该线路已于2025年10月17日起暂停运营',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule, undefined)
},
},
{
name: 'capture transit expense with payment context',
notification: {
id: 'n2',
channel: '绍兴公交',
text: '乘车码扣费2元绍兴北站->黄酒小镇',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule?.id, 'transit-card-expense')
assert.equal(result.transaction.amount, -2)
},
},
{
name: 'capture bank expense',
notification: {
id: 'n3',
channel: '招商银行',
text: '您尾号1234信用卡消费支出3.23元,商户支付宝-上海拉扎斯信息科技有限公司',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule?.id, 'bank-expense')
assert.equal(result.transaction.amount, -3.23)
},
},
{
name: 'capture wechat income',
notification: {
id: 'n4',
channel: '微信支付',
text: '收款到账12.50元,来自张三',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule?.id, 'wechat-income')
assert.equal(result.transaction.amount, 12.5)
},
},
]
for (const testCase of cases) {
const result = transformNotificationToTransaction(testCase.notification)
testCase.verify(result)
}
console.log(`rule smoke passed: ${cases.length} cases`)

View File

@@ -0,0 +1,57 @@
import fs from 'node:fs'
import path from 'node:path'
import notificationRules from '../src/config/notificationRules.js'
const rootDir = path.resolve(import.meta.dirname, '..')
const targetFile = path.join(
rootDir,
'android',
'app',
'src',
'main',
'java',
'com',
'echo',
'app',
'notification',
'NotificationRuleData.kt',
)
const toKotlinString = (value) => JSON.stringify(value).replace(/\$/g, '\\$')
const toKotlinStringList = (values = []) =>
values.length ? `listOf(${values.map((value) => toKotlinString(value)).join(', ')})` : 'emptyList()'
const toKotlinRegex = (spec) => {
if (!spec?.pattern) return 'null'
const flags = spec.flags?.includes('i') ? ', setOf(RegexOption.IGNORE_CASE)' : ''
return `Regex(${toKotlinString(spec.pattern)}${flags})`
}
const toRuleBlock = (rule) => ` NotificationRuleDefinition(
id = ${toKotlinString(rule.id)},
label = ${toKotlinString(rule.label)},
channels = ${toKotlinStringList(rule.channels)},
keywords = ${toKotlinStringList(rule.keywords)},
requiredTextPatterns = ${toKotlinStringList(rule.requiredTextPatterns)},
direction = NotificationRuleDirection.${rule.direction === 'income' ? 'INCOME' : 'EXPENSE'},
defaultCategory = ${toKotlinString(rule.defaultCategory)},
autoCapture = ${rule.autoCapture ? 'true' : 'false'},
merchantPattern = ${toKotlinRegex(rule.merchantPattern)},
defaultMerchant = ${
rule.defaultMerchant ? toKotlinString(rule.defaultMerchant) : 'null'
},
)`
const content = `package com.echo.app.notification
// Generated from src/config/notificationRules.js by scripts/sync-notification-rules.mjs.
internal object NotificationRuleData {
val fallbackRules: List<NotificationRuleDefinition> = listOf(
${notificationRules.map(toRuleBlock).join(',\n')}
)
}
`
fs.writeFileSync(targetFile, content)
console.log(`[rules:sync] wrote ${path.relative(rootDir, targetFile)}`)

View File

@@ -4,24 +4,22 @@ import { RouterView } from 'vue-router'
import { App } from '@capacitor/app' import { App } from '@capacitor/app'
import BottomDock from './components/BottomDock.vue' import BottomDock from './components/BottomDock.vue'
import AddEntryView from './views/AddEntryView.vue' import AddEntryView from './views/AddEntryView.vue'
import { useTransactionStore } from './stores/transactions' import { bootstrapApp } from './services/appBootstrap.js'
import { useUiStore } from './stores/ui' import { useUiStore } from './stores/ui'
const transactionStore = useTransactionStore()
const uiStore = useUiStore() const uiStore = useUiStore()
let backButtonListener = null let backButtonListener = null
onMounted(() => { void bootstrapApp()
transactionStore.ensureInitialized()
// Android 物理返回键:如果新增记录面板打开,则优先关闭面板而不是直接退出应用 onMounted(() => {
if (typeof App?.addListener === 'function') { if (typeof App?.addListener === 'function') {
App.addListener('backButton', ({ canGoBack }) => { App.addListener('backButton', ({ canGoBack }) => {
if (uiStore.addEntryVisible) { if (uiStore.addEntryVisible) {
uiStore.closeAddEntry() uiStore.closeAddEntry()
} else if (!canGoBack) { } else if (!canGoBack) {
// 这里保留默认行为(由 Capacitor 处理),不强制 exitApp // Keep Capacitor default back behavior.
} }
}) })
.then((handle) => { .then((handle) => {
@@ -42,21 +40,17 @@ onBeforeUnmount(() => {
</script> </script>
<template> <template>
<!-- 整体应用容器居中展示移动端画布配合沉浸式状态栏使用安全区域内边距 -->
<div class="min-h-screen bg-warmOffwhite text-stone-800 flex items-center justify-center"> <div class="min-h-screen bg-warmOffwhite text-stone-800 flex items-center justify-center">
<div <div
class="h-screen max-h-[844px] max-w-md w-full mx-auto bg-warmOffwhite shadow-2xl relative overflow-hidden flex flex-col" class="h-screen max-h-[844px] max-w-md w-full mx-auto bg-warmOffwhite shadow-2xl relative overflow-hidden flex flex-col"
style="padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);" style="padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);"
> >
<!-- 主内容区域 vue-router 控制具体页面 -->
<main class="flex-1 overflow-y-auto hide-scrollbar px-5 pt-2 pb-28 relative"> <main class="flex-1 overflow-y-auto hide-scrollbar px-5 pt-2 pb-28 relative">
<RouterView /> <RouterView />
</main> </main>
<!-- 底部 Dock 导航 -->
<BottomDock /> <BottomDock />
<!-- 新增记录底部弹窗在任意 Tab 上浮层显示 -->
<transition name="slide-up"> <transition name="slide-up">
<AddEntryView v-if="uiStore.addEntryVisible" /> <AddEntryView v-if="uiStore.addEntryVisible" />
</transition> </transition>

View File

@@ -0,0 +1,153 @@
const notificationRules = [
{
id: 'alipay-expense',
label: '支付宝消费',
channels: ['支付宝', 'Alipay'],
keywords: ['支付', '扣款', '支出', '消费', '成功支付'],
requiredTextPatterns: [],
direction: 'expense',
defaultCategory: 'Food',
autoCapture: false,
merchantPattern: {
pattern: '(?:向|收款方|商户)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)',
flags: 'i',
},
defaultMerchant: '',
},
{
id: 'alipay-income',
label: '支付宝收款',
channels: ['支付宝', 'Alipay'],
keywords: ['到账', '收入', '收款', '入账'],
requiredTextPatterns: [],
direction: 'income',
defaultCategory: 'Income',
autoCapture: true,
merchantPattern: {
pattern: '(?:来自|收款方|付款方|来源)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)',
flags: 'i',
},
defaultMerchant: '',
},
{
id: 'wechat-expense',
label: '微信消费',
channels: ['微信支付', '微信', 'WeChat'],
keywords: ['支付', '支出', '扣款', '消费成功'],
requiredTextPatterns: [],
direction: 'expense',
defaultCategory: 'Groceries',
autoCapture: false,
merchantPattern: {
pattern: '(?:向|收款方|商户)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)',
flags: '',
},
defaultMerchant: '',
},
{
id: 'wechat-income',
label: '微信收款',
channels: ['微信支付', '微信', 'WeChat'],
keywords: ['收款', '到账', '入账', '转入'],
requiredTextPatterns: [],
direction: 'income',
defaultCategory: 'Income',
autoCapture: true,
merchantPattern: {
pattern: '(?:来自|收款方|付款方|来源)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)',
flags: '',
},
defaultMerchant: '',
},
{
id: 'bank-income',
label: '银行入账',
channels: [
'招商银行',
'中国银行',
'建设银行',
'工商银行',
'农业银行',
'交通银行',
'浦发银行',
'兴业银行',
'光大银行',
'中信银行',
'广发银行',
'平安银行',
],
keywords: ['工资', '薪资', '代发', '到账', '入账', '收入'],
requiredTextPatterns: [],
direction: 'income',
defaultCategory: 'Income',
autoCapture: true,
merchantPattern: {
pattern: '(?:来自|付款方|来源)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)',
flags: '',
},
defaultMerchant: '',
},
{
id: 'bank-expense',
label: '银行卡支出',
channels: [
'招商银行',
'中国银行',
'建设银行',
'工商银行',
'农业银行',
'交通银行',
'浦发银行',
'兴业银行',
'光大银行',
'中信银行',
'广发银行',
'平安银行',
'借记卡',
'信用卡',
],
keywords: ['支出', '消费', '扣款', '刷卡消费', '银联消费'],
requiredTextPatterns: [],
direction: 'expense',
defaultCategory: 'Expense',
autoCapture: false,
merchantPattern: {
pattern: '(?:商户|商家|消费商户)\\s*([\\u4e00-\\u9fa5A-Za-z0-9\\s&-]+)',
flags: '',
},
defaultMerchant: '',
},
{
id: 'transit-card-expense',
label: '公交出行',
channels: [
'杭州通互联互通卡',
'杭州通',
'北京一卡通',
'上海公共交通卡',
'深圳通',
'苏州公交卡',
'交通联合',
'乘车码',
'地铁',
'公交',
'Mi Pay',
'Huawei Pay',
'华为钱包',
'小米钱包',
'OPPO 钱包',
],
keywords: [],
requiredTextPatterns: ['扣费', '扣款', '支付', '乘车码', '车费', '票价', '本次乘车', '实付', '优惠后'],
direction: 'expense',
defaultCategory: 'Transport',
autoCapture: true,
merchantPattern: {
pattern: '([\\u4e00-\\u9fa5]{2,}\\s*(?:-|->|→|至|到)\\s*[\\u4e00-\\u9fa5]{2,})',
flags: '',
},
defaultMerchant: '公交/地铁出行',
},
]
export default notificationRules

View File

@@ -0,0 +1,90 @@
export const TRANSACTION_CATEGORIES = [
{
value: 'Food',
label: '餐饮',
icon: 'ph-bowl-food',
bg: 'bg-orange-100',
color: 'text-orange-600',
budgetable: true,
},
{
value: 'Transport',
label: '通勤',
icon: 'ph-taxi',
bg: 'bg-blue-100',
color: 'text-blue-600',
budgetable: true,
},
{
value: 'Health',
label: '健康',
icon: 'ph-heartbeat',
bg: 'bg-rose-100',
color: 'text-rose-600',
budgetable: true,
},
{
value: 'Groceries',
label: '买菜',
icon: 'ph-basket',
bg: 'bg-amber-100',
color: 'text-amber-600',
budgetable: true,
},
{
value: 'Entertainment',
label: '娱乐',
icon: 'ph-game-controller',
bg: 'bg-fuchsia-100',
color: 'text-fuchsia-600',
budgetable: true,
},
{
value: 'Expense',
label: '一般支出',
icon: 'ph-receipt',
bg: 'bg-stone-100',
color: 'text-stone-600',
budgetable: true,
},
{
value: 'Income',
label: '收入',
icon: 'ph-wallet',
bg: 'bg-emerald-100',
color: 'text-emerald-600',
budgetable: false,
},
{
value: 'Uncategorized',
label: '其他',
icon: 'ph-note-pencil',
bg: 'bg-stone-100',
color: 'text-stone-500',
budgetable: true,
},
]
export const DEFAULT_TRANSACTION_CATEGORY = 'Food'
export const CATEGORY_CHIPS = [
{ label: '全部', value: 'all', icon: 'ph-asterisk' },
...TRANSACTION_CATEGORIES.map(({ label, value, icon }) => ({ label, value, icon })),
]
export const CATEGORY_META = TRANSACTION_CATEGORIES.reduce((acc, category) => {
acc[category.value] = category
return acc
}, {})
export const BUDGET_CATEGORY_OPTIONS = TRANSACTION_CATEGORIES.filter((category) => category.budgetable)
export const DEFAULT_CATEGORY_BUDGETS = BUDGET_CATEGORY_OPTIONS.reduce((acc, category) => {
acc[category.value] = 0
return acc
}, {})
export const getCategoryMeta = (category) =>
CATEGORY_META[category] || CATEGORY_META.Uncategorized
export const getCategoryLabel = (category) => getCategoryMeta(category).label

View File

@@ -0,0 +1,15 @@
import { useTransactionStore } from '../stores/transactions'
let bootstrapPromise = null
export const bootstrapApp = async () => {
if (!bootstrapPromise) {
const transactionStore = useTransactionStore()
bootstrapPromise = transactionStore.ensureInitialized().catch((error) => {
bootstrapPromise = null
throw error
})
}
return bootstrapPromise
}

View File

@@ -1,150 +1,32 @@
const fallbackRules = [ import notificationRulesSource from '../config/notificationRules.js'
// 支付宝消费:日常吃饭、网购等
{ const fallbackRules = notificationRulesSource.map((rule) => ({
id: 'alipay-expense', ...rule,
label: '支付宝消费', merchantPattern: rule.merchantPattern?.pattern
channels: ['支付宝', 'Alipay'], ? new RegExp(rule.merchantPattern.pattern, rule.merchantPattern.flags || '')
keywords: ['支付', '扣款', '支出', '消费', '成功支付'], : null,
direction: 'expense', }))
defaultCategory: 'Food',
autoCapture: false, const amountPatterns = [
merchantPattern: /向\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)/i, /(?:¥|¥|RMB|CNY|人民币)\s*(-?\d+(?:\.\d{1,2})?)/i,
}, /(-?\d+(?:\.\d{1,2})?)\s*(?:元|块|块钱)/,
// 支付宝收款 / 到账 /(?:金额|实付|扣费|扣款|消费|支出|收入|收款|到账|入账|转入|转出|支付|票价|车费|本次乘车)\D{0,8}?(-?\d+(?:\.\d{1,2})?)/,
{ /(-?\d+(?:\.\d{1,2})?)\s*(?:元|块|块钱)?\s*(?:已支付|已收款|到账|入账)/,
id: 'alipay-income',
label: '支付宝收款',
channels: ['支付宝', 'Alipay'],
keywords: ['到账', '收入', '收款', '入账'],
direction: 'income',
defaultCategory: 'Income',
autoCapture: true,
merchantPattern: /(?:来自|收款方)\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)/i,
},
// 微信消费
{
id: 'wechat-expense',
label: '微信消费',
channels: ['微信支付', '微信', 'WeChat'],
keywords: ['支付', '支出', '扣款', '消费成功'],
direction: 'expense',
defaultCategory: 'Groceries',
autoCapture: false,
merchantPattern: /向\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)/,
},
// 微信收款 / 转账入账
{
id: 'wechat-income',
label: '微信收款',
channels: ['微信支付', '微信', 'WeChat'],
keywords: ['收款', '到账', '入账', '转入'],
direction: 'income',
defaultCategory: 'Income',
autoCapture: true,
merchantPattern: /(?:来自|收款方)\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)/,
},
// 银行工资 / 常规入账
{
id: 'bank-income',
label: '工资到账',
channels: [
'招商银行',
'中国银行',
'建设银行',
'工商银行',
'农业银行',
'交通银行',
'浦发银行',
'兴业银行',
'光大银行',
'中信银行',
'广发银行',
'平安银行',
],
keywords: ['工资', '薪资', '代发', '到账', '入账', '收入'],
direction: 'income',
defaultCategory: 'Income',
autoCapture: true,
merchantPattern: /(?:来自|付款方|来源)\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)/,
},
// 银行消费 / 借记卡扣款
{
id: 'bank-expense',
label: '银行卡支出',
channels: [
'招商银行',
'中国银行',
'建设银行',
'工商银行',
'农业银行',
'交通银行',
'浦发银行',
'兴业银行',
'光大银行',
'中信银行',
'广发银行',
'平安银行',
'借记卡',
'信用卡',
],
keywords: ['支出', '消费', '扣款', '刷卡消费', '银联消费'],
direction: 'expense',
defaultCategory: 'Expense',
autoCapture: false,
merchantPattern: /(?:商户|商家|消费商户)\s*([\u4e00-\u9fa5A-Za-z0-9\s&]+)/,
},
// 手机公交卡 / 乘车码扣款(地铁、公交等),按交通分类
{
id: 'transit-card-expense',
label: '公交出行',
channels: [
'杭州通互联互通卡',
'杭州通',
'北京一卡通',
'上海公共交通卡',
'深圳通',
'苏州公交卡',
'交通联合',
'乘车码',
'地铁',
'公交',
'Mi Pay',
'Huawei Pay',
'华为钱包',
'小米钱包',
'OPPO 钱包',
],
// 对公交卡类通知,只要来源匹配即可视为出行支出,不强制正文关键字
keywords: [],
direction: 'expense',
defaultCategory: 'Transport',
autoCapture: true,
// 优先从正文中提取「文三路->祥园路」之类的起点-终点信息作为“商户”
merchantPattern: /([\u4e00-\u9fa5]{2,}\s*(?:-|—|>|→|至|到)\s*[\u4e00-\u9fa5]{2,})/,
// 若无法提取线路,则使用统一名称
defaultMerchant: '公交/地铁出行',
},
] ]
let cachedRules = [...fallbackRules] let cachedRules = [...fallbackRules]
let remoteRuleFetcher = async () => [] let remoteRuleFetcher = async () => []
/** const buildEmptyTransaction = (notification, options = {}) => ({
* 允许后续接入服务端规则同步,只需在应用启动时调用并注入实际的 fetch 函数。 id: options.id,
* 服务端可以返回一组规则对象,形如: merchant: options.merchant || 'Unknown',
* { category: options.category || 'Uncategorized',
* id: string; amount: 0,
* label?: string; date: new Date(options.date || notification?.createdAt || new Date().toISOString()).toISOString(),
* enabled?: boolean; // false 时在本地完全忽略此规则 note: notification?.text || '',
* priority?: number; // 预留优先级字段(当前仅在服务端使用) syncStatus: 'pending',
* channels?: string[]; // 匹配通知来源(标题 / 包名) })
* keywords?: string[]; // 匹配通知正文的关键字
* direction?: 'income' | 'expense';
* defaultCategory?: string;
* autoCapture?: boolean;
* }
* @param {(currentRules: Array) => Promise<Array>} fetcher
*/
export const setRemoteRuleFetcher = (fetcher) => { export const setRemoteRuleFetcher = (fetcher) => {
remoteRuleFetcher = typeof fetcher === 'function' ? fetcher : remoteRuleFetcher remoteRuleFetcher = typeof fetcher === 'function' ? fetcher : remoteRuleFetcher
} }
@@ -167,47 +49,44 @@ export const loadNotificationRules = async () => {
} }
} catch (err) { } catch (err) {
cachedRules = [...cachedRules] cachedRules = [...cachedRules]
console.warn('[rules] 使用本地规则,远程规则获取失败:', err) console.warn('[rules] using cached fallback rules because remote sync failed:', err)
} }
return cachedRules return cachedRules
} }
export const getCachedNotificationRules = () => cachedRules export const getCachedNotificationRules = () => cachedRules
// 从通知文本中提取交易金额,兼容「¥」「¥」「元」「人民币」等常见形式
const extractAmount = (text = '') => { const extractAmount = (text = '') => {
const primary = text.match( const normalized = String(text).replace(/,/g, '').trim()
/(?:[¥¥]|人民币)\s*(-?\d+(?:\.\d{1,2})?)|(-?\d+(?:\.\d{1,2})?)\s*元/,
) for (const pattern of amountPatterns) {
const value = primary?.[1] || primary?.[2] const match = normalized.match(pattern)
if (value) { const value = match?.[1]
return Math.abs(parseFloat(value)) if (!value) continue
const parsed = Math.abs(Number.parseFloat(value))
if (Number.isFinite(parsed) && parsed > 0) {
return parsed
}
} }
const loose = text.match(/(-?\d+(?:\.\d{1,2})?)/)
return loose?.[1] ? Math.abs(parseFloat(loose[1])) : 0 return 0
} }
// 判断字符串是否更像是「金额」而不是商户名用于避免把「1.00元」当成商户
const looksLikeAmount = (raw = '') => { const looksLikeAmount = (raw = '') => {
const value = String(raw).trim() const value = String(raw).trim()
if (!value) return false if (!value) return false
const amountPattern = /^[-\d.,]+\s*(?:元|块钱|¥|¥|人民币)?$/ return /^[-\d.,]+\s*(?:元|块|块钱|¥|¥|人民币)?$/i.test(value)
return amountPattern.test(value)
} }
const extractMerchant = (text, rule) => { const extractMerchant = (text, rule) => {
const content = text || '' const content = text || ''
if (rule?.merchantPattern instanceof RegExp) { if (rule?.merchantPattern instanceof RegExp) {
const m = content.match(rule.merchantPattern) const matched = content.match(rule.merchantPattern)
if (m?.[1]) return m[1].trim() if (matched?.[1]) return matched[1].trim()
} }
// 通用的「站点 A -> 站点 B」线路模式公交/地铁通知), const routeMatch = content.match(/([\u4e00-\u9fa5]{2,}\s*(?:-|->|→|至|到)\s*[\u4e00-\u9fa5]{2,})/)
// 即使未命中专用规则也尝试提取避免退化为金额或「Unknown」
const routeMatch = content.match(
/([\u4e00-\u9fa5]{2,}\s*(?:-|—|>|→|至|到|->)\s*[\u4e00-\u9fa5]{2,})/,
)
if (routeMatch?.[1]) { if (routeMatch?.[1]) {
return routeMatch[1].trim() return routeMatch[1].trim()
} }
@@ -218,16 +97,14 @@ const extractMerchant = (text, rule) => {
] ]
for (const pattern of genericPatterns) { for (const pattern of genericPatterns) {
const m = content.match(pattern) const matched = content.match(pattern)
if (m?.[1]) return m[1].trim() if (matched?.[1]) return matched[1].trim()
} }
// 针对「……支出(消费支付宝-上海拉扎斯信息科技有限公司)3.23元」这类银行通知,
// 优先尝试从括号中的「支付宝-商户名」结构中提取真正的商户名
const parenMatch = content.match(/\(([^)]+)\)/) const parenMatch = content.match(/\(([^)]+)\)/)
if (parenMatch?.[1]) { if (parenMatch?.[1]) {
const inner = parenMatch[1] const inner = parenMatch[1]
const payMatch = inner.match(/(?:支付宝|微信支付|微信)[-\s]*([^\d元¥¥]+)$/) const payMatch = inner.match(/(?:支付宝|微信支付|微信)[-\s]*([^\d元¥¥]+)$/)
if (payMatch?.[1]) { if (payMatch?.[1]) {
const candidate = payMatch[1].trim() const candidate = payMatch[1].trim()
if (candidate && !looksLikeAmount(candidate)) { if (candidate && !looksLikeAmount(candidate)) {
@@ -247,32 +124,48 @@ const extractMerchant = (text, rule) => {
const matchRule = (notification, rule) => { const matchRule = (notification, rule) => {
if (!rule || rule.enabled === false) return false if (!rule || rule.enabled === false) return false
const channel = notification?.channel || '' const channel = notification?.channel || ''
const text = notification?.text || '' const text = notification?.text || ''
// 频道命中:优先用通知标题/来源匹配,退而求其次用正文包含匹配(兼容 adb shell / 部分 ROM
const channelHit = const channelHit =
!rule.channels?.length || !rule.channels?.length ||
rule.channels.some((item) => channel.includes(item) || text.includes(item)) rule.channels.some((item) => channel.includes(item)) ||
(!channel && rule.channels.some((item) => text.includes(item)))
const keywordHit = !rule.keywords?.length || rule.keywords.some((word) => text.includes(word)) const keywordHit = !rule.keywords?.length || rule.keywords.some((word) => text.includes(word))
return channelHit && keywordHit const requiredTextHit =
!rule.requiredTextPatterns?.length ||
rule.requiredTextPatterns.some((word) => text.includes(word))
return channelHit && keywordHit && requiredTextHit
} }
/**
* 根据当前规则集生成交易草稿,并返回命中的规则信息
* @param {{ id: string, channel: string, text: string, createdAt: string }} notification
* @param {{ ruleSet?: Array, overrides?: object }} options
* @returns {{ transaction: import('../types/transaction').Transaction, rule?: object, requiresConfirmation: boolean }}
*/
export const transformNotificationToTransaction = (notification, options = {}) => { export const transformNotificationToTransaction = (notification, options = {}) => {
const ruleSet = options.ruleSet?.length ? options.ruleSet : cachedRules const ruleSet = options.ruleSet?.length ? options.ruleSet : cachedRules
const rule = ruleSet.find((item) => matchRule(notification, item)) const rule = ruleSet.find((item) => matchRule(notification, item))
const amountFromText = extractAmount(notification?.text)
const direction = options.direction || rule?.direction || 'expense' if (!rule) {
return {
transaction: buildEmptyTransaction(notification, options),
rule: undefined,
requiresConfirmation: false,
}
}
const amountFromText = extractAmount(notification?.text || '')
if (amountFromText <= 0) {
return {
transaction: buildEmptyTransaction(notification, options),
rule: undefined,
requiresConfirmation: false,
}
}
const direction = options.direction || rule.direction || 'expense'
const normalizedAmount = const normalizedAmount =
direction === 'income' ? Math.abs(amountFromText) : -Math.abs(amountFromText) direction === 'income' ? Math.abs(amountFromText) : -Math.abs(amountFromText)
let merchant = options.merchant || extractMerchant(notification?.text || '', rule) || 'Unknown' let merchant = options.merchant || extractMerchant(notification?.text || '', rule) || 'Unknown'
if (merchant === 'Unknown' && rule?.defaultMerchant) { if (merchant === 'Unknown' && rule.defaultMerchant) {
merchant = rule.defaultMerchant merchant = rule.defaultMerchant
} }
@@ -281,8 +174,8 @@ export const transformNotificationToTransaction = (notification, options = {}) =
const transaction = { const transaction = {
id: options.id, id: options.id,
merchant, merchant,
category: options.category || rule?.defaultCategory || 'Uncategorized', category: options.category || rule.defaultCategory || 'Uncategorized',
amount: Number.isFinite(normalizedAmount) ? normalizedAmount : 0, amount: normalizedAmount,
date: new Date(date).toISOString(), date: new Date(date).toISOString(),
note: notification?.text || '', note: notification?.text || '',
syncStatus: 'pending', syncStatus: 'pending',
@@ -290,7 +183,7 @@ export const transformNotificationToTransaction = (notification, options = {}) =
const requiresConfirmation = const requiresConfirmation =
options.requiresConfirmation ?? options.requiresConfirmation ??
!(rule?.autoCapture && transaction.amount !== 0 && merchant !== 'Unknown') !(rule.autoCapture && transaction.amount !== 0 && merchant !== 'Unknown')
return { transaction, rule, requiresConfirmation } return { transaction, rule, requiresConfirmation }
} }

View File

@@ -1,5 +1,6 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { ref } from 'vue' import { ref } from 'vue'
import { DEFAULT_CATEGORY_BUDGETS } from '../config/transactionCategories.js'
export const useSettingsStore = defineStore( export const useSettingsStore = defineStore(
'settings', 'settings',
@@ -7,17 +8,10 @@ export const useSettingsStore = defineStore(
const notificationCaptureEnabled = ref(true) const notificationCaptureEnabled = ref(true)
const aiAutoCategoryEnabled = ref(false) const aiAutoCategoryEnabled = ref(false)
const monthlyBudget = ref(12000) const monthlyBudget = ref(12000)
const budgetResetCycle = ref('monthly') // monthly | weekly | none | custom const budgetResetCycle = ref('monthly')
const budgetMonthlyResetDay = ref(1) // 每月第几天重置1-28 const budgetMonthlyResetDay = ref(1)
const budgetCustomStartDate = ref('') // 自定义起始日ISO 日期字符串) const budgetCustomStartDate = ref('')
const categoryBudgets = ref({ const categoryBudgets = ref({ ...DEFAULT_CATEGORY_BUDGETS })
Food: 0,
Transport: 0,
Health: 0,
Groceries: 0,
Entertainment: 0,
Uncategorized: 0,
})
const categoryBudgetEnabled = ref(false) const categoryBudgetEnabled = ref(false)
const profileName = ref('Echo 用户') const profileName = ref('Echo 用户')
const profileAvatar = ref('') const profileAvatar = ref('')
@@ -115,4 +109,3 @@ export const useSettingsStore = defineStore(
}, },
}, },
) )

View File

@@ -1,5 +1,10 @@
<script setup> <script setup>
import { computed, reactive, ref, watch } from 'vue' import { computed, reactive, ref, watch } from 'vue'
import {
DEFAULT_TRANSACTION_CATEGORY,
TRANSACTION_CATEGORIES,
getCategoryLabel,
} from '../config/transactionCategories.js'
import { useTransactionStore } from '../stores/transactions' import { useTransactionStore } from '../stores/transactions'
import { useUiStore } from '../stores/ui' import { useUiStore } from '../stores/ui'
import EchoInput from '../components/EchoInput.vue' import EchoInput from '../components/EchoInput.vue'
@@ -14,7 +19,7 @@ const dragStartY = ref(0)
const dragging = ref(false) const dragging = ref(false)
const dragOffset = ref(0) const dragOffset = ref(0)
const categories = ['Food', 'Transport', 'Health', 'Groceries', 'Entertainment', 'Income', 'Uncategorized'] const categories = TRANSACTION_CATEGORIES
const toDatetimeLocal = (value) => { const toDatetimeLocal = (value) => {
const date = value ? new Date(value) : new Date() const date = value ? new Date(value) : new Date()
@@ -26,7 +31,7 @@ const form = reactive({
type: 'expense', type: 'expense',
amount: '', amount: '',
merchant: '', merchant: '',
category: 'Food', category: DEFAULT_TRANSACTION_CATEGORY,
note: '', note: '',
date: toDatetimeLocal(), date: toDatetimeLocal(),
}) })
@@ -35,7 +40,7 @@ const resetForm = () => {
form.type = 'expense' form.type = 'expense'
form.amount = '' form.amount = ''
form.merchant = '' form.merchant = ''
form.category = 'Food' form.category = DEFAULT_TRANSACTION_CATEGORY
form.note = '' form.note = ''
form.date = toDatetimeLocal() form.date = toDatetimeLocal()
} }
@@ -146,8 +151,6 @@ const sheetStyle = computed(() => {
transition: dragging.value ? 'none' : 'transform 0.2s ease-out', transition: dragging.value ? 'none' : 'transform 0.2s ease-out',
} }
}) })
transactionStore.ensureInitialized()
</script> </script>
<template> <template>
@@ -169,10 +172,10 @@ transactionStore.ensureInitialized()
<div class="flex items-center justify-between mb-6"> <div class="flex items-center justify-between mb-6">
<div> <div>
<p class="text-xs text-stone-400 font-bold uppercase tracking-widest"> <p class="text-xs text-stone-400 font-bold uppercase tracking-widest">
{{ editingId ? '编辑记录' : '记录新消费' }} {{ editingId ? '编辑记录' : '记录新流水' }}
</p> </p>
<h3 class="text-xl font-extrabold text-stone-800"> <h3 class="text-xl font-extrabold text-stone-800">
{{ editingId ? '更新本地账本' : '快速入账' }} {{ editingId ? '更新本地账本' : '快速记一笔' }}
</h3> </h3>
</div> </div>
<button class="text-stone-400 text-sm font-bold" @click="closePanel">关闭</button> <button class="text-stone-400 text-sm font-bold" @click="closePanel">关闭</button>
@@ -214,7 +217,7 @@ transactionStore.ensureInitialized()
input-class="text-2xl font-bold" input-class="text-2xl font-bold"
> >
<template #prefix> <template #prefix>
<span class="text-stone-400 text-sm">¥</span> <span class="text-stone-400 text-sm"></span>
</template> </template>
</EchoInput> </EchoInput>
@@ -229,16 +232,16 @@ transactionStore.ensureInitialized()
<div class="mt-2 flex gap-2 overflow-x-auto hide-scrollbar pb-1"> <div class="mt-2 flex gap-2 overflow-x-auto hide-scrollbar pb-1">
<button <button
v-for="category in categories" v-for="category in categories"
:key="category" :key="category.value"
class="px-4 py-2 rounded-2xl text-xs font-bold border transition" class="px-4 py-2 rounded-2xl text-xs font-bold border transition"
:class=" :class="
form.category === category form.category === category.value
? 'bg-gradient-warm text-white border-transparent' ? 'bg-gradient-warm text-white border-transparent'
: 'bg-stone-50 text-stone-500 border-stone-100' : 'bg-stone-50 text-stone-500 border-stone-100'
" "
@click="form.category = category" @click="form.category = category.value"
> >
{{ category }} {{ getCategoryLabel(category.value) }}
</button> </button>
</div> </div>
</div> </div>
@@ -258,7 +261,7 @@ transactionStore.ensureInitialized()
v-model="form.note" v-model="form.note"
rows="2" rows="2"
class="mt-2 w-full rounded-2xl border border-stone-200 px-4 py-3 text-sm focus:outline-none focus:border-stone-400 resize-none" class="mt-2 w-full rounded-2xl border border-stone-200 px-4 py-3 text-sm focus:outline-none focus:border-stone-400 resize-none"
placeholder="可记录口味、心情或健康状态" placeholder="可记录口味、心情或其他背景信息"
/> />
</label> </label>
</div> </div>
@@ -272,7 +275,7 @@ transactionStore.ensureInitialized()
:disabled="saving" :disabled="saving"
@click="submitForm" @click="submitForm"
> >
{{ saving ? '保存中...' : editingId ? '保存修改' : '立即账' }} {{ saving ? '保存中...' : editingId ? '保存修改' : '立即账' }}
</button> </button>
<button <button

View File

@@ -1,4 +1,4 @@
<script setup> <script setup>
import { computed, onMounted, onBeforeUnmount } from 'vue' import { computed, onMounted, onBeforeUnmount } from 'vue'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { App } from '@capacitor/app' import { App } from '@capacitor/app'
@@ -7,6 +7,8 @@ import { useTransactionStore } from '../stores/transactions'
import { useTransactionEntry } from '../composables/useTransactionEntry' import { useTransactionEntry } from '../composables/useTransactionEntry'
import { useSettingsStore } from '../stores/settings' import { useSettingsStore } from '../stores/settings'
import { useUiStore } from '../stores/ui' import { useUiStore } from '../stores/ui'
import { getCategoryLabel, getCategoryMeta } from '../config/transactionCategories.js'
import { bootstrapApp } from '../services/appBootstrap.js'
const router = useRouter() const router = useRouter()
const transactionStore = useTransactionStore() const transactionStore = useTransactionStore()
@@ -20,10 +22,10 @@ const { notifications, confirmNotification, dismissNotification, processingId, s
let appStateListener = null let appStateListener = null
onMounted(async () => { onMounted(async () => {
await transactionStore.ensureInitialized() await bootstrapApp()
await syncNotifications() await syncNotifications()
try { try {
// App 从后台回到前台时,自动刷新本地账本和通知队列 // App 浠庡悗鍙板洖鍒板墠鍙版椂锛岃嚜鍔ㄥ埛鏂版湰鍦拌处鏈拰閫氱煡闃熷垪
appStateListener = await App.addListener('appStateChange', async ({ isActive }) => { appStateListener = await App.addListener('appStateChange', async ({ isActive }) => {
if (isActive) { if (isActive) {
await transactionStore.hydrateTransactions() await transactionStore.hydrateTransactions()
@@ -31,8 +33,7 @@ onMounted(async () => {
} }
}) })
} catch (error) { } catch (error) {
// Web 环境或插件不可用时忽略 // Web 鐜鎴栨彃浠朵笉鍙敤鏃跺拷鐣? console.warn('[notifications] appStateChange listener failed', error)
console.warn('[notifications] appStateChange listener failed', error)
} }
}) })
@@ -59,7 +60,7 @@ const periodStart = computed(() => {
const cycle = budgetResetCycle.value const cycle = budgetResetCycle.value
const now = new Date() const now = new Date()
if (cycle === 'weekly') { if (cycle === 'weekly') {
const day = now.getDay() || 7 // 周一=1周日=7 const day = now.getDay() || 7 // 鍛ㄤ竴=1锛屽懆鏃?7
const diff = day - 1 const diff = day - 1
return new Date(now.getFullYear(), now.getMonth(), now.getDate() - diff) return new Date(now.getFullYear(), now.getMonth(), now.getDate() - diff)
} }
@@ -76,7 +77,7 @@ const periodStart = computed(() => {
if (!settingsStore.budgetCustomStartDate) return null if (!settingsStore.budgetCustomStartDate) return null
return new Date(settingsStore.budgetCustomStartDate) return new Date(settingsStore.budgetCustomStartDate)
} }
// none:不限制周期 // none锛氫笉闄愬埗鍛ㄦ湡
return null return null
}) })
@@ -108,9 +109,9 @@ const remainingBudget = computed(() =>
const todayIncomeValue = computed(() => todaysIncome.value || 0) const todayIncomeValue = computed(() => todaysIncome.value || 0)
const todayExpenseValue = computed(() => Math.abs(todaysExpense.value || 0)) const todayExpenseValue = computed(() => Math.abs(todaysExpense.value || 0))
const formatCurrency = (value) => `¥ ${Math.abs(value || 0).toFixed(2)}` const formatCurrency = (value) => ` ${Math.abs(value || 0).toFixed(2)}`
const formatAmount = (value) => const formatAmount = (value) =>
`${value >= 0 ? '+' : '-'} ¥${Math.abs(value || 0).toFixed(2)}` `${value >= 0 ? '+' : '-'} ${Math.abs(value || 0).toFixed(2)}`
const formatTime = (value) => const formatTime = (value) =>
new Intl.DateTimeFormat('zh-CN', { hour: '2-digit', minute: '2-digit' }).format( new Intl.DateTimeFormat('zh-CN', { hour: '2-digit', minute: '2-digit' }).format(
new Date(value), new Date(value),
@@ -118,18 +119,6 @@ const formatTime = (value) =>
const recentTransactions = computed(() => latestTransactions.value.slice(0, 4)) const recentTransactions = computed(() => latestTransactions.value.slice(0, 4))
const categoryMeta = {
Food: { icon: 'ph-bowl-food', bg: 'bg-orange-100', color: 'text-orange-600' },
Transport: { icon: 'ph-taxi', bg: 'bg-blue-100', color: 'text-blue-600' },
Health: { icon: 'ph-heartbeat', bg: 'bg-rose-100', color: 'text-rose-600' },
Groceries: { icon: 'ph-basket', bg: 'bg-amber-100', color: 'text-amber-600' },
Income: { icon: 'ph-wallet', bg: 'bg-emerald-100', color: 'text-emerald-600' },
Uncategorized: { icon: 'ph-note-pencil', bg: 'bg-stone-100', color: 'text-stone-500' },
default: { icon: 'ph-note-pencil', bg: 'bg-stone-100', color: 'text-stone-500' },
}
const getCategoryMeta = (category) => categoryMeta[category] || categoryMeta.default
const goSettings = () => { const goSettings = () => {
router.push({ name: 'settings' }) router.push({ name: 'settings' })
} }
@@ -155,7 +144,7 @@ const openTransactionDetail = (tx) => {
<p class="text-xs text-stone-400 font-bold tracking-wider"> <p class="text-xs text-stone-400 font-bold tracking-wider">
{{ currentDayLabel }} {{ currentDayLabel }}
</p> </p>
<h1 class="text-2xl font-extrabold text-stone-800">今日概览</h1> <h1 class="text-2xl font-extrabold text-stone-800">浠婃棩姒傝</h1>
</div> </div>
<div <div
class="w-10 h-10 rounded-full bg-orange-50 p-0.5 cursor-pointer border border-orange-100" class="w-10 h-10 rounded-full bg-orange-50 p-0.5 cursor-pointer border border-orange-100"
@@ -181,7 +170,7 @@ const openTransactionDetail = (tx) => {
<div class="relative z-10 flex flex-col h-full justify-between"> <div class="relative z-10 flex flex-col h-full justify-between">
<div> <div>
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<p class="text-white/80 text-xs font-bold tracking-widest uppercase">本月结余</p> <p class="text-white/80 text-xs font-bold tracking-widest uppercase">湀缁撲綑</p>
<button <button
class="w-8 h-8 rounded-full bg-white/20 flex items-center justify-center backdrop-blur-md hover:bg-white/30 transition" class="w-8 h-8 rounded-full bg-white/20 flex items-center justify-center backdrop-blur-md hover:bg-white/30 transition"
> >
@@ -196,13 +185,13 @@ const openTransactionDetail = (tx) => {
<div class="flex gap-8"> <div class="flex gap-8">
<div> <div>
<p class="text-white/70 text-xs mb-0.5 flex items-center gap-1"> <p class="text-white/70 text-xs mb-0.5 flex items-center gap-1">
<i class="ph-bold ph-arrow-down-left" /> 收入 <i class="ph-bold ph-arrow-down-left" /> 鏀跺叆
</p> </p>
<p class="font-bold text-lg">{{ formatCurrency(totalIncome) }}</p> <p class="font-bold text-lg">{{ formatCurrency(totalIncome) }}</p>
</div> </div>
<div> <div>
<p class="text-white/70 text-xs mb-0.5 flex items-center gap-1"> <p class="text-white/70 text-xs mb-0.5 flex items-center gap-1">
<i class="ph-bold ph-arrow-up-right" /> 支出 <i class="ph-bold ph-arrow-up-right" />
</p> </p>
<p class="font-bold text-lg">{{ formatCurrency(Math.abs(totalExpense)) }}</p> <p class="font-bold text-lg">{{ formatCurrency(Math.abs(totalExpense)) }}</p>
</div> </div>
@@ -212,7 +201,7 @@ const openTransactionDetail = (tx) => {
<div class="bg-white rounded-2xl p-4 shadow-sm border border-stone-100"> <div class="bg-white rounded-2xl p-4 shadow-sm border border-stone-100">
<div class="flex justify-between items-center mb-2"> <div class="flex justify-between items-center mb-2">
<span class="text-xs font-bold text-stone-500">本期预算</span> <span class="text-xs font-bold text-stone-500">湡棰勭畻</span>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<span class="text-xs font-bold text-stone-800"> <span class="text-xs font-bold text-stone-800">
{{ Math.round(budgetUsage * 100) }}% {{ Math.round(budgetUsage * 100) }}%
@@ -221,8 +210,7 @@ const openTransactionDetail = (tx) => {
class="text-[10px] text-stone-400 underline-offset-2 hover:text-stone-600" class="text-[10px] text-stone-400 underline-offset-2 hover:text-stone-600"
@click="goSettings" @click="goSettings"
> >
去设置 鍘昏? </button>
</button>
</div> </div>
</div> </div>
<div class="w-full bg-stone-100 rounded-full h-2.5 overflow-hidden"> <div class="w-full bg-stone-100 rounded-full h-2.5 overflow-hidden">
@@ -232,8 +220,8 @@ const openTransactionDetail = (tx) => {
/> />
</div> </div>
<div class="flex justify-between mt-2 text-[10px] text-stone-400"> <div class="flex justify-between mt-2 text-[10px] text-stone-400">
<span>已用 {{ formatCurrency(Math.abs(periodExpense)) }}</span> <span>宸茬敤 {{ formatCurrency(Math.abs(periodExpense)) }}</span>
<span>剩余 {{ formatCurrency(remainingBudget) }}</span> <span> {{ formatCurrency(remainingBudget) }}</span>
</div> </div>
<div class="flex justify-between mt-1 text-[10px] text-stone-400"> <div class="flex justify-between mt-1 text-[10px] text-stone-400">
<span> <span>
@@ -252,18 +240,17 @@ const openTransactionDetail = (tx) => {
class="text-[10px] text-stone-400 underline-offset-2 hover:text-stone-600" class="text-[10px] text-stone-400 underline-offset-2 hover:text-stone-600"
@click="goSettings" @click="goSettings"
> >
去设置 鍘昏? </button>
</button>
</div> </div>
</div> </div>
<div class="grid grid-cols-2 gap-3"> <div class="grid grid-cols-2 gap-3">
<div class="bg-white rounded-2xl p-4 border border-stone-100 shadow-sm"> <div class="bg-white rounded-2xl p-4 border border-stone-100 shadow-sm">
<p class="text-xs text-stone-400 mb-2">今日收入</p> <p class="text-xs text-stone-400 mb-2">浠婃棩鏀跺叆</p>
<p class="text-xl font-bold text-emerald-600">{{ formatCurrency(todayIncomeValue) }}</p> <p class="text-xl font-bold text-emerald-600">{{ formatCurrency(todayIncomeValue) }}</p>
</div> </div>
<div class="bg-white rounded-2xl p-4 border border-stone-100 shadow-sm"> <div class="bg-white rounded-2xl p-4 border border-stone-100 shadow-sm">
<p class="text-xs text-stone-400 mb-2">今日支出</p> <p class="text-xs text-stone-400 mb-2">浠婃棩鏀</p>
<p class="text-xl font-bold text-rose-600">- {{ formatCurrency(todayExpenseValue) }}</p> <p class="text-xl font-bold text-rose-600">- {{ formatCurrency(todayExpenseValue) }}</p>
</div> </div>
</div> </div>
@@ -275,7 +262,7 @@ const openTransactionDetail = (tx) => {
class="text-xs font-bold text-gradient-warm" class="text-xs font-bold text-gradient-warm"
@click="goList" @click="goList"
> >
查看全部 鏌ョ湅鍏ㄩ儴
</button> </button>
</div> </div>
<div v-if="recentTransactions.length" class="space-y-4"> <div v-if="recentTransactions.length" class="space-y-4">
@@ -298,7 +285,7 @@ const openTransactionDetail = (tx) => {
<div> <div>
<p class="font-bold text-stone-800 text-sm">{{ tx.merchant }}</p> <p class="font-bold text-stone-800 text-sm">{{ tx.merchant }}</p>
<p class="text-[11px] text-stone-400"> <p class="text-[11px] text-stone-400">
{{ formatTime(tx.date) }} · {{ tx.category }} {{ formatTime(tx.date) }} {{ getCategoryLabel(tx.category) }}
</p> </p>
</div> </div>
</div> </div>
@@ -313,15 +300,15 @@ const openTransactionDetail = (tx) => {
</div> </div>
</div> </div>
<div v-else class="text-sm text-stone-400 text-center py-4"> <div v-else class="text-sm text-stone-400 text-center py-4">
还没有记录快去添加第一笔消费吧 杩樻病鏈夎褰曪紝蹇幓娣诲姞绗竴绗旀秷璐瑰惂锝?
</div> </div>
</div> </div>
<div class="space-y-3"> <div class="space-y-3">
<div class="flex justify-between items-end"> <div class="flex justify-between items-end">
<h3 class="font-bold text-lg text-stone-700">待确认通知</h3> <h3 class="font-bold text-lg text-stone-700">寰呯璁ら氱煡</h3>
<span class="text-[10px] bg-orange-100 text-orange-600 px-2 py-1 rounded-full font-bold"> <span class="text-[10px] bg-orange-100 text-orange-600 px-2 py-1 rounded-full font-bold">
自动捕获 姩鎹曡幏
</span> </span>
</div> </div>
@@ -341,7 +328,7 @@ const openTransactionDetail = (tx) => {
</div> </div>
<div class="flex-1"> <div class="flex-1">
<h4 class="font-bold text-stone-800 text-sm"> <h4 class="font-bold text-stone-800 text-sm">
{{ notif.channel }} · {{ formatTime(notif.createdAt) }} {{ notif.channel }} {{ formatTime(notif.createdAt) }}
</h4> </h4>
<p class="text-xs text-stone-400 leading-relaxed"> <p class="text-xs text-stone-400 leading-relaxed">
{{ notif.text }} {{ notif.text }}
@@ -353,19 +340,19 @@ const openTransactionDetail = (tx) => {
:disabled="processingId === notif.id" :disabled="processingId === notif.id"
@click="confirmNotification(notif.id)" @click="confirmNotification(notif.id)"
> >
入账 鍏ヨ处
</button> </button>
<button <button
class="text-[11px] text-stone-400" class="text-[11px] text-stone-400"
@click="dismissNotification(notif.id)" @click="dismissNotification(notif.id)"
> >
忽略 蹇界暐
</button> </button>
</div> </div>
</div> </div>
</div> </div>
<div v-else class="text-sm text-stone-400 text-center py-4 border border-dashed border-stone-100 rounded-2xl"> <div v-else class="text-sm text-stone-400 text-center py-4 border border-dashed border-stone-100 rounded-2xl">
暂无新通知享受慢生活 鏆傛棤鏂伴氱煡锛屼韩鍙楁參鐢熸椿 鈽曪笍
</div> </div>
</div> </div>
@@ -383,8 +370,8 @@ const openTransactionDetail = (tx) => {
<i class="ph-fill ph-robot text-xl" /> <i class="ph-fill ph-robot text-xl" />
</div> </div>
<div class="z-10"> <div class="z-10">
<h4 class="font-bold text-stone-700">AI 顾问</h4> <h4 class="font-bold text-stone-700">AI 椤鹃棶</h4>
<p class="text-xs text-stone-400 mt-1">分析我的消费习惯</p> <p class="text-xs text-stone-400 mt-1">鍒嗘瀽鎴戠殑娑堣垂涔犳儻</p>
</div> </div>
</div> </div>
@@ -400,10 +387,13 @@ const openTransactionDetail = (tx) => {
<i class="ph-fill ph-carrot text-xl" /> <i class="ph-fill ph-carrot text-xl" />
</div> </div>
<div class="z-10"> <div class="z-10">
<h4 class="font-bold text-stone-700">热量管理</h4> <h4 class="font-bold text-stone-700">噺绠</h4>
<p class="text-xs text-stone-400 mt-1">今日剩余 750 kcal</p> <p class="text-xs text-stone-400 mt-1">浠婃棩鍓 750 kcal</p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>

View File

@@ -1,6 +1,7 @@
<script setup> <script setup>
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { CATEGORY_CHIPS, getCategoryLabel } from '../config/transactionCategories.js'
import { useTransactionStore } from '../stores/transactions' import { useTransactionStore } from '../stores/transactions'
import { useUiStore } from '../stores/ui' import { useUiStore } from '../stores/ui'
@@ -8,17 +9,7 @@ const transactionStore = useTransactionStore()
const uiStore = useUiStore() const uiStore = useUiStore()
const { groupedTransactions, filters, loading } = storeToRefs(transactionStore) const { groupedTransactions, filters, loading } = storeToRefs(transactionStore)
const deletingId = ref('') const deletingId = ref('')
const categoryChips = CATEGORY_CHIPS
const categoryChips = [
{ label: '全部', value: 'all', icon: 'ph-asterisk' },
{ label: '餐饮', value: 'Food', icon: 'ph-bowl-food' },
{ label: '通勤', value: 'Transport', icon: 'ph-taxi' },
{ label: '健康', value: 'Health', icon: 'ph-heartbeat' },
{ label: '买菜', value: 'Groceries', icon: 'ph-basket' },
{ label: '娱乐', value: 'Entertainment', icon: 'ph-game-controller' },
{ label: '收入', value: 'Income', icon: 'ph-wallet' },
{ label: '其他', value: 'Uncategorized', icon: 'ph-dots-three-outline' },
]
const setCategory = (value) => { const setCategory = (value) => {
filters.value.category = value filters.value.category = value
@@ -29,7 +20,7 @@ const toggleTodayOnly = () => {
} }
const formatAmount = (value) => const formatAmount = (value) =>
`${value >= 0 ? '+' : '-'} ¥${Math.abs(value || 0).toFixed(2)}` `${value >= 0 ? '+' : '-'} ${Math.abs(value || 0).toFixed(2)}`
const formatTime = (value) => const formatTime = (value) =>
new Intl.DateTimeFormat('zh-CN', { hour: '2-digit', minute: '2-digit' }).format( new Intl.DateTimeFormat('zh-CN', { hour: '2-digit', minute: '2-digit' }).format(
@@ -53,8 +44,6 @@ const handleDelete = async (item) => {
} }
const hasData = computed(() => groupedTransactions.value.length > 0) const hasData = computed(() => groupedTransactions.value.length > 0)
transactionStore.ensureInitialized()
</script> </script>
<template> <template>
@@ -114,7 +103,7 @@ transactionStore.ensureInitialized()
<div> <div>
<h4 class="text-sm font-bold text-stone-500">{{ group.label }}</h4> <h4 class="text-sm font-bold text-stone-500">{{ group.label }}</h4>
<p class="text-[10px] text-stone-400"> <p class="text-[10px] text-stone-400">
支出 ¥{{ group.totalExpense.toFixed(2) }} 支出 {{ group.totalExpense.toFixed(2) }}
</p> </p>
</div> </div>
<span class="text-xs text-stone-300 font-bold">{{ group.dayKey }}</span> <span class="text-xs text-stone-300 font-bold">{{ group.dayKey }}</span>
@@ -145,10 +134,10 @@ transactionStore.ensureInitialized()
<p class="text-xs text-stone-400 mt-0.5"> <p class="text-xs text-stone-400 mt-0.5">
{{ formatTime(item.date) }} {{ formatTime(item.date) }}
<span v-if="item.category" class="text-stone-300"> <span v-if="item.category" class="text-stone-300">
· {{ item.category }} {{ getCategoryLabel(item.category) }}
</span> </span>
<span v-if="item.note" class="text-stone-300"> <span v-if="item.note" class="text-stone-300">
· {{ item.note }} {{ item.note }}
</span> </span>
</p> </p>
</div> </div>

View File

@@ -3,6 +3,7 @@ import { computed, onMounted, ref } from 'vue'
import NotificationBridge, { isNativeNotificationBridgeAvailable } from '../lib/notificationBridge' import NotificationBridge, { isNativeNotificationBridgeAvailable } from '../lib/notificationBridge'
import { useSettingsStore } from '../stores/settings' import { useSettingsStore } from '../stores/settings'
import EchoInput from '../components/EchoInput.vue' import EchoInput from '../components/EchoInput.vue'
import { BUDGET_CATEGORY_OPTIONS } from '../config/transactionCategories.js'
// 从 Vite 注入的版本号(来源于 package.json用于在设置页展示 // 从 Vite 注入的版本号(来源于 package.json用于在设置页展示
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
@@ -458,3 +459,4 @@ onMounted(() => {
</div> </div>
</div> </div>
</template> </template>