Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夜猫逐梦
1024程序员开源挑战赛
提交
90daab05
1
1024程序员开源挑战赛
项目概览
夜猫逐梦
/
1024程序员开源挑战赛
与 Fork 源项目一致
Fork自
GitCode / 1024程序员开源挑战赛(10.23-11.14)
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
1
1024程序员开源挑战赛
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
90daab05
编写于
9月 19, 2021
作者:
B
baiy
提交者:
ninecents
10月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
951cd909
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
129 addition
and
158 deletion
+129
-158
src/views/tool/websocket.vue
src/views/tool/websocket.vue
+129
-158
未找到文件。
src/views/tool/websocket.vue
浏览文件 @
90daab05
<
template
>
<
template
>
<div>
<Row
:gutter=
"10"
>
<Input
v-model=
"current.url"
class=
"page-option-block"
style=
"margin-bottom: 10px"
>
<Col
span=
"10"
>
<Row
:gutter=
"6"
>
<Col
span=
"18"
>
<Input
v-model=
"current.url"
>
<span
slot=
"prepend"
>
<span
slot=
"prepend"
>
<Badge
style=
"margin-left:10px"
:status=
"status ? 'success' : 'error'"
/>
<Badge
style=
"margin-left:10px"
:status=
"status ? 'success' : 'error'"
/>
</span>
</span>
<Button
slot=
"append"
v-if=
"!status"
@
click=
"handle()"
>
{{
$t
(
'
websocket_connect
'
)
}}
</Button>
<Button
slot=
"append"
v-else
@
click=
"handle()"
>
{{
$t
(
'
websocket_close
'
)
}}
</Button>
</Input>
</Input>
<Row
:gutter=
"10"
>
</Col>
<Col
span=
"10"
>
<Col
span=
"6"
>
<input-block
top=
"7px"
right=
"7px"
>
<Button
long
v-if=
"!status"
type=
"success"
@
click=
"handle()"
>
连接
</Button>
<heightResize
:append=
"['.page-option-block']"
>
<Button
long
v-else
type=
"error"
@
click=
"handle()"
>
断开
</Button>
<autoHeightTextarea
v-model=
"sendContent"
:placeholder=
"$t('websocket_send_content')"
/>
</Col>
</heightResize>
</Row>
<template
slot=
"extra"
>
<Input
style=
"margin: 10px 0 5px"
v-model=
"sendContent"
:rows=
"14"
type=
"textarea"
<Button
:disabled=
"!status"
type=
"primary"
size=
"small"
@
click=
"send"
>
{{
placeholder=
"发送内容"
></Input>
$t
(
'
websocket_send
'
)
<Button
type=
"primary"
@
click=
"send()"
long
>
发送
</Button>
}}
</Button>
</
template
>
</input-block>
</Col>
</Col>
<Col
span=
"14"
>
<Col
span=
"14"
>
<input-block
top=
"7px"
right=
"7px"
:text=
"$t('websocket_send')"
@
on-default-right-bottom-click=
"send"
>
<heightResize
:append=
"['.page-option-block']"
@
resize=
"logHeightSet"
>
<Card>
<Card>
<div
class=
"lists-block"
id=
"log"
<p
slot=
"title"
>
交互内容
</p>
:style=
"`height: ${logHeight}px;overflow: hidden;overflow-y:auto;`"
>
<template
slot=
"extra"
>
<div
v-if=
"lists.length === 0"
style=
"font-size: 14px;color: #999999"
>
<Button
style=
"margin-right: 5px"
size=
"small"
type=
"primary"
@
click=
"copyAll()"
>
复制全部
</Button>
{{ $t('websocket_log_content') }}
<Button
size=
"small"
type=
"primary"
@
click=
"clear()"
>
清空
</Button>
</div>
</
template
>
<div
v-else
v-for=
"(item,key) in lists"
:key=
"key"
>
<div
class=
"lists-block"
id=
"log"
style=
"height: 300px;overflow: hidden;overflow-y:auto;"
>
<div
v-for=
"(item,key) in lists"
:key=
"key"
>
<div
class=
"item"
v-if=
"item.type === 'send'"
style=
"color:green"
>
<div
class=
"item"
v-if=
"item.type === 'send'"
style=
"color:green"
>
{{ $t('websocket_you') }} {{ item.time
}}
你 {{item.time
}}
</div>
</div>
<div
class=
"item"
v-else-if=
"item.type === 'accept'"
style=
"color:blue"
>
<div
class=
"item"
v-else-if=
"item.type === 'accept'"
style=
"color:blue"
>
{{ $t('websocket_server') }} {{ item.time
}}
服务端 {{item.time
}}
</div>
</div>
<div
class=
"item"
v-else
>
<div
class=
"item"
v-else
>
{{ item.time
}}
{{item.time
}}
</div>
</div>
<div
class=
"item"
>
<div
class=
"item"
>
<Icon
style=
"cursor: pointer"
type=
"md-copy"
@
click=
"copy(item.content)"
/>
<Icon
style=
"cursor: pointer"
type=
"md-copy"
@
click=
"copy(item.content)"
/>
{{ item.content
}}
{{item.content
}}
</div>
</div>
</div>
</div>
</div>
</div>
</Card>
</Card>
</heightResize>
<
template
slot=
"extra"
>
<Button
style=
"margin-right: 5px"
size=
"small"
type=
"primary"
@
click=
"copyAll()"
>
{{
$t
(
'
websocket_copy
'
)
}}
</Button>
<Button
size=
"small"
type=
"primary"
@
click=
"clear()"
>
{{
$t
(
'
websocket_clear
'
)
}}
</Button>
</
template
>
</input-block>
</Col>
</Col>
</Row>
</Row>
</div>
</template>
</template>
<
script
>
<
script
>
import
moment
from
'
moment
'
import
moment
from
'
moment
'
import
heightResize
from
"
./components/heightResize
"
;
import
autoHeightTextarea
from
"
./components/autoHeightTextarea
"
;
export
default
{
export
default
{
components
:
{
heightResize
,
autoHeightTextarea
},
created
()
{
created
()
{
this
.
$initToolData
(
)
this
.
current
=
Object
.
assign
(
this
.
current
,
this
.
$getToolData
()
)
},
},
methods
:
{
methods
:
{
handle
()
{
handle
()
{
...
@@ -80,11 +62,6 @@ export default {
...
@@ -80,11 +62,6 @@ export default {
return
this
.
connect
();
return
this
.
connect
();
},
},
connect
()
{
connect
()
{
if
(
!
this
.
current
.
url
.
trim
())
{
return
}
this
.
$saveToolData
(
this
.
current
);
this
.
log
(
this
.
$t
(
'
websocket_connect_start
'
,
[
this
.
current
.
url
]).
toString
())
let
websocket
=
new
WebSocket
(
this
.
current
.
url
);
let
websocket
=
new
WebSocket
(
this
.
current
.
url
);
websocket
.
onopen
=
(
evt
)
=>
{
websocket
.
onopen
=
(
evt
)
=>
{
this
.
onOpen
(
evt
)
this
.
onOpen
(
evt
)
...
@@ -101,14 +78,13 @@ export default {
...
@@ -101,14 +78,13 @@ export default {
this
.
ws
=
websocket
;
this
.
ws
=
websocket
;
},
},
close
()
{
close
()
{
this
.
log
(
this
.
$t
(
'
websocket_close_start
'
,
[
this
.
current
.
url
]).
toString
())
this
.
ws
.
close
();
this
.
ws
.
close
();
},
},
clear
()
{
clear
()
{
this
.
lists
=
[];
this
.
lists
=
[];
},
},
log
(
content
,
type
=
"
other
"
)
{
log
(
content
,
type
=
"
other
"
)
{
this
.
lists
.
push
({
content
,
type
,
time
:
moment
().
format
(
"
YYYY-MM-DD HH:mm:ss
"
)});
this
.
lists
.
push
({
content
,
type
,
time
:
moment
().
format
(
"
YYYY-MM-DD HH:mm:ss
"
)});
this
.
$nextTick
(()
=>
{
this
.
$nextTick
(()
=>
{
let
log
=
document
.
getElementById
(
'
log
'
);
let
log
=
document
.
getElementById
(
'
log
'
);
log
.
scrollTop
=
log
.
scrollHeight
;
log
.
scrollTop
=
log
.
scrollHeight
;
...
@@ -123,52 +99,47 @@ export default {
...
@@ -123,52 +99,47 @@ export default {
send
()
{
send
()
{
try
{
try
{
if
(
!
this
.
status
)
{
if
(
!
this
.
status
)
{
throw
new
Error
(
this
.
$t
(
'
websocket_error_connect
'
).
toString
())
return
this
.
$Message
.
error
(
"
ws还没有连接,或者连接失败,请检测
"
);
}
}
if
(
!
this
.
sendContent
)
{
if
(
!
this
.
sendContent
)
{
throw
new
Error
(
this
.
$t
(
'
websocket_error_content
'
).
toString
())
return
this
.
$Message
.
error
(
"
发送内容不能为空
"
);
}
}
this
.
ws
.
send
(
this
.
sendContent
);
this
.
ws
.
send
(
this
.
sendContent
);
this
.
log
(
this
.
sendContent
,
'
send
'
)
this
.
log
(
this
.
sendContent
,
'
send
'
)
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
log
(
this
.
$t
(
'
websocket_error
'
,
[
e
.
message
]).
toString
()
)
this
.
log
(
'
错误异常:
'
+
e
)
}
}
},
},
onOpen
()
{
onOpen
()
{
this
.
status
=
true
;
this
.
status
=
true
;
this
.
log
(
this
.
$t
(
'
websocket_connect_ok
'
).
toString
()
)
this
.
log
(
"
连接成功
"
)
},
},
onClose
()
{
onClose
()
{
this
.
status
=
false
;
this
.
status
=
false
;
this
.
log
(
this
.
$t
(
'
websocket_close_ok
'
).
toString
()
)
this
.
log
(
"
连接关闭
"
)
},
},
onMessage
(
evt
)
{
onMessage
(
evt
)
{
this
.
log
(
evt
.
data
,
'
accept
'
)
this
.
log
(
evt
.
data
,
'
accept
'
)
},
},
onError
(
evt
)
{
onError
(
evt
)
{
this
.
log
(
this
.
$t
(
'
websocket_error
'
,
[
evt
.
data
()]).
toString
())
this
.
log
(
'
错误异常:
'
+
evt
.
data
())
},
logHeightSet
(
height
)
{
this
.
logHeight
=
Math
.
max
(
height
-
34
,
100
)
}
}
},
},
data
()
{
data
()
{
return
{
return
{
current
:
{
current
:
{
url
:
"
wss://echo.websocket.events
"
,
url
:
"
wss://echo.websocket.org
"
,
},
},
status
:
false
,
status
:
false
,
wx
:
null
,
wx
:
null
,
sendContent
:
""
,
sendContent
:
""
,
lists
:
[],
lists
:
[],
logHeight
:
100
,
}
}
},
},
}
}
</
script
>
</
script
>
<
style
scoped
>
<
style
scoped
>
.lists-block
{
.lists-block
{
font-size
:
14px
;
font-size
:
12px
;
line-height
:
28px
;
}
}
</
style
>
</
style
>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录