优化样式

This commit is contained in:
jyuesong
2022-01-20 13:33:52 +08:00
parent 4f8285fcf1
commit 130459d646
13 changed files with 241 additions and 66 deletions

View File

@@ -25,6 +25,21 @@ class Api {
); );
} }
static Future<HttpResponse<LoginBean>> loginTwo(
String userName,
String passWord,
String code,
) async {
return await Http.put<LoginBean>(
Url.loginTwo,
{
"username": userName,
"password": passWord,
"code": code,
},
);
}
static Future<HttpResponse<LoginBean>> loginByClientId( static Future<HttpResponse<LoginBean>> loginByClientId(
String id, String id,
String secret, String secret,

View File

@@ -130,9 +130,14 @@ class Http {
if (!getIt<UserInfoViewModel>().useSecretLogined) { if (!getIt<UserInfoViewModel>().useSecretLogined) {
exitLogin(); exitLogin();
} }
return HttpResponse(success: false, message: "没有该模块的访问权限", code: 0); return HttpResponse(success: false, message: "没有该模块的访问权限", code: 401);
}
if (e.response != null && e.response!.data != null) {
return HttpResponse(success: false, message: e.response?.data["message"] ?? e.message, code: e.response?.data["code"] ?? 0);
} else {
return HttpResponse(success: false, message: e.message, code: e.response?.statusCode ?? 0);
} }
return HttpResponse(success: false, message: e.message, code: 0);
} }
static HttpResponse<T> decodeResponse<T>( static HttpResponse<T> decodeResponse<T>(
@@ -187,7 +192,7 @@ class Http {
} else { } else {
return HttpResponse<T>( return HttpResponse<T>(
success: false, success: false,
code: -1000, code: response.data["code"],
message: response.data["message"], message: response.data["message"],
); );
} }

View File

@@ -16,7 +16,7 @@ class TokenInterceptor extends Interceptor {
options.headers["User-Agent"] = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"; options.headers["User-Agent"] = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1";
options.headers["Content-Type"] = "application/json;charset=UTF-8"; options.headers["Content-Type"] = "application/json;charset=UTF-8";
if (options.path != Url.loginByClientId) { if (options.path != Url.loginByClientId && options.path!= Url.loginTwo) {
options.queryParameters["t"] = options.queryParameters["t"] =
(DateTime.now().millisecondsSinceEpoch ~/ 1000).toString(); (DateTime.now().millisecondsSinceEpoch ~/ 1000).toString();
} }

View File

@@ -3,6 +3,7 @@ import '../userinfo_viewmodel.dart';
class Url { class Url {
static get login => "/api/user/login"; static get login => "/api/user/login";
static get loginTwo => "/api/user/two-factor/login";
static const loginByClientId = "/open/auth/token"; static const loginByClientId = "/open/auth/token";
static const user = "/api/user"; static const user = "/api/user";

View File

@@ -106,6 +106,11 @@ ThemeData darkTheme = ThemeData.dark().copyWith(
}, },
), ),
), ),
cupertinoOverrideTheme: const NoDefaultCupertinoThemeData(
brightness: Brightness.dark,
primaryColor: Color(0xffffffff),
scaffoldBackgroundColor: Colors.black,
),
); );
ThemeData lightTheme = ThemeData.light().copyWith( ThemeData lightTheme = ThemeData.light().copyWith(
brightness: Brightness.light, brightness: Brightness.light,
@@ -176,6 +181,11 @@ ThemeData lightTheme = ThemeData.light().copyWith(
}, },
), ),
), ),
cupertinoOverrideTheme: const NoDefaultCupertinoThemeData(
brightness: Brightness.light,
primaryColor: _primaryColor,
scaffoldBackgroundColor: Color(0xfff5f5f5),
),
); );
abstract class ThemeColors { abstract class ThemeColors {

View File

@@ -235,13 +235,23 @@ class _TaskDetailPageState extends ConsumerState<EnvDetailPage> {
content: Text("确认删除环境变量 ${widget.envBean.name ?? ""}"), content: Text("确认删除环境变量 ${widget.envBean.name ?? ""}"),
actions: [ actions: [
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("取消"), child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("确定"), child: Text(
"确定",
style: TextStyle(
color: primaryColor,
),
),
onPressed: () async { onPressed: () async {
Navigator.of(context).pop(); Navigator.of(context).pop();
await ref.read(envProvider).delEnv(widget.envBean.sId!); await ref.read(envProvider).delEnv(widget.envBean.sId!);

View File

@@ -208,17 +208,6 @@ class EnvItemCell extends StatelessWidget {
), ),
), ),
), ),
const SizedBox(
width: 5,
),
bean.status == 1
? const Icon(
Icons.dnd_forwardslash,
size: 16,
color: Colors.red,
)
: const SizedBox.shrink(),
const Spacer(),
], ],
), ),
), ),
@@ -259,21 +248,30 @@ class EnvItemCell extends StatelessWidget {
const SizedBox( const SizedBox(
width: 5, width: 5,
), ),
Expanded( Material(
child: Material( color: Colors.transparent,
color: Colors.transparent, child: Text(
child: Text( bean.remarks ?? "-",
bean.remarks ?? "-", maxLines: 1,
maxLines: 1, style: TextStyle(
style: TextStyle( height: 1,
height: 1, overflow: TextOverflow.ellipsis,
overflow: TextOverflow.ellipsis, color: ref.watch(themeProvider).themeColor.descColor(),
color: ref.watch(themeProvider).themeColor.descColor(), fontSize: 12,
fontSize: 12,
),
), ),
), ),
), ),
const SizedBox(
width: 5,
),
bean.status == 1
? const Icon(
Icons.dnd_forwardslash,
size: 12,
color: Colors.red,
)
: const SizedBox.shrink(),
const Spacer(),
], ],
), ),
), ),
@@ -319,13 +317,23 @@ class EnvItemCell extends StatelessWidget {
content: Text("确认删除环境变量 ${bean.name ?? ""}"), content: Text("确认删除环境变量 ${bean.name ?? ""}"),
actions: [ actions: [
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("取消"), child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("确定"), child: Text(
"确定",
style: TextStyle(
color: primaryColor,
),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
ref.read(envProvider).delEnv(bean.sId!); ref.read(envProvider).delEnv(bean.sId!);

View File

@@ -362,37 +362,95 @@ class _LoginPageState extends ConsumerState<LoginPage> {
response = await Api.loginByClientId(userName, password); response = await Api.loginByClientId(userName, password);
} }
if (response.success) { if (response.success) {
getIt<UserInfoViewModel>().updateToken(response.bean?.token ?? ""); loginSuccess(response, userName, password);
getIt<UserInfoViewModel>().useSecretLogin(!loginByUserName()); } else {
if (rememberPassword) { print(response.code);
getIt<UserInfoViewModel>().updateUserName(userName, password); (response.message ?? "请检查网络情况").toast();
} //420代表需要2步验证
if (response.code == 420) {
if (!loginByUserName()) { String twoFact = "";
Navigator.of(context).pushReplacementNamed(Routes.routeHomePage); showCupertinoDialog(
} else { context: context,
HttpResponse<UserBean> userResponse = await Api.user(); builder: (_) => CupertinoAlertDialog(
if (userResponse.success) { title: const Text("两步验证"),
if (userResponse.bean != null && userResponse.bean!.twoFactorActivated != null && userResponse.bean!.twoFactorActivated!) { content: Column(
("你已开启两步验证,App暂不支持").toast(); mainAxisSize: MainAxisSize.min,
children: [
Material(
color: Colors.transparent,
child: TextField(
onChanged: (value) {
twoFact = value;
},
maxLines: 1,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入code",
),
autofocus: true,
),
),
],
),
actions: [
CupertinoDialogAction(
child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoDialogAction(
child: Text(
"确定",
style: TextStyle(
color: primaryColor,
),
),
onPressed: () async {
Navigator.of(context).pop(true);
HttpResponse<LoginBean> response = await Api.loginTwo(userName, password, twoFact);
if (response.success) {
loginSuccess(response, userName, password);
} else {
loginFailed(response);
}
},
),
],
)).then((value) {
if (value == null) {
isLoading = false; isLoading = false;
setState(() {}); setState(() {});
} else {
Navigator.of(context).pushReplacementNamed(Routes.routeHomePage);
} }
} else { });
(response.message ?? "请检查网络情况").toast(); } else {
isLoading = false; isLoading = false;
setState(() {}); setState(() {});
}
} }
} else {
(response.message ?? "请检查网络情况").toast();
isLoading = false;
setState(() {});
} }
} }
void loginFailed(HttpResponse<LoginBean> response) {
(response.message ?? "请检查网络情况").toast();
isLoading = false;
setState(() {});
}
void loginSuccess(HttpResponse<LoginBean> response, String userName, String password) {
getIt<UserInfoViewModel>().updateToken(response.bean?.token ?? "");
getIt<UserInfoViewModel>().useSecretLogin(!loginByUserName());
if (rememberPassword) {
getIt<UserInfoViewModel>().updateUserName(userName, password);
}
Navigator.of(context).pushReplacementNamed(Routes.routeHomePage);
}
bool canClickLoginBtn() { bool canClickLoginBtn() {
if (isLoading) return false; if (isLoading) return false;

View File

@@ -334,13 +334,23 @@ class DependencyCell extends ConsumerWidget {
content: Text("确认删除依赖 ${bean.name ?? ""}"), content: Text("确认删除依赖 ${bean.name ?? ""}"),
actions: [ actions: [
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("取消"), child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("确定"), child: Text(
"确定",
style: TextStyle(
color: primaryColor,
),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
ref.read(dependencyProvider).del(type.name.toLowerCase(), sId ?? ""); ref.read(dependencyProvider).del(type.name.toLowerCase(), sId ?? "");

View File

@@ -297,16 +297,26 @@ class _OtherPageState extends ConsumerState<OtherPage> {
showCupertinoDialog( showCupertinoDialog(
context: context, context: context,
builder: (context) => CupertinoAlertDialog( builder: (context) => CupertinoAlertDialog(
title: const Text("退出登录吗?"), title: const Text("退出登录吗?"),
actions: [ actions: [
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("取消"), child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("确定"), child: Text(
"确定",
style: TextStyle(
color: primaryColor,
),
),
onPressed: () { onPressed: () {
getIt<UserInfoViewModel>().updateToken(""); getIt<UserInfoViewModel>().updateToken("");
Navigator.of(context).pushReplacementNamed(Routes.routeLogin); Navigator.of(context).pushReplacementNamed(Routes.routeLogin);

View File

@@ -84,13 +84,23 @@ class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage> with LazyLo
content: const Text("确认删除该脚本吗"), content: const Text("确认删除该脚本吗"),
actions: [ actions: [
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("取消"), child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("确定"), child: Text(
"确定",
style: TextStyle(
color: primaryColor,
),
),
onPressed: () async { onPressed: () async {
Navigator.of(context).pop(); Navigator.of(context).pop();
HttpResponse<NullResponse> result = await Api.delScript(widget.title, widget.path ?? ""); HttpResponse<NullResponse> result = await Api.delScript(widget.title, widget.path ?? "");

View File

@@ -367,13 +367,23 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
content: Text("确认删除定时任务 ${widget.taskBean.name ?? ""}"), content: Text("确认删除定时任务 ${widget.taskBean.name ?? ""}"),
actions: [ actions: [
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("取消"), child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("确定"), child: Text(
"确定",
style: TextStyle(
color: primaryColor,
),
),
onPressed: () async { onPressed: () async {
Navigator.of(context).pop(); Navigator.of(context).pop();
await ref.read(taskProvider).delCron(widget.taskBean.sId!); await ref.read(taskProvider).delCron(widget.taskBean.sId!);

View File

@@ -251,6 +251,7 @@ class TaskItemCell extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( Container(
width: MediaQuery.of(context).size.width,
color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : Colors.transparent, color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : Colors.transparent,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 15, horizontal: 15,
@@ -307,6 +308,7 @@ class TaskItemCell extends StatelessWidget {
height: 8, height: 8,
), ),
Row( Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Material( Material(
color: Colors.transparent, color: Colors.transparent,
@@ -332,6 +334,22 @@ class TaskItemCell extends StatelessWidget {
: const SizedBox.shrink(), : const SizedBox.shrink(),
], ],
), ),
const SizedBox(
height: 8,
),
Material(
color: Colors.transparent,
child: Text(
bean.command ?? "",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),
),
], ],
), ),
), ),
@@ -401,13 +419,23 @@ class TaskItemCell extends StatelessWidget {
content: Text("确认删除定时任务 ${bean.name ?? ""}"), content: Text("确认删除定时任务 ${bean.name ?? ""}"),
actions: [ actions: [
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("取消"), child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
CupertinoDialogAction( CupertinoDialogAction(
child: const Text("确定"), child: Text(
"确定",
style: TextStyle(
color: primaryColor,
),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
ref.read(taskProvider).delCron(bean.sId!); ref.read(taskProvider).delCron(bean.sId!);