更新
This commit is contained in:
@@ -16,8 +16,14 @@ class ServiceConstant {
|
||||
static String sleep_report = "/api/device/sleep/data";//睡眠报告
|
||||
static String device_share = "/api/device/share";//分享设备
|
||||
static String message_list = "/api/mesasge/list";//消息列表
|
||||
static String message_read = "/api/mesasge/read";//消息未读数量
|
||||
static String device_show = "/api/device/bind";//更新设备绑定
|
||||
static String disease_list = "/api/personnel/disease/list";//获取疾病类型
|
||||
static String share_deleted = "";//删除分享
|
||||
static String start_calibration = "";//开始校准
|
||||
static String calibration_process = "";//校准进度
|
||||
static String submit_repair = "";//提交报修
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,4 +23,8 @@ class AppConstants {
|
||||
double small_text_fontSize = 20.rpx; //普通文字字号
|
||||
double normal_text_fontSize = 26.rpx; //普通文字字号
|
||||
double title_text_fontSize = 30.rpx; //标题文字字号
|
||||
|
||||
double dropdown_height = 90.rpx; //标题文字字号
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
// lib/api_endpoints.dart
|
||||
|
||||
import 'package:vbvs_app/common/util/CommonVariables.dart';
|
||||
|
||||
class ApiEndpoints {
|
||||
// Base URL of the API
|
||||
static String baseUrl = '${CommonVariables.apiUrl}/api';
|
||||
|
||||
// Endpoints
|
||||
static String signIn = '$baseUrl/auth/account/info/signIn'; //登录
|
||||
static String getUserInfo = '$baseUrl/user/info'; //获取用户信息
|
||||
static String updateProfile = '$baseUrl/user/updateProfile'; //更新用户信息
|
||||
static String login_code = '$baseUrl/auth/msg/signIn'; //登录验证码
|
||||
static String wx_auth_code = '$baseUrl/auth/msg/wxAuth'; //微信授权验证码
|
||||
static String register = '$baseUrl/auth/account/info/signUp'; //注册
|
||||
static String reset_code = '$baseUrl/auth/msg/restore'; //重置验证码
|
||||
static String reset_pd = '$baseUrl/auth/account/info/restore/pw'; //重置密码
|
||||
static String updateUserInfo =
|
||||
'$baseUrl/auth/account/info/nameAndHead'; //更新用户资料
|
||||
static String autoLogin = '$baseUrl/auth/account/info/autoLogin'; //自动登录
|
||||
|
||||
//订单管理
|
||||
static String orderList = "/api/order/info/list"; //订单列表
|
||||
static String orderQianshou = "/api/order/info/get"; //签收
|
||||
|
||||
//分享设备
|
||||
static String deviceInvite = '$baseUrl/api/device/info/share'; //分享设备
|
||||
|
||||
// Add more endpoints as needed
|
||||
//添加/床垫控制日志
|
||||
static String addLog = '$baseUrl/oplog/add';
|
||||
}
|
||||
99
lib/common/util/CheckNetwork.dart
Normal file
99
lib/common/util/CheckNetwork.dart
Normal file
@@ -0,0 +1,99 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:vbvs_app/common/util/CommonVariables.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/pages/common/selectDialog.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
|
||||
|
||||
class Checknetwork {
|
||||
static final Connectivity _connectivity = Connectivity();
|
||||
static StreamSubscription<List<ConnectivityResult>>? subscription;
|
||||
static bool isShowDialog = false;
|
||||
|
||||
static connectivityResultChange(connectivityResult) {
|
||||
if (connectivityResult.contains(ConnectivityResult.mobile)) {
|
||||
print("ConnectivityResult:Mobile network available.");
|
||||
// Mobile network available.
|
||||
toInitData();
|
||||
} else if (connectivityResult.contains(ConnectivityResult.wifi)) {
|
||||
print("ConnectivityResult:Wi-fi is available.");
|
||||
toInitData();
|
||||
// Wi-fi is available.
|
||||
// Note for Android:
|
||||
// When both mobile and Wi-Fi are turned on system will return Wi-Fi only as active network type
|
||||
} else if (connectivityResult.contains(ConnectivityResult.ethernet)) {
|
||||
print("ConnectivityResult:Ethernet connection available.");
|
||||
toInitData();
|
||||
// Ethernet connection available.
|
||||
} else if (connectivityResult.contains(ConnectivityResult.vpn)) {
|
||||
print("ConnectivityResult:Vpn connection active.");
|
||||
toInitData();
|
||||
// Vpn connection active.
|
||||
// Note for iOS and macOS:
|
||||
// There is no separate network interface type for [vpn].
|
||||
// It returns [other] on any device (also simulator)
|
||||
} else if (connectivityResult.contains(ConnectivityResult.bluetooth)) {
|
||||
// Bluetooth connection available.
|
||||
} else if (connectivityResult.contains(ConnectivityResult.other)) {
|
||||
// Connected to a network which is not in the above mentioned networks.
|
||||
print(
|
||||
"ConnectivityResult:Connected to a network which is not in the above mentioned networks");
|
||||
toInitData();
|
||||
} else if (connectivityResult.contains(ConnectivityResult.none)) {
|
||||
// No available network types
|
||||
print("ConnectivityResult:No available network types");
|
||||
}
|
||||
}
|
||||
|
||||
static toInitData() async {
|
||||
CommonVariables.isNetWorkOn = true;
|
||||
if (isShowDialog) {
|
||||
Get.back();
|
||||
isShowDialog = false;
|
||||
}
|
||||
}
|
||||
|
||||
static checkNetwork() async {
|
||||
// Platform messages may fail, so we use a try/catch PlatformException.
|
||||
try {
|
||||
connectivityResultChange(await (_connectivity.checkConnectivity()));
|
||||
} on PlatformException catch (e) {
|
||||
print("Couldn't check connectivity status:Error:$e");
|
||||
}
|
||||
// 网络状态变化监听,登录成功后移出监听
|
||||
subscription = _connectivity.onConnectivityChanged
|
||||
.listen((List<ConnectivityResult> connectivityResult) {
|
||||
connectivityResultChange(connectivityResult);
|
||||
});
|
||||
if (CommonVariables.isNetWorkOn == false) {
|
||||
int index = 0;
|
||||
Timer.periodic(const Duration(seconds: 1), (t) {
|
||||
index++;
|
||||
if (index > 40 || CommonVariables.isNetWorkOn == true) {
|
||||
t.cancel();
|
||||
} else if (index > 20 && isShowDialog == false) {
|
||||
t.cancel();
|
||||
var context = Get.context;
|
||||
String name = "";
|
||||
if (Platform.isAndroid) {
|
||||
name = "安卓启用网络提示".tr;
|
||||
} else {
|
||||
name = "ios启用网络提示".tr;
|
||||
}
|
||||
// isShowDialog = true;
|
||||
// showCustomConfirmDialog(context!, name).then((d) {
|
||||
// isShowDialog = false;
|
||||
// });
|
||||
showTipDialog(context!,Text(name,style: TextStyle(
|
||||
color: themeController.currentColor.sc3,
|
||||
),));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,6 @@
|
||||
class CommonVariables {
|
||||
static bool isNetWorkOn = false;
|
||||
static bool test = false;
|
||||
static String supabaseUrl = "https://mht1.he-info.cn";
|
||||
// static String wsUrl = "ws://mht-server.he-info.cn/ws";
|
||||
// static String apiUrl = "https://mht-server.he-info.cn";
|
||||
// static String shoph5Url = "https://mht-web.he-info.cn";
|
||||
// static String supabaseUrl = "https://zhmht.swes.com.cn:3443";
|
||||
// static String wsUrl = "wss://zhmht.swes.com.cn:8089/ws";
|
||||
// static String apiUrl = "https://zhmht.swes.com.cn:8089";
|
||||
static String wsUrl = "ws://192.168.1.129:8088/ws";
|
||||
static String apiUrl = "http://192.168.1.129:8088";
|
||||
static String shoph5Url = "https://zhmht.swes.com.cn:1443";
|
||||
static String sleepUrl = "https://alltoone.he-info.cn";
|
||||
static String efKey = "ef_key";
|
||||
|
||||
// // android app 内部更新地址
|
||||
// static String androidInternalUpgradeUrl = "http://192.168.0.112:1234";
|
||||
|
||||
// 企业微信客服拉起的url地址
|
||||
static String wxKfUrl = "https://work.weixin.qq.com/kfid/kfc7d2337b9c07b1269";
|
||||
@@ -28,10 +13,5 @@ class CommonVariables {
|
||||
//备案时间
|
||||
static String ICPTime = "2022-2025";
|
||||
|
||||
// 分享复制文字信息
|
||||
static String shareText = "您的朋友邀请您使用《智慧眠花糖》APP,请复制后面链接在浏览器中打开! " +
|
||||
shoph5Url +
|
||||
"/#/pages/download/download";
|
||||
|
||||
static Map<String, Function(dynamic)> callMap = {};
|
||||
}
|
||||
|
||||
@@ -3,22 +3,15 @@ import 'dart:async';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/CommonVariables.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/controller/setting/language/language_controller.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
|
||||
ThemeController themeController = Get.find();
|
||||
|
||||
Future<void> initDataEf({String key = ""}) async {
|
||||
await ef.init(
|
||||
'${CommonVariables.supabaseUrl}/',
|
||||
key,
|
||||
nosqlEnableWebsocket: false,
|
||||
);
|
||||
}
|
||||
LanguageController languageController = Get.find();
|
||||
|
||||
class MyUtils {
|
||||
static ApiResponse formatResponse(
|
||||
@@ -330,15 +323,6 @@ String time_08_Formatter_pattern(String time, String pattern) {
|
||||
return DateFormat(pattern).format(DateTime.parse(time).toLocal());
|
||||
}
|
||||
|
||||
String storagePubSrc =
|
||||
"${CommonVariables.supabaseUrl}/storage/v1/object/public/";
|
||||
|
||||
getStorageResourceUrl(String v) {
|
||||
if (v.contains('http')) {
|
||||
return v;
|
||||
}
|
||||
return storagePubSrc + v;
|
||||
}
|
||||
|
||||
enum LoadingDialogIcon { ble, wifi, none }
|
||||
|
||||
|
||||
105
lib/common/util/requestWithLog.dart
Normal file
105
lib/common/util/requestWithLog.dart
Normal file
@@ -0,0 +1,105 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
|
||||
Future<ApiResponse> requestWithLog({
|
||||
required String logTitle,
|
||||
required MyHttpMethod method,
|
||||
required String queryUrl,
|
||||
Map<String, dynamic>? data,
|
||||
String successMsg = "操作成功",
|
||||
String errorMsg = "操作失败",
|
||||
void Function(ApiResponse res)? onSuccess,
|
||||
void Function(ApiResponse res)? onFailure,
|
||||
}) async {
|
||||
EasyDartModule.logger.info(logTitle);
|
||||
DailyLogUtils.writeLog(logTitle);
|
||||
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "请求失败".tr);
|
||||
try {
|
||||
String? language = "";
|
||||
if (languageController.selectLanguage != null) {
|
||||
language = languageController.selectLanguage.value!.language_code;
|
||||
}
|
||||
if (language != null && language.isNotEmpty) {
|
||||
if (queryUrl.contains("?")) {
|
||||
queryUrl += "&lang=$language";
|
||||
} else {
|
||||
queryUrl += "?lang=$language";
|
||||
}
|
||||
}
|
||||
successMsg = successMsg.tr;
|
||||
errorMsg = errorMsg.tr;
|
||||
|
||||
var response;
|
||||
|
||||
switch (method) {
|
||||
case MyHttpMethod.get:
|
||||
response = await EasyDartModule.dio.get(queryUrl);
|
||||
break;
|
||||
case MyHttpMethod.post:
|
||||
response = data != null
|
||||
? await EasyDartModule.dio.post(queryUrl, data: jsonEncode(data))
|
||||
: await EasyDartModule.dio.post(queryUrl);
|
||||
break;
|
||||
case MyHttpMethod.put:
|
||||
response = data != null
|
||||
? await EasyDartModule.dio.put(queryUrl, data: jsonEncode(data))
|
||||
: await EasyDartModule.dio.put(queryUrl);
|
||||
break;
|
||||
case MyHttpMethod.delete:
|
||||
response = data != null
|
||||
? await EasyDartModule.dio.delete(queryUrl, data: jsonEncode(data))
|
||||
: await EasyDartModule.dio.delete(queryUrl);
|
||||
break;
|
||||
}
|
||||
|
||||
if (response != null) {
|
||||
final responseData =
|
||||
response.data is String ? jsonDecode(response.data) : response.data;
|
||||
|
||||
apiResponse = ApiResponse.fromJson(responseData, (object) => object);
|
||||
|
||||
if (apiResponse.code == HttpStatusCodes.ok) {
|
||||
MyUtils.formatResponse(apiResponse, successMsg, errorMsg);
|
||||
onSuccess?.call(apiResponse);
|
||||
} else {
|
||||
apiResponse.msg = responseData['msg'] ?? errorMsg;
|
||||
onFailure?.call(apiResponse);
|
||||
}
|
||||
|
||||
return apiResponse;
|
||||
} else {
|
||||
apiResponse = ApiResponse(code: -1, msg: "服务器.失败".tr);
|
||||
onFailure?.call(apiResponse);
|
||||
return apiResponse;
|
||||
}
|
||||
} catch (e) {
|
||||
EasyDartModule.logger.error("$logTitle 失败->$e");
|
||||
DailyLogUtils.writeError("$logTitle 失败->$e");
|
||||
onFailure?.call(apiResponse);
|
||||
return apiResponse;
|
||||
}
|
||||
}
|
||||
|
||||
enum MyHttpMethod { get, post, put, delete }
|
||||
|
||||
extension HttpMethodExtension on MyHttpMethod {
|
||||
String get name {
|
||||
switch (this) {
|
||||
case MyHttpMethod.get:
|
||||
return 'GET';
|
||||
case MyHttpMethod.post:
|
||||
return 'POST';
|
||||
case MyHttpMethod.put:
|
||||
return 'PUT';
|
||||
case MyHttpMethod.delete:
|
||||
return 'DELETE';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user