Skip to content

Commit f818fba

Browse files
committed
feature:note
1 parent eee77ea commit f818fba

File tree

24 files changed

+1037
-147
lines changed

24 files changed

+1037
-147
lines changed

devtools_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: This file stores settings for Dart & Flutter DevTools.
2+
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
3+
extensions:

lib/src/navigation/model/app_tab.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ enum AppTab {
1515
final IconData icon;
1616
final String path;
1717

18+
static List<AppTab> get mobileTabs => [
19+
widgets,
20+
painter,
21+
knowledge,
22+
note,
23+
mine
24+
];
25+
1826
const AppTab(this.path, this.icon);
1927

2028
String label(AppL10n l10n) {
@@ -34,7 +42,7 @@ enum AppTab {
3442
AppTab.knowledge => l10n.mobileTabKnowledge,
3543
AppTab.tools => l10n.mobileTabTools,
3644
AppTab.mine => l10n.mobileTabMine,
37-
AppTab.note => '匠心巧记',
45+
AppTab.note => '巧记',
3846
};
3947
}
4048

lib/src/navigation/router/widgets/collection_route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ GoRoute get collectRoute => GoRoute(
1313

1414
GoRoute get noteRoute => GoRoute(
1515
path: AppRoute.note.path,
16-
builder: (_, __) => const ArticleAdmin(),
16+
builder: (_, __) => ArtSysScope(child: const ArticleAdmin()),
1717
// routes: [
1818
// GoRoute(path: AppRoute.collectionDetail.path, builder: collectionDetailBuilder),
1919
// ],

lib/src/navigation/view/mobile/pure_bottom_bar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class PureBottomBar extends StatelessWidget {
3131
showUnselectedLabels: true,
3232
showSelectedLabels: true,
3333
// backgroundColor: themeColor.itemColor,
34-
items: AppTab.values
34+
items: AppTab.mobileTabs
3535
.map((AppTab tab) => BottomNavigationBarItem(
3636
label: tab.label(l10n),
3737
icon: Icon(tab.icon),

lib/src/navigation/view/mobile/unit_navigation.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:flutter_unit/src/navigation/model/app_tab.dart';
1212
import 'package:treasure_tools/treasure_tools.dart';
1313
import 'package:widget_module/blocs/blocs.dart';
1414
import 'package:widget_module/widget_module.dart';
15-
15+
import 'package:note/note.dart';
1616
import 'pure_bottom_bar.dart';
1717

1818
/// create by 张风捷特烈 on 2020-04-11
@@ -63,7 +63,8 @@ class _UnitPhoneNavigationState extends State<UnitPhoneNavigation> {
6363
StandardHomePage(),
6464
GalleryUnit(),
6565
AlgoScope(child: ArtifactPage()),
66-
MobileToolPage(),
66+
ArtSysScope(child: MobileArticlePage()),
67+
// MobileToolPage(),
6768
UserPage(),
6869
],
6970
),

lib/src/starter/bridge/unit_bridge.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import 'package:app/app.dart';
66
class UnitNoteBridge with NoteModuleBridge{
77

88
@override
9-
Host get host => FxDio()<ScienceHostPure>();
9+
Host get host => FxDio()<LightServerHost>();
1010
}

modules/basic_system/app/lib/http/register.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import 'http.dart';
33

44
void registerHttpClient(){
55
FxDio().register(const ScienceHost(), repInterceptor: ScienceRepInterceptor());
6-
FxDio().register(const ScienceHostPure());
6+
FxDio().register(const LightServerHost());
77
FxDio().register(const UnitHost());
88
}

modules/basic_system/app/lib/http/science/science_host.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class ScienceHost extends Host {
2121
}
2222

2323

24-
class ScienceHostPure extends Host {
25-
const ScienceHostPure();
24+
class LightServerHost extends Host {
25+
const LightServerHost();
2626

2727
@override
2828
Map<HostEnv, String> get value => {
29-
HostEnv.release: 'toly1994.com',
30-
HostEnv.dev: '172.26.16.1',
29+
HostEnv.release: '82.157.176.209',
30+
HostEnv.dev: '127.0.0.1',
3131
};
3232

3333
@override
@@ -38,7 +38,7 @@ class ScienceHostPure extends Host {
3838
);
3939

4040
@override
41-
HostEnv get env => HostEnv.dev;
41+
HostEnv get env => HostEnv.release;
4242
}
4343

4444
enum ScienceApi {
Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,155 @@
1-
// TODO Implement this library.
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_bloc/flutter_bloc.dart';
3+
import 'package:fx_dio/fx_dio.dart';
4+
import 'package:note/src/repository/article_repository.dart';
5+
import 'package:note/src/repository/model/article.dart';
6+
7+
import '../repository/model/model.dart';
8+
9+
class ArtSysBloc extends Cubit<ArtSysState> {
10+
ArtSysBloc() : super(ArtSysState(articles: []));
11+
12+
ArticleRepository _repository = HttpArticleRepository();
13+
14+
TextEditingController titleCtrl = TextEditingController();
15+
TextEditingController ctrl = TextEditingController();
16+
17+
Future<void> loadFirstFrame() async {
18+
if(state.articles.isEmpty){
19+
emit(state.copyWith(status: const LoadingStatus()));
20+
}
21+
ApiRet<PaginateList<ArticlePo>> ret = await _repository.list(SizeFilter());
22+
if (ret.success) {
23+
ArtSysState newState = state.copyWith(
24+
articles: ret.data.list,
25+
status: SuccessStatus(ret.data.total),
26+
);
27+
emit(newState);
28+
_openCurrent();
29+
return;
30+
}
31+
print(ret.trace?.toString());
32+
ArtSysState newState = state.copyWith(
33+
status: FailedStatus(ret.trace?.error, ret.trace?.stack),
34+
);
35+
emit(newState);
36+
}
37+
38+
void _openCurrent() {
39+
int? id = state.active?.id;
40+
if (id != null) {
41+
open(id);
42+
}
43+
}
44+
45+
Future<void> newArticle() async {
46+
await _repository.create(
47+
ArticleCreatePayload(
48+
subtitle: '',
49+
title: '新建文档',
50+
url: '',
51+
cover: '',
52+
type: 1,
53+
createAt: DateTime.timestamp().toIso8601String(),
54+
),
55+
);
56+
await loadFirstFrame();
57+
}
58+
59+
void select(ArticlePo article) {
60+
if (article.type == 1) {
61+
open(article.id);
62+
} else {}
63+
titleCtrl.text = article.title;
64+
emit(state.copyWith(active: article));
65+
}
66+
67+
void open(int id) async {
68+
ApiRet<String> ret = await _repository.open(id);
69+
if (ret.success) {
70+
ctrl.text = ret.data;
71+
}
72+
}
73+
74+
void write(String content) async {
75+
int? id = state.active?.id;
76+
if (id != null) {
77+
ApiRet<bool> ret = await _repository.write(id, content);
78+
}
79+
}
80+
81+
void updateTitleV2() {
82+
ArticlePo? article = state.active;
83+
String title = titleCtrl.text;
84+
if (article != null) {
85+
updateTitle(article, title);
86+
}
87+
}
88+
89+
void updateTitle(ArticlePo article, String title) async {
90+
if (title == article.title) return;
91+
ApiRet<ArticlePo> ret = await _repository.update(
92+
article.id, ArticleUpdatePayload(title: title));
93+
if (ret.success) {
94+
open(article.id);
95+
loadFirstFrame();
96+
titleCtrl.text = ret.data.title;
97+
} else {
98+
print(ret.trace?.error);
99+
}
100+
}
101+
102+
Future<void> delete() async{
103+
int? id = state.active?.id;
104+
if (id != null) {
105+
ApiRet<bool> ret = await _repository.delete(id);
106+
await loadFirstFrame();
107+
108+
}
109+
110+
}
111+
}
112+
113+
sealed class ListStatus {
114+
const ListStatus();
115+
}
116+
117+
class LoadingStatus extends ListStatus {
118+
const LoadingStatus();
119+
}
120+
121+
class SuccessStatus extends ListStatus {
122+
final int total;
123+
124+
const SuccessStatus(this.total);
125+
}
126+
127+
class FailedStatus extends ListStatus {
128+
final Object? error;
129+
final StackTrace? trace;
130+
131+
const FailedStatus(this.error, [this.trace]);
132+
}
133+
134+
class ArtSysState {
135+
final List<ArticlePo> articles;
136+
final ArticlePo? active;
137+
final ListStatus status;
138+
139+
ArtSysState(
140+
{required this.articles,
141+
this.active,
142+
this.status = const LoadingStatus()});
143+
144+
ArtSysState copyWith({
145+
List<ArticlePo>? articles,
146+
ArticlePo? active,
147+
ListStatus? status,
148+
}) {
149+
return ArtSysState(
150+
articles: articles ?? this.articles,
151+
active: active ?? this.active,
152+
status: status ?? this.status,
153+
);
154+
}
155+
}

modules/knowledge_system/note/lib/src/repository/article_repository.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:convert';
2+
13
import 'package:fx_dio/fx_dio.dart';
24

35
import '../env/env.dart';
@@ -17,6 +19,8 @@ abstract class ArticleRepository {
1719
Future<ApiRet<bool>> delete(int id);
1820

1921
Future<ApiRet<ArticlePo>> update(int id,ArticleUpdatePayload payload);
22+
23+
Future<ApiRet<Hierarchy>> loadArticleTree();
2024
}
2125

2226
class HttpArticleRepository implements ArticleRepository {
@@ -89,4 +93,14 @@ class HttpArticleRepository implements ArticleRepository {
8993
},
9094
);
9195
}
96+
97+
@override
98+
Future<ApiRet<Hierarchy>> loadArticleTree() {
99+
return host.get<Hierarchy>(
100+
'/category',
101+
convertor: (rep) {
102+
return Hierarchy.fromJson(rep['data']);
103+
},
104+
);
105+
}
92106
}

modules/knowledge_system/note/lib/src/repository/model/article.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import 'package:intl/intl.dart';
2+
3+
4+
DateFormat _noteTimeShort = DateFormat('yyyy/M/d');
5+
DateFormat _noteTimeLong = DateFormat('yyyy/M/d HH:mm:ss');
6+
Duration offset = DateTime.now().timeZoneOffset;
7+
18
class ArticlePo {
29
final String title;
310
final String? subtitle;
@@ -21,6 +28,15 @@ class ArticlePo {
2128
this.id = -1,
2229
});
2330

31+
String get updateDate {
32+
return _noteTimeLong.format(DateTime.fromMillisecondsSinceEpoch(update).add(offset));
33+
}
34+
35+
36+
String get createDate =>
37+
_noteTimeShort.format(DateTime.fromMillisecondsSinceEpoch(create).add(offset));
38+
39+
2440
factory ArticlePo.fromApi(dynamic map) => ArticlePo(
2541
id: map['article_id'] ?? 0,
2642
title: map['title'] ?? '',
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Hierarchy {
2+
final int cateId;
3+
final String name;
4+
final int cateType;
5+
final int priority;
6+
final List<Hierarchy> children;
7+
8+
Hierarchy({
9+
required this.cateId,
10+
required this.name,
11+
this.cateType = 0,
12+
this.priority = 0,
13+
this.children = const [],
14+
});
15+
16+
factory Hierarchy.fromJson(Map<String, dynamic> json) {
17+
return Hierarchy(
18+
cateId: json['cate_id'] as int,
19+
name: json['name'] as String,
20+
cateType: json['cate_type'] as int? ?? 0,
21+
priority: json['priority'] as int? ?? 0,
22+
children: (json['children'] as List<dynamic>?)
23+
?.map((child) => Hierarchy.fromJson(child))
24+
.toList() ??
25+
[],
26+
);
27+
}
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export 'status.dart';
22
export 'article.dart';
3+
export 'category.dart';
34
export 'query.dart';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_bloc/flutter_bloc.dart';
3+
import 'package:note/note.dart';
4+
5+
class ArtSysScope extends StatelessWidget {
6+
final Widget child;
7+
8+
const ArtSysScope({super.key, required this.child});
9+
10+
@override
11+
Widget build(BuildContext context) {
12+
return BlocProvider<ArtSysBloc>(
13+
create: (_) => ArtSysBloc()..loadFirstFrame(),
14+
child: child,
15+
);
16+
}
17+
}

0 commit comments

Comments
 (0)