From 988052630ac26f85f302024f3123cb9de3ff4deb Mon Sep 17 00:00:00 2001 From: zhuce <821293938@qq.com> Date: Sat, 9 Mar 2024 14:28:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=BA=9B=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/api/login_api.dart | 2 +- lib/config/constant.dart | 81 ++++++++++++ lib/main.dart | 15 ++- lib/pages/login/login_page.dart | 21 +++- lib/util/device_id_utils.dart | 15 +++ lib/util/sp_util.dart | 85 +++++++++++++ lib/util/xhttp.dart | 2 +- pubspec.lock | 215 +++++++++++++++++++++++++++++++- pubspec.yaml | 3 + 9 files changed, 424 insertions(+), 15 deletions(-) create mode 100644 lib/config/constant.dart create mode 100644 lib/util/device_id_utils.dart create mode 100644 lib/util/sp_util.dart diff --git a/lib/api/login_api.dart b/lib/api/login_api.dart index e08b416..5892c07 100644 --- a/lib/api/login_api.dart +++ b/lib/api/login_api.dart @@ -15,6 +15,6 @@ class LoginApi { "wx_unionid": unionid }; var post = await xHttp.post("/v2/auth/get-access-token", data); - print(post); + // print(post); } } diff --git a/lib/config/constant.dart b/lib/config/constant.dart new file mode 100644 index 0000000..1f0e04c --- /dev/null +++ b/lib/config/constant.dart @@ -0,0 +1,81 @@ +class Constant{ +//测试地址 + static const String testHost = "http://api.test.jjsos.cn/"; + //线上地址 + static const String host = "http://api.jjsos.cn/"; + //图片的host + static const String pictureHost = "http://pic.jjsos.cn/"; + //工单签字地址 + static const String testWorkOrderUrl = "http://backend.test.jjsos.cn/old/elc-work-new-app?order_id="; + static const String workOrderUrl = "http://backend.jjsos.cn/old/elc-work-new-app?order_id="; + //是否在线 + static bool isOrderStar = false; + //是否打开页面 + static bool isOpen = false; + + //网络是否正常(心跳检测) + static bool weberror=false; + //上一次心跳时间 + static int heartbeatTime = 0; + static int onlineTime = 0; + //是否服务中 + static bool isService = false; + static bool isMain = false; + + //是否有消息 + static bool hasMessage = false; + static bool hasMessageInform = false; + + static const String WX_ID = "wx3bd407849a19c609"; + static const String WX_Secret = "efb0ca67e9b2a58fb5b460b8b4153563"; + + //当前位置 + static double lat = 0.00; + static double lng = 0.00; + static String address = ""; + //退出登录 + static const String OUT_LOGIN_TOKEN = "OUT_LOGIN_TOKEN"; + //抛单空驶订单签字回调 + static const String ORDER_EMPTY_SIGN_TOKEN = "ORDER_EMPTY_SIGN_TOKEN"; + //新订单来了 推送token + static const String ORDER_NEW_TOKEN = "ORDER_NEW_TOKEN"; + //取消推送 + static const String ORDER_CANCEL_TOKEN = "ORDER_CANCEL_TOKEN"; + //空时推送 + static const String ORDER_EMPTY_TOKEN = "ORDER_EMPTY_TOKEN"; + //订单刷新通知 + static const String ORDER_REFRESH_TOKEN = "ORDER_REFRESH_TOKEN"; + //订单支付完成 + static const String ORDER_PAY_TOKEN = "ORDER_PAY_TOKEN"; + //订单完成 + static const String ORDER_COMPLETE_TOKEN = "ORDER_COMPLETE_TOKEN"; + //音频token + //您有新的内部订单请注意查收 + static const int NEW_ORDER_INSIDE = 1; + //您有新的啾啾救援订单请注意查收 + static const int NEW_ORDER_JIUJIU = 2; + //订单已被后台关闭 + static const int ORDER_BACKSTAGE_CLOSE = 3; + //订单已被修改,请刷新 + static const int ORDER_BACKSTAGE_MODIFY = 4; + //关闭有费空时关闭 + static const int ORDER_BACKSTAGE_CLOSE_CHARGE = 5; + //您是否真的到达救援现场 + static const int WHETHER_ARRIVE_SCENE = 6; + //您已进入离线模式待网络正常后上传照片 + static const int ENTERED_OFFLINE_MODE = 7; + //真的关闭订单吗 + static const int ORDER_WHETHER_CLOSE = 8; + //完成后继续接单 + static const int ORDER_COMPLETE = 9; + //app当前版本号-版本管理 + static String newVersion="4.1.3.9"; + + //更新状态 0=未获取更新信息,1=无需更新,2=需要非强制更新,3=强制更新 4=接口异常(可登录) 5=网络异常(重试) + static int NECUPDATE =0; + + static bool isDriverMessage = false; + static bool isServiceTrailer = true; + static String arriveTipsStr = ""; + static String uploadStartStr = ""; +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 1eeccc4..2ad801b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'package:autosos_flutter/pages/home/home_page.dart'; import 'package:autosos_flutter/pages/login/login_page.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; void main() { runApp(const MyApp()); @@ -13,11 +14,13 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), - useMaterial3: true, - ), - home: const LoginPage()); + title: 'Flutter Demo', + theme: ThemeData( + colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + useMaterial3: true, + ), + home: const LoginPage(), + builder: EasyLoading.init(), + ); } } diff --git a/lib/pages/login/login_page.dart b/lib/pages/login/login_page.dart index 38d889d..08a9206 100644 --- a/lib/pages/login/login_page.dart +++ b/lib/pages/login/login_page.dart @@ -1,7 +1,10 @@ +import 'package:autosos_flutter/api/login_api.dart'; import 'package:autosos_flutter/util/xhttp.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; + + class LoginPage extends StatefulWidget { const LoginPage({super.key}); @@ -10,6 +13,8 @@ class LoginPage extends StatefulWidget { } class _LoginPageState extends State { + final TextEditingController _unameController = TextEditingController(); + final TextEditingController _pwdController = TextEditingController(); @override Widget build(BuildContext context) { return Scaffold( @@ -49,20 +54,22 @@ class _LoginPageState extends State { color: Colors.grey, ), ), - const Expanded( + Expanded( child: TextField( - decoration: InputDecoration(hintText: "请输入手机号"), + controller: _unameController, + decoration: const InputDecoration(hintText: "请输入手机号"), )), ], ), ), - const Padding( - padding: EdgeInsets.all(20), + Padding( + padding: const EdgeInsets.all(20), child: Row( children: [ Expanded( child: TextField( - decoration: InputDecoration(hintText: "请输入密码"), + controller: _pwdController, + decoration: const InputDecoration(hintText: "请输入密码"), )) ], ), @@ -93,6 +100,8 @@ class _LoginPageState extends State { } void _login() async{ - + String username = _unameController.text; + String password = _pwdController.text; + LoginApi.login(1, username, password, "", "", "", ""); } } diff --git a/lib/util/device_id_utils.dart b/lib/util/device_id_utils.dart new file mode 100644 index 0000000..0e94603 --- /dev/null +++ b/lib/util/device_id_utils.dart @@ -0,0 +1,15 @@ +import 'package:autosos_flutter/util/sp_util.dart'; +import 'package:basic_utils/basic_utils.dart'; +import 'package:uuid/uuid.dart'; + +class DeviceIdUtils{ + static String? getDeviceId(){ + SPUtil spUtil = SPUtil(); + var deviceId = spUtil.get("JJdeviceId"); + if(StringUtils.isNullOrEmpty(deviceId)){ + var uuid = const Uuid(); + return uuid.v1(); + } + return deviceId; + } +} \ No newline at end of file diff --git a/lib/util/sp_util.dart b/lib/util/sp_util.dart new file mode 100644 index 0000000..6ed4a49 --- /dev/null +++ b/lib/util/sp_util.dart @@ -0,0 +1,85 @@ +import 'dart:convert'; + +import 'package:shared_preferences/shared_preferences.dart'; + +class SPUtil{ + //创建工厂方法 + static SPUtil? _instance; + factory SPUtil() => _instance ??= SPUtil._initial(); + SharedPreferences? _preferences; + //创建命名构造函数 + SPUtil._initial() { + //为什么在这里需要新写init方法 主要是在命名构造中不能使用async/await + init(); + } + //初始化SharedPreferences + void init() async { + _preferences ??= await SharedPreferences.getInstance(); + } + + //到这里还没有完 有时候会遇到使用时提示 SharedPreferences 未初始化,所以还需要提供一个static 的方法 + static Future perInit() async { + if (_instance == null) { + //静态方法不能访问非静态变量所以需要创建变量再通过方法赋值回去 + SharedPreferences preferences = await SharedPreferences.getInstance(); + _instance = SPUtil._pre(preferences); + } + return _instance; + } + SPUtil._pre(SharedPreferences prefs) { + _preferences = prefs; + } + ///设置String类型的 + void setString(key, value) { + _preferences?.setString(key, value); + } + ///设置setStringList类型的 + void setStringList(key, value) { + _preferences?.setStringList(key, value); + } + ///设置setBool类型的 + void setBool(key, value) { + _preferences?.setBool(key, value); + } + ///设置setDouble类型的 + void setDouble(key, value) { + _preferences?.setDouble(key, value); + } + ///设置setInt类型的 + void setInt(key, value) { + _preferences?.setInt(key, value); + } + ///存储Json类型的 + void setJson(key, value) { + value = jsonEncode(value); + _preferences?.setString(key, value); + } + ///通过泛型来获取数据 + T? get(key) { + var result = _preferences?.get(key); + if (result != null) { + return result as T; + } + return null; + } + ///获取JSON + Map? getJson(key) { + String? result = _preferences?.getString(key); + if (result!=null && result!='') { + return jsonDecode(result); + } + return null; + } + ///文中的StringUtil中的isNotEmpty的判断 + /// static isNotEmpty(String? str) { + /// return str?.isNotEmpty ?? false; + /// } + ///清除全部 + void clean() { + _preferences?.clear(); + } + ///移除某一个 + void remove(key) { + _preferences?.remove(key); + } +} \ No newline at end of file diff --git a/lib/util/xhttp.dart b/lib/util/xhttp.dart index f00c135..85d81a2 100644 --- a/lib/util/xhttp.dart +++ b/lib/util/xhttp.dart @@ -41,7 +41,7 @@ class XHttp { static Dio dio = Dio(); // static Dio dio; - String _getBaseUrl() => 'https:xxx/'; + String _getBaseUrl() => 'http://api.test.jjsos.cn'; /// 通用全局单例,第一次使用时初始化。 XHttp._internal() { if ('' == dio.options.baseUrl) { diff --git a/pubspec.lock b/pubspec.lock index 7a23adc..f128666 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -33,6 +33,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.11.0" + basic_utils: + dependency: "direct main" + description: + name: basic_utils + sha256: "2064b21d3c41ed7654bc82cc476fd65542e04d60059b74d5eed490a4da08fc6c" + url: "https://pub.flutter-io.cn" + source: hosted + version: "5.7.0" boolean_selector: dependency: transitive description: @@ -65,6 +73,22 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.18.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.1.1" + crypto: + dependency: transitive + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.3" cupertino_icons: dependency: "direct main" description: @@ -89,6 +113,30 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.0" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.flutter-io.cn" + source: hosted + version: "7.0.0" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -131,6 +179,19 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + http: + dependency: transitive + description: + name: http + sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.2.0" http_parser: dependency: transitive description: @@ -139,6 +200,22 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "4.0.2" + js: + dependency: transitive + description: + name: js + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.7.1" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.8.1" lints: dependency: transitive description: @@ -147,6 +224,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.1" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.2.0" matcher: dependency: transitive description: @@ -179,6 +264,38 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.8.3" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.1" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.2" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.1" + platform: + dependency: transitive + description: + name: platform + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.1.4" plugin_platform_interface: dependency: transitive description: @@ -187,6 +304,70 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.8" + pointycastle: + dependency: transitive + description: + name: pointycastle + sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29" + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.7.4" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + sha256: "81429e4481e1ccfb51ede496e916348668fd0921627779233bd24cc3ff6abd02" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.2" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + sha256: "8568a389334b6e83415b6aae55378e158fbc2314e074983362d20c562780fb06" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.1" + shared_preferences_foundation: + dependency: transitive + description: + name: shared_preferences_foundation + sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.3.5" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.3.2" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.3.2" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + sha256: "7b15ffb9387ea3e237bb7a66b8a23d2147663d391cafc5c8f37b2e7b4bde5d21" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.2" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.3.2" sky_engine: dependency: transitive description: flutter @@ -200,6 +381,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.10.0" + sprintf: + dependency: transitive + description: + name: sprintf + sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" + url: "https://pub.flutter-io.cn" + source: hosted + version: "7.0.0" stack_trace: dependency: transitive description: @@ -256,6 +445,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.3.2" + uuid: + dependency: "direct main" + description: + name: uuid + sha256: cd210a09f7c18cbe5a02511718e0334de6559871052c90a90c0cca46a4aa81c8 + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.3.3" vector_math: dependency: transitive description: @@ -272,6 +469,22 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.3.0" + win32: + dependency: transitive + description: + name: win32 + sha256: "464f5674532865248444b4c3daca12bd9bf2d7c47f759ce2617986e7229494a8" + url: "https://pub.flutter-io.cn" + source: hosted + version: "5.2.0" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.4" sdks: dart: ">=3.2.6 <4.0.0" - flutter: ">=3.7.0" + flutter: ">=3.16.0" diff --git a/pubspec.yaml b/pubspec.yaml index d78250c..0850f20 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,9 @@ dependencies: amap_flutter_map: ^3.0.0 dio: ^5.4.1 flutter_easyloading: ^3.0.5 + shared_preferences: ^2.2.2 + basic_utils: ^5.7.0 + uuid: ^4.3.3 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.