Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mr-julyedu
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baiguangyao
mr-julyedu
Commits
79e360c7
Commit
79e360c7
authored
May 29, 2020
by
zhanghaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ml小程序
parent
f4d7f1c7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
15 deletions
+19
-15
src/components/interactive-tutorial/terminal/index.js
+19
-15
No files found.
src/components/interactive-tutorial/terminal/index.js
View file @
79e360c7
...
...
@@ -5,6 +5,7 @@ import 'xterm/css/xterm.css'
import
{
FitAddon
}
from
"xterm-addon-fit"
;
import
{
http
}
from
"@/utils"
import
{
Toast
}
from
"antd-mobile"
;
import
axios
from
'axios'
class
TerminalInterface
extends
Component
{
...
...
@@ -44,15 +45,15 @@ class TerminalInterface extends Component {
}
getAuthenticationData
=
()
=>
{
http
.
post
(
`http://47.93.119.175:8888/auth`
,
{
axios
.
post
(
`http://47.93.119.175:8888/auth`
,
{
username
:
'3guh394h3fhj0f4'
,
password
:
'okqdw029j038hrv3890cv'
,
},
{
withCredentials
:
false
withCredentials
:
false
,
}).
then
(
res
=>
{
const
{
code
,
msg
,
data
}
=
res
.
data
if
(
code
===
20
0
)
{
this
.
getLinkId
(
data
.
token
)
if
(
code
===
0
)
{
this
.
getLinkId
(
data
)
}
else
{
Toast
.
fail
(
msg
,
2
)
}
...
...
@@ -60,41 +61,44 @@ class TerminalInterface extends Component {
}
getLinkId
=
token
=>
{
http
.
post
(
`http://47.93.119.175:8888`
,
{},
{
axios
.
post
(
`http://47.93.119.175:8888`
,
{},
{
headers
:
{
Token
:
token
,
},
withCredentials
:
false
,
}).
then
(
res
=>
{
const
{
code
,
msg
,
data
}
=
res
.
data
if
(
code
===
200
)
{
this
.
connectServer
(
data
.
id
)
}
else
{
Toast
.
fail
(
msg
,
2
,
null
,
false
)
}
const
{
id
}
=
res
.
data
this
.
connectServer
(
id
)
})
}
connectServer
=
(
id
)
=>
{
this
.
socket
=
new
WebSocket
(
`
${
API
.
ws
}
?id=
${
id
}
`
)
this
.
socket
.
addEventListener
(
'open'
,
()
=>
{
console
.
log
(
'opened'
)
this
.
socket
.
send
(
JSON
.
stringify
({
data
:
this
.
props
.
filename
,
}))
})
this
.
socket
.
onmessage
=
event
=>
{
console
.
log
(
event
.
message
)
this
.
terminal
.
write
(
event
.
data
)
const
reader
=
new
FileReader
()
reader
.
onload
=
()
=>
{
this
.
terminal
.
write
(
this
.
ab2str
(
reader
.
result
))
}
reader
.
readAsArrayBuffer
(
event
.
data
)
}
this
.
socket
.
onerror
=
(
event
)
=>
{
console
.
log
(
event
)
// this.connectServer(id)
}
this
.
socket
.
onclose
=
(
event
)
=>
{
console
.
log
(
'closed'
)
console
.
log
(
event
)
}
}
ab2str
=
buf
=>
{
return
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
buf
));
}
render
()
{
const
{
terminalWidth
}
=
this
.
state
return
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment