home_page.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import 'package:deus_app/common/local/StoreHelper.dart';
  2. import 'package:deus_app/common/utils/ConstantString.dart';
  3. import 'package:deus_app/common/utils/DioUtil.dart';
  4. import 'package:deus_app/common/utils/ToastUtils.dart';
  5. import 'package:deus_app/generated/json/personal_data_count_entity_helper.dart';
  6. import 'package:deus_app/model/personal_data_count_entity.dart';
  7. import 'package:deus_app/model/user_response_entity.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:flutter/services.dart';
  10. class HomePage extends StatefulWidget {
  11. static var routeName = '/HomePage';
  12. List<UserAppResponseDataUserMenuList> userResponseEntity;
  13. HomePage({super.key,required this.userResponseEntity});
  14. @override
  15. _MineViewPageState createState() => _MineViewPageState();
  16. }
  17. class _MineViewPageState extends State<HomePage> {
  18. List items = [
  19. {"name": "今日维保任务", "num": 0},
  20. {"name": "今日巡检任务", "num": 0}
  21. ];
  22. // List icons = [
  23. // {
  24. // "name": "设备管理",
  25. // "image": "images/device_manage.png",
  26. // 'jump': DeviceManagePage.routeName
  27. // },
  28. // {
  29. // "name": "维保任务",
  30. // "image": "images/maintenance.png",
  31. // 'jump': MaintJobPage.routeName
  32. // },
  33. // {
  34. // "name": "巡检任务",
  35. // "image": "images/patrol_inspect.png",
  36. // 'jump': PatrolJobPage.routeName
  37. // },
  38. // {
  39. // "name": "报修管理",
  40. // "image": "images/maintenance_manage.png",
  41. // 'jump': RepairPage.routeName
  42. // },
  43. // ];
  44. int alarmCount = 0;
  45. @override
  46. void initState() {
  47. super.initState();
  48. fetchAlbum();
  49. }
  50. fetchAlbum() async {
  51. var result =
  52. await DioUtil().request("personalData/count", method: DioMethod.post);
  53. PersonalDataCountEntity entity =
  54. personalDataCountEntityFromJson(PersonalDataCountEntity(), result);
  55. if (entity.code == 0) {
  56. setState(() {
  57. items.clear();
  58. items.add({"name": "今日维保任务", "num": entity.data.maintJobCount});
  59. items.add({"name": "今日巡检任务", "num": entity.data.patrolJobCount});
  60. alarmCount = entity.data.alarmCount;
  61. });
  62. } else {
  63. showToast(entity.msg);
  64. }
  65. }
  66. void registerHandler() {}
  67. @override
  68. Widget build(BuildContext context) {
  69. DateTime? _dateTime;//上次点击的时间
  70. return WillPopScope(
  71. child: Scaffold(
  72. extendBodyBehindAppBar: true,
  73. appBar: AppBar(
  74. shadowColor: Colors.transparent,
  75. backgroundColor: Colors.transparent,
  76. systemOverlayStyle: SystemUiOverlayStyle.light
  77. .copyWith(statusBarColor: Colors.transparent),
  78. // title: Text(user != null ? user["nickname"] : "",style:TextStyle(color: Colors.white),),
  79. centerTitle: true,
  80. elevation: 0.0,
  81. toolbarHeight: 0,
  82. ),
  83. backgroundColor: const Color(0xfff4f6ff),
  84. body: Column(
  85. children: [
  86. Container(
  87. padding: EdgeInsets.only(
  88. left: 15,
  89. right: 15,
  90. top: MediaQuery.of(context).padding.top),
  91. height: MediaQuery.of(context).size.width * 0.53,
  92. decoration: BoxDecoration(
  93. image: DecorationImage(
  94. image: AssetImage("images/home_bg.jpg"),
  95. fit: BoxFit.cover),
  96. ),
  97. child: Column(
  98. children: [
  99. // Row(
  100. // mainAxisAlignment: MainAxisAlignment.end,
  101. // children: [
  102. // IconButton(
  103. // icon: Icon(Icons.settings),
  104. // color: Colors.white,
  105. // onPressed: () => {},
  106. // ),
  107. // ],
  108. // ),
  109. SizedBox(height: 35),
  110. Row(
  111. crossAxisAlignment:CrossAxisAlignment.start,
  112. children: [
  113. Image.asset(
  114. "images/head.png",
  115. width: 35,
  116. height: 35,
  117. ),
  118. SizedBox(width: 10),
  119. Text(
  120. StoreHelper.getStorage(ConstantString.name),
  121. style: TextStyle(
  122. color: Colors.white,
  123. fontWeight: FontWeight.bold,
  124. fontSize: 18),
  125. )
  126. ],
  127. ),
  128. SizedBox(height: 5),
  129. Row(
  130. children: [
  131. SizedBox(width: 45),
  132. Text(StoreHelper.getStorage(ConstantString.phone),
  133. style: TextStyle(
  134. color: Colors.white,
  135. fontWeight: FontWeight.bold,
  136. fontSize: 20))
  137. ],
  138. ),
  139. SizedBox(height: 6),
  140. Row(
  141. children: [
  142. SizedBox(width: 45),
  143. Text(StoreHelper.getStorage(ConstantString.orgName),
  144. style: TextStyle(
  145. color: Color(0xFFB7CAFF), fontSize: 14))
  146. ],
  147. ),
  148. ],
  149. ),
  150. ),
  151. Container(
  152. padding: EdgeInsets.all(10),
  153. margin: EdgeInsets.all(15),
  154. decoration: BoxDecoration(
  155. color: Colors.white,
  156. borderRadius: BorderRadius.circular(10)),
  157. child: Column(
  158. crossAxisAlignment: CrossAxisAlignment.start,
  159. children: [
  160. SizedBox(height: 15),
  161. Container(
  162. width: double.infinity,
  163. height: 40,
  164. alignment: Alignment.center,
  165. decoration: BoxDecoration(
  166. color: alarmCount > 0
  167. ? Colors.red
  168. : Color(0xff74b900),
  169. borderRadius: BorderRadius.circular(10)),
  170. child: Text(
  171. alarmCount > 0
  172. ? '今日告警数量:$alarmCount'
  173. : "当前设备运行正常",
  174. style: TextStyle(
  175. color: Color(0xffffffff), fontSize: 15))),
  176. SizedBox(
  177. height: 20,
  178. ),
  179. Text("待办任务",
  180. style: TextStyle(
  181. color: Color(0xff000000), fontSize: 18)),
  182. SizedBox(
  183. height: 10,
  184. ),
  185. GridView.builder(
  186. shrinkWrap: true,
  187. padding: const EdgeInsets.only(
  188. top: 10,
  189. ),
  190. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  191. crossAxisCount: 1,
  192. mainAxisSpacing: 10,
  193. crossAxisSpacing: 10,
  194. childAspectRatio:
  195. MediaQuery.of(context).size.width / 30,
  196. ),
  197. itemBuilder: (context, index) {
  198. Map item = items[index];
  199. return Row(
  200. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  201. children: [
  202. Text(item["name"],
  203. style: TextStyle(
  204. color: Color(0xff000000), fontSize: 13)),
  205. Text(item["num"].toString(),
  206. style: TextStyle(
  207. color: Color(0xff000000), fontSize: 13))
  208. ],
  209. );
  210. },
  211. itemCount: items.length,
  212. )
  213. ],
  214. ),
  215. ),
  216. Container(
  217. margin: EdgeInsets.only(left: 15, right: 15),
  218. decoration:
  219. BoxDecoration(borderRadius: BorderRadius.circular(10)),
  220. child: Column(
  221. crossAxisAlignment: CrossAxisAlignment.start,
  222. children: [
  223. GridView.builder(
  224. shrinkWrap: true,
  225. padding: const EdgeInsets.only(
  226. top: 0,
  227. ),
  228. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  229. crossAxisCount: 3,
  230. mainAxisSpacing: 10,
  231. crossAxisSpacing: 10,
  232. childAspectRatio:
  233. (MediaQuery.of(context).size.width / 3 - 60 / 3) /
  234. 120,
  235. ),
  236. itemBuilder: (context, index) {
  237. UserAppResponseDataUserMenuList item = widget.userResponseEntity[index];
  238. return GestureDetector(
  239. onTap: () =>
  240. Navigator.pushNamed(context, item.path),
  241. child: Container(
  242. padding: EdgeInsets.all(5),
  243. decoration: BoxDecoration(
  244. color: Color(0xffffffff),
  245. borderRadius: BorderRadius.circular(10)),
  246. child: Column(
  247. crossAxisAlignment: CrossAxisAlignment.center,
  248. mainAxisAlignment: MainAxisAlignment.center,
  249. children: [
  250. Image.asset(
  251. item.icon,
  252. width: 60,
  253. height: 60,
  254. ),
  255. SizedBox(height: 10),
  256. Text(item.title.toString(),
  257. style: TextStyle(
  258. color: Color(0xff000000),
  259. fontSize: 13))
  260. ],
  261. ),
  262. ),
  263. );
  264. },
  265. itemCount: widget.userResponseEntity.length,
  266. )
  267. ],
  268. ),
  269. ),
  270. ],
  271. )),
  272. onWillPop: () async{
  273. if(_dateTime == null || DateTime.now().difference(_dateTime!) > const Duration(seconds: 1)){
  274. _dateTime = DateTime.now();
  275. showToast('再按一次退出');
  276. return false;
  277. }
  278. SystemNavigator.pop();
  279. return true;
  280. });
  281. }
  282. }