我的接口补充

This commit is contained in:
2025-11-18 10:01:13 +08:00
parent 3a7f69d525
commit 5f12905eff
6 changed files with 144 additions and 30 deletions

View File

@@ -286,7 +286,7 @@ class CarInfoPage extends GetView<CarInfoController> {
const SizedBox(height: 10),
_buildTipItem(Icons.rule, '定期检查车辆状态和证件有效期'),
const SizedBox(height: 10),
_buildTipItem(Icons.headset_mic_outlined, '如有疑问请联系客服: 400-123-4567'),
_buildTipItem(Icons.headset_mic_outlined, '如有疑问请联系客服: 400-021-1773'),
],
),
),

View File

@@ -1,4 +1,7 @@
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:ln_jq_app/common/model/base_model.dart';
import 'package:ln_jq_app/common/model/vehicle_info.dart';
import 'package:ln_jq_app/common/styles/theme.dart';
import 'package:ln_jq_app/storage_service.dart';
import '../../login/view.dart';
@@ -12,6 +15,8 @@ class MineController extends GetxController with BaseControllerMixin {
@override
void onInit() {
super.onInit();
renderData();
renderViolation();
}
@override
@@ -19,9 +24,124 @@ class MineController extends GetxController with BaseControllerMixin {
super.onClose();
}
void logout() async{
void logout() async {
await StorageService.to.clearLoginInfo();
Get.offAll(() => LoginPage());
}
String rate = "";
String accident = "";
String historyBreakRules = "";
String vin = "";
String plateNumber = "";
String violationTotal = "0";
String violationScore = "0";
String violationDispose = "0";
void renderData() async {
if (StorageService.to.hasVehicleInfo) {
VehicleInfo? bean = StorageService.to.vehicleInfo;
if (bean == null) {
return;
}
vin = bean.vin;
plateNumber = bean.plateNumber;
}
showLoading("加载中");
try {
await Future.wait([
_fetchCompletionRate(), // 请求1完成率
_fetchAccidentCount(), // 请求2事故数
_fetchBreakRulesCount(), // 请求3违章数
]);
} catch (e, stackTrace) {
showErrorToast("加载数据失败,请稍后重试 $e");
} finally {
dismissLoading();
updateUi();
}
}
Future<void> _fetchCompletionRate() async {
final response = await HttpService.to.get(
'appointment/orderAddHyd/driverAppointmentCompletionRate?phone=${StorageService.to.phone}',
);
if (response != null) {
final result = BaseModel.fromJson(response.data);
if (result.code == 0 && result.data != null) {
rate = result.data.toString();
}
}
}
/// 获取历史事故数
Future<void> _fetchAccidentCount() async {
final response = await HttpService.to.get(
'appointment/truck/historyTrafficAccidentCount?vin=${vin}',
);
if (response != null) {
final result = BaseModel.fromJson(response.data);
if (result.code == 0 && result.data != null) {
accident = result.data.toString();
}
}
}
/// 获取历史违章数
Future<void> _fetchBreakRulesCount() async {
final response = await HttpService.to.get(
'appointment/truck/historyBreakRulesCount?vin=${vin}',
);
if (response != null) {
final result = BaseModel.fromJson(response.data);
if (result.code == 0 && result.data != null) {
historyBreakRules = result.data.toString();
}
}
}
void renderViolation() async {
// 违章信息查询
final originalHeaders = Map<String, dynamic>.from(HttpService.to.dio.options.headers);
try {
HttpService.to.setBaseUrl(AppTheme.jiaqing_service_url);
HttpService.to.dio.options.headers['appId'] = '97ad10eeb6b346f79e0d6ffd81e4d3c3';
var responseData = await HttpService.to.get(
"vehicleService/violation/queryViolationInfo_V2?plateNum=${plateNumber}",
);
if (responseData == null || responseData.data == null) {
return;
}
var result = BaseModel.fromJson(responseData.data);
if (result.code == 0 && result.data != null && result.data is List) {
List<dynamic> violationList = result.data as List;
int totalScore = 0;
int disposeCount = 0;
for (var item in violationList) {
if (item is Map<String, dynamic>) {
totalScore += (item['score'] as num?)?.toInt() ?? 0;
if (item['isDispose'] == 1) {
disposeCount++;
}
}
}
violationTotal = violationList.length.toString();
violationScore = totalScore.toString();
violationDispose = disposeCount.toString();
}
} catch (e) {
} finally {
HttpService.to.setBaseUrl(AppTheme.test_service_url);
HttpService.to.dio.options.headers = originalHeaders;
updateUi();
}
}
}

View File

@@ -1,14 +1,9 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ln_jq_app/common/styles/theme.dart';
import 'package:ln_jq_app/storage_service.dart';
import 'controller.dart';
// 假设您的 Controller 在这里,如果还没有,可以先创建一个空类
// import 'controller.dart';
// 为了演示,我们先创建一个空的 Controller
// class MineController extends GetxController {}
class MinePage extends GetView<MineController> {
const MinePage({super.key});
@@ -18,7 +13,6 @@ class MinePage extends GetView<MineController> {
init: MineController(),
id: 'mine',
builder: (_) {
// 将所有 UI 构建逻辑放在这里
return Scaffold(
backgroundColor: Colors.grey[100],
body: SingleChildScrollView(
@@ -28,14 +22,15 @@ class MinePage extends GetView<MineController> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildUserInfoCard(),
const SizedBox(height: 12),
const SizedBox(height: 5),
_buildDriverScoreCard(),
const SizedBox(height: 12),
const SizedBox(height: 5),
_buildMonthlyRecordCard(),
const SizedBox(height: 12),
const SizedBox(height: 5),
_buildTipsCard(),
const SizedBox(height: 20),
_buildLogoutButton(),
const SizedBox(height: 20),
],
),
),
@@ -114,9 +109,9 @@ class MinePage extends GetView<MineController> {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildStatItem('0', '违章总数'),
_buildStatItem('0', '扣分总数'),
_buildStatItem('0', '已处理'),
_buildStatItem(controller.violationTotal, '违章总数'),
_buildStatItem(controller.violationScore, '扣分总数'),
_buildStatItem(controller.violationDispose, '已处理'),
],
),
),
@@ -160,7 +155,7 @@ class MinePage extends GetView<MineController> {
fit: StackFit.expand,
children: [
CircularProgressIndicator(
value: 0.8, // 假设得分80%
value: 10, // 假设得分80%
strokeWidth: 8,
backgroundColor: Colors.grey[200],
valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
@@ -265,13 +260,15 @@ class MinePage extends GetView<MineController> {
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
_buildRecordRow(Icons.autorenew, '加氢预约践行率', '100%'),
_buildRecordRow(Icons.rate_review, '加氢预约践行率', controller.rate),
const Divider(),
_buildRecordRow(Icons.report_problem_outlined, '违章', '0起'),
_buildRecordRow(
Icons.report_problem_outlined,
'违章',
"${controller.historyBreakRules}",
),
const Divider(),
_buildRecordRow(Icons.warning_amber_rounded, '危险驾驶', '0起'),
const Divider(),
_buildRecordRow(Icons.car_crash_outlined, '交通事故', '0起'),
_buildRecordRow(Icons.car_crash_outlined, '交通事故', "${controller.accident}"),
],
),
),
@@ -291,9 +288,7 @@ class MinePage extends GetView<MineController> {
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(value, style: const TextStyle(color: Colors.grey, fontSize: 14)),
const SizedBox(width: 8),
const Icon(Icons.arrow_forward_ios, size: 14, color: Colors.grey),
Text(value, style: const TextStyle(color: AppTheme.themeColor, fontSize: 14)),
],
),
onTap: () {
@@ -315,7 +310,7 @@ class MinePage extends GetView<MineController> {
const SizedBox(height: 10),
_buildInfoItem(Icons.rule, '遵守交通规则,避免违章扣分'),
const SizedBox(height: 10),
_buildInfoItem(Icons.headset_mic_outlined, '如有疑问请联系客服: 400-123-4567'),
_buildInfoItem(Icons.headset_mic_outlined, '如有疑问请联系客服: 400-021-1773'),
],
),
),
@@ -335,7 +330,6 @@ class MinePage extends GetView<MineController> {
);
}
/// 5. 构建退出登录按钮
Widget _buildLogoutButton() {
return ElevatedButton(
onPressed: () {

View File

@@ -56,7 +56,7 @@ class ReservationPage extends GetView<C_ReservationController> {
const SizedBox(height: 10),
_buildTipItem(Icons.rule, '请确保车辆证件齐全'),
const SizedBox(height: 10),
_buildTipItem(Icons.headset_mic_outlined, '如有疑问请联系客服: 400-123-4567'),
_buildTipItem(Icons.headset_mic_outlined, '如有疑问请联系客服: 400-021-1773'),
],
),
),
@@ -457,7 +457,7 @@ class ReservationPage extends GetView<C_ReservationController> {
),
),
buttonStyleData: ButtonStyleData(
height: 60, // 增加高度以容纳两行文字
height: 40, // 增加高度以容纳两行文字
padding: const EdgeInsets.symmetric(horizontal: 12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),