home_view.dart 11 KB

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