diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 8d30395..b74d441 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -60,6 +60,9 @@ class _App { ///查找短信 String get find => '/app/user/content/find'; + ///查看短信列表 + String get findByStatus =>'/app/user/content/findByStatus'; + ///更新VIP状态(已合并至用户信息) String get updateVip => '/app/user/updateVip'; diff --git a/lib/model/contant_list_model.dart b/lib/model/contant_list_model.dart new file mode 100644 index 0000000..ddab7f8 --- /dev/null +++ b/lib/model/contant_list_model.dart @@ -0,0 +1,21 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; +part 'contant_list_model.g.dart'; + + +@JsonSerializable() +class ContantListModel extends Equatable{ + final int id; + final String content; + final int is_checked; + factory ContantListModel.fromJson(Map json) =>_$ContantListModelFromJson(json); + + + const ContantListModel({ + required this.id, + required this.content, + required this.is_checked, + }); + @override + List get props => [id,content,is_checked]; +} \ No newline at end of file diff --git a/lib/model/contant_list_model.g.dart b/lib/model/contant_list_model.g.dart new file mode 100644 index 0000000..05e351a --- /dev/null +++ b/lib/model/contant_list_model.g.dart @@ -0,0 +1,14 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'contant_list_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ContantListModel _$ContantListModelFromJson(Map json) => + ContantListModel( + id: json['id'] as int, + content: json['content'] as String, + is_checked: json['is_checked'] as int, + ); diff --git a/lib/model/network/api_client.dart b/lib/model/network/api_client.dart index 0c04024..a5d6145 100644 --- a/lib/model/network/api_client.dart +++ b/lib/model/network/api_client.dart @@ -5,8 +5,9 @@ import 'package:flutter/foundation.dart'; import 'package:platform/platform.dart'; import '../../constants/api.dart'; +import '../../utils/inner_model/base_list_model.dart'; import '../../utils/toast/cloud_toast.dart'; -import 'base_list_model.dart'; +// import 'base_list_model.dart'; import 'base_model.dart'; import 'net_interceptor.dart'; diff --git a/lib/providers/user_provider.dart b/lib/providers/user_provider.dart index 8f1caae..ab89c88 100644 --- a/lib/providers/user_provider.dart +++ b/lib/providers/user_provider.dart @@ -75,7 +75,7 @@ class UserProvider extends ChangeNotifier { notifyListeners(); } - Future updateConSms() async { + Future updateConSms(int num ) async { final prefs = await SharedPreferences.getInstance(); final service = FlutterBackgroundService(); var base = await apiClient.request(API.app.find, data: {'status': 1}); diff --git a/lib/ui/home/answer_idle.dart b/lib/ui/home/answer_idle.dart index 7e6ea85..f0d54eb 100644 --- a/lib/ui/home/answer_idle.dart +++ b/lib/ui/home/answer_idle.dart @@ -2,11 +2,13 @@ import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:project_telephony/ui/home/func/contant_func.dart'; import 'package:project_telephony/utils/headers.dart'; import 'package:provider/provider.dart'; import '../../base/base_style.dart'; import '../../constants/api.dart'; +import '../../model/contant_list_model.dart'; import '../../model/network/api_client.dart'; import '../../model/network/base_model.dart'; import '../../providers/user_provider.dart'; @@ -17,11 +19,11 @@ import 'add_sms_page.dart'; class AnswerIdleList extends StatefulWidget { final EasyRefreshController refreshController; final bool isIdle; - + final int num; // final List contant; const AnswerIdleList( - {Key? key, required this.refreshController, required this.isIdle}) + {Key? key, required this.refreshController, required this.isIdle,required this.num}) : super(key: key); @override @@ -31,6 +33,7 @@ class AnswerIdleList extends StatefulWidget { class _AnswerIdleListState extends State with AutomaticKeepAliveClientMixin { final userProvider = Provider.of(Get.context!, listen: false); + List answerList=[]; List textList = ['现在无法接听。有什么事吗?', '自定义短信内容']; List textListSMS = []; List smsIdList = []; @@ -56,16 +59,18 @@ class _AnswerIdleListState extends State // footer: MaterialFooter(), onRefresh: () async { await userProvider.updateUserInfo(); - userProvider.updateRefSms(); - updateList(); + answerList=await ContantFunc.getFindByStatus(widget.num); + print("这是数据$answerList"); + // userProvider.updateRefSms(); + // updateList(); setState(() {}); }, slivers: [ SliverList( delegate: SliverChildBuilderDelegate((context, index) { - return _getBox(textListSMS[index], index); - }, childCount: textListSMS.length)) + return _getBox(answerList[index], index); + }, childCount: answerList.length)), ])) : _getEmptyList() : Expanded( @@ -78,15 +83,18 @@ class _AnswerIdleListState extends State // footer: MaterialFooter(), onRefresh: () async { await userProvider.updateUserInfo(); - userProvider.updateRefSms(); - updateList(); + answerList=await ContantFunc.getFindByStatus(widget.num); + print("这是数据$answerList"); + // userProvider.updateRefSms(); + // updateList(); setState(() {}); }, slivers: [ SliverList( - delegate: SliverChildBuilderDelegate((context, index) { - return _getBox(textListSMS[index], index); - }, childCount: textListSMS.length)) + delegate: + SliverChildBuilderDelegate((context, index) { + return _getBox(answerList[index], index); + }, childCount: answerList.length)) ])) ], ); @@ -101,19 +109,20 @@ class _AnswerIdleListState extends State updateList() async { if (userProvider.isLogin) { - textListSMS.clear(); - smsIdList.clear(); + // textListSMS.clear(); + // smsIdList.clear(); int i = 0; // contentRef userProvider.userInfo.contentCon?.forEach((model) { - textListSMS.add(model.content); - smsIdList.add(model.id); + // textListSMS.add(model.content); + // smsIdList.add(model.id); if (model.isChecked == 1) { isCheck = i; } i++; }); - textListSMS.add("自定义短信内容"); + // "自定义短信内容" + } else { textListSMS = textList; } @@ -151,12 +160,12 @@ class _AnswerIdleListState extends State ); } - _getBox(String content, int index) { + _getBox(ContantListModel item,int index) { return GestureDetector( onTap: () async { - if (content != "自定义短信内容") { + if (item.content != "自定义短信内容") { BaseModel res = await apiClient.request(API.app.checked, - data: {'id': smsIdList[index], 'status': 1}); + data: {'id': item.id, 'status': 1}); if (res.code == 0) { setState(() {}); userProvider.updateUserInfo(); @@ -167,7 +176,7 @@ class _AnswerIdleListState extends State } } else { if (userProvider.userInfo.isVip == 1) { - if (textListSMS.length > 5) { + if (answerList.length > 5) { BotToast.showText(text: '自定义数量已达上限,请先删除不需要的短信'); } else { Get.to(AddSmsPage( @@ -184,9 +193,9 @@ class _AnswerIdleListState extends State setState(() {}); }, onLongPress: () { - if (content != "自定义短信内容") { - if (textListSMS.length == 2 || isCheck == index) { - if (textListSMS.length == 2) { + if (item.content != "自定义短信内容") { + if (answerList.length == 2 || isCheck == index) { + if (answerList.length == 2) { BotToast.showText(text: '最后一条内容不可删除'); } else if (isCheck == index) { BotToast.showText(text: '当前为选中内容,不可删除'); @@ -198,7 +207,7 @@ class _AnswerIdleListState extends State return Centertipsalterwidget( desText: '你确定要删除这个短信模版吗,删除之后无法还原。', title: '删除短信模板', - id: smsIdList[index], + id: item.id, callback: (bool status) { widget.refreshController.callRefresh(); }, @@ -228,7 +237,7 @@ class _AnswerIdleListState extends State ]), ), child: Text( - content, + item.content, style: TextStyle( fontSize: BaseStyle.fontSize28, color: index == isCheck diff --git a/lib/ui/home/content_connect_page.dart b/lib/ui/home/content_connect_page.dart index fccdb89..787082a 100644 --- a/lib/ui/home/content_connect_page.dart +++ b/lib/ui/home/content_connect_page.dart @@ -25,7 +25,7 @@ class _ContentConnectPageState extends State EasyRefreshController(); final EasyRefreshController _wasAnswerRefreshController = EasyRefreshController(); - + int state=1; @override void initState() { _tabController = TabController(length: 2, initialIndex: 0, vsync: this); @@ -71,8 +71,10 @@ class _ContentConnectPageState extends State labelStyle:const TextStyle(fontWeight:FontWeight.bold), onTap: (num) { if(num==0){ + state=1; _answerRefreshController.callRefresh(); }else{ + state=3; _wasAnswerRefreshController.callRefresh(); } }, @@ -99,10 +101,12 @@ class _ContentConnectPageState extends State // _getBox(), AnswerIdleList( // contant: const [], + num: state, refreshController: _answerRefreshController, isIdle: false, ), AnswerIdleList( // contant: const [], + num: state, refreshController: _wasAnswerRefreshController, isIdle: true, ) ])) diff --git a/lib/ui/home/func/contant_func.dart b/lib/ui/home/func/contant_func.dart new file mode 100644 index 0000000..4c80135 --- /dev/null +++ b/lib/ui/home/func/contant_func.dart @@ -0,0 +1,20 @@ +import 'package:project_telephony/constants/api.dart'; +import 'package:project_telephony/model/contant_list_model.dart'; +import 'package:project_telephony/model/network/api_client.dart'; +import 'package:project_telephony/utils/inner_model/base_list_model.dart'; + + +import '../../../utils/toast/cloud_toast.dart'; + +class ContantFunc { + static Future> getFindByStatus(int status) async { + BaseListModel res = + await apiClient.requestList(API.app.findByStatus, data:{'status': status}); + if(res.code!=0) { + CloudToast.show(res.msg); + return []; + }else{ + return res.nullSafetyList.map((e) => ContantListModel.fromJson(e)).toList(); + } + } +} diff --git a/lib/ui/widget/appdialog.dart b/lib/ui/widget/appdialog.dart index ef0b8c2..888ad2b 100644 --- a/lib/ui/widget/appdialog.dart +++ b/lib/ui/widget/appdialog.dart @@ -103,7 +103,7 @@ _getBotton(String bContent, context) { // }); CloudToast.show(res.msg); // BoxShadow.show(res.msg); - }else{ + } else{ CloudToast.show(res.msg); Navigator.pop(context); } diff --git a/lib/utils/inner_model/base_list_model.dart b/lib/utils/inner_model/base_list_model.dart new file mode 100644 index 0000000..3c453a1 --- /dev/null +++ b/lib/utils/inner_model/base_list_model.dart @@ -0,0 +1,32 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'base_list_model.g.dart'; + +@JsonSerializable() +class BaseListModel { + final int code; + final String msg; + final List data; + + BaseListModel({ + required this.code, + required this.msg, + required this.data, + }); + + factory BaseListModel.fromJson(Map json) => + _$BaseListModelFromJson(json); + + List get nullSafetyList { + if (data.isEmpty) { + return []; + } else if (data.isEmpty) { + return []; + } else { + return data; + } + } + + +} + diff --git a/lib/utils/inner_model/base_list_model.g.dart b/lib/utils/inner_model/base_list_model.g.dart new file mode 100644 index 0000000..2222290 --- /dev/null +++ b/lib/utils/inner_model/base_list_model.g.dart @@ -0,0 +1,14 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'base_list_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +BaseListModel _$BaseListModelFromJson(Map json) => + BaseListModel( + code: json['code'] as int, + msg: json['msg'] as String, + data: json['data'] as List, + ); diff --git a/lib/utils/inner_model/base_model.dart b/lib/utils/inner_model/base_model.dart new file mode 100644 index 0000000..68cc933 --- /dev/null +++ b/lib/utils/inner_model/base_model.dart @@ -0,0 +1,36 @@ +import 'package:dio/dio.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'base_model.g.dart'; + +@JsonSerializable() +class BaseModel { + int code; + String msg; + dynamic data; + BaseModel({ + required this.code, + required this.msg, + this.data, + }); + + + + List map(T Function(dynamic json) f) { + if (data == null) return []; + return (data! as List).map(f).toList(); + } + + factory BaseModel.unknown() => BaseModel( + code: -1, + msg: 'UNKNOW FAIL', + ); + + factory BaseModel.dioErr(DioError err) => BaseModel( + code: err.response?.statusCode ?? -1, + msg: err.message, + ); + + factory BaseModel.fromJson(Map json) => + _$BaseModelFromJson(json) as BaseModel; +} diff --git a/lib/utils/inner_model/base_model.g.dart b/lib/utils/inner_model/base_model.g.dart new file mode 100644 index 0000000..5c5ab19 --- /dev/null +++ b/lib/utils/inner_model/base_model.g.dart @@ -0,0 +1,13 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'base_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +BaseModel _$BaseModelFromJson(Map json) => BaseModel( + code: json['code'] as int, + msg: json['msg'] as String, + data: json['data'], + );