home_view.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:naiyouwl/app/component/button_select.dart';
  5. import 'package:naiyouwl/app/component/connection_status.dart';
  6. import 'package:naiyouwl/app/component/connection_widget.dart';
  7. import 'package:naiyouwl/app/component/sys_app_bar.dart';
  8. import 'package:naiyouwl/app/controller/controllers.dart';
  9. import 'package:naiyouwl/app/data/model/UserMode.dart';
  10. import 'package:url_launcher/url_launcher.dart';
  11. import '../../../routes/app_pages.dart';
  12. import '../../../utils/shell.dart';
  13. import '../controllers/home_controller.dart';
  14. import '../../connect/views/connect_view.dart';
  15. class HomeView extends GetView<HomeController> {
  16. const HomeView({Key? key}) : super(key: key);
  17. @override
  18. Widget build(BuildContext context) {
  19. return Container(
  20. decoration: const BoxDecoration(
  21. image: DecorationImage(
  22. image: AssetImage("assets/images/main/main.png"),
  23. fit: BoxFit.fill,
  24. ),
  25. ),
  26. child: Scaffold(
  27. backgroundColor: Colors.transparent,
  28. appBar: SysAppBar(title: const Text(""), actions: [
  29. Row(
  30. children: [
  31. IconButton(
  32. icon: const Icon(Icons.refresh),
  33. tooltip: '刷新节点',
  34. onPressed: () {
  35. controller.networkService.fetchNode();
  36. },
  37. ),
  38. IconButton(
  39. onPressed: () {
  40. controller.networkService.outlogin();
  41. },
  42. tooltip: '切换账号',
  43. icon: const Icon(Icons.exit_to_app)
  44. ),
  45. IconButton(
  46. onPressed: () {
  47. Get.toNamed(Routes.CONNECT);
  48. },
  49. tooltip: '连接详情',
  50. icon: const Icon(Icons.info_outline)
  51. )
  52. ],
  53. ),
  54. ],),
  55. body: Obx(() {
  56. if(controller.errAdminMsg.value){
  57. controller.errAdminMsg.value = false;
  58. Future.delayed(Duration.zero, () async {
  59. bool? result = await controllers.dialog.showNormalDialog(
  60. title: "提示",
  61. content: controller.errAdmin.value,
  62. cancelText: "取消",
  63. enterText: "确定",
  64. );
  65. if (result != null && result) {
  66. if(Platform.isWindows){
  67. await onRunAdmin();
  68. }
  69. }
  70. });
  71. }
  72. if (controllers.global.errorMsg.isNotEmpty) {
  73. String message = controllers.global.errorMsg.value;
  74. controllers.global.errorMsg.value = '';
  75. Future.delayed(Duration.zero, () async {
  76. bool? result = await controllers.dialog.showNormalDialog(
  77. title: "提示",
  78. content: message,
  79. cancelText: "取消",
  80. enterText: "确认",
  81. );
  82. if (result != null && result) {
  83. if(controllers.global.statusCode.value == 445){
  84. await launchUrl(Uri.parse(controller.UsersysConfig.value.userBuy ?? ""));
  85. }
  86. }
  87. });
  88. }
  89. return controller.isLoading.value
  90. ? const Center(child: CircularProgressIndicator())
  91. : SingleChildScrollView(
  92. child: Column(
  93. children: [
  94. UserStatusWidget(
  95. isActive: controller.GetEnable(),
  96. isLoading: controller.isLoading.value,
  97. username: controller.GetUserName(),
  98. expiryDate: controller.GetExpiredAt(),
  99. userTraffic: controller.GetTraffic(),
  100. onRefresh: () async {
  101. if (!controller.isLoading.value) {
  102. var userinfo = await controller.networkService.fetchUserinfo();
  103. if(userinfo != null )
  104. {
  105. controller.userMode.value = userinfo;
  106. }
  107. }
  108. },
  109. ),
  110. Padding(
  111. padding: const EdgeInsets.fromLTRB(20, 20, 0, 0),
  112. child: Row(
  113. children: controller.imageMap.entries.expand((entry) {
  114. return [
  115. GestureDetector(
  116. onTap: () => controller.onImageTap(entry.key),
  117. child: Image(
  118. image: AssetImage(entry.value),
  119. width: 60,
  120. height: 60,
  121. ),
  122. ),
  123. const SizedBox(width: 30),
  124. ];
  125. }).toList()..removeLast(),
  126. )
  127. ),
  128. const SizedBox(height: 35,),
  129. Padding(
  130. padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
  131. child: Row(
  132. children: [
  133. Text(controller.getHttp().toString()),
  134. const Spacer(),
  135. Text(controller.getSocket().toString()),
  136. ],
  137. ),
  138. ),
  139. ConnectionWidget(
  140. status: controller.connectStatus.value,
  141. onTap: () {
  142. controller.handleButtonClick();
  143. // if(controller.isConnect.value){
  144. // controller.connectionService.stopConnection();
  145. // } else {
  146. // controller.networkService.fetchAuthUser();
  147. // }
  148. },
  149. ),
  150. Align(
  151. alignment: Alignment.center,
  152. child: Text(controllers.global.msgStatus.value),
  153. ),
  154. const SizedBox(height: 20,),
  155. Padding(
  156. padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
  157. child: SizedBox(
  158. width: 200,
  159. height: 40,
  160. child: ElevatedButton(
  161. onPressed: () {
  162. controller.RouteNode();
  163. },
  164. style: ElevatedButton.styleFrom(
  165. foregroundColor: Colors.black,
  166. backgroundColor: Colors.white,
  167. shape: RoundedRectangleBorder(
  168. borderRadius: BorderRadius.circular(20),
  169. ),
  170. ),
  171. child: Text(controller.GetNode()),
  172. ),
  173. ),
  174. ),
  175. const SizedBox(height: 20,),
  176. Center(
  177. child: Row(
  178. mainAxisAlignment: MainAxisAlignment.center,
  179. children: [
  180. ButtonSelect(
  181. labels: ['setting_mode_rules'.tr,'setting_mode_global'.tr,],
  182. value: controllers.global.modes.indexOf(controllers.global.modesSelect.value),
  183. onSelect: (idx) => {
  184. controllers.global.updateMode(controllers.global.modes[idx])
  185. },
  186. ),
  187. ],
  188. ),
  189. ),
  190. const SizedBox(height: 20,),
  191. Text("版本号:${controllers.global.sysVersion.value}"),
  192. const SizedBox(height: 2,),
  193. if (controllers.global.sysInfo.value.isNotEmpty)
  194. Text("当前:${controllers.global.sysInfo.value}"),
  195. ],
  196. ),
  197. );
  198. })
  199. ),
  200. );
  201. }
  202. }
  203. class UserStatusWidget extends StatelessWidget {
  204. final Future<void> Function() onRefresh;
  205. final bool isActive;
  206. final bool isLoading;
  207. final String username;
  208. final String userTraffic;
  209. final String expiryDate;
  210. const UserStatusWidget({
  211. Key? key,
  212. required this.isActive,
  213. required this.isLoading,
  214. required this.username,
  215. required this.userTraffic,
  216. required this.expiryDate,
  217. required this.onRefresh
  218. }) : super(key: key);
  219. @override
  220. Widget build(BuildContext context) {
  221. return Align(
  222. alignment: Alignment.topCenter,
  223. child: Padding(
  224. padding: const EdgeInsets.fromLTRB(5.0, 0, 5.0, 0.0),
  225. child: Row(
  226. children: [
  227. const SizedBox(width: 80, height: 20),
  228. Column(
  229. crossAxisAlignment: CrossAxisAlignment.start,
  230. children: [
  231. Row(
  232. children: [
  233. Container(
  234. width: 150,
  235. child: Text(
  236. username,
  237. overflow: TextOverflow.ellipsis,
  238. softWrap: false,
  239. maxLines: 1,
  240. ),
  241. ),
  242. const SizedBox(width: 2),
  243. IconButton(
  244. tooltip: '刷新账号状态',
  245. icon: isLoading
  246. ? const CircularProgressIndicator()
  247. : Image(image: AssetImage("assets/images/main/refresh.png"), width: 20, height: 20),
  248. onPressed: () {
  249. if (!isLoading) {
  250. onRefresh();
  251. }
  252. },
  253. )
  254. ],
  255. ),
  256. Text(
  257. expiryDate,
  258. style: const TextStyle(fontSize: 12.0),
  259. ),
  260. Text(
  261. userTraffic,
  262. style: const TextStyle(fontSize: 12.0),
  263. )
  264. ],
  265. ),
  266. ],
  267. ),
  268. ),
  269. );
  270. }
  271. }
  272. /*
  273. const SizedBox(width: 20),
  274. if (Platform.isMacOS)
  275. ElevatedButton(
  276. onPressed: () async {
  277. if (controllers.cc_service.installStatus.value) {
  278. if(!controller.isRunning)
  279. {
  280. await controller.connectionService.UninstallService();
  281. } else {
  282. controllers.global.errorMsg.value = "先停止连接,在尝试";
  283. }
  284. } else {
  285. if(!controller.isRunning)
  286. {
  287. await controller.connectionService.installService();
  288. } else {
  289. controllers.global.errorMsg.value = "先停止连接,在尝试";
  290. }
  291. }
  292. // await controller.connectionService.checkServiceInstallation();
  293. },
  294. child: Text(controllers.cc_service.installStatus.value ? '卸载���务' : '安装服务'),
  295. ),
  296. */