From 63c4485141740f157749bda1e7892cce154ee300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz?= Date: Sun, 17 Dec 2023 15:10:41 +0800 Subject: [PATCH] Panel Info --- lib/controller.dart | 32 +++++++++ lib/main.dart | 2 + lib/ui/auth/login.dart | 7 +- lib/ui/auth/register.dart | 2 +- lib/ui/home.dart | 7 +- lib/ui/model/AppbarActions.dart | 10 +-- lib/ui/model/ToolDialog.dart | 6 +- lib/ui/panel/home.dart | 112 +++++++++++++++++++++----------- lib/util/FileIO.dart | 5 +- lib/util/cache/InfoCache.dart | 28 +++++--- lib/util/dio/auth/login.dart | 6 +- lib/util/dio/frpc/download.dart | 1 + lib/util/model/User.dart | 49 ++++++-------- 13 files changed, 173 insertions(+), 94 deletions(-) create mode 100644 lib/controller.dart diff --git a/lib/controller.dart b/lib/controller.dart new file mode 100644 index 00000000..a785ee08 --- /dev/null +++ b/lib/controller.dart @@ -0,0 +1,32 @@ +import 'package:get/get.dart'; +import 'package:nyalcf/util/cache/InfoCache.dart'; +import 'package:nyalcf/util/model/User.dart'; + +class Controller extends GetxController { + var user = "".obs; + var email = "".obs; + var token = "".obs; + var avatar = "".obs; + var inbound = 0.obs; + var outbound = 0.obs; + + var welcomeText = "好".obs; + + load() async { + User userinfo = await InfoCache.getInfo(); + user.value = userinfo.user; + email.value = userinfo.email; + token.value = userinfo.token; + avatar.value = userinfo.avatar; + inbound.value = userinfo.inbound; + outbound.value = userinfo.outbound; + + int hour = DateTime.now().hour; + + if (hour <= 12) { + welcomeText.value = "上午好"; + } else { + welcomeText.value = "下午好"; + } + } +} diff --git a/lib/main.dart b/lib/main.dart index 86216abe..25bd67a8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:nyalcf/controller.dart'; import 'package:nyalcf/ui/auth/login.dart'; import 'package:nyalcf/ui/auth/register.dart'; import 'package:nyalcf/ui/home.dart'; @@ -26,6 +27,7 @@ class App extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { + Get.put(Controller()); return GetMaterialApp( title: 'NyaLCF', routes: { diff --git a/lib/ui/auth/login.dart b/lib/ui/auth/login.dart index 39b675a3..9939df94 100644 --- a/lib/ui/auth/login.dart +++ b/lib/ui/auth/login.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:get/get.dart'; import 'package:nyalcf/util/cache/InfoCache.dart'; import 'package:nyalcf/util/dio/auth/login.dart'; import 'package:nyalcf/ui/model/AppbarActions.dart'; @@ -45,7 +46,7 @@ class _LoginState extends State { constraints: const BoxConstraints(maxWidth: 400.0), child: Column(children: [ const Text( - "登录到LocyanFrp", + "登录到LoCyanFrp", style: TextStyle(fontSize: 30), ), Form( @@ -107,9 +108,9 @@ class _LoginState extends State { //print(UserInfoCache.info); await InfoCache.setInfo(res); ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text('登录成功,欢迎您 ${res.UserName}'), + content: Text('登录成功,欢迎您 ${res.user}'), )); - Navigator.of(context).pushNamed("/panel/home"); + Get.toNamed("/panel/home"); } else { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text('登陆失败:${res}'), diff --git a/lib/ui/auth/register.dart b/lib/ui/auth/register.dart index 7d651c7f..5aa83dbf 100644 --- a/lib/ui/auth/register.dart +++ b/lib/ui/auth/register.dart @@ -32,7 +32,7 @@ class _RegisterState extends State { constraints: const BoxConstraints(maxWidth: 400.0), child: Column(children: [ const Text( - "注册LocyanFrp账户", + "注册LoCyanFrp账户", style: TextStyle(fontSize: 30), ), Form( diff --git a/lib/ui/home.dart b/lib/ui/home.dart index 778c9718..cb9ed243 100644 --- a/lib/ui/home.dart +++ b/lib/ui/home.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:get/get.dart'; import 'package:nyalcf/ui/model/FloatingActionButton.dart'; import 'model/AppbarActions.dart'; @@ -34,15 +35,13 @@ class Home extends StatelessWidget { Container( margin: const EdgeInsets.all(8.0), child: ElevatedButton( - onPressed: () => - Navigator.of(context).pushNamed("/login"), + onPressed: () => Get.toNamed("/login"), child: const Text("登录")), ), Container( margin: const EdgeInsets.all(8.0), child: ElevatedButton( - onPressed: () => - Navigator.of(context).pushNamed("/register"), + onPressed: () => Get.toNamed("/register"), child: const Text("注册"))), ], ), diff --git a/lib/ui/model/AppbarActions.dart b/lib/ui/model/AppbarActions.dart index 4a20c669..124e8f34 100644 --- a/lib/ui/model/AppbarActions.dart +++ b/lib/ui/model/AppbarActions.dart @@ -1,9 +1,13 @@ import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:nyalcf/controller.dart'; class AppbarActions { AppbarActions({required this.context}); + final Controller c = Get.find(); + final context; List list() { @@ -22,11 +26,9 @@ class AppbarActions { } List actions({List? append}) { - List l = list(); - if (append != null) { - return l; - } + List l = []; l.addAll(append ?? []); + l.addAll(list()); return l; } diff --git a/lib/ui/model/ToolDialog.dart b/lib/ui/model/ToolDialog.dart index 73bf6636..ba29e951 100644 --- a/lib/ui/model/ToolDialog.dart +++ b/lib/ui/model/ToolDialog.dart @@ -11,7 +11,7 @@ class ToolDialog { title: const Text("请问您今天想做点什么?"), children: [ SimpleDialogOption( - child: const Text("LocyanFrp Website"), + child: const Text("LoCyanFrp Website"), onPressed: () async { const url = 'https://www.locyanfrp.cn'; if (!await launchUrl(Uri.parse(url))) { @@ -22,7 +22,7 @@ class ToolDialog { } }), SimpleDialogOption( - child: const Text("LocyanFrp Dashboard"), + child: const Text("LoCyanFrp Dashboard"), onPressed: () async { const url = 'https://dashboard.locyanfrp.cn'; if (!await launchUrl(Uri.parse(url))) { @@ -33,7 +33,7 @@ class ToolDialog { } }), SimpleDialogOption( - child: const Text("LocyanFrp Dashboard (Preview)"), + child: const Text("LoCyanFrp Dashboard (Preview)"), onPressed: () async { const url = 'https://preview.locyanfrp.cn'; if (!await launchUrl(Uri.parse(url))) { diff --git a/lib/ui/panel/home.dart b/lib/ui/panel/home.dart index 170a48ca..d513af93 100644 --- a/lib/ui/panel/home.dart +++ b/lib/ui/panel/home.dart @@ -1,21 +1,18 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:nyalcf/ui/model/FloatingActionButton.dart'; -import 'package:nyalcf/util/cache/InfoCache.dart'; -import 'package:nyalcf/util/model/User.dart'; +import 'package:nyalcf/controller.dart'; import '../model/AppbarActions.dart'; class PanelHome extends StatelessWidget { - const PanelHome({super.key, required this.title}); + PanelHome({super.key, required this.title}); + final Controller c = Get.find(); final String title; @override Widget build(BuildContext context) { - - // GetX - final Controller c = Get.put(Controller()); c.load(); return Scaffold( @@ -25,41 +22,78 @@ class PanelHome extends StatelessWidget { backgroundColor: Colors.pink[100], automaticallyImplyLeading: false, actions: AppbarActions(context: context).actions(append: [ - IconButton( - onPressed: () => {}, - icon: ImageIcon(Image.network("").image), - color: Colors.white, - ), + Obx( + () => IconButton( + onPressed: () => {}, + icon: ImageIcon( + Image.network("${c.avatar}").image, + ), + ), + ) ]), ), - body: Center( - child: Container( - margin: const EdgeInsets.all(40.0), - child: Column( - children: [ - Obx(() => Text( - "${c.user}", - style: TextStyle(fontSize: 30), - )) - ], - ), - ), - ), + body: ListView(children: [ + Container( + margin: const EdgeInsets.all(40.0), + child: Container( + child: Column( + children: [ + Obx(() => Text( + "指挥官 ${c.user},${c.welcomeText}喵!", + style: TextStyle(fontSize: 15), + )), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Card( + child: Column( + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ListTile( + leading: Icon(Icons.info), + title: Text("指挥官信息"), + ), + Container( + margin: EdgeInsets.only( + left: 15.0, right: 15.0, bottom: 15.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Obx(() => Text("用户名:${c.user}")), + Obx(() => Text("邮箱:${c.email}")), + Obx(() => Text( + "限制速率:${c.inbound / 1024 * 8}Mbps/${c.outbound / 1024 * 8}Mbps")), + //Obx(() => Text("")) + ], + ), + ) + ], + ), + )), + Expanded( + child: Card( + child: Column( + children: [ + ListTile( + leading: Icon(Icons.announcement), + title: Text("公告"), + ), + Container( + margin: EdgeInsets.only(bottom: 15.0), + child: Text("看什么看,偷懒没写!(")), + ], + ), + )), + ], + ), + ], + ), + )), + ]), floatingActionButton: FloatingActionButtonX().button()); } } - -class Controller extends GetxController { - var user = "".obs; - var email = "".obs; - var token = "".obs; - var avatar = "".obs; - - load() async { - User userinfo = await InfoCache.getInfo(); - user = userinfo.user.obs; - email = userinfo.email.obs; - token = userinfo.token.obs; - avatar = userinfo.avatar.obs; - } -} diff --git a/lib/util/FileIO.dart b/lib/util/FileIO.dart index 7401063d..adea72e8 100644 --- a/lib/util/FileIO.dart +++ b/lib/util/FileIO.dart @@ -4,7 +4,6 @@ import 'dart:io'; import 'package:path_provider/path_provider.dart'; class FileIO { - final _support_path = getApplicationSupportDirectory(); final _cache_path = getApplicationCacheDirectory(); @@ -12,6 +11,7 @@ class FileIO { final File file = new File("${await _support_path}/$fi"); await file.writeAsString(data); } + Future readDataFromFile(String fi) async { final File file = new File("${await _support_path}/$fi"); return await file.readAsString(encoding: utf8); @@ -21,6 +21,7 @@ class FileIO { final File file = new File("${await _cache_path}/$fi"); await file.writeAsString(data); } + Future readCache(String fi, String data) async { final File file = new File("${_cache_path}/$fi"); return await file.readAsString(encoding: utf8); @@ -29,4 +30,4 @@ class FileIO { Future get cache_path { return _cache_path; } -} \ No newline at end of file +} diff --git a/lib/util/cache/InfoCache.dart b/lib/util/cache/InfoCache.dart index d65d54de..a3dc2ba8 100644 --- a/lib/util/cache/InfoCache.dart +++ b/lib/util/cache/InfoCache.dart @@ -3,27 +3,37 @@ import 'package:shared_preferences/shared_preferences.dart'; import '../model/User.dart'; class InfoCache { - static Future setInfo(User userinfo) async { SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setString("user_name", userinfo.user); prefs.setString("user_email", userinfo.email); prefs.setString("user_token", userinfo.token); prefs.setString("user_avatar", userinfo.avatar); + prefs.setInt("user_inbound", userinfo.inbound); + prefs.setInt("user_outbound", userinfo.outbound); + prefs.setString("user_frp_token", userinfo.frp_token); + prefs.setInt("user_traffic", userinfo.traffic); } static Future getInfo() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - String user = prefs.getString("user_name") ?? ""; - String email = prefs.getString("user_email") ?? ""; - String token = prefs.getString("user_token") ?? ""; + String user = prefs.getString("user_name") ?? ""; + String email = prefs.getString("user_email") ?? ""; + String token = prefs.getString("user_token") ?? ""; String avatar = prefs.getString("user_avatar") ?? ""; + int inbound = prefs.getInt("user_inbound") ?? 0; + int outbound = prefs.getInt("user_outbound") ?? 0; + String frp_token = prefs.getString("user_frp_token") ?? ""; + int traffic = prefs.getInt("user_traffic") ?? 0; return User( - user: user, - email: email, - token: token, - avatar: avatar - ); + user: user, + email: email, + token: token, + avatar: avatar, + inbound: inbound, + outbound: outbound, + frp_token: frp_token, + traffic: traffic); } static void reset() { diff --git a/lib/util/dio/auth/login.dart b/lib/util/dio/auth/login.dart index 174f828c..b4a38829 100644 --- a/lib/util/dio/auth/login.dart +++ b/lib/util/dio/auth/login.dart @@ -20,7 +20,11 @@ class LoginDio { user: resData["username"], email: resData["email"], token: resData["token"], - avatar: resData["avatar"]); + avatar: resData["avatar"], + inbound: resData['inbound'], + outbound: resData['outbound'], + frp_token: resData['frp_token'], + traffic: resData['traffic']); return userInfo; } else { return resData["msg"] ?? responseJson["status"]; diff --git a/lib/util/dio/frpc/download.dart b/lib/util/dio/frpc/download.dart index e69de29b..8b137891 100644 --- a/lib/util/dio/frpc/download.dart +++ b/lib/util/dio/frpc/download.dart @@ -0,0 +1 @@ + diff --git a/lib/util/model/User.dart b/lib/util/model/User.dart index 85b3d4e2..5d796589 100644 --- a/lib/util/model/User.dart +++ b/lib/util/model/User.dart @@ -3,35 +3,28 @@ class User { {required this.user, required this.email, required this.token, - required this.avatar}); + required this.avatar, + required this.inbound, + required this.outbound, + required this.frp_token, + required this.traffic}); - final user; - final email; - final token; - final avatar; + final String user; + final String email; + final String token; + final String avatar; + final int inbound; + final int outbound; + final String frp_token; + final int traffic; - String get Token { - return token; - } - - String get Email { - return email; - } - - String get UserName { - return user; - } - - String get Avatar { - return avatar; - } - - /* User.fromJson(Map json) - : user = json['username'], - token = json['token'], - email = json['email'], - avatar = json['avatar']; - - */ + : user = json['username'], + token = json['token'], + email = json['email'], + avatar = json['avatar'], + inbound = json['inbound'], + outbound = json['outbound'], + frp_token = json['frp_token'], + traffic = json['traffic']; }