Преглед на файлове

1、用户淘宝授权(未完成)

2、网络更新
3、appUI更新
tags/0.0.2
PH2 преди 4 години
родител
ревизия
f2056e5601
променени са 10 файла, в които са добавени 286 реда и са изтрити 48 реда
  1. +3
    -0
      lib/models/user/user_info_model.dart
  2. +9
    -1
      lib/models/user/user_info_model_notifier.dart
  3. +5
    -0
      lib/util/global_config.dart
  4. +11
    -8
      lib/util/log/log_widget.dart
  5. +40
    -28
      lib/util/log/net_widget.dart
  6. +6
    -4
      lib/util/net_util.dart
  7. +12
    -6
      lib/util/taobao/taobao_auth.dart
  8. +45
    -0
      lib/util/update/app_update_model.dart
  9. +150
    -0
      lib/util/update/app_update_util.dart
  10. +5
    -1
      pubspec.yaml

+ 3
- 0
lib/models/user/user_info_model.dart Целия файл

@@ -10,6 +10,7 @@ class UserInfoModel {
String username;
List<String> perms;
String registerInviteCodeEnable;
bool isTBAuth;

// 获取模糊手机号码
get blurMobile => !EmptyUtil.isEmpty(mobile) ? mobile.length == 11 ? '${mobile.substring(0, 3)}****${mobile.substring(7, mobile.length)}' : mobile : mobile;
@@ -23,6 +24,7 @@ class UserInfoModel {
mobile = json['mobile'];
perms = json['perms']?.cast<String>();
registerInviteCodeEnable = json['register_invite_code_enable'];
isTBAuth = json['isTBAuth'];
}

Map<String, dynamic> toJson() {
@@ -33,6 +35,7 @@ class UserInfoModel {
data['perms'] = this.perms;
data['mobile'] = this.mobile;
data['register_invite_code_enable'] = this.registerInviteCodeEnable;
data['isTBAuth'] = this.isTBAuth;
return data;
}



+ 9
- 1
lib/models/user/user_info_model_notifier.dart Целия файл

@@ -28,7 +28,15 @@ class UserInfoNotifier with ChangeNotifier {
}
return _userInfo;
}

/// 更新淘宝授权
void updateUserAuth(bool isAuth){
if(_userInfo != null){
_userInfo.isTBAuth = isAuth;
notifyListeners();
}
}
/// 更新用户数据
void setUserInfo(UserInfoModel loginUser) async {
print('${loginUser.toString()}');


+ 5
- 0
lib/util/global_config.dart Целия файл

@@ -14,9 +14,14 @@ class GlobalConfig {
/// 用户手机号码
static final String SHARED_KEY_MOBILE = 'sp_mobile';

/// 用户的淘宝授权key
static final String SHARED_KEY_ISAUTH = 'sp_auth';

/// 用户json
static final String SHARED_KEY_USER_INFO = 'sp_userinfo';



/// 货币类型
static final String MONEY_TYPE = "¥ ";
/// 天猫 淘宝类型


+ 11
- 8
lib/util/log/log_widget.dart Целия файл

@@ -129,14 +129,17 @@ class _LogWidgetState extends State<LogWidget> {
"${item.tabName} ${item.message} (${item.start.hour}:${item.start.minute}:${item.start.second}:${item.start.millisecond})",
style: TextStyle(fontSize: 16, color: color),
),
if (item.detail != null)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
item.detail,
style: TextStyle(fontSize: 14, color: color),
overflow: TextOverflow.ellipsis,
maxLines: 20,
// if (item.detail != null)
Visibility(
visible: item.detail != null,
child: Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
item.detail,
style: TextStyle(fontSize: 14, color: color),
overflow: TextOverflow.ellipsis,
maxLines: 20,
),
),
)
],


+ 40
- 28
lib/util/log/net_widget.dart Целия файл

@@ -127,34 +127,43 @@ class _NetWidgetState extends State<NetWidget> {
"[${item.type}] ${item.api}",
style: const TextStyle(fontSize: 16),
),
if (item.showDetail)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
"Request: ${item.req ?? ""}",
maxLines: 100,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 14),
// if (item.showDetail)
Visibility(
visible: item.showDetail,
child: Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
"Request: ${item.req ?? ""}",
maxLines: 100,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 14),
),
),
),
if (item.showDetail)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
"Response: ${item.res ?? ""}",
maxLines: 100,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 14),
// if (item.showDetail)
Visibility(
visible: item.showDetail,
child: Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
"Response: ${item.res ?? ""}",
maxLines: 100,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 14),
),
),
),
if (item.showDetail && item.headers != null)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
"Headers: ${item.headers ?? ""}",
maxLines: 100,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 14),
// if (item.showDetail && item.headers != null)
Visibility(
visible: (item.showDetail && item.headers != null),
child: Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
"Headers: ${item.headers ?? ""}",
maxLines: 100,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 14),
),
),
),
Padding(
@@ -217,10 +226,13 @@ class _NetWidgetState extends State<NetWidget> {
item.status.toString(),
style: TextStyle(fontSize: 20, color: color),
),
if (item.showDetail)
const Text(
"copy",
style: TextStyle(fontSize: 16, color: Colors.blue),
// if (item.showDetail)
Visibility(
visible: item.showDetail,
child: const Text(
"copy",
style: TextStyle(fontSize: 16, color: Colors.blue),
),
),
],
),


