documents_page.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import 'package:cpt_notice_board/modules/notice_board/page/notice_board_page.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:auto_route/auto_route.dart';
  4. import 'package:flutter_hooks/flutter_hooks.dart';
  5. import 'package:hooks_riverpod/hooks_riverpod.dart';
  6. import 'package:plugin_basic/modules/global_web_page.dart';
  7. import 'package:router/ext/auto_router_extensions.dart';
  8. import 'package:shared/utils/log_utils.dart';
  9. import 'package:shared/utils/color_utils.dart';
  10. import 'package:widgets/ext/ex_widget.dart';
  11. import 'package:widgets/load_state_layout.dart';
  12. import 'package:widgets/my_load_image.dart';
  13. import 'package:widgets/widget_export.dart';
  14. import 'package:cs_resources/generated/assets.dart';
  15. import '../../../router/page/notice_board_page_router.dart';
  16. import '../../documents_list/page/documents_list_page.dart';
  17. import '../vm/documents_vm.dart';
  18. @RoutePage()
  19. class DocumentsPage extends HookConsumerWidget {
  20. const DocumentsPage({Key? key}) : super(key: key);
  21. //启动当前页面
  22. static void startInstance({BuildContext? context}) {
  23. if (context != null) {
  24. context.router.push(const DocumentsPageRoute());
  25. } else {
  26. appRouter.push(const DocumentsPageRoute());
  27. }
  28. }
  29. Widget _buildItemLeftSection(BuildContext context, WidgetRef ref, item, _vm) {
  30. return Container(
  31. // color: Colors.blue,
  32. child: Text(
  33. item['name'],
  34. maxLines: 1, // 设置最大行数为2
  35. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  36. style: const TextStyle(
  37. fontSize: 16.0,
  38. color: Colors.black,
  39. fontWeight: FontWeight.w700), // 设置字体大小
  40. ),
  41. ).marginOnly(right: 17.5);
  42. }
  43. Widget _buildItemRightSection(
  44. BuildContext context, WidgetRef ref, item, _vm) {
  45. return Container(
  46. color: Colors.white,
  47. child: TextButton(
  48. onPressed: () {
  49. DocumentsListPage.startInstance(id: item['id']);
  50. // DocumentsListPage.startInstance(context: context);
  51. },
  52. style: TextButton.styleFrom(
  53. foregroundColor: Colors.black,
  54. backgroundColor: ColorUtils.string2Color('#4161D0'), // 背景颜色
  55. minimumSize: const Size(91.5, 30), // 最小宽度和高度
  56. padding:
  57. const EdgeInsets.symmetric(horizontal: 11.0, vertical: 9), // 内边距
  58. shape: RoundedRectangleBorder(
  59. borderRadius: BorderRadius.circular(5), // 圆角
  60. side: BorderSide(
  61. color: ColorUtils.string2Color('#4161D0'),
  62. width: 1.0,
  63. ), // 边框
  64. ),
  65. ),
  66. child: const Text(
  67. 'Open Folder',
  68. style: const TextStyle(
  69. color: Colors.white,
  70. ),
  71. ),
  72. ),
  73. );
  74. }
  75. // listitem
  76. Widget _buildSaleItem(BuildContext context, WidgetRef ref, item, _vm) {
  77. String url = item['url'];
  78. return Container(
  79. decoration: const BoxDecoration(
  80. color: Colors.white,
  81. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  82. boxShadow: [
  83. BoxShadow(color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
  84. ],
  85. ),
  86. child: Row(
  87. mainAxisAlignment: MainAxisAlignment.center,
  88. crossAxisAlignment: CrossAxisAlignment.center,
  89. mainAxisSize: MainAxisSize.max,
  90. children: [
  91. Container(
  92. width: MediaQuery.of(context).size.width - 30,
  93. height: 70,
  94. child: Row(
  95. mainAxisAlignment: MainAxisAlignment.start,
  96. crossAxisAlignment: CrossAxisAlignment.center,
  97. children: [
  98. Expanded(child: _buildItemLeftSection(context, ref, item, _vm)),
  99. url == ''
  100. ? Container(
  101. width: 120,
  102. child: _buildItemRightSection(context, ref, item, _vm),
  103. // child: TextButton(onPressed: (){}, child: Text("fdsfds")),
  104. )
  105. : Container(),
  106. ],
  107. ).paddingOnly(left: 20, right: 20),
  108. ).constrained(
  109. minHeight: 70,
  110. ),
  111. ],
  112. ).onTap(() {
  113. // 去详情
  114. if (url != '') {
  115. // _vm.launchURL(url);
  116. GlobalWebPage.startInstance(
  117. context: context, title: item['name'], url: url);
  118. }
  119. // DocumentsListPage.startInstance(context: context);
  120. }),
  121. ).marginOnly(left: 15, bottom: 15, right: 15);
  122. }
  123. // list
  124. Widget _buildSaleList(BuildContext context, WidgetRef ref, _vm) {
  125. final state = ref.watch(documentsVmProvider);
  126. return SliverList(
  127. delegate: SliverChildBuilderDelegate((context, index) {
  128. return _buildSaleItem(context, ref, state.list![index], _vm);
  129. }, childCount: state.list!.length));
  130. }
  131. @override
  132. Widget build(BuildContext context, WidgetRef ref) {
  133. final vm = ref.read(documentsVmProvider.notifier);
  134. final state = ref.watch(documentsVmProvider);
  135. useEffect(() {
  136. // 组件挂载时执行 - 执行接口请求
  137. Future.microtask(() => vm.initPageData());
  138. return () {
  139. // 组件卸载时执行
  140. Log.d("property_news_page 组件卸载时执行");
  141. };
  142. }, []);
  143. return Scaffold(
  144. // appBar: AppBar(title: Text("资产")),
  145. body: SizedBox(
  146. width: double.infinity,
  147. height: double.infinity,
  148. child: EasyRefresh(
  149. controller: vm.refreshController,
  150. // 上拉加载
  151. onLoad: () async {
  152. Log.d("----onLoad");
  153. vm.loadMore();
  154. },
  155. // 下拉刷新
  156. onRefresh: () async {
  157. Log.d("----onRefresh");
  158. vm.onRefresh();
  159. },
  160. child: Container(
  161. color: ColorUtils.string2Color('#F2F3F6'),
  162. padding: const EdgeInsets.only(top: 15),
  163. child: LoadStateLayout(
  164. state: state.loadingState,
  165. errorMessage: state.errorMessage,
  166. errorRetry: () {
  167. vm.retryRequest();
  168. },
  169. successSliverWidget: [_buildSaleList(context, ref, vm)],
  170. ),
  171. ))),
  172. );
  173. }
  174. }