feat(e2e): autologin patch (dev) + 登录态路由测试脚本

- util_web devAutologin: localStorage[_test_token]=user|pass -> 登录API写Hive+dispatch currentUser
- 延迟3s执行等 Flutter/Hive ready (否则 httpPost hang)
- main.dart 调用 devAutologin
- run_auth.js: 注入token遍历登录态路由
- 已验证: autologin API 200 OK
This commit is contained in:
2026-08-03 01:50:12 +08:00
parent 901e42a41b
commit 33b54fe454
10 changed files with 221 additions and 0 deletions

View File

@@ -199,6 +199,9 @@ class Util {
return box;
}
/// DEV ONLY stub (原生不自动登录)
static void devAutologin() {}
static Widget showImage(String imageUrl, {double? width, double? height,
BoxFit? fit, Widget Function(BuildContext, String, dynamic)? errorWidget}) {
if (imageUrl != null && imageUrl.isNotEmpty && imageUrl.startsWith('https:')) {

View File

@@ -41,6 +41,28 @@ class Util {
return box;
}
/// DEV ONLY (e2e tests): 读 localStorage['_test_token'] = 'username|password',
/// 调登录 API 写 Hive + dispatch currentUser。测试后移除。
static Future<void> devAutologin() async {
try {
final t = window.localStorage['_test_token'];
if (t == null || t.isEmpty) return;
final parts = t.split('|');
if (parts.length < 2) return;
print('CK_AUTOLOGIN_CALL');
await HttpUtil.httpPost('v1/oauth-wisetronic/access_token', (response) async {
final box = await getBox();
await box.put(Constants.KEY_ACCESS_TOKEN, response.data['access_token']);
await box.put(Constants.KEY_USER_ID, response.data['user_id']);
store.dispatch(UpdateCurrentUser(User.fromJson(response.data['user'])));
print('CK_AUTOLOGIN_OK');
},
queryParameters: {'client_id': Utils.getPlatformName(), 'grant_type': 'password'},
body: {'username': parts[0], 'password': parts[1], 'fcm_token': ''},
isFormData: true, businessId: Constants.BUSINESS_ID);
} catch (e) { print('CK_AUTOLOGIN_EX: ${e.toString().substring(0, 150)}'); }
}
static Widget showImage(String imageUrl, {double? width, double? height,
BoxFit? fit, Widget Function(BuildContext, String?, dynamic)? errorWidget}) {
return Image.network(imageUrl,