From 8414606bfa8d219e99bc9b850b4791c441174b64 Mon Sep 17 00:00:00 2001 From: jack ning Date: Mon, 16 May 2022 07:12:21 +0800 Subject: [PATCH] update --- bytedesk_demo/pubspec.yaml | 2 +- .../blocs/leavemsg_bloc/leavemsg_bloc.dart | 3 +- .../blocs/leavemsg_bloc/leavemsg_event.dart | 11 +- .../lib/http/bytedesk_leavemsg_api.dart | 16 +- .../lib/repositories/leavemsg_repository.dart | 6 +- .../lib/ui/leavemsg/page/leavemsg_page.dart | 326 ++++++++++-------- .../lib/util/bytedesk_constants.dart | 2 +- 7 files changed, 210 insertions(+), 156 deletions(-) diff --git a/bytedesk_demo/pubspec.yaml b/bytedesk_demo/pubspec.yaml index a1124f6..8e70e47 100644 --- a/bytedesk_demo/pubspec.yaml +++ b/bytedesk_demo/pubspec.yaml @@ -46,7 +46,7 @@ dependencies: # 请在ios/Podfile中添加:use_frameworks! vibration: ^1.7.3 # 在线客服 https://pub.dev/packages/bytedesk_kefu - bytedesk_kefu: ^1.2.9 + bytedesk_kefu: ^1.3.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. diff --git a/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_bloc.dart b/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_bloc.dart index 11bd06d..5b67632 100755 --- a/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_bloc.dart +++ b/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_bloc.dart @@ -27,8 +27,7 @@ class LeaveMsgBloc extends Bloc { SubmitLeaveMsgEvent event, Emitter emit) async { emit(LeaveMsgSubmiting()); try { - // final JsonResult jsonResult = - await leaveMsgRepository.submitLeaveMsg(event.content, event.imageUrls); + await leaveMsgRepository.submitLeaveMsg(event.wid, event.aid, event.type, event.mobile, event.email, event.content); emit(LeaveMsgSubmitSuccessState()); } catch (error) { print(error); diff --git a/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_event.dart b/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_event.dart index d976578..abaab45 100755 --- a/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_event.dart +++ b/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_event.dart @@ -15,10 +15,15 @@ class GetLeaveMsgCategoryEvent extends LeaveMsgEvent { } class SubmitLeaveMsgEvent extends LeaveMsgEvent { - final List? imageUrls; + // final List? imageUrls; + final String? wid; + final String? aid; + final String? type; + final String? mobile; + final String? email; final String? content; - - SubmitLeaveMsgEvent({@required this.content, @required this.imageUrls}) + // @required this.imageUrls + SubmitLeaveMsgEvent({@required this.wid, @required this.aid, @required this.type, @required this.mobile, @required this.email, @required this.content}) : super(); } diff --git a/bytedesk_kefu/lib/http/bytedesk_leavemsg_api.dart b/bytedesk_kefu/lib/http/bytedesk_leavemsg_api.dart index bc4cadc..d176aa9 100755 --- a/bytedesk_kefu/lib/http/bytedesk_leavemsg_api.dart +++ b/bytedesk_kefu/lib/http/bytedesk_leavemsg_api.dart @@ -33,14 +33,12 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi { return categories; } - // TODO: 提交意见反馈 - Future submitLeaveMsg( - String? content, List? imageUrls) async { + // TODO: 提交意见反馈 , List? imageUrls + Future submitLeaveMsg(String? wid, String? aid, String? type, + String? mobile, String? email, String? content) async { // - var body = json.encode({"content": content, "client": client}); - // - // final initUrl = '$baseUrl/api/feedback/create'; - final initUrl = Uri.http(BytedeskConstants.host, '/api/leavemsg/create'); + var body = json.encode({"wid": wid, "aid": aid, "type": type, "mobile": mobile, "email": email,"content": content, "client": client}); + final initUrl = Uri.http(BytedeskConstants.host, '/api/leavemsg/save'); final initResponse = await this.httpClient.post(initUrl, headers: getHeaders(), body: body); //解决json解析中的乱码问题 @@ -48,12 +46,12 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + print("submitLeaveMsg:"); + print(responseJson); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); } - // return User.fromJson(responseJson); return JsonResult(); } diff --git a/bytedesk_kefu/lib/repositories/leavemsg_repository.dart b/bytedesk_kefu/lib/repositories/leavemsg_repository.dart index 0f02913..6da9b10 100755 --- a/bytedesk_kefu/lib/repositories/leavemsg_repository.dart +++ b/bytedesk_kefu/lib/repositories/leavemsg_repository.dart @@ -11,9 +11,9 @@ class LeaveMsgRepository { return await bytedeskHttpApi.getHelpLeaveMsgCategories(uid); } - Future submitLeaveMsg( - String? content, List? imageUrls) async { - return await bytedeskHttpApi.submitLeaveMsg(content, imageUrls); + // , List? imageUrls + Future submitLeaveMsg(String? wid, String? aid, String? type, String? mobile, String? email, String? content) async { + return await bytedeskHttpApi.submitLeaveMsg(wid, aid, type, mobile, email, content); } Future upload(String? filePath) async { diff --git a/bytedesk_kefu/lib/ui/leavemsg/page/leavemsg_page.dart b/bytedesk_kefu/lib/ui/leavemsg/page/leavemsg_page.dart index ffb1e1e..79c3bf4 100755 --- a/bytedesk_kefu/lib/ui/leavemsg/page/leavemsg_page.dart +++ b/bytedesk_kefu/lib/ui/leavemsg/page/leavemsg_page.dart @@ -1,12 +1,12 @@ -import 'dart:io'; +// import 'dart:io'; import 'package:bytedesk_kefu/blocs/leavemsg_bloc/bloc.dart'; -import 'package:bytedesk_kefu/ui/widget/image_choose_widget.dart'; +// import 'package:bytedesk_kefu/ui/widget/image_choose_widget.dart'; import 'package:bytedesk_kefu/ui/widget/my_button.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; -import 'package:image_picker/image_picker.dart'; +// import 'package:image_picker/image_picker.dart'; class LeaveMsgPage extends StatefulWidget { // @@ -15,6 +15,10 @@ class LeaveMsgPage extends StatefulWidget { final String? type; final String? tip; // + // String? mobile; + // String? email; + // String? content; + // LeaveMsgPage( {Key? key, @required this.wid, @@ -30,11 +34,13 @@ class LeaveMsgPage extends StatefulWidget { class _LeaveMsgPageState extends State { // ScrollController _scrollController = new ScrollController(); // 滚动监听 - TextEditingController _textEditController = new TextEditingController(); - ImagePicker picker = ImagePicker(); - List _imageUrls = []; - List _fileList = []; - File? _selectedImageFile; + // TextEditingController _nameEditController = new TextEditingController(); + TextEditingController _mobileEditController = new TextEditingController(); + TextEditingController _contentEditController = new TextEditingController(); + // ImagePicker picker = ImagePicker(); + // List _imageUrls = []; + // List _fileList = []; + // File? _selectedImageFile; // List mSubmitFileList = []; @override @@ -55,11 +61,11 @@ class _LeaveMsgPageState extends State { @override Widget build(BuildContext context) { // - print('fileList的内容: $_fileList'); - if (_selectedImageFile != null) { - _fileList.add(_selectedImageFile!); - } - _selectedImageFile = null; + // print('fileList的内容: $_fileList'); + // if (_selectedImageFile != null) { + // _fileList.add(_selectedImageFile!); + // } + // _selectedImageFile = null; // // TODO: 右上角增加:我的留言,查看留言记录及回复 return Scaffold( @@ -74,10 +80,10 @@ class _LeaveMsgPageState extends State { child: InkWell( onTap: () { // 提交 - BlocProvider.of(context) - ..add(SubmitLeaveMsgEvent( - imageUrls: _imageUrls, - content: _textEditController.text)); + // BlocProvider.of(context) + // ..add(SubmitLeaveMsgEvent( + // imageUrls: _imageUrls, + // content: _contentEditController.text)); }, child: Text( '提交', @@ -95,9 +101,9 @@ class _LeaveMsgPageState extends State { Fluttertoast.showToast(msg: '上传图片中'); } else if (state is UploadImageSuccess) { // 图片url - if (!_imageUrls.contains(state.url)) { - _imageUrls.add(state.url); - } + // if (!_imageUrls.contains(state.url)) { + // _imageUrls.add(state.url); + // } } else if (state is LeaveMsgSubmiting) { Fluttertoast.showToast(msg: '提交留言中'); } else if (state is LeaveMsgSubmitSuccessState) { @@ -113,6 +119,44 @@ class _LeaveMsgPageState extends State { padding: EdgeInsets.only(top: 5.0, left: 10, right: 10), child: Column( children: [ + // Container( + // // constraints: BoxConstraints( + // // minHeight: 150, + // // ), + // // color: Color(0xffffffff), + // margin: EdgeInsets.only(top: 15), + // child: TextField( + // controller: _nameEditController, + // // maxLines: 5, + // // maxLength: 500, + // decoration: InputDecoration( + // hintText: "称呼", + // hintStyle: + // TextStyle(color: Color(0xff999999), fontSize: 16), + // contentPadding: EdgeInsets.only(left: 15, right: 15), + // border: InputBorder.none, + // ), + // ), + // ), + Container( + // constraints: BoxConstraints( + // minHeight: 150, + // ), + // color: Color(0xffffffff), + margin: EdgeInsets.only(top: 15), + child: TextField( + controller: _mobileEditController, + // maxLines: 5, + // maxLength: 500, + decoration: InputDecoration( + hintText: "手机号", + hintStyle: + TextStyle(color: Color(0xff999999), fontSize: 16), + contentPadding: EdgeInsets.only(left: 15, right: 15), + border: InputBorder.none, + ), + ), + ), Container( constraints: BoxConstraints( minHeight: 150, @@ -120,11 +164,11 @@ class _LeaveMsgPageState extends State { // color: Color(0xffffffff), margin: EdgeInsets.only(top: 15), child: TextField( - controller: _textEditController, + controller: _contentEditController, maxLines: 5, maxLength: 500, decoration: InputDecoration( - hintText: "快说点儿什么吧......", + hintText: "留言内容", hintStyle: TextStyle(color: Color(0xff999999), fontSize: 16), contentPadding: EdgeInsets.only(left: 15, right: 15), @@ -132,86 +176,94 @@ class _LeaveMsgPageState extends State { ), ), ), - GridView.count( - shrinkWrap: true, - primary: false, - crossAxisCount: 3, - children: List.generate(_fileList.length + 1, (index) { - // 这个方法体用于生成GridView中的一个item - var content; - if (index == _fileList.length) { - // 添加图片按钮 - var addCell = Center( - child: Image.asset( - 'assets/images/feedback/mine_feedback_add_image.png', - width: double.infinity, - height: double.infinity, - )); - content = GestureDetector( - onTap: () { - // 添加图片 - // pickImage(context); - showModalBottomSheet( - context: context, - builder: (context) { - return ImageChooseWidget( - pickImageCallBack: () { - _pickImage(); - }, - takeImageCallBack: () { - _takeImage(); - }, - ); - }); - }, - child: addCell, - ); - } else { - // 被选中的图片 - content = Stack( - children: [ - Center( - child: Image.file( - _fileList[index], - width: double.infinity, - height: double.infinity, - fit: BoxFit.cover, - ), - ), - Align( - alignment: Alignment.topRight, - child: InkWell( - onTap: () { - _fileList.removeAt(index); - _selectedImageFile = null; - setState(() {}); - }, - child: Image.asset( - 'assets/images/feedback/mine_feedback_ic_del.png', - width: 20.0, - height: 20.0, - ), - ), - ) - ], - ); - } - return Container( - margin: const EdgeInsets.all(10.0), - width: 80.0, - height: 80.0, - color: const Color(0xFFffffff), - child: content, - ); - }), - ), + // GridView.count( + // shrinkWrap: true, + // primary: false, + // crossAxisCount: 3, + // children: List.generate(_fileList.length + 1, (index) { + // // 这个方法体用于生成GridView中的一个item + // var content; + // if (index == _fileList.length) { + // // 添加图片按钮 + // var addCell = Center( + // child: Image.asset( + // 'assets/images/feedback/mine_feedback_add_image.png', + // width: double.infinity, + // height: double.infinity, + // )); + // content = GestureDetector( + // onTap: () { + // // 添加图片 + // // pickImage(context); + // showModalBottomSheet( + // context: context, + // builder: (context) { + // return ImageChooseWidget( + // pickImageCallBack: () { + // _pickImage(); + // }, + // takeImageCallBack: () { + // _takeImage(); + // }, + // ); + // }); + // }, + // child: addCell, + // ); + // } else { + // // 被选中的图片 + // content = Stack( + // children: [ + // Center( + // child: Image.file( + // _fileList[index], + // width: double.infinity, + // height: double.infinity, + // fit: BoxFit.cover, + // ), + // ), + // Align( + // alignment: Alignment.topRight, + // child: InkWell( + // onTap: () { + // _fileList.removeAt(index); + // _selectedImageFile = null; + // setState(() {}); + // }, + // child: Image.asset( + // 'assets/images/feedback/mine_feedback_ic_del.png', + // width: 20.0, + // height: 20.0, + // ), + // ), + // ) + // ], + // ); + // } + // return Container( + // margin: const EdgeInsets.all(10.0), + // width: 80.0, + // height: 80.0, + // color: const Color(0xFFffffff), + // child: content, + // ); + // }), + // ), MyButton( onPressed: () { // + // BlocProvider.of(context) + // ..add(SubmitLeaveMsgEvent( + // imageUrls: _imageUrls, + // content: _contentEditController.text)); BlocProvider.of(context) ..add(SubmitLeaveMsgEvent( - imageUrls: _imageUrls, - content: _textEditController.text)); + wid: widget.wid, + aid: widget.aid, + type: widget.type, + mobile: _mobileEditController.text, + email: "", + content: _contentEditController.text)); }, text: '提交', ) @@ -222,46 +274,46 @@ class _LeaveMsgPageState extends State { } // 选择图片 - Future _pickImage() async { - if (_fileList.length >= 9) { - Fluttertoast.showToast(msg: "最多选取9张图片"); - return; - } - try { - XFile? pickedFile = await picker.pickImage( - source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); - print('pick image path: ${pickedFile!.path}'); - setState(() { - _selectedImageFile = File(pickedFile.path); - }); - // - BlocProvider.of(context) - ..add(UploadImageEvent(filePath: pickedFile.path)); - } catch (e) { - print('pick image error ${e.toString()}'); - Fluttertoast.showToast(msg: "未选取图片"); - } - } + // Future _pickImage() async { + // if (_fileList.length >= 9) { + // Fluttertoast.showToast(msg: "最多选取9张图片"); + // return; + // } + // try { + // XFile? pickedFile = await picker.pickImage( + // source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); + // print('pick image path: ${pickedFile!.path}'); + // setState(() { + // _selectedImageFile = File(pickedFile.path); + // }); + // // + // BlocProvider.of(context) + // ..add(UploadImageEvent(filePath: pickedFile.path)); + // } catch (e) { + // print('pick image error ${e.toString()}'); + // Fluttertoast.showToast(msg: "未选取图片"); + // } + // } // 拍照 - Future _takeImage() async { - if (_fileList.length >= 9) { - Fluttertoast.showToast(msg: "最多选取9张图片"); - return; - } - try { - XFile? pickedFile = await picker.pickImage( - source: ImageSource.camera, maxWidth: 800, imageQuality: 95); - print('take image path: ${pickedFile!.path}'); - setState(() { - _selectedImageFile = File(pickedFile.path); - }); - // - BlocProvider.of(context) - ..add(UploadImageEvent(filePath: pickedFile.path)); - } catch (e) { - print('take image error ${e.toString()}'); - Fluttertoast.showToast(msg: "未选取图片"); - } - } + // Future _takeImage() async { + // if (_fileList.length >= 9) { + // Fluttertoast.showToast(msg: "最多选取9张图片"); + // return; + // } + // try { + // XFile? pickedFile = await picker.pickImage( + // source: ImageSource.camera, maxWidth: 800, imageQuality: 95); + // print('take image path: ${pickedFile!.path}'); + // setState(() { + // _selectedImageFile = File(pickedFile.path); + // }); + // // + // BlocProvider.of(context) + // ..add(UploadImageEvent(filePath: pickedFile.path)); + // } catch (e) { + // print('take image error ${e.toString()}'); + // Fluttertoast.showToast(msg: "未选取图片"); + // } + // } } diff --git a/bytedesk_kefu/lib/util/bytedesk_constants.dart b/bytedesk_kefu/lib/util/bytedesk_constants.dart index e2b4704..3d27e63 100755 --- a/bytedesk_kefu/lib/util/bytedesk_constants.dart +++ b/bytedesk_kefu/lib/util/bytedesk_constants.dart @@ -45,7 +45,7 @@ class BytedeskConstants { // static const String httpBaseUrliOS = 'http://' + mqttHost + ':8000'; // static const String httpUploadUrl = 'http://' + mqttHost + ':8000'; // static const String host = mqttHost + ':8000'; - // static const String mqttHost = '192.168.0.104'; + // static const String mqttHost = '192.168.0.102'; // 线上 static const bool isDebug = false; // false;