+ 6
- 4
lib/util/net_util.dart Целия файл

@@ -47,7 +47,7 @@ class NetUtil {
if (_dio == null) {
var setting = await NativeUtil.getSetting();
String domain = setting['domain']; //'http://www.hairuyi.com/';
_config(domain, proxyUrl: '192.168.0.112:8888');
_config(domain, proxyUrl: '192.168.0.66:8866');
}
return _dio;
}
@@ -108,8 +108,9 @@ class NetUtil {
Dio dio = await NetUtil.getInstance().dio;
response = await dio.request(path,
data: sign,
options:
Options(method: enumToString(method), headers: {'token': token}));
options: Options(method: enumToString(method), headers: {'token': token, 'app_version': sign['app_version']}),
// options: Options(method: enumToString(method), headers: sign),
);
} on DioError catch (e) {
_formatError(e);
}
@@ -222,7 +223,8 @@ class NetUtil {
params['device_id'] = androidInfo?.androidId;
}
// 应用版本号
params["app_version"] = packageInfo.version;
params["app_version_name"] = packageInfo.version;
params["app_version"] = packageInfo.buildNumber;
// 分辨率
params["solution"] =
"${window.physicalSize.width.floor()}*${window.physicalSize.height.floor()}";


+ 12
- 6
lib/util/taobao/taobao_auth.dart Целия файл

@@ -7,6 +7,7 @@ import 'package:fluttertoast/fluttertoast.dart';
import 'package:zhiying_comm/models/profile/profile_model.dart';
import 'package:zhiying_comm/util/taobao/taobao_auth_alert.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:provider/provider.dart';

class TaobaoAuth {
static ProfileModel _profile;
@@ -33,25 +34,30 @@ class TaobaoAuth {
}
String url = data['data']['redirect_url'];
print("授权链接" + url);
TradeResult result;
if (Platform.isAndroid) {
TradeResult result = await FlutterAlibc.openByUrl(
result = await FlutterAlibc.openByUrl(
url: url, backUrl: "alisdk://", isAuth: true);
// TradeResult result = await FlutterAlibc.openByUrl(url: '');
Logger.debug('${result.errorCode} ${result.errorMessage} ');
} else if (Platform.isIOS) {
TradeResult result = await FlutterAlibc.openByUrl(url: url);
result = await FlutterAlibc.openByUrl(url: url);
// TradeResult result = await FlutterAlibc.openByUrl(url: '');
Logger.debug('${result.errorCode} ${result.errorMessage} ');
}
if(null !=result && result.errorCode == '0'){
Provider.of<UserInfoNotifier>(context).updateUserAuth(true);
}
}
}

