From dfa155d683ee4a69e306a185321bf24b3d0a44aa Mon Sep 17 00:00:00 2001 From: orz12 Date: Sat, 2 Mar 2024 12:49:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E7=94=B5=E8=84=91?= =?UTF-8?q?=E7=89=88=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/webview/controller.dart | 4 +-- lib/pages/webview/view.dart | 50 +++++++++++++++++++------------ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/lib/pages/webview/controller.dart b/lib/pages/webview/controller.dart index 0ac7c65d..dc130db8 100644 --- a/lib/pages/webview/controller.dart +++ b/lib/pages/webview/controller.dart @@ -40,9 +40,9 @@ class WebviewController extends GetxController { webviewInit(); } - webviewInit() { + webviewInit({String uaType = 'mob'}) { controller - ..setUserAgent(Request().headerUa()) + ..setUserAgent(Request().headerUa(type: uaType)) ..setJavaScriptMode(JavaScriptMode.unrestricted) ..setNavigationDelegate( NavigationDelegate( diff --git a/lib/pages/webview/view.dart b/lib/pages/webview/view.dart index c448c4a7..55b975ce 100644 --- a/lib/pages/webview/view.dart +++ b/lib/pages/webview/view.dart @@ -27,29 +27,32 @@ class _WebviewPageState extends State { actions: [ const SizedBox(width: 4), IconButton( - tooltip: '刷新', + tooltip: '刷新网页', onPressed: () { _webviewController.controller.reload(); }, icon: Icon(Icons.refresh_outlined, color: Theme.of(context).colorScheme.primary), ), - IconButton( - tooltip: '用外部浏览器打开', - onPressed: () { - launchUrl(Uri.parse(_webviewController.url)); - }, - icon: Icon(Icons.open_in_browser_outlined, - color: Theme.of(context).colorScheme.primary), - ), - Obx( - () => _webviewController.type.value == 'login' - ? TextButton( - onPressed: () => _webviewController.confirmLogin(null), - child: const Text('刷新登录状态'), - ) - : const SizedBox(), - ), + if (_webviewController.type.value != 'login') + IconButton( + tooltip: '用外部浏览器打开', + onPressed: () { + launchUrl(Uri.parse(_webviewController.url)); + }, + icon: Icon(Icons.open_in_browser_outlined, + color: Theme.of(context).colorScheme.primary), + ), + if (_webviewController.type.value == 'login')...[ + TextButton( + onPressed: () => _webviewController.confirmLogin(null), + child: const Text('刷新登录态'), + ), + TextButton( + child: const Text('电脑版'), + onPressed: () => _webviewController.webviewInit(uaType: 'pc'), + ) + ], const SizedBox(width: 12) ], ), @@ -66,14 +69,23 @@ class _WebviewPageState extends State { ), ), ), - if (_webviewController.type.value == 'login') + if (_webviewController.type.value == 'login') ...[ Container( width: double.infinity, color: Theme.of(context).colorScheme.onInverseSurface, padding: const EdgeInsets.only( left: 12, right: 12, top: 6, bottom: 6), - child: const Text('登录成功未自动跳转? 请点击右上角「刷新登录状态」'), + child: const Text('登录成功未自动跳转? 请点击右上角「刷新登录态」'), ), + const SizedBox(height: 4), + Container( + width: double.infinity, + color: Theme.of(context).colorScheme.onInverseSurface, + padding: const EdgeInsets.only( + left: 12, right: 12, top: 6, bottom: 6), + child: const Text('如需二维码登录,请点击「电脑版」,放大左侧二维码,截图后官方app或另一设备扫码,授权后点击「刷新登录态」'), + ), + ], Expanded( child: WebViewWidget(controller: _webviewController.controller), ),