Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rudern
物联大师
提交
28d38829
物
物联大师
项目概览
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,体验更适合开发者的 AI 搜索 >>
提交
28d38829
编写于
9月 01, 2020
作者:
J
Jason
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改了好多
上级
d5d0d6c7
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
182 addition
and
147 deletion
+182
-147
dtu/channel.go
dtu/channel.go
+5
-5
dtu/misc.go
dtu/misc.go
+2
-2
portal/src/app/main/channel-edit/channel-edit.component.html
portal/src/app/main/channel-edit/channel-edit.component.html
+93
-53
portal/src/app/main/channel-edit/channel-edit.component.scss
portal/src/app/main/channel-edit/channel-edit.component.scss
+4
-0
portal/src/app/main/channel-edit/channel-edit.component.ts
portal/src/app/main/channel-edit/channel-edit.component.ts
+10
-35
portal/src/app/main/channel/channel.component.html
portal/src/app/main/channel/channel.component.html
+12
-11
portal/src/app/main/channel/channel.component.ts
portal/src/app/main/channel/channel.component.ts
+1
-1
portal/src/app/main/main.module.ts
portal/src/app/main/main.module.ts
+6
-2
types/channel.go
types/channel.go
+16
-23
web/api/channel.go
web/api/channel.go
+30
-12
web/api/router.go
web/api/router.go
+3
-3
未找到文件。
dtu/channel.go
浏览文件 @
28d38829
...
...
@@ -32,7 +32,7 @@ func NewChannel(channel *types.Channel) *Channel {
}
func
(
c
*
Channel
)
Open
()
error
{
if
c
.
IsServer
{
if
c
.
Net
.
IsServer
{
return
c
.
Listen
()
}
else
{
return
c
.
Dial
()
...
...
@@ -40,7 +40,7 @@ func (c *Channel) Open() error {
}
func
(
c
*
Channel
)
Dial
()
error
{
conn
,
err
:=
net
.
Dial
(
c
.
Net
,
c
.
Addr
)
conn
,
err
:=
net
.
Dial
(
c
.
Net
.
Type
,
c
.
Net
.
Addr
)
if
err
!=
nil
{
return
err
}
...
...
@@ -54,16 +54,16 @@ func (c *Channel) Dial() error {
func
(
c
*
Channel
)
Listen
()
error
{
var
err
error
switch
c
.
Net
{
switch
c
.
Net
.
Type
{
case
"tcp"
,
"tcp4"
,
"tcp6"
,
"unix"
:
c
.
listener
,
err
=
net
.
Listen
(
c
.
Net
,
c
.
Addr
)
c
.
listener
,
err
=
net
.
Listen
(
c
.
Net
.
Type
,
c
.
Net
.
Addr
)
if
err
!=
nil
{
return
err
}
go
c
.
accept
()
case
"udp"
,
"udp4"
,
"udp6"
,
"unixgram"
:
c
.
packetConn
,
err
=
net
.
ListenPacket
(
c
.
Net
,
c
.
Addr
)
c
.
packetConn
,
err
=
net
.
ListenPacket
(
c
.
Net
.
Type
,
c
.
Net
.
Addr
)
if
err
!=
nil
{
return
err
...
...
dtu/misc.go
浏览文件 @
28d38829
...
...
@@ -55,7 +55,7 @@ func CreateChannel(c *types.Channel) (*Channel, error) {
return
startChannel
(
c
)
}
func
GetChannel
(
id
int
64
)
(
*
Channel
,
error
)
{
func
GetChannel
(
id
int
)
(
*
Channel
,
error
)
{
v
,
ok
:=
channels
.
Load
(
id
)
if
!
ok
{
return
nil
,
errors
.
New
(
"通道不存在"
)
...
...
@@ -63,7 +63,7 @@ func GetChannel(id int64) (*Channel, error) {
return
v
.
(
*
Channel
),
nil
}
func
DeleteChannel
(
id
int
64
)
error
{
func
DeleteChannel
(
id
int
)
error
{
v
,
ok
:=
channels
.
Load
(
id
)
if
!
ok
{
return
errors
.
New
(
"通道不存在"
)
...
...
portal/src/app/main/channel-edit/channel-edit.component.html
浏览文件 @
28d38829
<form
nz-form
nzLayout=
"horizontal"
[formGroup]=
"validateForm"
(ngSubmit)=
"submit()"
>
<nz-form-item>
<nz-form-label>
名称
</nz-form-label>
<nz-form-control
nzErrorTip=
"请输入名称"
>
<input
nz-input
formControlName=
"name"
placeholder=
"名称"
/>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>
序列号
</nz-form-label>
<nz-form-control
nzErrorTip=
"请输入序列号"
>
<input
nz-input
formControlName=
"serial"
placeholder=
"序列号"
/>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>
网络类型
</nz-form-label>
<nz-form-control
nzErrorTip=
"请输入类型"
>
<input
nz-input
formControlName=
"net"
placeholder=
"下拉"
/>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>
地址
</nz-form-label>
<nz-form-control
nzErrorTip=
"请输入地址"
>
<input
nz-input
formControlName=
"addr"
placeholder=
":1843"
/>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>
服务端
</nz-form-label>
<nz-form-control
nzErrorTip=
"请勾选"
>
<nz-switch
formControlName=
"is_server"
></nz-switch>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>
心跳
</nz-form-label>
<nz-form-control
nzErrorTip=
"请勾选"
>
<label
nz-checkbox
formControlName=
"heart_beat.enable"
>
<span>
启用
</span>
</label>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>
注册包
</nz-form-label>
<nz-form-control
nzErrorTip=
"请勾选"
>
<label
nz-checkbox
formControlName=
"register.enable"
>
<span>
启用
</span>
</label>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-control>
<button
nz-button
nzType=
"primary"
>
保存
</button>
</nz-form-control>
</nz-form-item>
</form>
<div
class=
"item"
nz-row
nzAlign=
"middle"
>
<div
nz-col
nzSpan=
"4"
>
名称
</div>
<div
nz-col
nzSpan=
"20"
>
<input
nz-input
[(ngModel)]=
"channel.name"
placeholder=
"名称"
/>
</div>
</div>
<div
class=
"item"
nz-row
nzAlign=
"middle"
>
<div
nz-col
nzSpan=
"4"
>
网络
</div>
<div
nz-col
nzSpan=
"20"
>
<nz-input-group
style=
"display: flex"
>
<nz-select
[(ngModel)]=
"channel.net.is_server"
>
<nz-option
nzLabel=
"服务端"
[nzValue]=
"true"
></nz-option>
<nz-option
nzLabel=
"客户端"
[nzValue]=
"false"
></nz-option>
</nz-select>
<nz-select
[(ngModel)]=
"channel.net.type"
style=
"width:80px;"
>
<nz-option
nzLabel=
"TCP"
nzValue=
"tcp"
></nz-option>
<nz-option
nzLabel=
"UDP"
nzValue=
"udp"
></nz-option>
</nz-select>
<input
nz-input
[(ngModel)]=
"channel.net.addr"
placeholder=
":1843"
style=
"flex: 1;"
>
</nz-input-group>
</div>
</div>
<div
class=
"item"
nz-row
nzAlign=
"middle"
>
<div
nz-col
nzSpan=
"4"
>
禁用
</div>
<div
nz-col
nzSpan=
"20"
>
<nz-switch
[(ngModel)]=
"channel.disabled"
></nz-switch>
</div>
</div>
<div
class=
"item"
nz-row
nzAlign=
"middle"
>
<div
nz-col
nzSpan=
"4"
>
注册包
</div>
<div
nz-col
nzSpan=
"20"
>
<nz-switch
[(ngModel)]=
"channel.register.enable"
></nz-switch>
</div>
</div>
<div
*ngIf=
"channel.register.enable"
>
<div
class=
"item"
nz-row
nzAlign=
"middle"
>
<div
nz-col
nzSpan=
"6"
nzOffset=
"2"
>
正则表达式
</div>
<div
nz-col
nzSpan=
"16"
>
<input
nz-input
[(ngModel)]=
"channel.register.regex"
/>
</div>
</div>
</div>
<div
class=
"item"
nz-row
nzAlign=
"middle"
>
<div
nz-col
nzSpan=
"4"
>
心跳包
</div>
<div
nz-col
nzSpan=
"20"
>
<nz-switch
[(ngModel)]=
"channel.heart_beat.enable"
></nz-switch>
</div>
</div>
<div
*ngIf=
"channel.heart_beat.enable"
>
<div
class=
"item"
nz-row
nzAlign=
"middle"
>
<div
nz-col
nzSpan=
"6"
nzOffset=
"2"
>
间隔(秒)
</div>
<div
nz-col
nzSpan=
"16"
>
<nz-input-number
[(ngModel)]=
"channel.heart_beat.interval"
[nzMin]=
"5"
[nzMax]=
"60"
[nzStep]=
"1"
></nz-input-number>
</div>
</div>
<div
class=
"item"
nz-row
nzAlign=
"middle"
>
<div
nz-col
nzSpan=
"6"
nzOffset=
"2"
>
内容(十六进制)
</div>
<div
nz-col
nzSpan=
"16"
>
<input
nz-input
[(ngModel)]=
"channel.heart_beat.content"
/>
</div>
</div>
</div>
<button
nz-button
nzType=
"primary"
(click)=
"submit()"
>
保存
</button>
portal/src/app/main/channel-edit/channel-edit.component.scss
浏览文件 @
28d38829
.item
{
margin-bottom
:
20px
;
}
portal/src/app/main/channel-edit/channel-edit.component.ts
浏览文件 @
28d38829
...
...
@@ -12,40 +12,29 @@ export class ChannelEditComponent implements OnInit {
@
Input
()
channel
:
any
=
{};
validateForm
!
:
FormGroup
;
constructor
(
private
as
:
ApiService
,
private
fb
:
FormBuilder
,
private
drawerRef
:
NzDrawerRef
<
string
>
)
{
constructor
(
private
as
:
ApiService
,
private
drawerRef
:
NzDrawerRef
<
string
>
)
{
}
ngOnInit
():
void
{
this
.
init
Form
({});
this
.
init
Channel
({});
if
(
this
.
channel
.
id
)
{
this
.
as
.
get
(
'
channel/
'
+
this
.
channel
.
id
).
subscribe
(
res
=>
{
this
.
channel
=
res
.
data
;
this
.
init
Form
(
this
.
channel
);
this
.
init
Channel
(
this
.
channel
);
});
}
}
submit
():
void
{
for
(
const
i
in
this
.
validateForm
.
controls
)
{
this
.
validateForm
.
controls
[
i
].
markAsDirty
();
this
.
validateForm
.
controls
[
i
].
updateValueAndValidity
();
}
if
(
!
this
.
validateForm
.
valid
)
{
return
;
}
if
(
this
.
channel
.
id
)
{
this
.
as
.
put
(
'
channel/
'
+
this
.
channel
.
id
,
this
.
validateForm
.
value
).
subscribe
(
res
=>
{
this
.
as
.
put
(
'
channel/
'
+
this
.
channel
.
id
,
this
.
channel
).
subscribe
(
res
=>
{
console
.
log
(
res
);
// TODO 修改成功
this
.
drawerRef
.
close
(
res
.
data
);
});
}
else
{
this
.
as
.
post
(
'
channel
'
,
this
.
validateForm
.
value
).
subscribe
(
res
=>
{
this
.
as
.
post
(
'
channel
'
,
this
.
channel
).
subscribe
(
res
=>
{
console
.
log
(
res
);
// TODO 保存成功
this
.
drawerRef
.
close
(
res
.
data
);
...
...
@@ -53,25 +42,11 @@ export class ChannelEditComponent implements OnInit {
}
}
initForm
(
item
):
void
{
if
(
!
item
.
register
)
item
.
register
=
{};
if
(
!
item
.
heart_beat
)
item
.
heart_beat
=
{};
initChannel
(
item
):
void
{
item
.
net
=
item
.
net
||
{
is_server
:
true
,
type
:
'
tcp
'
,
addr
:
'
:1843
'
};
item
.
register
=
item
.
register
||
{};
item
.
heart_beat
=
item
.
heart_beat
||
{};
this
.
validateForm
=
this
.
fb
.
group
({
name
:
[
item
.
name
,
[
Validators
.
required
]],
// tags: [item.tags],
serial
:
[
item
.
serial
],
net
:
[
item
.
net
,
[
Validators
.
required
]],
addr
:
[
item
.
addr
,
[
Validators
.
required
]],
is_server
:
[
item
.
is_server
],
disabled
:
[
item
.
disabled
],
'
register.enable
'
:
[
item
.
register
.
enable
],
'
register.regex
'
:
[
item
.
register
.
regex
],
'
heart_beat.enable
'
:
[
item
.
heart_beat
.
enable
],
'
heart_beat.interval
'
:
[
item
.
heart_beat
.
interval
],
'
heart_beat.content
'
:
[
item
.
heart_beat
.
content
],
});
this
.
channel
=
item
;
}
}
portal/src/app/main/channel/channel.component.html
浏览文件 @
28d38829
<
app-toolbar
>
<nz-
button-group
>
<
nz-space
>
<nz-
space-item
>
<button
nz-button
(click)=
"load()"
>
<i
nz-icon
nzType=
"reload"
></i>
刷新
</button>
</nz-space-item>
<nz-space-item>
<button
nz-button
(click)=
"edit()"
>
<i
nz-icon
nzType=
"plus"
></i>
创建
</button>
</nz-
button-group
>
</
app-toolbar
>
</nz-
space-item
>
</
nz-space
>
<nz-table
#basicTable
[nzData]=
"channels"
>
<thead>
<tr>
<th>
ID
</th>
<th>
名称
</th>
<th>
标签
</th>
<th>
序号
</th>
<th>
网络
</th>
<th>
地址
</th>
<th>
状态
</th>
<th>
创建时间
</th>
<th></th>
</tr>
...
...
@@ -28,13 +29,13 @@
<td>
{{ data.id }}
</td>
<td>
{{ data.name }}
</td>
<td>
{{ data.tags }}
</td>
<td>
{{ data.serial }}
</td>
<td>
{{ data.net }}
</td>
<td>
{{ data.addr }}
</td>
<td>
{{ data.created }}
</td>
<td>
{{ data.net.is_server ? '服务端':'客户端' }} {{data.net.type}} {{data.net.addr}}
</td>
<td>
{{data.disabled ? '禁用' : ''}}
<a>
启动/停止
</a>
<nz-divider
nzType=
"vertical"
></nz-divider>
</td>
<td>
{{ data.created | amDateFormat:'YYYY-MM-DD HH:mm:ss' }}
</td>
<td>
<a>
<i
nz-icon
nzType=
"delete"
></i>
</a>
...
...
portal/src/app/main/channel/channel.component.ts
浏览文件 @
28d38829
...
...
@@ -32,7 +32,7 @@ export class ChannelComponent implements OnInit {
this
.
drawer
.
create
({
nzTitle
:
c
?
'
编辑
'
:
'
创建
'
,
nzMaskClosable
:
false
,
nzWidth
:
4
00
,
nzWidth
:
5
00
,
nzContent
:
ChannelEditComponent
,
nzContentParams
:
{
channel
:
c
||
{}
...
...
portal/src/app/main/main.module.ts
浏览文件 @
28d38829
...
...
@@ -14,8 +14,8 @@ import {
NzCheckboxModule
,
NzDividerModule
,
NzDrawerModule
,
NzFormModule
,
NzIconModule
,
NzInputModule
,
NzModalModule
,
NzPopconfirmModule
,
NzSwitchModule
,
NzInputModule
,
NzInputNumberModule
,
NzModalModule
,
NzPopconfirmModule
,
NzS
electModule
,
NzS
witchModule
,
NzTableModule
,
NzToolTipModule
}
from
'
ng-zorro-antd
'
;
...
...
@@ -31,6 +31,7 @@ import {ChannelDetailComponent} from './channel-detail/channel-detail.component'
import
{
LinkDetailComponent
}
from
'
./link-detail/link-detail.component
'
;
import
{
UserEditComponent
}
from
'
./user-edit/user-edit.component
'
;
import
{
LinkMonitorComponent
}
from
'
./link-monitor/link-monitor.component
'
;
import
{
NzSpaceModule
}
from
"
ng-zorro-antd/space
"
;
@
NgModule
({
...
...
@@ -64,6 +65,9 @@ import {LinkMonitorComponent} from './link-monitor/link-monitor.component';
IconsProviderModule
,
NzDividerModule
,
NzDrawerModule
,
NzSelectModule
,
NzSpaceModule
,
NzInputNumberModule
,
],
bootstrap
:
[
MainComponent
]
})
...
...
types/channel.go
浏览文件 @
28d38829
...
...
@@ -2,15 +2,23 @@ package types
import
"time"
type
NetConf
struct
{
Type
string
`json:"type"`
Addr
string
`json:"addr"`
IsServer
bool
`json:"is_server"`
Timeout
int
`json:"timeout"`
//TODO 改为秒
}
type
RegisterConf
struct
{
Enable
bool
Length
int
Regex
string
Enable
bool
`json:"enable"`
Length
int
`json:"length"`
Regex
string
`json:"regex"`
}
type
HeartBeatConf
struct
{
Enable
bool
Content
[]
byte
Enable
bool
`json:"enable"`
Interval
int
`json:"interval"`
//TODO 改为秒
Content
[]
byte
`json:"content"`
}
type
Channel
struct
{
...
...
@@ -18,24 +26,9 @@ type Channel struct {
Name
string
`json:"name"`
Tags
[]
string
`json:"tags"`
Serial
string
`storm:"index" json:"serial"`
Net
string
`json:"net"`
Addr
string
`json:"addr"`
IsServer
bool
`json:"is_server"`
Timeout
int
`json:"timeout"`
//TODO 改为秒
Register
struct
{
Enable
bool
`json:"enable"`
Length
int
`json:"length"`
Regex
string
`json:"regex"`
}
`json:"register"`
HeartBeat
struct
{
Enable
bool
`json:"enable"`
Interval
int
`json:"interval"`
//TODO 改为秒
Content
[]
byte
`json:"content"`
}
`json:"heart_beat"`
Net
NetConf
`json:"net"`
Register
RegisterConf
`json:"register"`
HeartBeat
HeartBeatConf
`json:"heart_beat"`
Disabled
bool
`json:"disabled"`
Created
time
.
Time
`json:"created"`
...
...
web/api/channel.go
浏览文件 @
28d38829
...
...
@@ -7,7 +7,8 @@ import (
"github.com/zgwit/dtu-admin/types"
)
func
channelAll
(
ctx
*
gin
.
Context
)
{
func
channels
(
ctx
*
gin
.
Context
)
{
var
cs
[]
types
.
Channel
err
:=
storage
.
DB
(
"channel"
)
.
All
(
&
cs
)
if
err
!=
nil
{
...
...
@@ -17,11 +18,6 @@ func channelAll(ctx *gin.Context) {
replyOk
(
ctx
,
cs
)
}
func
channels
(
ctx
*
gin
.
Context
)
{
cs
:=
dtu
.
Channels
()
replyOk
(
ctx
,
cs
)
}
func
channelCreate
(
ctx
*
gin
.
Context
)
{
var
channel
types
.
Channel
if
err
:=
ctx
.
ShouldBindJSON
(
&
channel
);
err
!=
nil
{
...
...
@@ -29,14 +25,15 @@ func channelCreate(ctx *gin.Context) {
return
}
//创建并启动
c
,
err
:=
dtu
.
CreateChannel
(
&
channel
)
err
:=
storage
.
DB
(
"channel"
)
.
Save
(
&
channel
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
replyOk
(
ctx
,
c
)
//TODO 启动服务
replyOk
(
ctx
,
channel
)
}
func
channelDelete
(
ctx
*
gin
.
Context
)
{
...
...
@@ -45,17 +42,36 @@ func channelDelete(ctx *gin.Context) {
replyError
(
ctx
,
err
)
return
}
err
:=
dtu
.
DeleteChannel
(
pid
.
Id
)
err
:=
storage
.
DB
(
"channel"
)
.
DeleteStruct
(
&
types
.
Channel
{
ID
:
pid
.
Id
})
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
//TODO 删除服务
replyOk
(
ctx
,
nil
)
}
func
channelModify
(
ctx
*
gin
.
Context
)
{
var
channel
types
.
Channel
if
err
:=
ctx
.
ShouldBindJSON
(
&
channel
);
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
//TODO 不能全部字段更新,应该先取值,修改,再存入
err
:=
storage
.
DB
(
"channel"
)
.
Update
(
&
channel
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
//TODO 重新启动服务
replyOk
(
ctx
,
channel
)
}
func
channelGet
(
ctx
*
gin
.
Context
)
{
...
...
@@ -64,13 +80,15 @@ func channelGet(ctx *gin.Context) {
replyError
(
ctx
,
err
)
return
}
c
,
err
:=
dtu
.
GetChannel
(
pid
.
Id
)
var
channel
types
.
Channel
err
:=
storage
.
DB
(
"channel"
)
.
One
(
"ID"
,
pid
.
Id
,
&
channel
)
if
err
!=
nil
{
replyError
(
ctx
,
err
)
return
}
replyOk
(
ctx
,
c
)
replyOk
(
ctx
,
c
hannel
)
}
func
channelStart
(
ctx
*
gin
.
Context
)
{
...
...
web/api/router.go
浏览文件 @
28d38829
...
...
@@ -17,12 +17,12 @@ type paramSearch struct {
}
type
paramId
struct
{
Id
int
64
`uri:"id"`
Id
int
`uri:"id"`
}
type
paramId2
struct
{
Id
int
64
`uri:"id"`
Id2
int
64
`uri:"id2"`
Id
int
`uri:"id"`
Id2
int
`uri:"id2"`
}
func
RegisterRoutes
(
app
*
gin
.
RouterGroup
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录