200 lines
4.2 KiB
Dart
200 lines
4.2 KiB
Dart
import '../models/record.dart';
|
||
|
||
/// 分类配置
|
||
class CategoryConfig {
|
||
static const Map<String, Map<String, dynamic>> expenseCategories = {
|
||
'food': {
|
||
'name': '餐饮',
|
||
'iconKey': 'food',
|
||
'sortOrder': 0,
|
||
},
|
||
'shopping': {
|
||
'name': '购物',
|
||
'iconKey': 'shopping',
|
||
'sortOrder': 1,
|
||
},
|
||
'transport': {
|
||
'name': '交通',
|
||
'iconKey': 'transport',
|
||
'sortOrder': 2,
|
||
},
|
||
'entertainment': {
|
||
'name': '娱乐',
|
||
'iconKey': 'entertainment',
|
||
'sortOrder': 3,
|
||
},
|
||
'housing': {
|
||
'name': '住房',
|
||
'iconKey': 'housing',
|
||
'sortOrder': 4,
|
||
},
|
||
'utilities': {
|
||
'name': '水电',
|
||
'iconKey': 'utilities',
|
||
'sortOrder': 5,
|
||
},
|
||
'medical': {
|
||
'name': '医疗',
|
||
'iconKey': 'medical',
|
||
'sortOrder': 6,
|
||
},
|
||
'education': {
|
||
'name': '教育',
|
||
'iconKey': 'education',
|
||
'sortOrder': 7,
|
||
},
|
||
'clothing': {
|
||
'name': '服饰',
|
||
'iconKey': 'clothing',
|
||
'sortOrder': 8,
|
||
},
|
||
'travel': {
|
||
'name': '旅行',
|
||
'iconKey': 'travel',
|
||
'sortOrder': 9,
|
||
},
|
||
'sports': {
|
||
'name': '运动',
|
||
'iconKey': 'sports',
|
||
'sortOrder': 10,
|
||
},
|
||
'beauty': {
|
||
'name': '美容',
|
||
'iconKey': 'beauty',
|
||
'sortOrder': 11,
|
||
},
|
||
'digital': {
|
||
'name': '数码',
|
||
'iconKey': 'digital',
|
||
'sortOrder': 12,
|
||
},
|
||
'pets': {
|
||
'name': '宠物',
|
||
'iconKey': 'pets',
|
||
'sortOrder': 13,
|
||
},
|
||
'gifts': {
|
||
'name': '礼物',
|
||
'iconKey': 'gifts',
|
||
'sortOrder': 14,
|
||
},
|
||
'books': {
|
||
'name': '书籍',
|
||
'iconKey': 'books',
|
||
'sortOrder': 15,
|
||
},
|
||
'insurance': {
|
||
'name': '保险',
|
||
'iconKey': 'insurance',
|
||
'sortOrder': 16,
|
||
},
|
||
'children': {
|
||
'name': '育儿',
|
||
'iconKey': 'children',
|
||
'sortOrder': 17,
|
||
},
|
||
'social': {
|
||
'name': '社交',
|
||
'iconKey': 'social',
|
||
'sortOrder': 18,
|
||
},
|
||
'car': {
|
||
'name': '汽车',
|
||
'iconKey': 'car',
|
||
'sortOrder': 19,
|
||
},
|
||
};
|
||
|
||
static const Map<String, Map<String, dynamic>> incomeCategories = {
|
||
'salary': {
|
||
'name': '工资',
|
||
'iconKey': 'salary',
|
||
'sortOrder': 0,
|
||
},
|
||
'bonus': {
|
||
'name': '奖金',
|
||
'iconKey': 'bonus',
|
||
'sortOrder': 1,
|
||
},
|
||
'investment': {
|
||
'name': '投资',
|
||
'iconKey': 'investment',
|
||
'sortOrder': 2,
|
||
},
|
||
'partTime': {
|
||
'name': '兼职',
|
||
'iconKey': 'partTime',
|
||
'sortOrder': 3,
|
||
},
|
||
'dividend': {
|
||
'name': '分红',
|
||
'iconKey': 'dividend',
|
||
'sortOrder': 4,
|
||
},
|
||
'rental': {
|
||
'name': '租金',
|
||
'iconKey': 'rental',
|
||
'sortOrder': 5,
|
||
},
|
||
'refund': {
|
||
'name': '报销',
|
||
'iconKey': 'refund',
|
||
'sortOrder': 6,
|
||
},
|
||
'lottery': {
|
||
'name': '中奖',
|
||
'iconKey': 'lottery',
|
||
'sortOrder': 7,
|
||
},
|
||
'gifts_received': {
|
||
'name': '礼金',
|
||
'iconKey': 'gifts_received',
|
||
'sortOrder': 8,
|
||
},
|
||
'pension': {
|
||
'name': '养老金',
|
||
'iconKey': 'pension',
|
||
'sortOrder': 9,
|
||
},
|
||
'interest': {
|
||
'name': '利息',
|
||
'iconKey': 'interest',
|
||
'sortOrder': 10,
|
||
},
|
||
'business': {
|
||
'name': '经营',
|
||
'iconKey': 'business',
|
||
'sortOrder': 11,
|
||
},
|
||
'royalties': {
|
||
'name': '版权',
|
||
'iconKey': 'royalties',
|
||
'sortOrder': 12,
|
||
},
|
||
};
|
||
|
||
/// 获取分类配置
|
||
static List<Category> getCategoriesByType(RecordType type) {
|
||
final map = type == RecordType.expense ? expenseCategories : incomeCategories;
|
||
return map.entries.map((entry) => Category(
|
||
id: entry.key,
|
||
name: entry.value['name'],
|
||
iconKey: entry.value['iconKey'],
|
||
type: type,
|
||
sortOrder: entry.value['sortOrder'],
|
||
)).toList()
|
||
..sort((a, b) => a.sortOrder.compareTo(b.sortOrder));
|
||
}
|
||
|
||
/// 转换为JSON格式,方便存储和同步
|
||
static Map<String, dynamic> toJson() => {
|
||
'expense': expenseCategories,
|
||
'income': incomeCategories,
|
||
};
|
||
|
||
/// 从JSON格式转换回对象
|
||
static CategoryConfig fromJson(Map<String, dynamic> json) {
|
||
// TODO: 实现从JSON恢复配置的逻辑
|
||
return CategoryConfig();
|
||
}
|
||
} |