Merge branch 'refs/heads/dev'

# Conflicts:
#	lib/common_widget/rank_song_row.dart
#	lib/models/universal_bean.dart
#	lib/view/music_view.dart
#	pubspec.lock
#	pubspec.yaml
dev
Spark 2 weeks ago
commit 5ef4804e2f

@ -41,9 +41,10 @@ class commentMusic {
Response response = await dio.post( Response response = await dio.post(
_postComment, _postComment,
data: { data: {
'musicId': musicId, 'content': content,
'password': content, 'MusicId': musicId,
'Authorization':Authorization 'Authorization':Authorization
}, },
options: Options(headers:{'Authorization':Authorization,'Content-Type':'application/json;charset=UTF-8'}) options: Options(headers:{'Authorization':Authorization,'Content-Type':'application/json;charset=UTF-8'})
); );
@ -59,21 +60,26 @@ class getCommentApi {
required String musicId, required String musicId,
required String pageNo, required String pageNo,
required String pageSize, required String pageSize,
required String Authorization required String Authorization,
}) async { }) async {
Response response = await dio.get( Response response = await dio.get(
_postComment, _postComment,
queryParameters: {'musicId':musicId,'pageNo':pageNo,'pageSize':pageSize}, queryParameters: {
options: Options(headers:{'Authorization':Authorization,'Content-Type':'application/json;charset=UTF-8'}) 'musicId': musicId,
'pageNo': pageNo,
'pageSize': pageSize,
},
options: Options(headers: {
'Authorization': Authorization,
'Content-Type': 'application/json;charset=UTF-8',
}),
); );
print(response.data); print(response.data);
return GetCommentBean.formMap(response.data); return GetCommentBean.formMap(response.data);
} }
} }

@ -35,8 +35,7 @@ class ReleaseApi {
queryParameters: {'singerName':singerName,'name':name,'introduce':introduce}, queryParameters: {'singerName':singerName,'name':name,'introduce':introduce},
data: formData, data: formData,
options: Options(headers:{'Authorization':Authorization, options: Options(headers:{'Authorization':Authorization,
'Content-Type':'multipart/form-data;boundary=--------------------------741231434897925203274596', })
'Content-Length':'2858240'})
); );
print(response.data); print(response.data);
return UniversalBean.formMap(response.data); return UniversalBean.formMap(response.data);

