Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rudern
物联大师
提交
5382ea64
物
物联大师
项目概览
rudern
/
物联大师
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
物
物联大师
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5382ea64
编写于
9月 03, 2020
作者:
J
Jason
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
将通道改好了
上级
bf868b0e
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
128 addition
and
50 deletion
+128
-50
db/xorm.go
db/xorm.go
+2
-0
dtu/channel.go
dtu/channel.go
+14
-12
model/channel.go
model/channel.go
+2
-2
portal/src/app/api.service.ts
portal/src/app/api.service.ts
+10
-9
portal/src/app/main/channel-edit/channel-edit.component.html
portal/src/app/main/channel-edit/channel-edit.component.html
+4
-4
portal/src/app/main/channel/channel.component.html
portal/src/app/main/channel/channel.component.html
+19
-8
portal/src/app/main/channel/channel.component.ts
portal/src/app/main/channel/channel.component.ts
+70
-7
web/api/channel.go
web/api/channel.go
+4
-4
web/api/link.go
web/api/link.go
+1
-1
web/api/router.go
web/api/router.go
+2
-3
未找到文件。
db/xorm.go
浏览文件 @
5382ea64
...
...
@@ -2,6 +2,8 @@ package db
import
(
_
"github.com/go-sql-driver/mysql"
//_ "github.com/lib/pq" //PostgreSQL
//_ "github.com/mattn/go-sqlite3" //需要GCC并且启用CGO
"github.com/zgwit/dtu-admin/conf"
"github.com/zgwit/dtu-admin/model"
"log"
...
...
dtu/channel.go
浏览文件 @
5382ea64
...
...
@@ -11,7 +11,6 @@ import (
"time"
)
type
Channel
struct
{
model
.
Channel
...
...
@@ -33,15 +32,18 @@ func NewChannel(channel *model.Channel) *Channel {
}
func
(
c
*
Channel
)
Open
()
error
{
if
c
.
IsServer
{
switch
c
.
Role
{
case
"server"
:
return
c
.
Listen
()
}
else
{
case
"client"
:
return
c
.
Dial
()
default
:
return
errors
.
New
(
"未知角色"
)
}
}
func
(
c
*
Channel
)
Dial
()
error
{
conn
,
err
:=
net
.
Dial
(
c
.
Type
,
c
.
Addr
)
conn
,
err
:=
net
.
Dial
(
c
.
Net
,
c
.
Addr
)
if
err
!=
nil
{
return
err
}
...
...
@@ -55,16 +57,16 @@ func (c *Channel) Dial() error {
func
(
c
*
Channel
)
Listen
()
error
{
var
err
error
switch
c
.
Type
{
switch
c
.
Net
{
case
"tcp"
,
"tcp4"
,
"tcp6"
,
"unix"
:
c
.
listener
,
err
=
net
.
Listen
(
c
.
Type
,
c
.
Addr
)
c
.
listener
,
err
=
net
.
Listen
(
c
.
Net
,
c
.
Addr
)
if
err
!=
nil
{
return
err
}
go
c
.
accept
()
case
"udp"
,
"udp4"
,
"udp6"
,
"unixgram"
:
c
.
packetConn
,
err
=
net
.
ListenPacket
(
c
.
Type
,
c
.
Addr
)
c
.
packetConn
,
err
=
net
.
ListenPacket
(
c
.
Net
,
c
.
Addr
)
if
err
!=
nil
{
return
err
...
...
model/channel.go
浏览文件 @
5382ea64
...
...
@@ -8,9 +8,9 @@ type Channel struct {
//Tags string `json:"tags" xorm:"varchar(256)"`
Disabled
bool
`json:"disabled" xorm:"default 0"`
//此处 禁用 直接放到顶级,Update无效
Type
string
`json:"type" xorm:"varchar(16) notnull"`
Role
string
`json:"role" xorm:"varchar(16) notnull"`
Net
string
`json:"net" xorm:"varchar(16) notnull"`
Addr
string
`json:"addr" xorm:"varchar(128) notnull"`
IsServer
bool
`json:"is_server" xorm:"default 0"`
Timeout
int
`json:"timeout"`
//TODO 改为秒
RegisterEnable
bool
`json:"register_enable" xorm:"default 0"`
...
...
portal/src/app/api.service.ts
浏览文件 @
5382ea64
...
...
@@ -30,15 +30,16 @@ export class ApiService {
}
return
of
({
error
:
err
.
message
});
}),
// 统一错误处理
map
((
ret
:
any
)
=>
{
if
(
ret
&&
ret
.
error
)
{
// 有错误统一显示并不是好的做法
this
.
message
.
create
(
'
error
'
,
ret
.
error
);
throw
new
Error
(
ret
.
error
);
}
return
ret
;
}));
// 统一错误处理,阻断 complete
// map((ret: any) => {
// if (ret && ret.error) {
// // 有错误统一显示并不是好的做法
// this.message.create('error', ret.error);
// throw new Error(ret.error);
// }
// return ret;
// })
);
}
get
(
uri
:
string
,
params
?:
{
[
k
:
string
]:
any
}):
Observable
<
any
>
{
...
...
portal/src/app/main/channel-edit/channel-edit.component.html
浏览文件 @
5382ea64
...
...
@@ -13,11 +13,11 @@
</div>
<div
nz-col
nzSpan=
"20"
>
<nz-input-group
style=
"display: flex"
>
<nz-select
[(ngModel)]=
"channel.
is_server
"
>
<nz-option
nzLabel=
"服务端"
[nzValue]=
"true
"
></nz-option>
<nz-option
nzLabel=
"客户端"
[nzValue]=
"false
"
></nz-option>
<nz-select
[(ngModel)]=
"channel.
role
"
>
<nz-option
nzLabel=
"服务端"
nzValue=
"server
"
></nz-option>
<nz-option
nzLabel=
"客户端"
nzValue=
"client
"
></nz-option>
</nz-select>
<nz-select
[(ngModel)]=
"channel.
type
"
style=
"width:80px;"
>
<nz-select
[(ngModel)]=
"channel.
net
"
style=
"width:80px;"
>
<nz-option
nzLabel=
"TCP"
nzValue=
"tcp"
></nz-option>
<nz-option
nzLabel=
"UDP"
nzValue=
"udp"
></nz-option>
</nz-select>
...
...
portal/src/app/main/channel/channel.component.html
浏览文件 @
5382ea64
<nz-space>
<nz-space-item>
<button
nz-button
(click)=
"load()"
>
<button
nz-button
(click)=
"load()"
[nzLoading]=
"loading"
>
<i
nz-icon
nzType=
"reload"
></i>
刷新
</button>
...
...
@@ -11,24 +11,35 @@
创建
</button>
</nz-space-item>
<nz-space-item>
TODO: 按名称搜索,标签筛选,状态筛选等,以及排序,后台翻页
</nz-space-item>
<nz-space-item>
<nz-input-group
nzSearch
nzCompact
[nzAddOnAfter]=
"suffixButton"
>
<input
type=
"text"
nz-input
[(ngModel)]=
"keyword"
placeholder=
"名称、地址"
/>
</nz-input-group>
<ng-template
#suffixButton
>
<button
nz-button
nzSearch
(click)=
"search()"
>
搜索
</button>
</ng-template>
</nz-space-item>
</nz-space>
<nz-table
#basicTable
[nzData]=
"channels"
>
<nz-table
#tbl
[nzData]=
"channels"
nzTableLayout=
"fixed"
[nzFrontPagination]=
"false"
[nzPageSize]=
"pageSize"
[nzPageIndex]=
"pageIndex"
[nzTotal]=
"total"
[nzLoading]=
"loading"
(nzQueryParams)=
"onTableQuery($event)"
>
<thead>
<tr>
<th>
ID
</th>
<th>
名称
</th>
<th>
网络
</th>
<th>
状态
</th>
<th>
创建时间
</th>
<th
nzColumnKey=
"role"
nzShowFilter
[nzFilterFn]=
"true"
[nzFilters]=
"roleFilters"
>
角色
</th>
<th
nzColumnKey=
"net"
nzShowFilter
[nzFilterFn]=
"true"
[nzFilters]=
"netFilters"
>
网络
</th>
<th
nzColumnKey=
"status"
nzShowFilter
[nzFilterFn]=
"true"
[nzFilters]=
"statusFilters"
>
状态
</th>
<th
nzColumnKey=
"created"
nzColumnKey=
"created"
[nzSortFn]=
"true"
>
创建时间
</th>
<th></th>
</tr>
</thead>
<tbody>
<tr
*ngFor=
"let data of
basicTable
.data"
>
<tr
*ngFor=
"let data of
tbl
.data"
>
<td>
{{ data.id }}
</td>
<td>
{{ data.name }}
</td>
<td>
{{ data.is_server ? '服务端':'客户端' }} {{data.type}} {{data.addr}}
</td>
<td>
{{ data.role }}
</td>
<td>
{{data.net}} {{data.addr}}
</td>
<td>
{{data.disabled ? '禁用' : ''}}
<a>
启动/停止
</a>
...
...
portal/src/app/main/channel/channel.component.ts
浏览文件 @
5382ea64
import
{
Component
,
OnInit
,
ViewContainerRef
}
from
'
@angular/core
'
;
import
{
ApiService
}
from
'
../../api.service
'
;
import
{
ChannelEditComponent
}
from
'
../channel-edit/channel-edit.component
'
;
import
{
NzDrawerService
,
NzModalService
}
from
'
ng-zorro-antd
'
;
import
{
NzDrawerService
,
NzModalService
,
NzTableQueryParams
}
from
'
ng-zorro-antd
'
;
import
{
ChannelDetailComponent
}
from
"
../channel-detail/channel-detail.component
"
;
@
Component
({
...
...
@@ -12,22 +12,70 @@ import {ChannelDetailComponent} from "../channel-detail/channel-detail.component
export
class
ChannelComponent
implements
OnInit
{
channels
:
[];
total
=
0
;
pageIndex
=
1
;
pageSize
=
10
;
sortField
=
null
;
sortOrder
=
null
;
filters
=
[];
keyword
=
''
;
loading
=
false
;
constructor
(
private
as
:
ApiService
,
private
modal
:
NzModalService
,
private
viewContainerRef
:
ViewContainerRef
,
private
drawer
:
NzDrawerService
)
{
roleFilters
=
[{
text
:
'
服务器
'
,
value
:
true
},
{
text
:
'
客户端
'
,
value
:
false
}];
netFilters
=
[{
text
:
'
TCP
'
,
value
:
'
tcp
'
},
{
text
:
'
UDP
'
,
value
:
'
udp
'
}];
statusFilters
=
[{
text
:
'
启动
'
,
value
:
1
}];
constructor
(
private
as
:
ApiService
,
private
modal
:
NzModalService
,
private
viewContainerRef
:
ViewContainerRef
,
private
drawer
:
NzDrawerService
)
{
}
ngOnInit
():
void
{
this
.
loadFilters
();
}
reload
():
void
{
this
.
pageIndex
=
1
;
this
.
keyword
=
''
;
this
.
load
();
}
load
():
void
{
this
.
as
.
get
(
'
channels
'
).
subscribe
(
res
=>
{
if
(
res
.
ok
)
{
this
.
loading
=
true
;
this
.
as
.
post
(
'
channels
'
,
{
offset
:
(
this
.
pageIndex
-
1
)
*
this
.
pageSize
,
length
:
this
.
pageSize
,
sortKey
:
this
.
sortField
,
sortOrder
:
this
.
sortOrder
,
filters
:
this
.
filters
,
keyword
:
this
.
keyword
,
}).
subscribe
(
res
=>
{
console
.
log
(
'
res
'
,
res
);
this
.
channels
=
res
.
data
;
}
this
.
total
=
res
.
total
;
},
error
=>
{
console
.
log
(
'
error
'
,
error
);
},
()
=>
{
this
.
loading
=
false
;
});
}
loadFilters
():
void
{
// this.as.get('distinct/copy/host').subscribe(res => {
// console.log('res', res);
// this.hosts = res.data.map(h => {
// return {
// text: h.host,
// value: h.host
// };
// });
// }, error => {
// console.log('error', error);
// });
}
edit
(
c
?):
void
{
this
.
drawer
.
create
({
nzTitle
:
c
?
'
编辑
'
:
'
创建
'
,
...
...
@@ -35,7 +83,7 @@ export class ChannelComponent implements OnInit {
nzWidth
:
500
,
nzContent
:
ChannelEditComponent
,
nzContentParams
:
{
channel
:
c
||
{}
channel
:
c
||
{
net
:
'
tcp
'
,
addr
:
'
:1843
'
,
is_server
:
true
}
}
});
}
...
...
@@ -51,4 +99,19 @@ export class ChannelComponent implements OnInit {
});
}
onTableQuery
(
params
:
NzTableQueryParams
):
void
{
const
{
pageSize
,
pageIndex
,
sort
,
filter
}
=
params
;
this
.
pageSize
=
pageSize
;
this
.
pageIndex
=
pageIndex
;
const
currentSort
=
sort
.
find
(
item
=>
item
.
value
!==
null
);
this
.
sortField
=
(
currentSort
&&
currentSort
.
key
)
||
null
;
this
.
sortOrder
=
(
currentSort
&&
currentSort
.
value
)
||
null
;
this
.
filters
=
filter
;
this
.
load
();
}
search
():
void
{
this
.
pageIndex
=
1
;
this
.
load
();
}
}
web/api/channel.go
浏览文件 @
5382ea64
...
...
@@ -11,7 +11,7 @@ import (
)
func
channels
(
ctx
*
gin
.
Context
)
{
var
cs
[]
model
.
Channel
cs
:=
make
([]
model
.
Channel
,
0
)
var
body
paramSearch
err
:=
ctx
.
ShouldBind
(
&
body
)
...
...
@@ -20,7 +20,7 @@ func channels(ctx *gin.Context) {
return
}
//op := db.Engine.Where("type=?", body.
Type
)
//op := db.Engine.Where("type=?", body.
Net
)
op
:=
db
.
Engine
.
NewSession
()
for
_
,
filter
:=
range
body
.
Filters
{
if
len
(
filter
.
Value
)
>
0
{
...
...
@@ -33,7 +33,7 @@ func channels(ctx *gin.Context) {
}
if
body
.
Keyword
!=
""
{
kw
:=
"%"
+
body
.
Keyword
+
"%"
op
.
And
(
"name like ? or
type like ? or addr like ?"
,
kw
,
kw
,
kw
)
op
.
And
(
"name like ? or
addr like ?"
,
kw
,
kw
)
}
op
.
Limit
(
body
.
Length
,
body
.
Offset
)
...
...
@@ -134,7 +134,7 @@ func channelModify(ctx *gin.Context) {
//log.Println("update", channel)
_
,
err
:=
db
.
Engine
.
ID
(
pid
.
Id
)
.
Cols
(
"name"
,
"disabled"
,
"type"
,
"addr"
,
"
is_server
"
,
"timeout"
,
"type"
,
"addr"
,
"
role
"
,
"timeout"
,
"register_enable"
,
"register_regex"
,
"heart_beat_enable"
,
"heart_beat_interval"
,
"heart_beat_content"
,
"heart_beat_is_hex"
,
"plugin_id"
)
.
Update
(
&
channel
)
...
...
web/api/link.go
浏览文件 @
5382ea64
...
...
@@ -17,7 +17,7 @@ func links(ctx *gin.Context) {
return
}
//op := db.Engine.Where("type=?", body.
Type
)
//op := db.Engine.Where("type=?", body.
Net
)
op
:=
db
.
Engine
.
NewSession
()
for
_
,
filter
:=
range
body
.
Filters
{
if
len
(
filter
.
Value
)
>
0
{
...
...
web/api/router.go
浏览文件 @
5382ea64
...
...
@@ -55,8 +55,7 @@ func RegisterRoutes(app *gin.RouterGroup) {
app
.
POST
(
"/password"
,
authPassword
)
//TODO 转移至子目录,并使用中间件,检查session及权限
app
.
GET
(
"/channels"
,
channels
)
//app.POST("/channels")
app
.
POST
(
"/channels"
,
channels
)
app
.
POST
(
"/channel"
,
channelCreate
)
app
.
DELETE
(
"/channel/:id"
,
channelDelete
)
app
.
PUT
(
"/channel/:id"
,
channelModify
)
...
...
@@ -70,7 +69,7 @@ func RegisterRoutes(app *gin.RouterGroup) {
app
.
GET
(
"/channel/:id/link/:id2/statistic"
)
app
.
GET
(
"/channel/:id/link/:id2/pipe"
)
//转Websocket透传
app
.
GE
T
(
"/links"
,
links
)
app
.
POS
T
(
"/links"
,
links
)
app
.
DELETE
(
"/link/:id"
,
linkDelete
)
app
.
PUT
(
"/link/:id"
,
linkModify
)
app
.
GET
(
"/link/:id"
,
linkGet
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录