dyn addition jump

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-05-15 13:35:13 +08:00
parent 205ae2bf55
commit 070ecad54b
6 changed files with 370 additions and 162 deletions

View File

@@ -243,10 +243,10 @@ class DynamicsHttp {
} }
static Future<LoadingState<VoteInfo>> doVote({ static Future<LoadingState<VoteInfo>> doVote({
required int voteId, required voteId,
required List<int> votes, required List<int> votes,
bool anonymity = false, bool anonymity = false,
int? dynamicId, dynamicId,
}) async { }) async {
final csrf = Accounts.main.csrf; final csrf = Accounts.main.csrf;
final data = { final data = {

View File

@@ -396,8 +396,10 @@ class Vote {
int? type; int? type;
int? uid; int? uid;
int? voteId; int? voteId;
String? desc;
Vote.fromJson(Map<String, dynamic> json) { Vote.fromJson(Map<String, dynamic> json) {
desc = json['desc'];
choiceCnt = json['choice_cnt']; choiceCnt = json['choice_cnt'];
share = json['share']; share = json['share'];
defaultShare = json['default_share']; defaultShare = json['default_share'];
@@ -805,6 +807,7 @@ class RichTextNodeItem {
String? type; String? type;
String? rid; String? rid;
List<OpusPicsModel>? pics; List<OpusPicsModel>? pics;
String? jumpUrl;
RichTextNodeItem.fromJson(Map<String, dynamic> json) { RichTextNodeItem.fromJson(Map<String, dynamic> json) {
emoji = json['emoji'] != null ? Emoji.fromJson(json['emoji']) : null; emoji = json['emoji'] != null ? Emoji.fromJson(json['emoji']) : null;
@@ -817,6 +820,7 @@ class RichTextNodeItem {
: (json['pics'] as List?) : (json['pics'] as List?)
?.map((e) => OpusPicsModel.fromJson(e)) ?.map((e) => OpusPicsModel.fromJson(e))
.toList(); .toList();
jumpUrl = json['jump_url'];
} }
} }

View File

@@ -208,7 +208,7 @@ class OpusContent extends StatelessWidget {
showVoteDialog( showVoteDialog(
context, context,
element.linkCard!.card!.vote?.voteId ?? element.linkCard!.card!.vote?.voteId ??
int.parse(element.linkCard!.card!.oid!), element.linkCard!.card!.oid,
); );
return; return;
} }

View File

@@ -1,197 +1,400 @@
import 'package:PiliPlus/build_config.dart';
import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart'; import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
import 'package:PiliPlus/http/dynamics.dart'; import 'package:PiliPlus/http/dynamics.dart';
import 'package:PiliPlus/models/dynamics/result.dart'; import 'package:PiliPlus/models/dynamics/result.dart';
import 'package:PiliPlus/pages/dynamics/widgets/vote.dart';
import 'package:PiliPlus/utils/app_scheme.dart'; import 'package:PiliPlus/utils/app_scheme.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
/// TODO 点击跳转
Widget addWidget( Widget addWidget(
ThemeData theme, DynamicItemModel item, BuildContext context, type, ThemeData theme, DynamicItemModel item, BuildContext context, type,
{floor = 1}) { {floor = 1}) {
Color bgColor = floor == 1 late final Color bgColor = floor == 1
? theme.dividerColor.withOpacity(0.08) ? theme.dividerColor.withOpacity(0.08)
: theme.colorScheme.surface; : theme.colorScheme.surface;
switch (type) { try {
case 'ADDITIONAL_TYPE_UGC': switch (type) {
final content = item.modules.moduleDynamic!.additional!.ugc!;
// 转发的投稿 // 转发的投稿
return InkWell( case 'ADDITIONAL_TYPE_UGC':
onTap: content.jumpUrl == null final ugc = item.modules.moduleDynamic!.additional!.ugc!;
? null final borderRadius = floor == 1 ? null : StyleString.mdRadius;
: () { return Padding(
PiliScheme.routePushFromUrl(content.jumpUrl!); padding: const EdgeInsets.only(top: 6),
}, child: Material(
child: Container( borderRadius: borderRadius,
padding: color: bgColor,
const EdgeInsets.only(left: 12, top: 8, right: 12, bottom: 8), child: InkWell(
color: bgColor, borderRadius: borderRadius,
child: Row( onTap: ugc.jumpUrl == null
children: [ ? null
NetworkImgLayer( : () {
width: 120, PiliScheme.routePushFromUrl(ugc.jumpUrl!);
height: 75, },
src: content.cover, child: Padding(
), padding:
const SizedBox(width: 10), const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
Expanded( child: Row(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
Text( NetworkImgLayer(
content.title!, width: 120,
maxLines: 2, height: 75,
overflow: TextOverflow.ellipsis, src: ugc.cover,
), ),
const SizedBox(height: 4), const SizedBox(width: 10),
Text( Expanded(
content.descSecond!, child: Column(
style: TextStyle( crossAxisAlignment: CrossAxisAlignment.start,
color: theme.colorScheme.outline, mainAxisAlignment: MainAxisAlignment.start,
fontSize: theme.textTheme.labelMedium!.fontSize, children: [
Text(
ugc.title!,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Text(
ugc.descSecond!,
style: TextStyle(
color: theme.colorScheme.outline,
fontSize: theme.textTheme.labelMedium!.fontSize,
),
)
],
), ),
) ),
], ],
), ),
), ),
], ),
), ),
), );
);
case 'ADDITIONAL_TYPE_RESERVE': case 'ADDITIONAL_TYPE_RESERVE':
final content = item.modules.moduleDynamic!.additional!.reserve!; final reserve = item.modules.moduleDynamic!.additional!.reserve!;
return content.state != -1 late final borderRadius = floor == 1 ? null : StyleString.mdRadius;
? content.title != null return reserve.state != -1
? Padding( ? reserve.title != null
padding: const EdgeInsets.only(top: 8), ? Padding(
child: InkWell( padding: const EdgeInsets.only(top: 6),
onTap: () {}, child: Material(
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 10),
color: bgColor, color: bgColor,
borderRadius: borderRadius,
child: InkWell(
onTap: () {},
borderRadius: borderRadius,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 10),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
reserve.title!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 1),
Text.rich(
TextSpan(
style: TextStyle(
color: theme.colorScheme.outline,
fontSize: theme
.textTheme.labelMedium!.fontSize,
),
children: [
if (reserve.desc1 != null)
TextSpan(text: reserve.desc1!.text),
const TextSpan(text: ' '),
if (reserve.desc2 != null)
TextSpan(text: reserve.desc2!.text),
],
),
)
],
),
),
if (reserve.button != null)
Builder(
builder: (context) {
final btn = reserve.button!;
final isReserved = btn.status == btn.type;
final bool canJump = btn.jumpUrl != null;
return FilledButton.tonal(
style: FilledButton.styleFrom(
foregroundColor: canJump
? null
: isReserved
? theme.colorScheme.onSurface
.withOpacity(0.38)
: null,
backgroundColor: canJump
? null
: isReserved
? theme.colorScheme.onSurface
.withOpacity(0.12)
: null,
visualDensity: VisualDensity.compact,
padding: const EdgeInsets.symmetric(
horizontal: 16),
tapTargetSize:
MaterialTapTargetSize.shrinkWrap,
),
onPressed: canJump
? () {
PiliScheme.routePushFromUrl(
btn.jumpUrl!);
}
: btn.disable == 1
? null
: () async {
var res = await DynamicsHttp
.dynReserve(
reserveId: reserve.rid,
curBtnStatus: btn.status,
dynamicIdStr: item.idStr,
reserveTotal:
reserve.reserveTotal,
);
if (res['status']) {
reserve
..desc2?.text =
res['data']
['desc_update']
..reserveTotal =
res['data']
['reserve_update']
..button!.status = res[
'data']
['final_btn_status'];
if (context.mounted) {
(context as Element?)
?.markNeedsBuild();
}
} else {
SmartDialog.showToast(
res['msg']);
}
},
child: Text(
btn.jumpText != null
? btn.jumpText!
: isReserved
? btn.checkText!
: btn.uncheckText!,
),
);
},
),
],
),
),
),
),
)
: const SizedBox.shrink()
: const SizedBox.shrink();
// 商品
case 'ADDITIONAL_TYPE_GOODS':
final content = item.modules.moduleDynamic!.additional!.goods!;
if (content.items?.isNotEmpty == true) {
final borderRadius = floor == 1 ? null : StyleString.mdRadius;
return Padding(
padding: const EdgeInsets.only(top: 6),
child: Material(
color: bgColor,
borderRadius: borderRadius,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: content.items!.map((e) {
return InkWell(
borderRadius: borderRadius,
onTap: () {
PiliScheme.routePushFromUrl(e.jumpUrl!);
},
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
child: Row( child: Row(
children: [ children: [
if (e.cover?.isNotEmpty == true) ...[
NetworkImgLayer(
width: 45,
height: 45,
src: e.cover,
radius: 6,
),
const SizedBox(width: 10),
],
Expanded( Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
content.title!, e.name!,
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
const SizedBox(height: 1), if (e.price?.isNotEmpty == true)
Text.rich( Text.rich(
TextSpan( TextSpan(
style: TextStyle( children: [
color: theme.colorScheme.outline, TextSpan(
fontSize: text: '${e.price}',
theme.textTheme.labelMedium!.fontSize, style: TextStyle(
color: theme.colorScheme.primary,
),
),
const TextSpan(
text: '',
style: TextStyle(fontSize: 12),
),
],
), ),
children: [
if (content.desc1 != null)
TextSpan(text: content.desc1!.text),
const TextSpan(text: ' '),
if (content.desc2 != null)
TextSpan(text: content.desc2!.text),
],
), ),
)
], ],
), ),
), ),
if (content.button != null) if (e.jumpDesc?.isNotEmpty == true) ...[
Builder( const SizedBox(width: 10),
builder: (context) { FilledButton.tonal(
final btn = content.button!; onPressed: () {
final isReserved = btn.status == btn.type; PiliScheme.routePushFromUrl(e.jumpUrl!);
final bool canJump = btn.jumpUrl != null;
return FilledButton.tonal(
style: FilledButton.styleFrom(
foregroundColor: canJump
? null
: isReserved
? theme.colorScheme.onSurface
.withOpacity(0.38)
: null,
backgroundColor: canJump
? null
: isReserved
? theme.colorScheme.onSurface
.withOpacity(0.12)
: null,
visualDensity: VisualDensity.compact,
padding: const EdgeInsets.symmetric(
horizontal: 16),
tapTargetSize:
MaterialTapTargetSize.shrinkWrap,
),
onPressed: canJump
? () {
PiliScheme.routePushFromUrl(
btn.jumpUrl!);
}
: btn.disable == 1
? null
: () async {
var res =
await DynamicsHttp.dynReserve(
reserveId: content.rid,
curBtnStatus: btn.status,
dynamicIdStr: item.idStr,
reserveTotal:
content.reserveTotal,
);
if (res['status']) {
content
..desc2?.text =
res['data']['desc_update']
..reserveTotal = res['data']
['reserve_update']
..button!.status = res['data']
['final_btn_status'];
if (context.mounted) {
(context as Element?)
?.markNeedsBuild();
}
} else {
SmartDialog.showToast(
res['msg']);
}
},
child: Text(
btn.jumpText != null
? btn.jumpText!
: isReserved
? btn.checkText!
: btn.uncheckText!,
),
);
}, },
style: FilledButton.styleFrom(
shape: const RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(6)),
),
padding:
const EdgeInsets.symmetric(horizontal: 10),
visualDensity: const VisualDensity(
horizontal: -2, vertical: -3),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: Text(e.jumpDesc!),
), ),
],
], ],
), ),
), ),
), );
) }).toList(),
: const SizedBox.shrink() ),
: const SizedBox.shrink(); ),
case 'ADDITIONAL_TYPE_GOODS': );
// final content = item.modules.moduleDynamic!.additional!.goods; }
// 商品 return const SizedBox.shrink();
return const SizedBox.shrink(); // case 'ADDITIONAL_TYPE_MATCH':
case 'ADDITIONAL_TYPE_MATCH':
// final content = item.modules.moduleDynamic!.additional!.match; // final content = item.modules.moduleDynamic!.additional!.match;
return const SizedBox.shrink(); // return const SizedBox.shrink();
case 'ADDITIONAL_TYPE_COMMON': // case 'ADDITIONAL_TYPE_COMMON':
// final content = item.modules.moduleDynamic!.additional!.common; // final content = item.modules.moduleDynamic!.additional!.common;
return const SizedBox.shrink(); // return const SizedBox.shrink();
case 'ADDITIONAL_TYPE_VOTE': case 'ADDITIONAL_TYPE_VOTE':
return const SizedBox.shrink(); final vote = item.modules.moduleDynamic!.additional!.vote!;
default: final borderRadius = floor == 1 ? null : StyleString.mdRadius;
return const SizedBox.shrink(); return Padding(
padding: const EdgeInsets.only(top: 6),
child: Material(
color: bgColor,
borderRadius: borderRadius,
child: InkWell(
borderRadius: borderRadius,
onTap: () {
showVoteDialog(
context,
vote.voteId,
item.idStr,
);
},
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
child: Row(
children: [
Container(
decoration: BoxDecoration(
color: floor == 1
? theme.colorScheme.surface
: theme.dividerColor.withOpacity(0.08),
borderRadius:
const BorderRadius.all(Radius.circular(8)),
),
width: 70,
height: 56,
child: const Icon(Icons.bar_chart_rounded),
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
vote.desc!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
'${Utils.numFormat(vote.joinNum)}人参与',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 13, color: theme.colorScheme.outline),
),
],
),
),
const SizedBox(width: 10),
FilledButton.tonal(
onPressed: () {
showVoteDialog(
context,
vote.voteId,
item.idStr,
);
},
style: FilledButton.styleFrom(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(6)),
),
padding: const EdgeInsets.symmetric(horizontal: 10),
visualDensity:
const VisualDensity(horizontal: -2, vertical: -3),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: const Text('参与'),
),
],
),
),
),
),
);
default:
if (BuildConfig.isDebug) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text('additional panel\ntype: $type'),
);
}
return const SizedBox.shrink();
}
} catch (e) {
return Padding(
padding: const EdgeInsets.all(12),
child: SelectableText(
'''
additional panel error
id: ${item.idStr}
type: $type
err: $e''',
),
);
} }
} }

