Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夜猫逐梦
1024程序员开源挑战赛
提交
d7705543
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看板
提交
d7705543
编写于
6月 22, 2019
作者:
B
baiy
提交者:
ninecents
10月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加websocket工具
上级
efb824f9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
153 addition
and
3 deletion
+153
-3
package.json
package.json
+1
-1
public/tool.html
public/tool.html
+1
-1
src/tool.router.js
src/tool.router.js
+4
-0
src/tool/config.js
src/tool/config.js
+2
-1
src/views/tool/websocket.vue
src/views/tool/websocket.vue
+145
-0
未找到文件。
package.json
浏览文件 @
d7705543
{
"name"
:
"c-tool"
,
"version"
:
"0.0.1
4
"
,
"version"
:
"0.0.1
5
"
,
"private"
:
true
,
"scripts"
:
{
"serve"
:
"vue-cli-service serve --port 8081"
,
...
...
public/tool.html
浏览文件 @
d7705543
...
...
@@ -4,7 +4,7 @@
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width,initial-scale=1.0"
>
<title>
popup
</title>
<title>
Ctool 程序开发常用工具
</title>
</head>
<body>
<div
id=
"page"
style=
"width: 800px;height: 550px;margin: 0 auto;padding: 0 6px;overflow-y:auto;"
>
...
...
src/tool.router.js
浏览文件 @
d7705543
...
...
@@ -70,6 +70,10 @@ const routes = [
path
:
"
/tool/crontab
"
,
component
:
r
=>
require
([
'
./views/tool/crontab.vue
'
],
r
)
},
{
path
:
"
/tool/websocket
"
,
component
:
r
=>
require
([
'
./views/tool/websocket.vue
'
],
r
)
},
];
const
router
=
new
Router
({
routes
});
...
...
src/tool/config.js
浏览文件 @
d7705543
...
...
@@ -40,7 +40,8 @@ const tool = [
{
"
name
"
:
"
randomString
"
,
"
title
"
:
"
随机字符生成
"
,
cat
:
[
"
other
"
]},
{
"
name
"
:
"
phpArraySerialize
"
,
"
title
"
:
"
PHP数组/序列化
"
,
cat
:
[
"
conversion
"
]},
{
"
name
"
:
"
diffs
"
,
"
title
"
:
"
文本差异化对比
"
,
cat
:
[
"
other
"
]},
{
"
name
"
:
"
crontab
"
,
"
title
"
:
"
Crontab校验工具
"
,
cat
:
[
"
other
"
]},
{
"
name
"
:
"
crontab
"
,
"
title
"
:
"
crontab校验
"
,
cat
:
[
"
other
"
]},
{
"
name
"
:
"
websocket
"
,
"
title
"
:
"
websocket调试
"
,
cat
:
[
"
other
"
]},
];
// 徽章是否显示
...
...
src/views/tool/websocket.vue
0 → 100644
浏览文件 @
d7705543
<
template
>
<Row
:gutter=
"10"
>
<Col
span=
"10"
>
<Row
:gutter=
"6"
>
<Col
span=
"18"
>
<Input
v-model=
"current.url"
>
<span
slot=
"prepend"
>
<Badge
style=
"margin-left:10px"
:status=
"status ? 'success' : 'error'"
/>
</span>
</Input>
</Col>
<Col
span=
"6"
>
<Button
long
v-if=
"!status"
type=
"success"
@
click=
"handle()"
>
连接
</Button>
<Button
long
v-else
type=
"error"
@
click=
"handle()"
>
断开
</Button>
</Col>
</Row>
<Input
style=
"margin: 10px 0 5px"
v-model=
"sendContent"
:rows=
"14"
type=
"textarea"
placeholder=
"发送内容"
></Input>
<Button
type=
"primary"
@
click=
"send()"
long
>
发送
</Button>
</Col>
<Col
span=
"14"
>
<Card>
<p
slot=
"title"
>
交互内容
</p>
<template
slot=
"extra"
>
<Button
style=
"margin-right: 5px"
size=
"small"
type=
"primary"
@
click=
"copyAll()"
>
复制全部
</Button>
<Button
size=
"small"
type=
"primary"
@
click=
"clear()"
>
清空
</Button>
</
template
>
<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"
>
你发送的信息 {{item.time}}
</div>
<div
class=
"item"
v-else-if=
"item.type === 'accept'"
style=
"color:blue"
>
服务端响应消息 {{item.time}}
</div>
<div
class=
"item"
v-else
>
{{item.time}}
</div>
<div
class=
"item"
>
<Icon
style=
"cursor: pointer"
type=
"md-copy"
@
click=
"copy(item.content)"
/>
{{item.content}}
</div>
</div>
</div>
</Card>
</Col>
</Row>
</template>
<
script
>
import
{
formatDate
}
from
"
../../helper
"
;
export
default
{
created
()
{
this
.
current
=
Object
.
assign
(
this
.
current
,
this
.
$getToolData
())
},
methods
:
{
handle
()
{
if
(
this
.
status
)
{
return
this
.
close
();
}
return
this
.
connect
();
},
connect
()
{
let
websocket
=
new
WebSocket
(
this
.
current
.
url
);
websocket
.
onopen
=
(
evt
)
=>
{
this
.
onOpen
(
evt
)
};
websocket
.
onclose
=
(
evt
)
=>
{
this
.
onClose
(
evt
)
};
websocket
.
onmessage
=
(
evt
)
=>
{
this
.
onMessage
(
evt
)
};
websocket
.
onerror
=
(
evt
)
=>
{
this
.
onError
(
evt
)
};
this
.
ws
=
websocket
;
},
close
()
{
this
.
ws
.
close
();
},
clear
()
{
this
.
lists
=
[];
},
log
(
content
,
type
=
"
other
"
)
{
this
.
lists
.
push
({
content
,
type
,
time
:
formatDate
(
new
Date
())});
this
.
$nextTick
(()
=>
{
let
log
=
document
.
getElementById
(
'
log
'
);
log
.
scrollTop
=
log
.
scrollHeight
;
})
},
copy
(
s
)
{
this
.
$clipboardCopy
(
s
);
},
copyAll
()
{
this
.
copy
(
JSON
.
stringify
(
this
.
lists
));
},
send
()
{
try
{
if
(
!
this
.
status
)
{
return
this
.
$Message
.
error
(
"
ws还没有连接,或者连接失败,请检测
"
);
}
if
(
!
this
.
sendContent
)
{
return
this
.
$Message
.
error
(
"
发送内容不能为空
"
);
}
this
.
ws
.
send
(
this
.
sendContent
);
this
.
log
(
this
.
sendContent
,
'
send
'
)
}
catch
(
e
)
{
this
.
log
(
'
错误异常:
'
+
e
)
}
},
onOpen
()
{
this
.
status
=
true
;
this
.
log
(
"
连接成功
"
)
},
onClose
()
{
this
.
status
=
false
;
this
.
log
(
"
连接关闭
"
)
},
onMessage
(
evt
)
{
this
.
log
(
evt
.
data
,
'
accept
'
)
},
onError
(
evt
)
{
this
.
log
(
'
错误异常:
'
+
evt
.
data
())
}
},
data
()
{
return
{
current
:
{
url
:
"
ws://echo.websocket.org
"
,
},
status
:
false
,
wx
:
null
,
sendContent
:
""
,
lists
:
[],
}
},
}
</
script
>
<
style
scoped
>
.lists-block
{
font-size
:
12px
;
}
</
style
>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录