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({String uaType = 'mob'}) {
controller
..setUserAgent(Request().headerUa())
..setUserAgent(Request().headerUa(type: uaType))
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(

View File

@@ -27,13 +27,14 @@ class _WebviewPageState extends State<WebviewPage> {
actions: [
const SizedBox(width: 4),
IconButton(
tooltip: '刷新',
tooltip: '刷新网页',
onPressed: () {
_webviewController.controller.reload();
},
icon: Icon(Icons.refresh_outlined,
color: Theme.of(context).colorScheme.primary),
),
if (_webviewController.type.value != 'login')
IconButton(
tooltip: '用外部浏览器打开',
onPressed: () {
@@ -42,14 +43,16 @@ class _WebviewPageState extends State<WebviewPage> {
icon: Icon(Icons.open_in_browser_outlined,
color: Theme.of(context).colorScheme.primary),
),
Obx(
() => _webviewController.type.value == 'login'
? TextButton(
if (_webviewController.type.value == 'login')...<Widget>[
TextButton(
onPressed: () => _webviewController.confirmLogin(null),
child: const Text('刷新登录'),
)
: const SizedBox(),
child: const Text('刷新登录态'),
),
TextButton(
child: const Text('电脑版'),
onPressed: () => _webviewController.webviewInit(uaType: 'pc'),
)
],
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(
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),
),