View File

@@ -123,10 +123,7 @@ TextSpan? richNode(
), ),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () { ..onTap = () {
final dynIdStr = item.basic?.commentIdStr; showVoteDialog(context, i.rid, item.basic?.commentIdStr);
final dynId =
dynIdStr != null ? int.tryParse(dynIdStr) : null;
showVoteDialog(context, int.parse(i.rid!), dynId);
}, },
), ),
); );
@@ -175,7 +172,6 @@ TextSpan? richNode(
); );
break; break;
/// TODO 商品
case 'RICH_TEXT_NODE_TYPE_GOODS': case 'RICH_TEXT_NODE_TYPE_GOODS':
spanChildren spanChildren
..add( ..add(
@@ -192,6 +188,12 @@ TextSpan? richNode(
TextSpan( TextSpan(
text: '${i.text} ', text: '${i.text} ',
style: authorStyle, style: authorStyle,
recognizer: i.jumpUrl == null
? null
: (TapGestureRecognizer()
..onTap = () {
PiliScheme.routePushFromUrl(i.jumpUrl!);
}),
), ),
); );
break; break;

View File

@@ -340,8 +340,7 @@ class PercentageChip<T> extends StatelessWidget {
// } // }
// } // }
Future showVoteDialog(BuildContext context, int voteId, Future showVoteDialog(BuildContext context, voteId, [dynamicId]) async {
[int? dynamicId]) async {
final voteInfo = await DynamicsHttp.voteInfo(voteId); final voteInfo = await DynamicsHttp.voteInfo(voteId);
if (context.mounted) { if (context.mounted) {
if (voteInfo.isSuccess) { if (voteInfo.isSuccess) {