站点信息,保存 数据

This commit is contained in:
2025-11-05 17:21:03 +08:00
parent 36910b8b32
commit 71aa1101be
6 changed files with 169 additions and 43 deletions

View File

@@ -294,14 +294,10 @@
inputFileListPaths = ( inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
); );
inputPaths = (
);
name = "[CP] Embed Pods Frameworks"; name = "[CP] Embed Pods Frameworks";
outputFileListPaths = ( outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
); );
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
@@ -374,14 +370,10 @@
inputFileListPaths = ( inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
); );
inputPaths = (
);
name = "[CP] Copy Pods Resources"; name = "[CP] Copy Pods Resources";
outputFileListPaths = ( outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
); );
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";

View File

@@ -0,0 +1,30 @@
import 'package:dio/dio.dart';
import 'package:ln_jq_app/storage_service.dart';
/// 专门用于处理和添加 Token 的拦截器
class TokenInterceptor extends Interceptor {
// 定义您想要使用的 Token Key
final String tokenKey;
// 构造函数,允许外部传入自定义的 Key默认为 'Authorization'
TokenInterceptor({this.tokenKey = 'Authorization'});
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
// 从 StorageService 中获取已保存的 token
final String? token = StorageService.to.token;
// 如果 token 存在,就添加到请求头中
if (token != null && token.isNotEmpty) {
// 检查请求头中是否已存在这个key避免重复添加
if (!options.headers.containsKey(tokenKey)) {
// 使用我们自定义的 key 添加 token
options.headers[tokenKey] = token;
}
}
// 调用 handler.next(options) 以继续执行请求
// 这一步至关重要,否则请求会被中断
super.onRequest(options, handler);
}
}

View File

