home_page.dart 11 KB

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