documents_page.dart 6.4 KB

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