home_page.dart 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. return 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 + 10),
  91. height: MediaQuery.of(context).size.width * 0.53,
  92. decoration: BoxDecoration(
  93. image: DecorationImage(
  94. image: AssetImage("images/home_bg.jpg"), fit: BoxFit.cover),
  95. ),
  96. child: Column(
  97. children: [
  98. Row(
  99. mainAxisAlignment: MainAxisAlignment.end,
  100. children: [
  101. IconButton(
  102. icon: Icon(Icons.settings),
  103. color: Colors.white,
  104. onPressed: () => showToast("text"),
  105. ),
  106. ],
  107. ),
  108. Row(
  109. children: [
  110. Image.asset(
  111. "images/head.png",
  112. width: 40,
  113. height: 40,
  114. ),
  115. SizedBox(width: 10),
  116. Text(
  117. StoreHelper.getStorage(ConstantString.name),
  118. style: TextStyle(
  119. color: Colors.white,
  120. fontWeight: FontWeight.bold,
  121. fontSize: 15),
  122. )
  123. ],
  124. ),
  125. SizedBox(height: 20),
  126. Row(
  127. children: [
  128. SizedBox(width: 50),
  129. Text(StoreHelper.getStorage(ConstantString.phone),
  130. style: TextStyle(
  131. color: Colors.white,
  132. fontWeight: FontWeight.bold,
  133. fontSize: 18))
  134. ],
  135. ),
  136. SizedBox(height: 10),
  137. Row(
  138. children: [
  139. SizedBox(width: 50),
  140. Text(StoreHelper.getStorage(ConstantString.orgName),
  141. style:
  142. TextStyle(color: Color(0xffaaaaaa), fontSize: 15))
  143. ],
  144. ),
  145. ],
  146. ),
  147. ),
  148. Container(
  149. padding: EdgeInsets.all(10),
  150. margin: EdgeInsets.all(15),
  151. decoration: BoxDecoration(
  152. color: Colors.white, borderRadius: BorderRadius.circular(10)),
  153. child: Column(
  154. crossAxisAlignment: CrossAxisAlignment.start,
  155. children: [
  156. SizedBox(height: 15),
  157. Container(
  158. width: double.infinity,
  159. height: 40,
  160. alignment: Alignment.center,
  161. decoration: BoxDecoration(
  162. color:
  163. alarmCount > 0 ? Colors.red : Color(0xff74b900),
  164. borderRadius: BorderRadius.circular(10)),
  165. child: Text(
  166. alarmCount > 0 ? '今日告警数量:$alarmCount' : "当前设备运行正常",
  167. style: TextStyle(
  168. color: Color(0xffffffff), fontSize: 15))),
  169. SizedBox(
  170. height: 20,
  171. ),
  172. Text("待办任务",
  173. style: TextStyle(color: Color(0xff000000), fontSize: 18)),
  174. SizedBox(
  175. height: 10,
  176. ),
  177. GridView.builder(
  178. shrinkWrap: true,
  179. padding: const EdgeInsets.only(
  180. top: 10,
  181. ),
  182. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  183. crossAxisCount: 1,
  184. mainAxisSpacing: 10,
  185. crossAxisSpacing: 10,
  186. childAspectRatio: MediaQuery.of(context).size.width / 30,
  187. ),
  188. itemBuilder: (context, index) {
  189. Map item = items[index];
  190. return Row(
  191. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  192. children: [
  193. Text(item["name"],
  194. style: TextStyle(
  195. color: Color(0xff000000), fontSize: 13)),
  196. Text(item["num"].toString(),
  197. style: TextStyle(
  198. color: Color(0xff000000), fontSize: 13))
  199. ],
  200. );
  201. },
  202. itemCount: items.length,
  203. )
  204. ],
  205. ),
  206. ),
  207. Container(
  208. margin: EdgeInsets.only(left: 15, right: 15),
  209. decoration:
  210. BoxDecoration(borderRadius: BorderRadius.circular(10)),
  211. child: Column(
  212. crossAxisAlignment: CrossAxisAlignment.start,
  213. children: [
  214. GridView.builder(
  215. shrinkWrap: true,
  216. padding: const EdgeInsets.only(
  217. top: 0,
  218. ),
  219. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  220. crossAxisCount: 3,
  221. mainAxisSpacing: 10,
  222. crossAxisSpacing: 10,
  223. childAspectRatio:
  224. (MediaQuery.of(context).size.width / 3 - 60 / 3) /
  225. 120,
  226. ),
  227. itemBuilder: (context, index) {
  228. Map item = icons[index];
  229. return GestureDetector(
  230. onTap: () => Navigator.pushNamed(context, item['jump']),
  231. child: Container(
  232. padding: EdgeInsets.all(5),
  233. decoration: BoxDecoration(
  234. color: Color(0xffffffff),
  235. borderRadius: BorderRadius.circular(10)),
  236. child: Column(
  237. crossAxisAlignment: CrossAxisAlignment.center,
  238. mainAxisAlignment: MainAxisAlignment.center,
  239. children: [
  240. Image.asset(
  241. item["image"],
  242. width: 60,
  243. height: 60,
  244. ),
  245. SizedBox(height: 10),
  246. Text(item["name"].toString(),
  247. style: TextStyle(
  248. color: Color(0xff000000), fontSize: 13))
  249. ],
  250. ),
  251. ),
  252. );
  253. },
  254. itemCount: icons.length,
  255. )
  256. ],
  257. ),
  258. ),
  259. ],
  260. ));
  261. }
  262. }