@ -1,25 +1,29 @@
class GetCommentBean { class GetCommentBean {
int? code; int? code;
String? msg; String? msg;
int? total; int? total;
List<CommentBean>? rows; List<CommentBean>? rows;
GetCommentBean.formMap(Map map) { GetCommentBean.formMap(Map<String, dynamic> map) {
code = map['code']; code = map['code'] as int?;
msg = map['msg']; msg = map['msg'] as String?;
total = map['total'];
List<dynamic>? rowList = map['rows']; // data data total rows
if (rowList == null) return; Map<String, dynamic>? data = map['data'];
if (data != null) {
total = data['total'] as int?;
rows = rowList List<dynamic>? rowList = data['rows'];
.map((item) => CommentBean._formMap(item)) if (rowList != null) {
.toList(); rows = rowList.map((item) => CommentBean.formMap(item as Map<String, dynamic>)).toList();
} else {
rows = []; // rows
}
} else {
rows = []; // data
}
} }
} }
class CommentBean { class CommentBean {
int? id; int? id;
@ -28,11 +32,11 @@ class CommentBean {
String? username; String? username;
String? avatar; String? avatar;
CommentBean._formMap(Map map) { CommentBean.formMap(Map<String, dynamic> map) {
id = map['id']; id = map['id'] as int?;
content = map['content']; content = map['content'] as String? ?? 'No content';
time = map['time']; time = map['time'] as String? ?? 'Unknown time';
username = map['username']; username = map['username'] as String? ?? 'Anonymous';
avatar = map['avatar']; avatar = map['avatar'] as String? ?? 'Default avatar';
} }
} }

@ -8,6 +8,8 @@ import 'package:music_player_miao/widget/text_field.dart';
class CommentView extends StatefulWidget { class CommentView extends StatefulWidget {
@override @override
_CommentViewState createState() => _CommentViewState(); _CommentViewState createState() => _CommentViewState();
@ -39,23 +41,27 @@ class _CommentViewState extends State<CommentView> {
musicId: '1', musicId: '1',
pageNo: '0', pageNo: '0',
pageSize: '10', pageSize: '10',
Authorization: AppData().currentToken); Authorization: AppData().currentToken,
);
// rows
if (bean1.rows == null) {
print('No comments found');
return;
}
setState(() { setState(() {
comments = bean1.rows!.map((rows) => rows.content!).toList(); comments = bean1.rows!.map((rows) => rows.content ?? 'No content').toList();
commentTimes = bean1.rows!.map((rows) => rows.time!).toList(); commentTimes = bean1.rows!.map((rows) => rows.time ?? 'Unknown time').toList();
commentHeader = bean1.rows!.map((rows) => rows.avatar!).toList(); commentHeader = bean1.rows!.map((rows) => rows.avatar ?? 'Default avatar').toList();
commentName = bean1.rows!.map((rows) => rows.username!).toList(); commentName = bean1.rows!.map((rows) => rows.username ?? 'Anonymous').toList();
playlistCount = comments.length; playlistCount = comments.length;
}); });
} catch (error) { } catch (error) {
if (error != null) {
print('Response data: $error');
} else {
print('Error fetching songlist data: $error'); print('Error fetching songlist data: $error');
} }
} }
}
@ -164,17 +170,22 @@ class _CommentViewState extends State<CommentView> {
), ),
IconButton( IconButton(
onPressed: () { onPressed: () {
// setState(() { setState(() {
// ascendingOrder = !ascendingOrder; ascendingOrder = !ascendingOrder;
// comments.sort((a, b) {
// int compare = ascendingOrder // 使
// ? commentTimes.indexOf(a).compareTo( List<int> sortedIndexes = List<int>.generate(comments.length, (i) => i);
// commentTimes.indexOf(b)) sortedIndexes.sort((a, b) {
// : commentTimes.indexOf(b).compareTo( DateTime timeA = DateTime.parse(commentTimes[a]);
// commentTimes.indexOf(a)); DateTime timeB = DateTime.parse(commentTimes[b]);
// return compare; return ascendingOrder ? timeA.compareTo(timeB) : timeB.compareTo(timeA);
// }); });
// });
comments = [for (var i in sortedIndexes) comments[i]];
commentTimes = [for (var i in sortedIndexes) commentTimes[i]];
commentHeader = [for (var i in sortedIndexes) commentHeader[i]];
commentName = [for (var i in sortedIndexes) commentName[i]];
});
}, },
icon: Image.asset( icon: Image.asset(
ascendingOrder ascendingOrder
@ -284,21 +295,35 @@ class _CommentViewState extends State<CommentView> {
); );
} }
void submitComment() { void submitComment() async {
String comment = commentController.text; String comment = commentController.text.trim();
if (comment.isNotEmpty) { if (comment.isEmpty) {
DateTime currentTime = DateTime.now(); print('Comment cannot be empty');
String formattedTime = "${currentTime.year}/${currentTime Get.snackbar('错误', '评论不能为空');
.month}/${currentTime.day} ${currentTime.hour}:${currentTime.minute}"; return;
}
print('Submitting comment with content: $comment');
setState(() { try {
comments.add(comment); UniversalBean bean = await commentMusic().comment(
commentTimes.add(formattedTime); musicId: widget.initialSongIndex,
commentName.add(AppData().currentUsername); content: comment,
commentHeader.add(AppData().currentAvatar); Authorization: AppData().currentToken,
);
//
if (bean.code == 200) {
print('Comment submitted successfully');
commentController.clear(); commentController.clear();
playlistCount++; _fetchSonglistData(); //
}); } else {
print('Failed to submit comment: ${bean.msg}');
Get.snackbar('错误', bean.msg ?? '评论提交失败');
}
} catch (error) {
print('Error submitting comment: $error');
} }
} }
} }

@ -7,7 +7,11 @@ import '../../view_model/home_view_model.dart';
import '../api/api_music_likes.dart'; import '../api/api_music_likes.dart';
import '../api/api_collection.dart'; import '../api/api_collection.dart';
import '../common/download_manager.dart'; import '../common/download_manager.dart';
import '../api/api_music_list.dart';
import '../api/api_collection.dart';
import '../common_widget/Song_widegt.dart'; import '../common_widget/Song_widegt.dart';
import '../models/getMusicList_bean.dart';
import '../view/commend_view.dart';
import '../models/universal_bean.dart'; import '../models/universal_bean.dart';
class MusicView extends StatefulWidget { class MusicView extends StatefulWidget {
@ -436,7 +440,12 @@ class _MusicViewState extends State<MusicView> {
), ),
IconButton( IconButton(
onPressed: () { onPressed: () {
Image.asset("assets/img/music_good.png"); Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CommentView(initialSongIndex: widget.initialSongIndex),
),
);
}, },
icon: Image.asset( icon: Image.asset(
"assets/img/music_commend_un.png", "assets/img/music_commend_un.png",

Loading…
Cancel
Save