// 返回是否授权
static Future<bool> isAuth() async {
if (_profile != null) {
return _profile.isAuth;
}
// if (_profile != null) {
// return _profile.isAuth;
// }
Map<String, dynamic> data = Map<String, dynamic>.from(
await NetUtil.post('/api/v1/user/profile', method: NetMethod.GET));
if (data['code'] == 1) {


+ 45
- 0
lib/util/update/app_update_model.dart Целия файл

@@ -0,0 +1,45 @@
class AppUpdateModel {
String appDownloadThirdpartyUrl;
String appDownloadUrl;
String appVersion;
String appVersionName;
String dialog;
String isForce;
String isThirdparty;
String tip;

AppUpdateModel({
this.appDownloadThirdpartyUrl,
this.appDownloadUrl,
this.appVersion,
this.appVersionName,
this.dialog,
this.isForce,
this.isThirdparty,
this.tip,
});

AppUpdateModel.fromJson(Map<String, dynamic> json) {
appDownloadThirdpartyUrl = json['app_download_thirdparty_url'];
appDownloadUrl = json['app_download_url'];
appVersion = json['app_version'];
appVersionName = json['app_version_name'];
dialog = json['dialog'];
isForce = json['is_force'];
isThirdparty = json['is_thirdparty'];
tip = json['tip'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['app_download_thirdparty_url'] = this.appDownloadThirdpartyUrl;
data['app_download_url'] = this.appDownloadUrl;
data['app_version'] = this.appVersion;
data['app_version_name'] = this.appVersionName;
data['dialog'] = this.dialog;
data['is_force'] = this.isForce;
data['is_thirdparty'] = this.isThirdparty;
data['tip'] = this.tip;
return data;
}
}

+ 150
- 0
lib/util/update/app_update_util.dart Целия файл

@@ -0,0 +1,150 @@
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_update_dialog/flutter_update_dialog.dart';
// import 'package:flutter_xupdate/flutter_xupdate.dart';
import 'package:package_info/package_info.dart';
import 'package:zhiying_comm/util/update/app_update_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:fluttertoast/fluttertoast.dart';

import '../log/let_log.dart';

///
/// App更新工具类
///
class AppUpdateUtil {
///
/// 初始化更新插件
///
static void initXUpdate() {
if (Platform.isAndroid) {
// FlutterXUpdate.init(
//
// ///是否输出日志
// debug: true,
//
// ///是否使用post请求
// isPost: false,
//
// ///post请求是否是上传json
// isPostJson: false,
//
// ///是否开启自动模式
// isWifiOnly: false,
//
// ///是否开启自动模式
// isAutoMode: false,
//
// ///需要设置的公共参数
// supportSilentInstall: false,
//
// ///在下载过程中,如果点击了取消的话,是否弹出切换下载方式的重试提示弹窗
// enableRetry: false)
// .then((value) {
// // updateMessage("初始化成功: $value");
// Logger.log('初始化成功: $value');
// }).catchError((error) {
// print(error);
// });

// FlutterXUpdate.setErrorHandler(onUpdateError: (Map<String, dynamic> message) async {
// Logger.warn(message);
// // setState(() {
// // _message = "$message";
// // });
// });
} else {
// updateMessage("ios暂不支持XUpdate更新");
Logger.log('ios暂不支持XUpdate更新');
}
}

///
/// 检查并且更新app
///
static void updateApp(BuildContext context) async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
Logger.log('version = ${packageInfo.version}, buildNum = ${packageInfo.buildNumber}');
var result = await NetUtil.post('/api/v1/appcheck', params: {'app_version': packageInfo.buildNumber}, method: NetMethod.GET);
customStyle(context, onUpdate: (){
Navigator.pop(context);
});
// UpdateEntity updateEntity = await _checkAppUpdate();
// // 有新版本,进行更新
// if (!EmptyUtil.isEmpty(updateEntity) && updateEntity.hasUpdate) {
// if (Platform.isAndroid) {
// FlutterXUpdate.updateByInfo(
// updateEntity: updateEntity,
// supportBackgroundUpdate: true,
// );
// } else if (Platform.isIOS) {
// // TODO 完成IOS更新
// String updateUrl = updateEntity.downloadUrl;
// customStyle(context, onUpdate: (){
//
//
//
// Navigator.pop(context);
// });
// }
// } else {
// Fluttertoast.showToast(msg: '已经是最新版本了~');
// }
}

/// 检查是否有新版本
// static Future<UpdateEntity> _checkAppUpdate() async {
// try {
// PackageInfo packageInfo = await PackageInfo.fromPlatform();
// // var result = await NetUtil.post('/api/v1/appcheck', params: {'app_version': packageInfo.version}, method: NetMethod.GET);
//
// var result = {
// 'dialog': '1',
// 'is_force': '0',
// 'app_version': '5',
// 'app_version_name': '5.0.0',
// 'tip': '\n1、优化api接口。\n2、添加使用demo演示。\n3、新增自定义更新服务API接口。\n4、优化更新提示界面。',
// 'app_download_url': 'http://imtt.dd.qq.com/16891/apk/FAD58DEFE56A938D86B123DEA4E298EB.apk?fsname=com.hairuyi.www_5.8.8_469.apk&hsr=4d5s',
// };
// AppUpdateModel model = AppUpdateModel.fromJson(result);
// if (!EmptyUtil.isEmpty(model)) {
// // ⚠️ isIgnorable 目前只有两种状态,为强制更新和不强制更新(每次进来都会提示更新UI弹窗)
// return UpdateEntity(
// hasUpdate: model?.dialog == '1',
// isIgnorable: false,
// isForce: model?.isForce == '1',
// versionCode: int.parse(model?.appVersion ?? '1'),
// versionName: model?.appVersionName,
// downloadUrl: model?.appDownLoadUrl,
// updateContent: model?.tip,
// );
// }
// } catch (e, s) {
// Logger.error(e, s);
// }
// return null;
// }

static void customStyle(BuildContext context, {@required VoidCallback onUpdate }) {
UpdateDialog.showUpdate(context,
width: 250,
title: "是否升级到4.1.4版本?",
updateContent: "新版本大小:2.0M\n1.xxxxxxx\n2.xxxxxxx\n3.xxxxxxx",
titleTextSize: 14,
contentTextSize: 12,
buttonTextSize: 12,
// topImage: Image.asset('assets/bg_update_top.png'),
extraHeight: 5,
radius: 8,
themeColor: Colors.redAccent,
progressBackgroundColor: Color(0x5AFFAC5D),
isForce: false,
updateButtonText: '升级',
ignoreButtonText: '忽略此版本',
enableIgnore: true, onIgnore: () {
Navigator.pop(context);
}, onUpdate: onUpdate);
}
}

+ 5
- 1
pubspec.yaml Целия файл

@@ -32,9 +32,13 @@ dependencies:
webview_flutter: ^0.3.22+1
# 京东sdk
jdsdk: ^0.0.1
# Android app更新
# flutter_xupdate: ^1.0.0
# app更新dialogUI(用于IOS,以便统一样式)
flutter_update_dialog: 1.0.0
flutter_alibc:
git:
ref: 0.0.1
ref: 0.0.3
url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_flutter_alibc.git
url_launcher: ^5.6.0



Зареждане…
Отказ
Запис