Browse Source

GlobalWebPage的网页与富文本兼容

liukai 1 week ago
parent
commit
b20ee481a8

+ 1 - 0
packages/cpt_main/lib/modules/home/latest_news/property/latest_news_property_view_model.dart

@@ -113,6 +113,7 @@ class LatestNewsPropertyViewModel extends _$LatestNewsPropertyViewModel with Dio
 
   /// 去详情页面
   void gotoLatestNewsDetail(BuildContext context, LatestNewsList data) async {
+    //先获取到详情
     final result = await _mainRepository.fetchLatestNewsDetail(id: data.id ?? "");
     if (result.isSuccess) {
       GlobalWebPage.startInstance(context: context, title: S.current.latest_news, url: result.data?.content ?? "");

+ 35 - 6
packages/cs_plugin_basic/lib/modules/global_web_page.dart

@@ -1,12 +1,17 @@
+import 'package:cs_resources/theme/app_colors_theme.dart';
 import 'package:flutter/material.dart';
+import 'package:plugin_basic/dialog/country_code_selecter.dart';
 import 'package:plugin_basic/router/basic_page_router.dart';
 import 'package:shared/utils/log_utils.dart';
 import 'package:hooks_riverpod/hooks_riverpod.dart';
+import 'package:widgets/ext/ex_widget.dart';
+import 'package:widgets/my_appbar.dart';
+import 'package:widgets/widget_export.dart';
 import '../widget/webview_page.dart';
 import 'package:auto_route/auto_route.dart';
 
 /*
- * 全局的公共Web页面
+ * 全局的公共Web页面,兼容网页与富文本展示
  */
 @RoutePage()
 class GlobalWebPage extends HookConsumerWidget {
@@ -34,10 +39,34 @@ class GlobalWebPage extends HookConsumerWidget {
   @override
   Widget build(BuildContext context, WidgetRef ref) {
     Log.d("GlobalWebPage 的参数 isShowAppBar:$isShowAppBar title:$title initialUrl:$initialUrl ");
-    return WebViewPage(
-      showAppbar: isShowAppBar,
-      initialUrl: initialUrl,
-      arguments: {'title': title},
-    );
+
+    if (initialUrl.startsWith('http')) {
+      //网页加载
+      return WebViewPage(
+        showAppbar: isShowAppBar,
+        initialUrl: initialUrl,
+        arguments: {'title': title},
+      );
+    } else {
+      //富文本加载
+      return Scaffold(
+          backgroundColor: context.appColors.whiteBG,
+          appBar: isShowAppBar
+              ? MyAppBar.appBar(
+                  context,
+                  title ?? "",
+                  backgroundColor: context.appColors.backgroundWhite,
+                )
+              : null,
+          body: SafeArea(
+            bottom: true,
+            top: false,
+            child: SingleChildScrollView(
+              scrollDirection: Axis.vertical,
+              physics: const BouncingScrollPhysics(),
+              child: Html(data: initialUrl).paddingOnly(left: 10, right: 10),
+            ),
+          ));
+    }
   }
 }