Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx_flutter_message
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx_flutter_message
Commits
74cec6fc
提交
74cec6fc
authored
9月 18, 2024
作者:
张国庆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加网络请求能力,消息接口请求抽取到插件
上级
1b3f1fc2
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
171 行增加
和
20 行删除
+171
-20
clx_flutter_message.dart
lib/clx_flutter_message.dart
+3
-19
api.dart
lib/core/api/api.dart
+77
-0
message_net.dart
lib/core/api/message_net.dart
+86
-0
message_config.dart
lib/core/model/message_config.dart
+4
-0
pubspec.yaml
pubspec.yaml
+1
-1
没有找到文件。
lib/clx_flutter_message.dart
浏览文件 @
74cec6fc
...
@@ -3,6 +3,7 @@ import 'package:clx_flutter_message/util/toast_util.dart';
...
@@ -3,6 +3,7 @@ import 'package:clx_flutter_message/util/toast_util.dart';
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'clx_flutter_message_platform_interface.dart'
;
import
'clx_flutter_message_platform_interface.dart'
;
import
'common/constant.dart'
;
import
'common/constant.dart'
;
import
'core/api/message_net.dart'
;
import
'core/model/message_config.dart'
;
import
'core/model/message_config.dart'
;
import
'core/model/message_data.dart'
;
import
'core/model/message_data.dart'
;
import
'core/notice/notice_dialog_widget.dart'
;
import
'core/notice/notice_dialog_widget.dart'
;
...
@@ -23,28 +24,11 @@ class ClxFlutterMessage {
...
@@ -23,28 +24,11 @@ class ClxFlutterMessage {
MessageConfig
messageConfig
=
MessageConfig
();
MessageConfig
messageConfig
=
MessageConfig
();
abstract
class
BaseMessageConfig
with
NotificationManager
,
NoticeManager
{
abstract
class
BaseMessageConfig
with
NotificationManager
,
NoticeManager
,
MessageNet
{
//处理消息页面跳转
//处理消息页面跳转
void
onJumpToMessagePage
(
String
page
,
dynamic
arguments
);
void
onJumpToMessagePage
(
String
page
,
dynamic
arguments
);
//获取未处理消息
Future
<
List
<
MessageData
>>
getUnReadMessage
();
//获取未处理的公告
Future
<
List
<
MessageData
>>
getUnReadNotice
();
// 标记消息为已读
Future
<
bool
>
markReadAction
(
MessageData
?
message
);
// 删除消息
Future
<
bool
>
removeMessageAction
(
MessageData
?
message
);
//忽略消息
Future
<
bool
>
ignoreAction
(
MessageData
?
message
);
//标记消息已经展示
void
setMessageShowed
(
MessageData
?
message
);
//连接websocket 获取及时消息
//连接websocket 获取及时消息
Future
<
void
>
connectWebSocket
(
BuildContext
context
)
async
{
Future
<
void
>
connectWebSocket
(
BuildContext
context
)
async
{
String
userNo
=
messageConfig
.
userKey
;
String
userNo
=
messageConfig
.
userKey
;
...
...
lib/core/api/api.dart
0 → 100644
浏览文件 @
74cec6fc
// Dio 网络请求工具类
import
'dart:convert'
;
import
'package:clx_flutter_message/clx_flutter_message.dart'
;
// ignore: depend_on_referenced_packages
import
'package:dio/dio.dart'
;
import
'package:flutter/foundation.dart'
;
class
Api
{
static
final
dio
=
messageConfig
.
dio
;
// 构建网络请求同步请求
Future
<
dynamic
>
requestSync
({
required
String
requestUrl
,
required
Method
method
,
Map
<
String
,
dynamic
>?
queryParameters
,
Object
?
data
,
})
async
{
try
{
var
response
=
await
dio
?.
request
(
requestUrl
,
queryParameters:
queryParameters
,
data:
data
,
options:
_checkOptions
(
method
.
value
),
);
try
{
var
data
=
response
?.
data
;
if
(
data
is
Map
)
{
return
data
;
}
else
if
(
data
is
String
)
{
return
_jsonDecode
(
data
);
}
return
data
;
}
catch
(
e
)
{
debugPrint
(
"数据解析错误:
${e.toString()}
"
);
return
{
"code"
:
400
,
"message"
:
"数据解析错误"
};
}
}
on
DioException
catch
(
e
)
{
if
(
e
.
response
!=
null
)
{
debugPrint
(
"请求错误:
${e.response!.statusCode}
${e.response!.requestOptions.path}
"
);
}
else
{
// Something happened in setting up or sending the request that triggered an Error
debugPrint
(
"请求错误:
${e.error}
"
);
}
return
{
"code"
:
500
,
"message"
:
"服务器请求错误"
};
}
}
// Options
Options
_checkOptions
(
String
method
)
{
Options
options
=
Options
();
options
.
method
=
method
;
return
options
;
}
// jsonDecode
Map
<
String
,
dynamic
>
_jsonDecode
(
String
json
)
{
return
jsonDecode
(
json
);
}
}
enum
Method
{
get
,
post
,
put
,
patch
,
delete
,
}
extension
MethodExtension
on
Method
{
String
get
value
=>
[
'GET'
,
'POST'
,
'PUT'
,
'PATCH'
,
'DELETE'
][
index
];
}
lib/core/api/message_net.dart
0 → 100644
浏览文件 @
74cec6fc
import
'package:clx_flutter_message/core/api/api.dart'
;
import
'../../clx_flutter_message.dart'
;
mixin
MessageNet
{
final
api
=
Api
();
//获取未处理消息
Future
<
List
<
MessageData
>>
getUnReadMessage
()
async
{
var
result
=
await
_fetchMessage
(
2
);
if
(
result
[
'code'
]
==
0
)
{
var
data
=
result
[
'data'
]?[
'records'
];
if
(
data
!=
null
&&
data
is
List
)
{
return
Future
(()
=>
data
.
map
((
e
)
=>
MessageData
.
fromJson
(
e
)).
toList
());
}
}
return
Future
(()
=>
List
.
empty
());
}
//获取未处理的公告
Future
<
List
<
MessageData
>>
getUnReadNotice
()
async
{
var
result
=
await
_fetchMessage
(
1
);
if
(
result
[
'code'
]
==
0
)
{
var
data
=
result
[
'data'
]?[
'records'
];
if
(
data
!=
null
&&
data
is
List
)
{
return
Future
(()
=>
data
.
map
((
e
)
=>
MessageData
.
fromJson
(
e
)).
toList
());
}
}
return
Future
(()
=>
List
.
empty
());
}
// 标记消息为已读
Future
<
bool
>
markReadAction
(
MessageData
?
message
)
async
{
if
(
message
?.
status
==
10
)
return
Future
.
value
(
true
);
var
result
=
await
api
.
requestSync
(
method:
Method
.
put
,
requestUrl:
'/message-in-app/message/record/updateRecord'
,
queryParameters:
{
'id'
:
message
?.
id
,
'status'
:
10
,
});
return
result
[
'code'
]
==
0
;
}
// 删除消息
Future
<
bool
>
removeMessageAction
(
MessageData
?
message
)
async
{
var
result
=
await
api
.
requestSync
(
method:
Method
.
put
,
requestUrl:
'/message-in-app/message/record/deleteMessage'
,
queryParameters:
{
'id'
:
message
?.
id
,
});
return
result
[
'code'
]
==
0
;
}
//忽略消息
Future
<
bool
>
ignoreAction
(
MessageData
?
message
)
{
return
markReadAction
(
message
);
}
//标记消息已经展示
void
setMessageShowed
(
MessageData
?
message
)
{
if
(
message
==
null
)
{
return
;
}
api
.
requestSync
(
method:
Method
.
put
,
requestUrl:
'/message-in-app/message/record/updateRecordShow'
,
queryParameters:
{
'id'
:
message
.
id
,
'showStatus'
:
1
});
}
Future
<
dynamic
>
_fetchMessage
(
showTypes
)
async
{
var
result
=
await
api
.
requestSync
(
requestUrl:
'/message-in-app/message/record/pageShowMessage'
,
method:
Method
.
post
,
data:
{
'pageNum'
:
1
,
'pageSize'
:
100
,
'accessKey'
:
messageConfig
.
inAppAccessKey
,
'showTypes'
:
[
showTypes
]
},
);
return
result
;
}
}
lib/core/model/message_config.dart
浏览文件 @
74cec6fc
import
'package:clx_flutter_message/clx_flutter_message.dart'
;
import
'package:clx_flutter_message/clx_flutter_message.dart'
;
// ignore: depend_on_referenced_packages
import
'package:dio/dio.dart'
;
class
MessageConfig
{
class
MessageConfig
{
// websocket 连接地址
// websocket 连接地址
...
@@ -15,4 +17,6 @@ class MessageConfig {
...
@@ -15,4 +17,6 @@ class MessageConfig {
String
accessToken
=
""
;
String
accessToken
=
""
;
BaseMessageConfig
?
messageManagement
;
BaseMessageConfig
?
messageManagement
;
Dio
?
dio
;
}
}
pubspec.yaml
浏览文件 @
74cec6fc
...
@@ -18,11 +18,11 @@ dependencies:
...
@@ -18,11 +18,11 @@ dependencies:
cached_network_image
:
^3.3.0
cached_network_image
:
^3.3.0
fluttertoast
:
8.2.4
fluttertoast
:
8.2.4
get
:
^4.6.6
get
:
^4.6.6
dev_dependencies
:
dev_dependencies
:
flutter_test
:
flutter_test
:
sdk
:
flutter
sdk
:
flutter
flutter_lints
:
^2.0.0
flutter_lints
:
^2.0.0
dio
:
^5.7.0
# For information on the generic Dart part of this file, see the
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# following page: https://dart.dev/tools/pub/pubspec
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论