Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwplvx
Aurora
提交
e61349a4
Aurora
项目概览
lwplvx
/
Aurora
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Aurora
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e61349a4
编写于
10月 12, 2021
作者:
lwplvx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use ajax post json in plugin
上级
9eda52d0
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
103 addition
and
89 deletion
+103
-89
Aurora.Microservices/Aurora.Core/Aurora.Core.Api/Controllers/TranslateController.cs
...a.Core/Aurora.Core.Api/Controllers/TranslateController.cs
+5
-5
Aurora.Microservices/Aurora.Core/Aurora.Core.IService/Dto/RocketDto.cs
...ervices/Aurora.Core/Aurora.Core.IService/Dto/RocketDto.cs
+2
-2
Aurora.Microservices/Aurora.Core/Aurora.Core.IService/IRocketService.cs
...rvices/Aurora.Core/Aurora.Core.IService/IRocketService.cs
+2
-2
Aurora.Microservices/Aurora.Core/Aurora.Core.Service/AutomapperProfiles/RocketWordProfile.cs
...rora.Core.Service/AutomapperProfiles/RocketWordProfile.cs
+15
-0
Aurora.Microservices/Aurora.Core/Aurora.Core.Service/RocketService.cs
...services/Aurora.Core/Aurora.Core.Service/RocketService.cs
+9
-9
Samples/chrome-plugins/translation-rocket/js/background.js
Samples/chrome-plugins/translation-rocket/js/background.js
+39
-42
Samples/translation-rocket-app/utils/signalR.js
Samples/translation-rocket-app/utils/signalR.js
+31
-29
未找到文件。
Aurora.Microservices/Aurora.Core/Aurora.Core.Api/Controllers/TranslateController.cs
浏览文件 @
e61349a4
...
...
@@ -44,12 +44,12 @@ namespace Aurora.Core.Api.Controllers
/// biu word
/// </summary>
/// <returns></returns>
public
async
Task
<
ResponseModel
<
RocketDto
>>
Rocket
(
Rocket
Dto
model
)
public
async
Task
<
ActionResult
>
Rocket
(
RocketWord
Dto
model
)
{
var
res
=
await
_rocketService
.
Rocket
(
model
);
//
var res = await _rocketService.Rocket(model);
await
_hubContext
.
Clients
.
All
.
SendAsync
(
"rocketWord"
,
model
);
return
res
;
return
Ok
(
"Echo:"
+
model
.
Text
);
//
res;
}
[
HttpGet
]
...
...
@@ -57,10 +57,10 @@ namespace Aurora.Core.Api.Controllers
/// biu word
/// </summary>
/// <returns></returns>
public
async
Task
<
ResponseModel
<
RocketDto
>>
Test
()
public
async
Task
<
ResponseModel
<
Rocket
Word
Dto
>>
Test
()
{
await
_hubContext
.
Clients
.
All
.
SendAsync
(
"rocketWord"
,
"model"
);
return
new
ResponseModel
<
Rocket
Dto
>(
new
Rocket
Dto
());
return
new
ResponseModel
<
Rocket
WordDto
>(
new
RocketWord
Dto
());
}
}
}
Aurora.Microservices/Aurora.Core/Aurora.Core.IService/Dto/RocketDto.cs
浏览文件 @
e61349a4
...
...
@@ -2,9 +2,9 @@ using System;
namespace
Aurora.Core.IService.Dto
{
public
class
RocketDto
:
BaseDto
public
class
Rocket
Word
Dto
:
BaseDto
{
public
string
Name
{
get
;
set
;
}
public
string
Text
{
get
;
set
;
}
public
string
Remark
{
get
;
set
;
}
public
int
CatetoryId
{
get
;
set
;
}
}
...
...
Aurora.Microservices/Aurora.Core/Aurora.Core.IService/IRocketService.cs
浏览文件 @
e61349a4
...
...
@@ -8,7 +8,7 @@ namespace Aurora.Core.IService
{
public
interface
IRocketService
{
Task
<
ResponseModel
<
List
<
RocketDto
>>>
GetList
();
Task
<
ResponseModel
<
Rocket
Dto
>>
Rocket
(
Rocket
Dto
model
);
Task
<
ResponseModel
<
List
<
Rocket
Word
Dto
>>>
GetList
();
Task
<
ResponseModel
<
Rocket
WordDto
>>
Rocket
(
RocketWord
Dto
model
);
}
}
Aurora.Microservices/Aurora.Core/Aurora.Core.Service/AutomapperProfiles/RocketWordProfile.cs
0 → 100644
浏览文件 @
e61349a4
using
System
;
using
Aurora.Core.Domain.Entities
;
using
Aurora.Core.IService.Dto
;
using
AutoMapper
;
namespace
Aurora.Core.Service.AutomapperProfiles
{
public
class
RocketWordProfile
:
Profile
{
public
RocketWordProfile
()
{
CreateMap
<
RocketWord
,
RocketWordDto
>().
ReverseMap
();
}
}
}
Aurora.Microservices/Aurora.Core/Aurora.Core.Service/RocketService.cs
浏览文件 @
e61349a4
...
...
@@ -28,27 +28,27 @@ namespace Aurora.Core.Service
_readonlyDbContext
=
readonlyDbContext
;
}
public
async
Task
<
ResponseModel
<
List
<
RocketDto
>>>
GetList
()
public
async
Task
<
ResponseModel
<
List
<
Rocket
Word
Dto
>>>
GetList
()
{
var
list
=
await
_readonlyDbContext
.
Categories
.
ToListAsync
();
var
dtoList
=
_mapper
.
Map
<
List
<
RocketDto
>>(
list
);
var
dtoList
=
_mapper
.
Map
<
List
<
Rocket
Word
Dto
>>(
list
);
var
res
=
new
ResponseModel
<
List
<
RocketDto
>>(
dtoList
);
var
res
=
new
ResponseModel
<
List
<
Rocket
Word
Dto
>>(
dtoList
);
return
res
;
}
public
async
Task
<
ResponseModel
<
RocketDto
>>
GetById
(
int
id
)
public
async
Task
<
ResponseModel
<
Rocket
Word
Dto
>>
GetById
(
int
id
)
{
var
entity
=
await
_readonlyDbContext
.
Categories
.
FirstOrDefaultAsync
(
m
=>
m
.
ID
==
id
);
var
dto
=
_mapper
.
Map
<
RocketDto
>(
entity
);
var
dto
=
_mapper
.
Map
<
Rocket
Word
Dto
>(
entity
);
var
res
=
new
ResponseModel
<
RocketDto
>(
dto
);
var
res
=
new
ResponseModel
<
Rocket
Word
Dto
>(
dto
);
return
res
;
}
public
async
Task
<
ResponseModel
<
Rocket
Dto
>>
Rocket
(
Rocket
Dto
model
)
public
async
Task
<
ResponseModel
<
Rocket
WordDto
>>
Rocket
(
RocketWord
Dto
model
)
{
#
region
保存到数据库
...
...
@@ -67,9 +67,9 @@ namespace Aurora.Core.Service
#
endregion
var
dto
=
_mapper
.
Map
<
RocketDto
>(
entity
);
var
dto
=
_mapper
.
Map
<
Rocket
Word
Dto
>(
entity
);
var
res
=
new
ResponseModel
<
RocketDto
>(
dto
);
var
res
=
new
ResponseModel
<
Rocket
Word
Dto
>(
dto
);
return
res
;
}
...
...
Samples/chrome-plugins/translation-rocket/js/background.js
浏览文件 @
e61349a4
...
...
@@ -30,27 +30,31 @@ function openUrlCurrentTab(url) {
function
handleStateChange
()
{}
chrome
.
contextMenus
.
create
({
title
:
'
发射选择的单词:%s
'
,
// %s表示选中的文字
contexts
:
[
'
selection
'
],
// 只有当选中文字时才会出现此右键菜单
onclick
:
function
(
params
)
{
chrome
.
browserAction
.
setBadgeText
({
text
:
'
new
'
})
chrome
.
browserAction
.
setBadgeBackgroundColor
({
color
:
[
255
,
0
,
0
,
255
]
})
let
ajax
=
httpHelp
let
url
=
'
http://localhost:8000/Translate/Test
'
ajax
.
get
(
url
,
{},
(
res
)
=>
{
console
.
log
(
res
)
},
(
e
)
=>
{
console
.
log
(
e
)
},
)
},
})
if
(
chrome
.
contextMenus
)
{
chrome
.
contextMenus
.
create
({
title
:
'
发射选择的单词:%s
'
,
// %s表示选中的文字
contexts
:
[
'
selection
'
],
// 只有当选中文字时才会出现此右键菜单
onclick
:
function
(
params
)
{
chrome
.
browserAction
.
setBadgeText
({
text
:
'
new
'
})
chrome
.
browserAction
.
setBadgeBackgroundColor
({
color
:
[
255
,
0
,
0
,
255
]
})
let
ajax
=
httpHelp
let
url
=
'
http://localhost:8000/Translate/Rocket
'
ajax
.
post
(
url
,
{},
// { text: encodeURI(params.selectionText) },
{
text
:
params
.
selectionText
},
(
res
)
=>
{
console
.
log
(
res
)
},
(
e
)
=>
{
console
.
log
(
e
)
},
)
},
})
}
// 常用工具函数
var
httpHelp
=
{
...
...
@@ -61,7 +65,7 @@ var httpHelp = {
* @param failFunc function 请求失败的回调
* @param isJson boolean true: 解析json false:文本请求 默认值true
*/
get
:
function
(
url
,
headers
,
successFunc
,
failFunc
,
isJson
)
{
get
:
function
(
url
,
headers
,
successFunc
,
failFunc
)
{
// 拼接url加query
// if (query) {
// var params = tools.formatParams(query)
...
...
@@ -95,14 +99,7 @@ var httpHelp = {
if
(
xhr
.
readyState
===
4
)
{
if
(
xhr
.
status
===
200
)
{
// 用户传了回调才执行
// isJson默认值为true,要解析json
if
(
isJson
===
undefined
)
{
isJson
=
true
}
var
res
=
isJson
?
JSON
.
parse
(
xhr
.
responseText
==
''
?
'
{}
'
:
xhr
.
responseText
)
:
xhr
.
responseText
successFunc
&&
successFunc
(
res
)
successFunc
&&
successFunc
(
JSON
.
parse
(
xhr
.
responseText
))
}
else
{
// 请求失败
failFunc
&&
failFunc
()
...
...
@@ -118,11 +115,11 @@ var httpHelp = {
* @param failFunc function 请求失败的回调
* @param isJson boolean true: 解析json false:文本请求 默认值true
*/
post
:
function
(
url
,
headers
,
data
,
successFunc
,
failFunc
,
isJson
)
{
var
formData
=
new
FormData
()
for
(
var
i
in
data
)
{
formData
.
append
(
i
,
data
[
i
])
}
post
:
function
(
url
,
headers
,
data
,
successFunc
,
failFunc
)
{
//
var formData = new FormData()
//
for (var i in data) {
//
formData.append(i, data[i])
//
}
//得到xhr对象
var
xhr
=
null
if
(
XMLHttpRequest
)
{
...
...
@@ -140,17 +137,17 @@ var httpHelp = {
xhr
.
setRequestHeader
(
key
,
headers
[
key
])
}
}
xhr
.
send
(
formData
)
// set `Content-Type` header
xhr
.
setRequestHeader
(
'
Content-Type
'
,
'
application/json
'
)
// send rquest with JSON payload
xhr
.
send
(
JSON
.
stringify
(
data
))
// xhr.send(formData)
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
===
4
)
{
if
(
xhr
.
status
===
200
)
{
// 判断isJson是否传进来了
isJson
=
isJson
===
undefined
?
true
:
isJson
successFunc
&&
successFunc
(
isJson
?
JSON
.
parse
(
xhr
.
responseText
)
:
xhr
.
responseText
,
)
successFunc
&&
successFunc
(
JSON
.
parse
(
xhr
.
responseText
))
}
else
{
// 请求失败
failFunc
&&
failFunc
()
...
...
Samples/translation-rocket-app/utils/signalR.js
浏览文件 @
e61349a4
//引入安装的signalr包
import
*
as
signalR
from
'
../signalr
'
// import baseUrl from 'http://localhost:8000'
let
baseUrl
=
'
http://localhost:8000
'
;
let
baseUrl
=
'
http://localhost:8000
'
;
var
userId
=
null
;
const
location
=
window
.
location
;
if
(
location
.
search
)
{
const
tabStatus
=
location
.
search
.
split
(
"
&
"
)[
0
]
.
split
(
"
=
"
)[
1
]
.
split
(
"
_
"
);
userId
=
location
.
search
.
split
(
"
&
"
)[
1
].
split
(
"
=
"
)[
1
];
const
tabStatus
=
location
.
search
.
split
(
"
&
"
)[
0
]
.
split
(
"
=
"
)[
1
]
.
split
(
"
_
"
);
userId
=
location
.
search
.
split
(
"
&
"
)[
1
].
split
(
"
=
"
)[
1
];
}
const
connection
=
new
signalR
.
HubConnectionBuilder
()
//服务器地址
.
withUrl
(
`
${
baseUrl
}
/hub/TranslateRocketHub?userId=
${
userId
}
`
,
{})
.
build
()
//服务器地址
.
withUrl
(
`
${
baseUrl
}
/hub/TranslateRocketHub?userId=
${
userId
}
`
,
{})
.
build
()
// 自动重连
async
function
start
()
{
try
{
await
connection
.
start
()
console
.
log
(
'
connected
'
)
}
catch
(
err
)
{
console
.
log
(
err
)
setTimeout
(()
=>
start
(),
5000
)
}
try
{
await
connection
.
start
()
console
.
log
(
'
connected
'
)
}
catch
(
err
)
{
console
.
log
(
err
)
setTimeout
(()
=>
start
(),
5000
)
}
}
connection
.
onclose
(
async
()
=>
{
await
start
()
await
start
()
})
connection
.
on
(
"
rocketWord
"
,
function
(
param
)
{
console
.
log
(
param
)
});
//接收服务器端消息ReceiveMessage的处理程序
connection
.
on
(
"
ReceiveMessage
"
,
function
(
param
)
{
console
.
log
(
param
)
// if (param.user)
// $('#content').append(param.user + ":");
// if (param.message)
// $('#content').append(param.message + ":");
connection
.
on
(
"
ReceiveMessage
"
,
function
(
param
)
{
console
.
log
(
param
)
// if (param.user)
// $('#content').append(param.user + ":");
// if (param.message)
// $('#content').append(param.message + ":");
});
//发送消息至服务器端SendMessage方法
...
...
@@ -48,8 +50,8 @@ connection.on("ReceiveMessage", function (param) {
//将创建的signal赋值给Vue实例
export
default
{
// install方法的第一个参数是 Vue 构造器,第二个参数是一个可选的选项对象。
install
:
function
(
Vue
)
{
Vue
.
prototype
.
signalr
=
connection
}
}
\ No newline at end of file
// install方法的第一个参数是 Vue 构造器,第二个参数是一个可选的选项对象。
install
:
function
(
Vue
)
{
Vue
.
prototype
.
signalr
=
connection
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录