hyzp_ybqx-Commit001:代码刚转换好,编译通过
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
import 'dart:convert';
|
||||
import 'Storage.dart';
|
||||
import '../config/Config.dart';
|
||||
|
||||
class CartServices {
|
||||
static addCart(item) async {
|
||||
//把对象转换成Map类型的数据
|
||||
item = CartServices.formatCartData(item);
|
||||
|
||||
/*
|
||||
1、获取本地存储的cartList数据
|
||||
2、判断cartList是否有数据
|
||||
有数据:
|
||||
1、判断购物车有没有当前数据:
|
||||
有当前数据:
|
||||
1、让购物车中的当前数据数量 等于以前的数量+现在的数量
|
||||
2、重新写入本地存储
|
||||
|
||||
没有当前数据:
|
||||
1、把购物车cartList的数据和当前数据拼接,拼接后重新写入本地存储。
|
||||
|
||||
没有数据:
|
||||
1、把当前商品数据以及属性数据放在数组中然后写入本地存储
|
||||
|
||||
|
||||
|
||||
List list=[
|
||||
{"_id": "1",
|
||||
"title": "磨砂牛皮男休闲鞋-有属性",
|
||||
"price": 688,
|
||||
"selectedAttr": "牛皮 ,系带,黄色",
|
||||
"count": 4,
|
||||
"pic":"public\upload\RinsvExKu7Ed-ocs_7W1DxYO.png",
|
||||
"checked": true
|
||||
},
|
||||
{"_id": "2",
|
||||
"title": "磨xxxxxxxxxxxxx",
|
||||
"price": 688,
|
||||
"selectedAttr": "牛皮 ,系带,黄色",
|
||||
"count": 2,
|
||||
"pic":"public\upload\RinsvExKu7Ed-ocs_7W1DxYO.png",
|
||||
"checked": true
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
|
||||
*/
|
||||
|
||||
try {
|
||||
List cartListData = json.decode(await Storage.getString('cartList'));
|
||||
|
||||
//判断购物车有没有当前数据
|
||||
bool hasData = cartListData.any((value) {
|
||||
return value['_id'] == item['_id'] &&
|
||||
value['selectedAttr'] == item['selectedAttr'];
|
||||
});
|
||||
|
||||
if (hasData) {
|
||||
for (var i = 0; i < cartListData.length; i++) {
|
||||
if (cartListData[i]['_id'] == item['_id'] &&
|
||||
cartListData[i]['selectedAttr'] == item['selectedAttr']) {
|
||||
cartListData[i]["count"] = cartListData[i]["count"] + 1;
|
||||
}
|
||||
}
|
||||
await Storage.setString('cartList', json.encode(cartListData));
|
||||
} else {
|
||||
cartListData.add(item);
|
||||
await Storage.setString('cartList', json.encode(cartListData));
|
||||
}
|
||||
} catch (e) {
|
||||
List tempList = [];
|
||||
tempList.add(item);
|
||||
await Storage.setString('cartList', json.encode(tempList));
|
||||
}
|
||||
}
|
||||
|
||||
//过滤数据
|
||||
static formatCartData(item) {
|
||||
//处理图片
|
||||
String pic = item.pic;
|
||||
pic = Config.domain + pic.replaceAll('\\', '/');
|
||||
|
||||
final Map data = new Map<String, dynamic>();
|
||||
data['_id'] = item.sId;
|
||||
data['title'] = item.num;
|
||||
//处理 string 和int类型的价格
|
||||
if (item.price is int || item.price is double) {
|
||||
data['price'] = item.price;
|
||||
} else {
|
||||
data['price'] = double.parse(item.price);
|
||||
}
|
||||
data['selectedAttr'] = item.selectedAttr;
|
||||
data['count'] = item.count;
|
||||
data['pic'] = pic;
|
||||
//是否选中
|
||||
data['checked'] = true;
|
||||
return data;
|
||||
}
|
||||
|
||||
//获取购物车选中的数据
|
||||
static getCheckOutData() async {
|
||||
List cartListData = [];
|
||||
List tempCheckOutData = [];
|
||||
try {
|
||||
cartListData = json.decode(await Storage.getString('cartList'));
|
||||
} catch (e) {
|
||||
cartListData = [];
|
||||
}
|
||||
for (var i = 0; i < cartListData.length; i++) {
|
||||
if (cartListData[i]["checked"] == true) {
|
||||
tempCheckOutData.add(cartListData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return tempCheckOutData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'dart:convert';
|
||||
import '../services/Storage.dart';
|
||||
class CheckOutServices{
|
||||
//计算总价
|
||||
static getAllPrice(checkOutListData) {
|
||||
var tempAllPrice=0.0;
|
||||
for (var i = 0; i < checkOutListData.length; i++) {
|
||||
if (checkOutListData[i]["checked"] == true) {
|
||||
tempAllPrice += checkOutListData[i]["price"] * checkOutListData[i]["count"];
|
||||
}
|
||||
}
|
||||
return tempAllPrice;
|
||||
}
|
||||
static removeUnSelectedCartItem() async{
|
||||
|
||||
List _cartList=[];
|
||||
List _tempList=[];
|
||||
//获取购物车的数据
|
||||
try {
|
||||
List cartListData = json.decode(await Storage.getString('cartList'));
|
||||
_cartList = cartListData;
|
||||
} catch (e) {
|
||||
_cartList = [];
|
||||
}
|
||||
|
||||
for (var i = 0; i < _cartList.length; i++) {
|
||||
if (_cartList[i]["checked"] == false) {
|
||||
_tempList.add(_cartList[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Storage.setString("cartList", json.encode(_tempList));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
import 'package:event_bus/event_bus.dart';
|
||||
|
||||
//Bus 初始化
|
||||
|
||||
EventBus eventBus = EventBus();
|
||||
|
||||
//监听统计数据改变事件
|
||||
class StatisDataUpdate {
|
||||
String str;
|
||||
|
||||
StatisDataUpdate(String _str) {
|
||||
this.str = _str;
|
||||
}
|
||||
}
|
||||
|
||||
//监听 g_userInfo.userGroupIDlist 更新事件
|
||||
class GroupIdUpdateEvent {
|
||||
String str;
|
||||
|
||||
GroupIdUpdateEvent(String _str) {
|
||||
this.str = _str;
|
||||
}
|
||||
}
|
||||
|
||||
//监听人脸注册数据更新事件
|
||||
class FaceRegUpdateEvent {
|
||||
String str;
|
||||
|
||||
FaceRegUpdateEvent(String _str) {
|
||||
this.str = _str;
|
||||
}
|
||||
}
|
||||
|
||||
//监听 选择点位过滤 更新事件
|
||||
class SelectDwfliterUpdateEvent {
|
||||
String str;
|
||||
String selectedValue;
|
||||
|
||||
SelectDwfliterUpdateEvent(String _str, String _selectedValue) {
|
||||
this.str = _str;
|
||||
this.selectedValue = _selectedValue;
|
||||
}
|
||||
}
|
||||
|
||||
//监听 选择显示违章记录 更新事件
|
||||
class SelectWzjlUpdateEvent {
|
||||
String str;
|
||||
String selectedValue;
|
||||
|
||||
SelectWzjlUpdateEvent(String _str, String _selectedValue) {
|
||||
this.str = _str;
|
||||
this.selectedValue = _selectedValue;
|
||||
}
|
||||
}
|
||||
|
||||
//选择LED点位 更新事件
|
||||
class SelectLedDwUpdateEvent {
|
||||
String str;
|
||||
String selectedValue;
|
||||
|
||||
SelectLedDwUpdateEvent(String _str, String _selectedValue) {
|
||||
this.str = _str;
|
||||
this.selectedValue = _selectedValue;
|
||||
}
|
||||
}
|
||||
|
||||
//LED字幕添加广播
|
||||
class LedXsxxUpdateEvent {
|
||||
String str;
|
||||
|
||||
LedXsxxUpdateEvent(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
//监听违章信息推送状态更新事件
|
||||
// class HycsTsztUpdateEvent {
|
||||
// String str;
|
||||
// HycsTsztUpdateEvent(String str) {
|
||||
// this.str = str;
|
||||
// }
|
||||
// }
|
||||
|
||||
//黑烟初审数据审核广播
|
||||
class HycsDataUpdateEvent {
|
||||
String str;
|
||||
|
||||
HycsDataUpdateEvent(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
//监听点位视频信息数据更新事件
|
||||
class DwspUpdateEvent {
|
||||
String str;
|
||||
|
||||
DwspUpdateEvent(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
//黑烟初审数据审核Radio选项改变广播
|
||||
class HycsDataAuditRadioEvent {
|
||||
String str;
|
||||
int selectedRadio;
|
||||
|
||||
HycsDataAuditRadioEvent(String str, int selectedRadio) {
|
||||
this.str = str;
|
||||
this.selectedRadio = selectedRadio;
|
||||
}
|
||||
}
|
||||
|
||||
//黑烟初审数据审核Dropdown选项改变广播
|
||||
class HycsDataAuditDropdownEvent {
|
||||
String str;
|
||||
String selectedValue;
|
||||
|
||||
HycsDataAuditDropdownEvent(String str, String _selectedValse) {
|
||||
this.str = str;
|
||||
this.selectedValue = _selectedValse;
|
||||
}
|
||||
}
|
||||
|
||||
//黑烟审核 sfyc 改变广播
|
||||
class HycsDataAuditSfyc {
|
||||
String str;
|
||||
|
||||
HycsDataAuditSfyc(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
//黑烟审核推送交警Checkbox改变广播
|
||||
class HycsDataAuditCheckboxButton {
|
||||
String str;
|
||||
bool checkValue;
|
||||
|
||||
HycsDataAuditCheckboxButton(String str, bool _checkValue) {
|
||||
this.str = str;
|
||||
this.checkValue = _checkValue;
|
||||
}
|
||||
}
|
||||
|
||||
//违章信息数据审核广播
|
||||
class WzxxDataAuditEvent {
|
||||
String str;
|
||||
|
||||
WzxxDataAuditEvent(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
//设备管理信息数据更新广播
|
||||
class SbglDataUpdateEvent {
|
||||
String str;
|
||||
|
||||
SbglDataUpdateEvent(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
//违章信息数据更新广播
|
||||
class WzxxDataUpdateEvent {
|
||||
String str;
|
||||
|
||||
WzxxDataUpdateEvent(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
//违章信息Listview滚动广播
|
||||
class WzxxDataScrollEvent {
|
||||
int firstIndex = 0; //ListView当前显示页面首项0基序号
|
||||
int lastIndex = 0; //ListView当前显示页面末项0基序号
|
||||
WzxxDataScrollEvent(int _firstIndex, int _lastIndex) {
|
||||
this.firstIndex = _firstIndex;
|
||||
this.lastIndex = _lastIndex;
|
||||
}
|
||||
}
|
||||
|
||||
//商品详情广播数据
|
||||
class ProductContentEvent {
|
||||
String str;
|
||||
|
||||
ProductContentEvent(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
//用户中心广播
|
||||
class UserEvent {
|
||||
String str;
|
||||
|
||||
UserEvent(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
//收货地址广播
|
||||
class AddressEvent {
|
||||
String str;
|
||||
|
||||
AddressEvent(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
//结算页面
|
||||
class CheckOutEvent {
|
||||
String str;
|
||||
|
||||
CheckOutEvent(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'Storage.dart';
|
||||
|
||||
class SearchServices {
|
||||
static setHistoryData(keywords) async {
|
||||
/*
|
||||
1、获取本地存储里面的数据 (searchList)
|
||||
|
||||
2、判断本地存储是否有数据
|
||||
|
||||
2.1、如果有数据
|
||||
|
||||
1、读取本地存储的数据
|
||||
2、判断本地存储中有没有当前数据,
|
||||
如果有不做操作、
|
||||
如果没有当前数据,本地存储的数据和当前数据拼接后重新写入
|
||||
|
||||
|
||||
2.2、如果没有数据
|
||||
|
||||
直接把当前数据放在数组中写入到本地存储
|
||||
|
||||
|
||||
*/
|
||||
|
||||
try {
|
||||
List searchListData = json.decode(await Storage.getString('searchList'));
|
||||
|
||||
print(searchListData);
|
||||
var hasData = searchListData.any((v) {
|
||||
return v == keywords;
|
||||
});
|
||||
if (!hasData) {
|
||||
searchListData.add(keywords);
|
||||
await Storage.setString('searchList', json.encode(searchListData));
|
||||
}
|
||||
} catch (e) {
|
||||
List tempList = new List();
|
||||
tempList.add(keywords);
|
||||
await Storage.setString('searchList', json.encode(tempList));
|
||||
}
|
||||
}
|
||||
static getHistoryList() async{
|
||||
try {
|
||||
List searchListData = json.decode(await Storage.getString('searchList'));
|
||||
return searchListData;
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
static clearHistoryList() async{
|
||||
await Storage.remove('searchList');
|
||||
}
|
||||
static removeHistoryData(keywords) async{
|
||||
List searchListData = json.decode(await Storage.getString('searchList'));
|
||||
searchListData.remove(keywords);
|
||||
await Storage.setString('searchList', json.encode(searchListData));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:get_it/get_it.dart';
|
||||
import './TelAndSmsService.dart';
|
||||
|
||||
GetIt locator = GetIt.instance;
|
||||
|
||||
bool locatorIsRegistered = false;
|
||||
|
||||
void setupLocator() {
|
||||
//解决登录后、退出登录、再次登录时,导致 TelAndSmsService 重复注册红屏报错问题
|
||||
//I/flutter ( 6555): The following ArgumentError was thrown building Builder:
|
||||
// I/flutter ( 6555): Invalid argument(s): Object/factory with type TelAndSmsService is already registered inside GetIt.
|
||||
if (!locatorIsRegistered) {
|
||||
locatorIsRegistered = true;
|
||||
locator.registerSingleton(TelAndSmsService());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'dart:convert';
|
||||
import 'package:crypto/crypto.dart';
|
||||
|
||||
class SignServices{
|
||||
|
||||
static getSign(json){
|
||||
|
||||
List attrKeys=json.keys.toList();
|
||||
attrKeys.sort(); //排序 ASCII 字符顺序进行升序排列
|
||||
String str='';
|
||||
for(var i=0;i<attrKeys.length;i++){
|
||||
str+="${attrKeys[i]}${json[attrKeys[i]]}";
|
||||
}
|
||||
return md5.convert(utf8.encode(str)).toString();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class Storage {
|
||||
static Future<void> setString(String key, String value) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
sp.setString(key, value);
|
||||
}
|
||||
|
||||
static Future<String> getString(String key) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(key);
|
||||
}
|
||||
|
||||
static Future<void> setBool(String key, bool value) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
sp.setBool(key, value);
|
||||
}
|
||||
|
||||
static Future<bool> getBool(String key) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
return sp.getBool(key);
|
||||
}
|
||||
|
||||
static Future<void> remove(String key) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
sp.remove(key);
|
||||
}
|
||||
|
||||
static Future<void> clear() async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
sp.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class TelAndSmsService {
|
||||
void call(String number) => launch("tel:$number");
|
||||
void sendSms(String number) => launch("sms:$number");
|
||||
void sendEmail(String email) => launch("mailto:$email");
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
import '../services/Storage.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
class UserServices{
|
||||
static getUserInfo() async{
|
||||
List userinfo;
|
||||
try {
|
||||
List userInfoData = json.decode(await Storage.getString('userInfo'));
|
||||
userinfo = userInfoData;
|
||||
} catch (e) {
|
||||
userinfo = [];
|
||||
}
|
||||
return userinfo;
|
||||
}
|
||||
static getUserLoginState() async{
|
||||
var userInfo=await UserServices.getUserInfo();
|
||||
if(userInfo.length>0&&userInfo[0]["username"]!=""){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static loginOut(){
|
||||
Storage.remove('userInfo');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user