237 lines
6.4 KiB
Dart
237 lines
6.4 KiB
Dart
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../network/api.dart';
|
|
import '../../network/dio_manager.dart';
|
|
import '../../util/SharedPreferencesHelper.dart';
|
|
import '../../util/eventBus.dart';
|
|
import '../../util/util.dart';
|
|
import '../dialog/UpdateDialog.dart';
|
|
import 'state.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class MinefragmentLogic extends GetxController {
|
|
final MinefragmentState state = MinefragmentState();
|
|
User? userInfoBean;
|
|
bool isProxy = false;
|
|
String ageMsg = "";
|
|
var isVip = 0.obs;
|
|
var likeCount = 0;
|
|
var like_me_count = 0;
|
|
var recent_visit_count = 0;
|
|
|
|
num like_me_count_new = 0;
|
|
num recent_visit_count_new = 0;
|
|
String avatar = "";
|
|
String name = "";
|
|
int gender = -1;
|
|
int role = -1;
|
|
int age = -1;
|
|
int orientation = -1;
|
|
|
|
bool has_pwd = false;
|
|
bool isUpdateVersion = false;
|
|
bool isShwGoodReview = false;
|
|
String enterHomeInfoMsg = "进入主页";
|
|
String joinedCircle = "";
|
|
String vipMsg = "十几种专属特权等你领取";
|
|
|
|
@override
|
|
void onInit() async {
|
|
super.onInit();
|
|
SharedPreferencesHelper sp = await SharedPreferencesHelper.getInstance();
|
|
if (sp.getString(SharedPreferencesHelper.LOGINPHONE) == '18800000100') {
|
|
isProxy = true;
|
|
} else {
|
|
isProxy = false;
|
|
}
|
|
|
|
getMode();
|
|
checkVersion();
|
|
checkShowPositiveFeedBack();
|
|
EventBusManager.on<CommentVipEvent>().listen((event) {
|
|
isVip.value = event.vip;
|
|
// update();
|
|
});
|
|
}
|
|
|
|
loadData() {
|
|
getMode();
|
|
checkVersion();
|
|
checkShowPositiveFeedBack();
|
|
}
|
|
|
|
Future<void> checkVersion() async {
|
|
var data = await DioManager.instance.get(url: Api.APP_VERSION);
|
|
var bean = BaseResponse<UpdateInfo>.fromJson(
|
|
data, (data) => UpdateInfo.fromJson(data));
|
|
if (bean.isSuccess()) {
|
|
isUpdateVersion = bean.data.update == 1;
|
|
update();
|
|
}
|
|
}
|
|
|
|
getMode() async {
|
|
var data = await DioManager.instance.get(url: Api.getUserMine);
|
|
var bean = BaseResponse<MineResponseBean>.fromJson(
|
|
data, (data) => MineResponseBean.fromJson(data));
|
|
if (bean.isSuccess()) {
|
|
likeCount = bean.data.likeCount ?? 0;
|
|
like_me_count = bean.data.likeMeCount ?? 0;
|
|
recent_visit_count = bean.data.recentVisitCount ?? 0;
|
|
joinedCircle = "${"加入了${bean.data.joininterestcount}"}个圈子";
|
|
enterHomeInfoMsg = bean.data.mainGuideText;
|
|
|
|
has_pwd = bean.data.has_pwd;
|
|
SharedPreferences sharedPreferences =
|
|
await SharedPreferences.getInstance();
|
|
if(bean.data.user.vip>0){
|
|
vipMsg = "会员时长剩余${bean.data.vipExpireDays}天";
|
|
}
|
|
|
|
int likeMeCount = sharedPreferences.getInt(SharedPreferencesHelper.LIKEMECOUNT)??0;
|
|
int recentVisitCount = sharedPreferences.getInt(SharedPreferencesHelper.RECENTVISITCOUNT)??0;
|
|
sharedPreferences.setString(SharedPreferencesHelper.PHOTO, bean.data.phone);
|
|
like_me_count_new = likeMeCount - like_me_count;
|
|
print("***************");
|
|
print("$likeMeCount-$like_me_count=$like_me_count_new");
|
|
|
|
recent_visit_count_new = recentVisitCount - recent_visit_count;
|
|
|
|
// like_me_count_new = recentVisitCount.toInt() - bean.data.likeMeCount.toInt();
|
|
|
|
userInfoBean = bean.data.user;
|
|
|
|
if (userInfoBean != null) {
|
|
avatar = userInfoBean!.avatarThumb;
|
|
sharedPreferences.setString(SharedPreferencesHelper.AVATAR, avatar ?? '');
|
|
name = userInfoBean!.nickname;
|
|
sharedPreferences.setString(SharedPreferencesHelper.NAME, name ?? '');
|
|
gender = userInfoBean!.gender;
|
|
role = userInfoBean!.role;
|
|
age = userInfoBean!.age;
|
|
orientation = userInfoBean!.orientation;
|
|
isVip.value = userInfoBean!.vip;
|
|
|
|
SharedPreferencesHelper.getInstance().then((sharedPreferences) {
|
|
sharedPreferences.setInt(SharedPreferencesHelper.VIP, isVip.value);
|
|
sharedPreferences.setInt(
|
|
SharedPreferencesHelper.USERID, userInfoBean!.id);
|
|
});
|
|
|
|
ageMsg = getAgeCOntent(gender, age, role, orientation);
|
|
}
|
|
|
|
update();
|
|
} else {
|
|
showOKToast(bean.msg);
|
|
}
|
|
}
|
|
|
|
void checkShowPositiveFeedBack() async {
|
|
var data = await DioManager.instance.get(url: Api.showPositiveFeedBack);
|
|
isShwGoodReview = data['data'];
|
|
update();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
class User {
|
|
int id;
|
|
bool has_pwd;
|
|
String nickname;
|
|
String avatar;
|
|
String signature;
|
|
String birthday;
|
|
int age;
|
|
int vip;
|
|
int gender;
|
|
int role;
|
|
int orientation;
|
|
double lng;
|
|
double lat;
|
|
String city;
|
|
String avatarThumb;
|
|
|
|
User({
|
|
required this.id,
|
|
required this.has_pwd,
|
|
required this.nickname,
|
|
required this.avatar,
|
|
required this.signature,
|
|
required this.birthday,
|
|
required this.age,
|
|
required this.vip,
|
|
required this.gender,
|
|
required this.role,
|
|
required this.orientation,
|
|
required this.lng,
|
|
required this.lat,
|
|
required this.city,
|
|
required this.avatarThumb,
|
|
});
|
|
|
|
factory User.fromJson(Map<String, dynamic> json) {
|
|
return User(
|
|
id: json['id'],
|
|
has_pwd: json['has_pwd'] ?? false,
|
|
nickname: json['nickname'],
|
|
avatar: json['avatar'],
|
|
signature: json['signature'],
|
|
birthday: json['birthday'],
|
|
age: json['age'],
|
|
vip: json['vip'],
|
|
gender: json['gender'],
|
|
role: json['role'],
|
|
orientation: json['orientation'],
|
|
lng: json['lng'],
|
|
lat: json['lat'],
|
|
city: json['city'],
|
|
avatarThumb: json['avatar_thumb'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class MineResponseBean {
|
|
User user;
|
|
int likeCount;
|
|
int likeMeCount;
|
|
int recentVisitCount;
|
|
String? vipExpireDate;
|
|
int? vipExpireDays;
|
|
bool? has_pwd;
|
|
String phone;
|
|
int? joininterestcount;
|
|
String mainGuideText;
|
|
|
|
MineResponseBean(
|
|
{required this.user,
|
|
required this.likeCount,
|
|
required this.likeMeCount,
|
|
required this.recentVisitCount,
|
|
this.vipExpireDate,
|
|
this.vipExpireDays,
|
|
required this.phone,
|
|
required this.has_pwd,
|
|
required this.joininterestcount,
|
|
required this.mainGuideText});
|
|
|
|
factory MineResponseBean.fromJson(Map<String, dynamic> json) {
|
|
return MineResponseBean(
|
|
user: User.fromJson(json['user']),
|
|
likeCount: json['like_count'],
|
|
has_pwd: json['has_pwd'],
|
|
phone: json['phone'],
|
|
likeMeCount: json['like_me_count'],
|
|
recentVisitCount: json['recent_visit_count'],
|
|
vipExpireDate: json['vip_expire_date'],
|
|
vipExpireDays: json['vip_expire_days'],
|
|
joininterestcount: json['join_interest_count'],
|
|
mainGuideText:json['main_guide_text'],
|
|
|
|
|
|
);
|
|
}
|
|
}
|