@@ -2,6 +2,7 @@ import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:get_storage/get_storage.dart'; import 'package:get_storage/get_storage.dart';
import 'package:getx_scaffold/getx_scaffold.dart'; import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:ln_jq_app/common/model/base_model.dart'; import 'package:ln_jq_app/common/model/base_model.dart';
import 'package:ln_jq_app/common/token_interceptor.dart';
import 'package:ln_jq_app/storage_service.dart'; import 'package:ln_jq_app/storage_service.dart';
import 'common/styles/theme.dart'; import 'common/styles/theme.dart';
@@ -52,7 +53,10 @@ void main() async {
void initHttpSet() { void initHttpSet() {
// 设置基础 URL // 设置基础 URL
HttpService.to.setBaseUrl(AppTheme.test_service_url); HttpService.to.setBaseUrl(AppTheme.test_service_url);
//指定请求头
HttpService.to.dio.interceptors.add(
TokenInterceptor(tokenKey: 'asoco-token'),
);
// 设置全局响应处理器 // 设置全局响应处理器
HttpService.to.setOnResponseHandler((response) async { HttpService.to.setOnResponseHandler((response) async {
try { try {

View File

@@ -1,5 +1,6 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart'; import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:ln_jq_app/common/model/base_model.dart';
import 'package:ln_jq_app/pages/login/view.dart'; import 'package:ln_jq_app/pages/login/view.dart';
import '../../../storage_service.dart'; import '../../../storage_service.dart';
@@ -13,7 +14,7 @@ class ReservationController extends GetxController with BaseControllerMixin {
final List<String> operationStatusOptions = ['营运中', '维修中', '暂停营业', '站点关闭']; final List<String> operationStatusOptions = ['营运中', '维修中', '暂停营业', '站点关闭'];
// 当前选中的值,默认为'运营中' // 当前选中的值,默认为'运营中'
late String selectedOperationStatus; String selectedOperationStatus = "";
ReservationController() { ReservationController() {
selectedOperationStatus = operationStatusOptions[0]; // 初始化选中值 selectedOperationStatus = operationStatusOptions[0]; // 初始化选中值
@@ -26,14 +27,68 @@ class ReservationController extends GetxController with BaseControllerMixin {
renderData(); renderData();
} }
String name = "";
String address = "";
String phone = "";
String costPrice = ""; //氢气价格
String customerPrice = ""; //官方价格
String startBusiness = "";
String endBusiness = "";
String timeStr = "";
String operatingEnterprise = "";
String hydrogenId = "";
Future<void> renderData() async { Future<void> renderData() async {
showLoading("加载中"); showLoading("加载中");
// 模拟网络请求延迟 try {
await Future.delayed(const Duration(seconds: 1)); var responseData = await HttpService.to.get(
'appointment/station/getStationInfoById?hydrogenId=${StorageService.to.userId}',
);
dismissLoading(); if (responseData == null && responseData!.data == null) {
updateUi(); dismissLoading();
showToast('暂时无法获取站点信息');
return;
}
try {
var result = BaseModel.fromJson(responseData.data);
name = result.data["name"];
hydrogenId = result.data["hydrogenId"].toString();
address = result.data["address"];
costPrice = result.data["costPrice"].toString();
customerPrice = result.data["customerPrice"].toString();
phone = result.data["phone"];
startBusiness = result.data["startBusiness"];
endBusiness = result.data["endBusiness"];
operatingEnterprise = result.data["operatingEnterprise"].toString();
selectedOperationStatus = result.data["siteStatusName"].toString();
if (startBusiness.isNotEmpty && endBusiness.isNotEmpty) {
// 营业时间为24小时的特殊处理
if (startBusiness == "00:00:00" && endBusiness == "23:59:59") {
timeStr = "24小时营业";
} else {
timeStr = '${startBusiness.substring(0, 5)} - ${endBusiness.substring(0, 5)}';
}
} else {
timeStr = "时间未设置";
}
operatingEnterprise = operatingEnterprise.isEmpty ? "暂未设置" : operatingEnterprise;
updateUi();
dismissLoading();
} catch (e) {
// 如果解析 JSON 失败
dismissLoading();
showToast('数据异常');
}
} catch (e) {
dismissLoading();
}
} }
/// 更新运营状态的方法 /// 更新运营状态的方法
@@ -44,18 +99,45 @@ class ReservationController extends GetxController with BaseControllerMixin {
} }
} }
void saveInfo() { void saveInfo() async {
// TODO: 在这里执行保存信息的逻辑 showLoading("保存中");
// 1. 获取所有输入框和下拉框的最新值
// 2. 调用API接口将数据提交到服务器 try {
// 3. 根据接口返回结果给出提示(成功或失败) var responseData = await HttpService.to.post(
Get.snackbar('提示', '保存成功!'); // 示例:显示一个成功的提示 'appointment/station/updateStationStatus',
data: {
'hydrogenId': hydrogenId,
'siteStatus': selectedOperationStatus == "营运中"
? "0"
: selectedOperationStatus == "维修中"
? "1"
: selectedOperationStatus == "站点关闭"
? "2"
: selectedOperationStatus == "暂停营业"
? "3"
: 0,
'updateTime': getNowDateTimeString(),
},
);
if (responseData == null && responseData!.data == null) {
dismissLoading();
showToast('服务暂不可用,请稍后');
return;
}
var result = BaseModel.fromJson(responseData.data);
if (result.code == 0) {
showSuccessToast("保存成功");
}
dismissLoading();
} catch (e) {
dismissLoading();
}
} }
void logout() async{ void logout() async {
// TODO: 在这里执行退出登录的逻辑 // TODO: 在这里执行退出登录的逻辑
//清理本地缓存的用户信息 导航到登录页面 //清理本地缓存的用户信息 导航到登录页面
HttpService.to.clearAuthorization();
await StorageService.to.clearLoginInfo(); await StorageService.to.clearLoginInfo();
Get.offAll(() => LoginPage()); Get.offAll(() => LoginPage());

View File

@@ -44,15 +44,25 @@ class ReservationPage extends GetView<ReservationController> {
children: [ children: [
ListTile( ListTile(
leading: const Icon(Icons.local_gas_station, color: Colors.blue, size: 40), leading: const Icon(Icons.local_gas_station, color: Colors.blue, size: 40),
title: const Text('H2加氢站', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18)), title: Text(
subtitle: const Text('上海市浦东新区张江高科技园区'), controller.name,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
subtitle: Text(controller.address),
trailing: Container( trailing: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4), padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.blue[100], color: Colors.blue[100],
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
), ),
child: const Text('运营中', style: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold, fontSize: 12)), child: Text(
controller.selectedOperationStatus,
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
), ),
), ),
const Divider(height: 1, indent: 16, endIndent: 16), const Divider(height: 1, indent: 16, endIndent: 16),
@@ -61,8 +71,8 @@ class ReservationPage extends GetView<ReservationController> {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [ children: [
_buildHeaderStat('¥45', '氢气价格'), _buildHeaderStat('¥${controller.costPrice}', '氢气价格'),
_buildHeaderStat('24h', '营业时间'), _buildHeaderStat(controller.timeStr, '营业时间'),
_buildHeaderStat('98%', '设备状态'), _buildHeaderStat('98%', '设备状态'),
], ],
), ),
@@ -76,7 +86,14 @@ class ReservationPage extends GetView<ReservationController> {
Widget _buildHeaderStat(String value, String label) { Widget _buildHeaderStat(String value, String label) {
return Column( return Column(
children: [ children: [
Text(value, style: const TextStyle(color: Colors.blue, fontSize: 20, fontWeight: FontWeight.bold)), Text(
value,
style: const TextStyle(
color: Colors.blue,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4), const SizedBox(height: 4),
Text(label, style: const TextStyle(color: Colors.grey, fontSize: 12)), Text(label, style: const TextStyle(color: Colors.grey, fontSize: 12)),
], ],
@@ -95,15 +112,15 @@ class ReservationPage extends GetView<ReservationController> {
children: [ children: [
// --- 基本信息 --- // --- 基本信息 ---
_buildSectionTitle('基本信息'), _buildSectionTitle('基本信息'),
_buildDisplayField(label: '站点名称', value: 'H2加氢站'), _buildDisplayField(label: '站点名称', value: controller.name),
_buildDisplayField(label: '运营企业', value: '上海氢能科技有限公司'), _buildDisplayField(label: '运营企业', value: controller.operatingEnterprise),
_buildDisplayField(label: '站点地址', value: '上海市浦东新区张江高科技园区'), _buildDisplayField(label: '站点地址', value: controller.address),
const SizedBox(height: 16), const SizedBox(height: 16),
// --- 价格信息 --- // --- 价格信息 ---
_buildSectionTitle('价格信息'), _buildSectionTitle('价格信息'),
_buildDisplayField(label: '氢气价格 (元/kg)', value: '45'), _buildDisplayField(label: '氢气价格 (元/kg)', value: controller.costPrice),
_buildDisplayField(label: '官方价格 (元/kg)', value: '50'), _buildDisplayField(label: '官方价格 (元/kg)', value: controller.customerPrice),
const SizedBox(height: 16), const SizedBox(height: 16),
// --- 运营信息 --- // --- 运营信息 ---
@@ -114,10 +131,7 @@ class ReservationPage extends GetView<ReservationController> {
DropdownButtonFormField<String>( DropdownButtonFormField<String>(
value: controller.selectedOperationStatus, value: controller.selectedOperationStatus,
items: controller.operationStatusOptions.map((String value) { items: controller.operationStatusOptions.map((String value) {
return DropdownMenuItem<String>( return DropdownMenuItem<String>(value: value, child: Text(value));
value: value,
child: Text(value),
);
}).toList(), }).toList(),
onChanged: controller.onOperationStatusChanged, onChanged: controller.onOperationStatusChanged,
decoration: InputDecoration( decoration: InputDecoration(
@@ -126,8 +140,8 @@ class ReservationPage extends GetView<ReservationController> {
), ),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
_buildDisplayField(label: '营业时间', value: '24小时营业'), _buildDisplayField(label: '营业时间', value: controller.timeStr),
_buildDisplayField(label: '联系电话', value: '021-12345678'), _buildDisplayField(label: '联系电话', value: controller.phone),
const SizedBox(height: 24), const SizedBox(height: 24),
//保存按钮 //保存按钮
@@ -176,7 +190,10 @@ class ReservationPage extends GetView<ReservationController> {
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
elevation: 2, elevation: 2,
), ),
child: const Text('退出登录', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)), child: const Text(
'退出登录',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
); );
} }
@@ -227,7 +244,9 @@ class ReservationPage extends GetView<ReservationController> {
children: [ children: [
Icon(icon, color: Colors.blue, size: 20), Icon(icon, color: Colors.blue, size: 20),
const SizedBox(width: 10), const SizedBox(width: 10),
Expanded(child: Text(text, style: const TextStyle(fontSize: 14, color: Colors.black54))), Expanded(
child: Text(text, style: const TextStyle(fontSize: 14, color: Colors.black54)),
),
], ],
); );
} }

View File

@@ -273,14 +273,13 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
dismissLoading(); dismissLoading();
showToast('登录成功,欢迎您'); showToast('登录成功,欢迎您');
HttpService.to.setAuthorization(token);
// 跳转到主页,并清除所有历史页面 // 跳转到主页,并清除所有历史页面
Get.offAll(() => B_BaseWidgetsPage()); Get.offAll(() => B_BaseWidgetsPage());
} catch (e) { } catch (e) {
// 如果解析 JSON 失败 // 如果解析 JSON 失败
dismissLoading(); dismissLoading();
showToast('登录失败:返回数据解析失败${e.toString()}'); showToast('登录失败:数据异常');
} }
} catch (e) { } catch (e) {
dismissLoading(); dismissLoading();