feat: 黑名单查看、屏蔽黑名单用户推荐/最热 #22
This commit is contained in:
156
lib/pages/blacklist/index.dart
Normal file
156
lib/pages/blacklist/index.dart
Normal file
@ -0,0 +1,156 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/common/widgets/http_error.dart';
|
||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||
import 'package:pilipala/http/black.dart';
|
||||
import 'package:pilipala/models/user/black.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import 'package:pilipala/utils/utils.dart';
|
||||
|
||||
class BlackListPage extends StatefulWidget {
|
||||
const BlackListPage({super.key});
|
||||
|
||||
@override
|
||||
State<BlackListPage> createState() => _BlackListPageState();
|
||||
}
|
||||
|
||||
class _BlackListPageState extends State<BlackListPage> {
|
||||
final BlackListController _blackListController =
|
||||
Get.put(BlackListController());
|
||||
final ScrollController scrollController = ScrollController();
|
||||
Future? _futureBuilderFuture;
|
||||
bool _isLoadingMore = false;
|
||||
Box setting = GStrorage.setting;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_futureBuilderFuture = _blackListController.queryBlacklist();
|
||||
scrollController.addListener(
|
||||
() async {
|
||||
if (scrollController.position.pixels >=
|
||||
scrollController.position.maxScrollExtent - 200) {
|
||||
if (!_isLoadingMore) {
|
||||
_isLoadingMore = true;
|
||||
await _blackListController.queryBlacklist(type: 'onLoad');
|
||||
_isLoadingMore = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
List<int> blackMidsList =
|
||||
_blackListController.blackList.map<int>((e) => e.mid!).toList();
|
||||
setting.put(SettingBoxKey.blackMidsList, blackMidsList);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
titleSpacing: 0,
|
||||
centerTitle: false,
|
||||
title: Obx(
|
||||
() => Text(
|
||||
'黑名单管理 (${_blackListController.blackList.length} / 5000)',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () async => await _blackListController.queryBlacklist(),
|
||||
child: FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
var data = snapshot.data;
|
||||
if (data['status']) {
|
||||
List<BlackListItem> list = _blackListController.blackList;
|
||||
return Obx(
|
||||
() => list.length == 1
|
||||
? const SizedBox()
|
||||
: ListView.builder(
|
||||
controller: scrollController,
|
||||
itemCount: list.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return ListTile(
|
||||
onTap: () {},
|
||||
leading: NetworkImgLayer(
|
||||
width: 45,
|
||||
height: 45,
|
||||
type: 'avatar',
|
||||
src: list[index].face,
|
||||
),
|
||||
title: Text(
|
||||
list[index].uname!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
subtitle: Text(
|
||||
Utils.dateFormat(list[index].mtime),
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color:
|
||||
Theme.of(context).colorScheme.outline),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
dense: true,
|
||||
// trailing: TextButton(
|
||||
// onPressed: () {},
|
||||
// child: const Text('移除'),
|
||||
// ),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
HttpError(
|
||||
errMsg: data['msg'],
|
||||
fn: () => _blackListController.queryBlacklist(),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 骨架屏
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class BlackListController extends GetxController {
|
||||
int currentPage = 1;
|
||||
int pageSize = 50;
|
||||
RxList<BlackListItem> blackList = [BlackListItem()].obs;
|
||||
|
||||
Future queryBlacklist({type = 'init'}) async {
|
||||
if (type == 'init') {
|
||||
currentPage = 1;
|
||||
}
|
||||
var result = await BlackHttp.blackList(pn: currentPage, ps: pageSize);
|
||||
if (result['status']) {
|
||||
if (type == 'init') {
|
||||
blackList.value = result['data'].list;
|
||||
} else {
|
||||
blackList.addAll(result['data'].list);
|
||||
}
|
||||
|
||||
currentPage += 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
58
lib/pages/setting/privacy_setting.dart
Normal file
58
lib/pages/setting/privacy_setting.dart
Normal file
@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
class PrivacySetting extends StatefulWidget {
|
||||
const PrivacySetting({super.key});
|
||||
|
||||
@override
|
||||
State<PrivacySetting> createState() => _PrivacySettingState();
|
||||
}
|
||||
|
||||
class _PrivacySettingState extends State<PrivacySetting> {
|
||||
bool userLogin = false;
|
||||
Box user = GStrorage.user;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
userLogin = user.get(UserBoxKey.userLogin) ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
TextStyle titleStyle = Theme.of(context).textTheme.titleMedium!;
|
||||
TextStyle subTitleStyle = Theme.of(context)
|
||||
.textTheme
|
||||
.labelMedium!
|
||||
.copyWith(color: Theme.of(context).colorScheme.outline);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: false,
|
||||
titleSpacing: 0,
|
||||
title: Text(
|
||||
'隐私设置',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
onTap: () {
|
||||
if (!userLogin) {
|
||||
SmartDialog.showToast('登录后查看');
|
||||
return;
|
||||
}
|
||||
Get.toNamed('/blackListPage');
|
||||
},
|
||||
dense: false,
|
||||
title: Text('黑名单管理', style: titleStyle),
|
||||
subtitle: Text('已拉黑用户', style: subTitleStyle),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -19,6 +19,11 @@ class SettingPage extends StatelessWidget {
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
onTap: () => Get.toNamed('/privacySetting'),
|
||||
dense: false,
|
||||
title: const Text('隐私设置'),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () => Get.toNamed('/playSetting'),
|
||||
dense: false,
|
||||
|
||||
Reference in New Issue
Block a user