feat: 新增电脑版登录

This commit is contained in:
orz12
2024-03-02 12:49:40 +08:00
parent b72c951389
commit dfa155d683
2 changed files with 33 additions and 21 deletions

View File

@@ -40,9 +40,9 @@ class WebviewController extends GetxController {
webviewInit(); webviewInit();
} }
webviewInit() { webviewInit({String uaType = 'mob'}) {
controller controller
..setUserAgent(Request().headerUa()) ..setUserAgent(Request().headerUa(type: uaType))
..setJavaScriptMode(JavaScriptMode.unrestricted) ..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate( ..setNavigationDelegate(
NavigationDelegate( NavigationDelegate(

View File

@@ -27,29 +27,32 @@ class _WebviewPageState extends State<WebviewPage> {
actions: [ actions: [
const SizedBox(width: 4), const SizedBox(width: 4),
IconButton( IconButton(
tooltip: '刷新', tooltip: '刷新网页',
onPressed: () { onPressed: () {
_webviewController.controller.reload(); _webviewController.controller.reload();
}, },
icon: Icon(Icons.refresh_outlined, icon: Icon(Icons.refresh_outlined,
color: Theme.of(context).colorScheme.primary), color: Theme.of(context).colorScheme.primary),
), ),
IconButton( if (_webviewController.type.value != 'login')
tooltip: '用外部浏览器打开', IconButton(
onPressed: () { tooltip: '用外部浏览器打开',
launchUrl(Uri.parse(_webviewController.url)); onPressed: () {
}, launchUrl(Uri.parse(_webviewController.url));
icon: Icon(Icons.open_in_browser_outlined, },
color: Theme.of(context).colorScheme.primary), icon: Icon(Icons.open_in_browser_outlined,
), color: Theme.of(context).colorScheme.primary),
Obx( ),
() => _webviewController.type.value == 'login' if (_webviewController.type.value == 'login')...<Widget>[
? TextButton( TextButton(
onPressed: () => _webviewController.confirmLogin(null), onPressed: () => _webviewController.confirmLogin(null),
child: const Text('刷新登录'), child: const Text('刷新登录态'),
) ),
: const SizedBox(), TextButton(
), child: const Text('电脑版'),
onPressed: () => _webviewController.webviewInit(uaType: 'pc'),
)
],
const SizedBox(width: 12) const SizedBox(width: 12)
], ],
), ),
@@ -66,14 +69,23 @@ class _WebviewPageState extends State<WebviewPage> {
), ),
), ),
), ),
if (_webviewController.type.value == 'login') if (_webviewController.type.value == 'login') ...<Widget>[
Container( Container(
width: double.infinity, width: double.infinity,
color: Theme.of(context).colorScheme.onInverseSurface, color: Theme.of(context).colorScheme.onInverseSurface,
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
left: 12, right: 12, top: 6, bottom: 6), 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( Expanded(
child: WebViewWidget(controller: _webviewController.controller), child: WebViewWidget(controller: _webviewController.controller),
), ),