Merge branch 'main' into feature-m3Design
This commit is contained in:
@ -104,6 +104,9 @@ class Api {
|
|||||||
// 楼中楼
|
// 楼中楼
|
||||||
static const String replyReplyList = '/x/v2/reply/reply';
|
static const String replyReplyList = '/x/v2/reply/reply';
|
||||||
|
|
||||||
|
// 评论点赞
|
||||||
|
static const String likeReply = '/x/v2/reply/action';
|
||||||
|
|
||||||
// 发表评论
|
// 发表评论
|
||||||
// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/comment/action.md
|
// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/comment/action.md
|
||||||
static const String replyAdd = '/x/v2/reply/add';
|
static const String replyAdd = '/x/v2/reply/add';
|
||||||
@ -142,6 +145,10 @@ class Api {
|
|||||||
// https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?host_mid=548196587&offset=&page=1&features=itemOpusStyle
|
// https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?host_mid=548196587&offset=&page=1&features=itemOpusStyle
|
||||||
static const String followDynamic = '/x/polymer/web-dynamic/v1/feed/all';
|
static const String followDynamic = '/x/polymer/web-dynamic/v1/feed/all';
|
||||||
|
|
||||||
|
// 动态点赞
|
||||||
|
static const String likeDynamic =
|
||||||
|
'https://api.vc.bilibili.com/dynamic_like/v1/dynamic_like/thumb';
|
||||||
|
|
||||||
// 获取稍后再看
|
// 获取稍后再看
|
||||||
static const String seeYouLater = '/x/v2/history/toview';
|
static const String seeYouLater = '/x/v2/history/toview';
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
class HttpString {
|
class HttpString {
|
||||||
static const String baseUrl = 'https://www.bilibili.com';
|
static const String baseUrl = 'https://www.bilibili.com';
|
||||||
static const String baseApiUrl = 'https://api.bilibili.com';
|
static const String baseApiUrl = 'https://api.bilibili.com';
|
||||||
|
static const String tUrl = 'https://api.vc.bilibili.com';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,4 +50,31 @@ class DynamicsHttp {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 动态点赞
|
||||||
|
static Future likeDynamic({
|
||||||
|
required String? dynamicId,
|
||||||
|
required int? up,
|
||||||
|
}) async {
|
||||||
|
var res = await Request().post(
|
||||||
|
Api.likeDynamic,
|
||||||
|
queryParameters: {
|
||||||
|
'dynamic_id': dynamicId,
|
||||||
|
'up': up,
|
||||||
|
'csrf': await Request.getCsrf(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
return {
|
||||||
|
'status': true,
|
||||||
|
'data': res.data['data'],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
'status': false,
|
||||||
|
'data': [],
|
||||||
|
'msg': res.data['message'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,6 +38,8 @@ class Request {
|
|||||||
dio.interceptors.add(cookieManager);
|
dio.interceptors.add(cookieManager);
|
||||||
var cookie = await cookieManager.cookieJar
|
var cookie = await cookieManager.cookieJar
|
||||||
.loadForRequest(Uri.parse(HttpString.baseUrl));
|
.loadForRequest(Uri.parse(HttpString.baseUrl));
|
||||||
|
var cookie2 = await cookieManager.cookieJar
|
||||||
|
.loadForRequest(Uri.parse(HttpString.tUrl));
|
||||||
if (cookie.isEmpty) {
|
if (cookie.isEmpty) {
|
||||||
try {
|
try {
|
||||||
await Request().get(HttpString.baseUrl);
|
await Request().get(HttpString.baseUrl);
|
||||||
@ -45,6 +47,13 @@ class Request {
|
|||||||
log("setCookie, ${e.toString()}");
|
log("setCookie, ${e.toString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cookie2.isEmpty) {
|
||||||
|
try {
|
||||||
|
await Request().get(HttpString.tUrl);
|
||||||
|
} catch (e) {
|
||||||
|
log("setCookie, ${e.toString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移除cookie
|
// 移除cookie
|
||||||
@ -99,7 +108,6 @@ class Request {
|
|||||||
options.headers['x-bili-mid'] = user.get(UserBoxKey.userMid).toString();
|
options.headers['x-bili-mid'] = user.get(UserBoxKey.userMid).toString();
|
||||||
}
|
}
|
||||||
dio.options = options;
|
dio.options = options;
|
||||||
|
|
||||||
//添加拦截器
|
//添加拦截器
|
||||||
dio.interceptors
|
dio.interceptors
|
||||||
..add(ApiInterceptor())
|
..add(ApiInterceptor())
|
||||||
|
|||||||
@ -70,4 +70,32 @@ class ReplyHttp {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 评论点赞
|
||||||
|
static Future likeReply({
|
||||||
|
required int type,
|
||||||
|
required int oid,
|
||||||
|
required int rpid,
|
||||||
|
required int action,
|
||||||
|
}) async {
|
||||||
|
var res = await Request().post(
|
||||||
|
Api.likeReply,
|
||||||
|
queryParameters: {
|
||||||
|
'type': type,
|
||||||
|
'oid': oid,
|
||||||
|
'rpid': rpid,
|
||||||
|
'action': action,
|
||||||
|
'csrf': await Request.getCsrf(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
return {'status': true, 'data': res.data['data']};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
'status': false,
|
||||||
|
'date': [],
|
||||||
|
'msg': res.data['message'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,9 +46,9 @@ class DynamicsController extends GetxController {
|
|||||||
RxInt initialValue = 1.obs;
|
RxInt initialValue = 1.obs;
|
||||||
|
|
||||||
Future queryFollowDynamic({type = 'init'}) async {
|
Future queryFollowDynamic({type = 'init'}) async {
|
||||||
// if (type == 'init') {
|
if (type == 'init') {
|
||||||
// dynamicsList!.value = [];
|
dynamicsList.clear();
|
||||||
// }
|
}
|
||||||
var res = await DynamicsHttp.followDynamic(
|
var res = await DynamicsHttp.followDynamic(
|
||||||
page: type == 'init' ? 1 : page,
|
page: type == 'init' ? 1 : page,
|
||||||
type: dynamicsType.value.values,
|
type: dynamicsType.value.values,
|
||||||
|
|||||||
@ -42,7 +42,6 @@ class DynamicDetailController extends GetxController {
|
|||||||
sort: sortType.index,
|
sort: sortType.index,
|
||||||
);
|
);
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
res['data'] = ReplyData.fromJson(res['data']);
|
|
||||||
acount.value = res['data'].page.acount;
|
acount.value = res['data'].page.acount;
|
||||||
if (res['data'].replies.isNotEmpty) {
|
if (res['data'].replies.isNotEmpty) {
|
||||||
currentPage = currentPage + 1;
|
currentPage = currentPage + 1;
|
||||||
|
|||||||
@ -236,7 +236,7 @@ class _DynamicsPageState extends State<DynamicsPage>
|
|||||||
List<DynamicItemModel> list =
|
List<DynamicItemModel> list =
|
||||||
_dynamicsController.dynamicsList;
|
_dynamicsController.dynamicsList;
|
||||||
return Obx(
|
return Obx(
|
||||||
() => list.length == 1
|
() => list.isEmpty
|
||||||
? skeleton()
|
? skeleton()
|
||||||
: SliverList(
|
: SliverList(
|
||||||
delegate:
|
delegate:
|
||||||
|
|||||||
@ -1,15 +1,62 @@
|
|||||||
// 操作栏
|
// 操作栏
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:pilipala/http/dynamics.dart';
|
||||||
import 'package:pilipala/models/dynamics/result.dart';
|
import 'package:pilipala/models/dynamics/result.dart';
|
||||||
import 'package:pilipala/pages/dynamics/index.dart';
|
import 'package:pilipala/pages/dynamics/index.dart';
|
||||||
|
|
||||||
|
class ActionPanel extends StatefulWidget {
|
||||||
|
ActionPanel({
|
||||||
|
super.key,
|
||||||
|
this.item,
|
||||||
|
});
|
||||||
|
var item;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ActionPanel> createState() => _ActionPanelState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ActionPanelState extends State<ActionPanel> {
|
||||||
final DynamicsController _dynamicsController = Get.put(DynamicsController());
|
final DynamicsController _dynamicsController = Get.put(DynamicsController());
|
||||||
|
late ModuleStatModel stat;
|
||||||
|
|
||||||
Widget action(item, context) {
|
@override
|
||||||
ModuleStatModel stat = item.modules.moduleStat;
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
stat = widget.item!.modules.moduleStat;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 动态点赞
|
||||||
|
onLikeDynamic() async {
|
||||||
|
var item = widget.item!;
|
||||||
|
String dynamicId = item.idStr!;
|
||||||
|
// 1 已点赞 2 不喜欢 0 未操作
|
||||||
|
Like like = item.modules.moduleStat.like;
|
||||||
|
int count = int.parse(like.count!);
|
||||||
|
bool status = like.status!;
|
||||||
|
int up = status ? 2 : 1;
|
||||||
|
var res = await DynamicsHttp.likeDynamic(dynamicId: dynamicId, up: up);
|
||||||
|
if (res['status']) {
|
||||||
|
SmartDialog.showToast(!status ? '点赞成功' : '取消赞');
|
||||||
|
if (up == 1) {
|
||||||
|
item.modules.moduleStat.like.count = (count + 1).toString();
|
||||||
|
item.modules.moduleStat.like.status = true;
|
||||||
|
} else {
|
||||||
|
item.modules.moduleStat.like.count = (count - 1).toString();
|
||||||
|
item.modules.moduleStat.like.status = false;
|
||||||
|
}
|
||||||
|
setState(() {});
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(res['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var color = Theme.of(context).colorScheme.outline;
|
||||||
|
var primary = Theme.of(context).colorScheme.primary;
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
children: [
|
children: [
|
||||||
@ -27,7 +74,7 @@ Widget action(item, context) {
|
|||||||
),
|
),
|
||||||
TextButton.icon(
|
TextButton.icon(
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
_dynamicsController.pushDetail(item, 1, action: 'comment'),
|
_dynamicsController.pushDetail(widget.item, 1, action: 'comment'),
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
FontAwesomeIcons.comment,
|
FontAwesomeIcons.comment,
|
||||||
size: 16,
|
size: 16,
|
||||||
@ -39,17 +86,33 @@ Widget action(item, context) {
|
|||||||
label: Text(stat.comment!.count ?? '评论'),
|
label: Text(stat.comment!.count ?? '评论'),
|
||||||
),
|
),
|
||||||
TextButton.icon(
|
TextButton.icon(
|
||||||
onPressed: () {},
|
onPressed: () => onLikeDynamic(),
|
||||||
icon: const Icon(
|
icon: Icon(
|
||||||
FontAwesomeIcons.thumbsUp,
|
stat.like!.status!
|
||||||
|
? FontAwesomeIcons.solidThumbsUp
|
||||||
|
: FontAwesomeIcons.thumbsUp,
|
||||||
size: 16,
|
size: 16,
|
||||||
|
color: stat.like!.status! ? primary : color,
|
||||||
),
|
),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
|
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
|
||||||
foregroundColor: Theme.of(context).colorScheme.outline,
|
foregroundColor: Theme.of(context).colorScheme.outline,
|
||||||
),
|
),
|
||||||
label: Text(stat.like!.count ?? '点赞'),
|
label: AnimatedSwitcher(
|
||||||
|
duration: const Duration(milliseconds: 400),
|
||||||
|
transitionBuilder: (Widget child, Animation<double> animation) {
|
||||||
|
return ScaleTransition(scale: animation, child: child);
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
stat.like!.count ?? '点赞',
|
||||||
|
key: ValueKey<String>(stat.like!.count!),
|
||||||
|
style: TextStyle(
|
||||||
|
color: stat.like!.status! ? primary : color,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ class DynamicPanel extends StatelessWidget {
|
|||||||
content(item, context, source),
|
content(item, context, source),
|
||||||
forWard(item, context, _dynamicsController, source),
|
forWard(item, context, _dynamicsController, source),
|
||||||
const SizedBox(height: 2),
|
const SizedBox(height: 2),
|
||||||
if (source == null) action(item, context),
|
if (source == null) ActionPanel(item: item),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -9,6 +9,8 @@ import 'package:pilipala/pages/video/detail/controller.dart';
|
|||||||
import 'package:pilipala/pages/video/detail/replyNew/index.dart';
|
import 'package:pilipala/pages/video/detail/replyNew/index.dart';
|
||||||
import 'package:pilipala/utils/utils.dart';
|
import 'package:pilipala/utils/utils.dart';
|
||||||
|
|
||||||
|
import 'zan.dart';
|
||||||
|
|
||||||
class ReplyItem extends StatelessWidget {
|
class ReplyItem extends StatelessWidget {
|
||||||
ReplyItem({
|
ReplyItem({
|
||||||
super.key,
|
super.key,
|
||||||
@ -282,29 +284,7 @@ class ReplyItem extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(
|
ZanButton(replyItem: replyItem, replyType: replyType),
|
||||||
height: 32,
|
|
||||||
child: TextButton(
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
FontAwesomeIcons.thumbsUp,
|
|
||||||
size: 16,
|
|
||||||
color: color,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text(
|
|
||||||
replyItem!.like.toString(),
|
|
||||||
style: TextStyle(
|
|
||||||
color: color,
|
|
||||||
fontSize:
|
|
||||||
Theme.of(context).textTheme.labelSmall!.fontSize),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onPressed: () {},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 5)
|
const SizedBox(width: 5)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
82
lib/pages/video/detail/reply/widgets/zan.dart
Normal file
82
lib/pages/video/detail/reply/widgets/zan.dart
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
import 'package:pilipala/http/reply.dart';
|
||||||
|
import 'package:pilipala/models/common/reply_type.dart';
|
||||||
|
import 'package:pilipala/models/video/reply/item.dart';
|
||||||
|
|
||||||
|
class ZanButton extends StatefulWidget {
|
||||||
|
ZanButton({
|
||||||
|
super.key,
|
||||||
|
this.replyItem,
|
||||||
|
this.replyType,
|
||||||
|
});
|
||||||
|
|
||||||
|
ReplyItemModel? replyItem;
|
||||||
|
final ReplyType? replyType;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ZanButton> createState() => _ZanButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ZanButtonState extends State<ZanButton> {
|
||||||
|
// 评论点赞
|
||||||
|
onLikeReply() async {
|
||||||
|
ReplyItemModel replyItem = widget.replyItem!;
|
||||||
|
int oid = replyItem.oid!;
|
||||||
|
int rpid = replyItem.rpid!;
|
||||||
|
// 1 已点赞 2 不喜欢 0 未操作
|
||||||
|
int action = replyItem.action == 0 ? 1 : 0;
|
||||||
|
var res = await ReplyHttp.likeReply(
|
||||||
|
type: widget.replyType!.index, oid: oid, rpid: rpid, action: action);
|
||||||
|
if (res['status']) {
|
||||||
|
SmartDialog.showToast(replyItem.action == 0 ? '点赞成功' : '取消赞');
|
||||||
|
if (action == 1) {
|
||||||
|
replyItem.like = replyItem.like! + 1;
|
||||||
|
replyItem.action = 1;
|
||||||
|
} else {
|
||||||
|
replyItem.like = replyItem.like! - 1;
|
||||||
|
replyItem.action = 0;
|
||||||
|
}
|
||||||
|
setState(() {});
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(res['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var color = Theme.of(context).colorScheme.outline;
|
||||||
|
var primary = Theme.of(context).colorScheme.primary;
|
||||||
|
return SizedBox(
|
||||||
|
height: 32,
|
||||||
|
child: TextButton(
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
widget.replyItem!.action == 1
|
||||||
|
? FontAwesomeIcons.solidThumbsUp
|
||||||
|
: FontAwesomeIcons.thumbsUp,
|
||||||
|
size: 16,
|
||||||
|
color: widget.replyItem!.action == 1 ? primary : color,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
AnimatedSwitcher(
|
||||||
|
duration: const Duration(milliseconds: 400),
|
||||||
|
transitionBuilder: (Widget child, Animation<double> animation) {
|
||||||
|
return ScaleTransition(scale: animation, child: child);
|
||||||
|
},
|
||||||
|
child: Text(widget.replyItem!.like.toString(),
|
||||||
|
key: ValueKey<int>(widget.replyItem!.like!),
|
||||||
|
style: TextStyle(
|
||||||
|
color: widget.replyItem!.action == 1 ? primary : color,
|
||||||
|
fontSize:
|
||||||
|
Theme.of(context).textTheme.labelSmall!.fontSize)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onPressed: () => onLikeReply(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -58,10 +58,13 @@ class WebviewController extends GetxController {
|
|||||||
try {
|
try {
|
||||||
var cookies =
|
var cookies =
|
||||||
await WebviewCookieManager().getCookies(HttpString.baseUrl);
|
await WebviewCookieManager().getCookies(HttpString.baseUrl);
|
||||||
var apiCookies =
|
var apiCookies = await WebviewCookieManager()
|
||||||
await WebviewCookieManager().getCookies(HttpString.baseUrl);
|
.getCookies(HttpString.baseApiUrl);
|
||||||
|
var tCookies =
|
||||||
|
await WebviewCookieManager().getCookies(HttpString.tUrl);
|
||||||
await SetCookie.onSet(cookies, HttpString.baseUrl);
|
await SetCookie.onSet(cookies, HttpString.baseUrl);
|
||||||
await SetCookie.onSet(apiCookies, HttpString.baseApiUrl);
|
await SetCookie.onSet(apiCookies, HttpString.baseApiUrl);
|
||||||
|
await SetCookie.onSet(tCookies, HttpString.tUrl);
|
||||||
await UserHttp.userInfo();
|
await UserHttp.userInfo();
|
||||||
var result = await UserHttp.userInfo();
|
var result = await UserHttp.userInfo();
|
||||||
print('网页登录: $result');
|
print('网页登录: $result');
|
||||||
|
|||||||
Reference in New Issue
Block a user