张萌 4 years ago
commit ca06e54c00

@ -1,10 +1,20 @@
class API { class API {
static const String host = 'http://192.168.2.201:8804/IntelligentCommunity'; ///HOST
static const String host = 'http://192.168.2.201:8804';
///
static const String baseURL = '$host/IntelligentCommunity/app';
///
static String get resource => '$host/static'; static String get resource => '$host/static';
static String image(String path) => '$resource$path';
static const int networkTimeOut = 10000; static const int networkTimeOut = 10000;
static _Login login = _Login(); static _Login login = _Login();
static _User user = _User(); static _User user = _User();
static _Manager manager = _Manager(); static _Manager manager = _Manager();
static _Upload upload = _Upload();
} }
class _Login { class _Login {
@ -48,6 +58,9 @@ class _User {
/// ///
String get updateTel => '/user/personalData/updateTel'; String get updateTel => '/user/personalData/updateTel';
///
String get udpdateAvatar => '/user/personalData/updateHeadPortrait';
} }
class _Manager { class _Manager {
@ -72,3 +85,11 @@ class _Manager {
/// ///
String get reportRepairDelete => '/user/reportRepair/falseDelete'; String get reportRepairDelete => '/user/reportRepair/falseDelete';
} }
class _Upload {
///
String get uploadArticle => '/user/upload/uploadArticle';
///
String get uploadAvatar => '/user/upload/appHeadSculpture';
}

@ -2,7 +2,6 @@ import 'package:akuCommunity/pages/splash/splash_page.dart';
import 'package:akuCommunity/provider/sign_up_provider.dart'; import 'package:akuCommunity/provider/sign_up_provider.dart';
import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/developer_util.dart'; import 'package:akuCommunity/utils/developer_util.dart';
import 'package:akuCommunity/utils/hive_store.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';

@ -2,7 +2,7 @@ import 'package:common_utils/common_utils.dart';
class UserInfoModel { class UserInfoModel {
int id; int id;
List<String> imgUrls; String imgUrl;
String name; String name;
String nickName; String nickName;
String tel; String tel;
@ -28,7 +28,7 @@ class UserInfoModel {
UserInfoModel( UserInfoModel(
{this.id, {this.id,
this.imgUrls, this.imgUrl,
this.name, this.name,
this.nickName, this.nickName,
this.tel, this.tel,
@ -37,23 +37,12 @@ class UserInfoModel {
UserInfoModel.fromJson(Map<String, dynamic> json) { UserInfoModel.fromJson(Map<String, dynamic> json) {
id = json['id']; id = json['id'];
imgUrls = json['imgUrls'].cast<String>(); if (json['imgUrls'] != null)
imgUrl = (json['imgUrls'] as List).first['url'];
name = json['name']; name = json['name'];
nickName = json['nickName']; nickName = json['nickName'];
tel = json['tel']; tel = json['tel'];
sex = json['sex']; sex = json['sex'];
birthday = json['birthday']; birthday = json['birthday'];
} }
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['imgUrls'] = this.imgUrls;
data['name'] = this.name;
data['nickName'] = this.nickName;
data['tel'] = this.tel;
data['sex'] = this.sex;
data['birthday'] = this.birthday;
return data;
}
} }

@ -1,4 +1,5 @@
import 'package:akuCommunity/const/resource.dart'; import 'package:akuCommunity/const/resource.dart';
import 'package:akuCommunity/constants/api.dart';
import 'package:akuCommunity/pages/activities_page/activities_page.dart'; import 'package:akuCommunity/pages/activities_page/activities_page.dart';
import 'package:akuCommunity/pages/address_page/address_page.dart'; import 'package:akuCommunity/pages/address_page/address_page.dart';
import 'package:akuCommunity/pages/life_pay/life_pay_page.dart'; import 'package:akuCommunity/pages/life_pay/life_pay_page.dart';
@ -118,14 +119,16 @@ class _PersonalIndexState extends State<PersonalIndex>
margin: EdgeInsets.only(left: 32.w), margin: EdgeInsets.only(left: 32.w),
child: Row( child: Row(
children: [ children: [
Container( Hero(
tag: 'AVATAR',
child: ClipOval( child: ClipOval(
child: CachedImageWrapper( child: FadeInImage.assetNetwork(
url: //TODO PLACEHOLDER
'https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1851283359,3457678391&fm=26&gp=0.jpg', placeholder: R.ASSETS_ICONS_PROPOSAL_PNG,
width: 106.w, image: API
.image(userProvider.userInfoModel.imgUrl),
height: 106.w, height: 106.w,
isSigned: userProvider.isSigned, width: 106.w,
), ),
), ),
), ),

@ -1,11 +1,16 @@
import 'dart:io'; import 'dart:io';
import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/const/resource.dart';
import 'package:akuCommunity/constants/api.dart';
import 'package:akuCommunity/pages/personal/change_nick_name_page.dart'; import 'package:akuCommunity/pages/personal/change_nick_name_page.dart';
import 'package:akuCommunity/pages/personal/update_tel_page.dart'; import 'package:akuCommunity/pages/personal/update_tel_page.dart';
import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/network/base_file_model.dart';
import 'package:akuCommunity/utils/network/net_util.dart';
import 'package:akuCommunity/widget/bee_scaffold.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart';
import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/utils/headers.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart'; import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -56,6 +61,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
} }
_pickAvatar() async { _pickAvatar() async {
final userProvider = Provider.of<UserProvider>(context, listen: false);
PickedFile file = await Get.bottomSheet(CupertinoActionSheet( PickedFile file = await Get.bottomSheet(CupertinoActionSheet(
title: '选择头像'.text.isIntrinsic.make(), title: '选择头像'.text.isIntrinsic.make(),
actions: [ actions: [
@ -77,8 +83,20 @@ class _UserProfilePageState extends State<UserProfilePage> {
child: '取消'.text.isIntrinsic.make(), child: '取消'.text.isIntrinsic.make(),
), ),
)); ));
if (file == null) return; if (file == null)
//TODO upload avatar. return;
else {
//Upload Avatar
Function cancel = BotToast.showLoading();
File rawFile = File(file.path);
BaseFileModel model =
await NetUtil().upload(API.upload.uploadAvatar, rawFile);
if (model.status)
userProvider.updateAvatar(model.url);
else
BotToast.showText(text: model.message);
cancel();
}
} }
@override @override
@ -88,7 +106,21 @@ class _UserProfilePageState extends State<UserProfilePage> {
title: '个人资料', title: '个人资料',
body: ListView( body: ListView(
children: [ children: [
_buildTile('头像', CircleAvatar(), onPressed: _pickAvatar), _buildTile(
'头像',
Hero(
tag: 'AVATAR',
child: ClipOval(
child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_ICONS_PROPOSAL_PNG,
image: API.image(userProvider.userInfoModel.imgUrl),
height: 56.w,
width: 56.w,
),
),
),
onPressed: _pickAvatar,
),
_buildTile( _buildTile(
'姓名', '姓名',
userProvider.userInfoModel.name.text.make(), userProvider.userInfoModel.name.text.make(),

@ -82,6 +82,7 @@ class SignFunc {
BaseModel baseModel = await NetUtil().get( BaseModel baseModel = await NetUtil().get(
API.user.userDetail, API.user.userDetail,
); );
if (baseModel.data == null) return null;
return UserDetailModel.fromJson(baseModel.data); return UserDetailModel.fromJson(baseModel.data);
} }
} }

@ -77,11 +77,14 @@ class UserProvider extends ChangeNotifier {
Future setBirthday(DateTime date) async { Future setBirthday(DateTime date) async {
BaseModel baseModel = await NetUtil().post( BaseModel baseModel = await NetUtil().post(
API.user.setBirthday, API.user.setBirthday,
params: {'birthday': DateUtil.formatDate(date,format: "yyyy-MM-dd HH:mm:ss")}, params: {
'birthday': DateUtil.formatDate(date, format: "yyyy-MM-dd HH:mm:ss")
},
showMessage: true, showMessage: true,
); );
if (baseModel.status) { if (baseModel.status) {
_userInfoModel.birthday = DateUtil.formatDate(date,format: "yyyy-MM-dd HH:mm:ss"); _userInfoModel.birthday =
DateUtil.formatDate(date, format: "yyyy-MM-dd HH:mm:ss");
notifyListeners(); notifyListeners();
} }
} }
@ -111,4 +114,18 @@ class UserProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
} }
///
Future updateAvatar(String path) async {
BaseModel model = await NetUtil().post(
API.user.udpdateAvatar,
params: {
'fileUrls': [path]
},
showMessage: true,
);
if (model.status) {
await updateProfile();
}
}
} }

@ -0,0 +1,19 @@
class BaseFileModel {
String message;
String url;
bool status;
BaseFileModel({
this.message,
this.url,
this.status,
});
BaseFileModel.err(
{this.message = '未知错误', this.url = '', this.status = false});
BaseFileModel.fromJson(Map<String, dynamic> json) {
message = json['message'] ?? '';
url = json['url'] ?? null;
status = json['status'] ?? false;
}
}

@ -1,12 +1,15 @@
import 'dart:io';
import 'package:akuCommunity/pages/sign/sign_in_page.dart'; import 'package:akuCommunity/pages/sign/sign_in_page.dart';
import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/network/base_file_model.dart';
import 'package:akuCommunity/utils/network/base_list_model.dart'; import 'package:akuCommunity/utils/network/base_list_model.dart';
import 'package:akuCommunity/utils/network/base_model.dart'; import 'package:akuCommunity/utils/network/base_model.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/constants/api.dart';
import 'package:get/get.dart' hide Response; import 'package:get/get.dart' hide Response, FormData, MultipartFile;
import 'package:logger/logger.dart'; import 'package:logger/logger.dart';
import 'package:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -27,7 +30,7 @@ class NetUtil {
errorMethodCount: 4, errorMethodCount: 4,
)); ));
BaseOptions options = BaseOptions( BaseOptions options = BaseOptions(
baseUrl: '${API.host}/app', baseUrl: API.baseURL,
connectTimeout: API.networkTimeOut, connectTimeout: API.networkTimeOut,
receiveTimeout: API.networkTimeOut, receiveTimeout: API.networkTimeOut,
sendTimeout: API.networkTimeOut, sendTimeout: API.networkTimeOut,
@ -118,6 +121,27 @@ class NetUtil {
return BaseListModel.err(); return BaseListModel.err();
} }
Future<BaseFileModel> upload(String path, File file) async {
try {
Response res = await _dio.post(path,
data: FormData.fromMap({
'file': await MultipartFile.fromFile(file.path),
}));
_logger.v({
'path': res.request.path,
'header': res.request.headers,
'params': res.request.queryParameters,
'data': res.data,
});
LoggerData.addData(res);
BaseFileModel baseListModel = BaseFileModel.fromJson(res.data);
return baseListModel;
} on DioError catch (e) {
_parseErr(e);
}
return BaseFileModel.err();
}
_parseErr(DioError err) { _parseErr(DioError err) {
_logger.v({ _logger.v({
'type': err.type.toString(), 'type': err.type.toString(),
@ -148,8 +172,8 @@ class NetUtil {
_parseRequestError(BaseModel model, {bool showMessage = false}) { _parseRequestError(BaseModel model, {bool showMessage = false}) {
final userProvider = Provider.of<UserProvider>(Get.context, listen: false); final userProvider = Provider.of<UserProvider>(Get.context, listen: false);
if (!model.status && model.message == '登录失效,请登录') { if (!model.status && model.message == '登录失效,请登录') {
Get.offAll(SignInPage());
userProvider.logout(); userProvider.logout();
Get.offAll(SignInPage());
} }
if (!model.status || showMessage) { if (!model.status || showMessage) {
BotToast.showText(text: model.message); BotToast.showText(text: model.message);

@ -43,13 +43,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.39.17" version: "0.39.17"
animations:
dependency: transitive
description:
name: animations
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.2"
animator: animator:
dependency: transitive dependency: transitive
description: description:
@ -803,7 +796,7 @@ packages:
description: description:
path: "." path: "."
ref: HEAD ref: HEAD
resolved-ref: c972545147e812d192795a56b33357aefd60d479 resolved-ref: "38c7b0431c56f2357b6ef1298009b9b4ff0586c0"
url: "http://192.168.2.201:8099/aku_fe/power_logger.git" url: "http://192.168.2.201:8099/aku_fe/power_logger.git"
source: git source: git
version: "0.0.1" version: "0.0.1"

Loading…
Cancel
Save