Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OP17
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
template admin
OP17
Commits
ec775f99
Commit
ec775f99
authored
Nov 28, 2021
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 方便的JSON编辑器
parent
58e10380
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
1 deletion
+76
-1
index.html
form/index.html
+76
-1
No files found.
form/index.html
View file @
ec775f99
...
...
@@ -16,9 +16,32 @@
position
:
absolute
;
top
:
0
;
left
:
0
;
width
:
65%
;
right
:
180px
;
height
:
100%
;
}
.upload-container
{
width
:
100px
;
height
:
40px
;
position
:
absolute
;
right
:
40px
;
border-radius
:
2px
;
border
:
1px
solid
#dcdfe6
;
line-height
:
100px
;
margin
:
10px
;
text-align
:
center
;
display
:
flex
;
align-items
:
center
;
justify-content
:
center
;
}
.hide-fileinput
{
position
:
absolute
;
top
:
0px
;
left
:
0px
;
width
:
100%
;
height
:
100%
;
opacity
:
0
;
cursor
:
pointer
;
}
</style>
...
...
@@ -26,6 +49,10 @@
<body
onload=
"loadData();"
style=
"background-color: white;"
>
<pre
id=
"saveDataTextarea"
></pre>
<div
class=
"upload-container"
>
<div
class=
"upload-file"
>
上传文件
</div>
<input
class=
"hide-fileinput"
type=
"file"
name=
"file"
onchange=
"uploadFile()"
>
</div>
</body>
<script>
...
...
@@ -45,9 +72,57 @@
window
.
courseware
.
getData
((
data
)
=>
{
try
{
editor
.
setValue
(
JSON
.
stringify
(
data
,
null
,
2
));
editor
.
gotoLine
(
editor
.
session
.
getLength
());
}
catch
(
error
)
{}
},
"
cocos_001
"
);
}
function
uploadFile
(){
const
dom
=
document
.
querySelector
(
"
.hide-fileinput
"
);
const
file
=
dom
.
files
[
0
];
dom
.
setAttribute
(
"
disabled
"
,
true
);
document
.
querySelector
(
"
.upload-file
"
).
innerHTML
=
"
上传中...
"
;
commonUploadFile
(
file
,
(
data
)
=>
{
try
{
const
d
=
JSON
.
parse
(
data
);
const
protocolStr
=
document
.
location
.
protocol
;
const
url
=
d
.
url
.
replace
(
/http:/g
,
protocolStr
)
.
replace
(
/https:/g
,
protocolStr
);
editor
.
insert
(
url
);
}
catch
(
error
)
{}
dom
.
removeAttribute
(
"
disabled
"
);
document
.
querySelector
(
"
.upload-file
"
).
innerHTML
=
"
上传文件
"
;
});
}
function
commonUploadFile
(
file
,
callback
)
{
const
uploadUrl
=
window
.
courseware
.
uploadUrl
();
//上传文件的路径
const
uploadData
=
window
.
courseware
.
uploadData
();
//上传文件必须要的参数
const
formData
=
new
FormData
();
formData
.
append
(
"
file
"
,
file
);
for
(
const
key
in
uploadData
)
{
formData
.
append
(
key
,
uploadData
[
key
]);
}
var
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
"
post
"
,
uploadUrl
);
//回调
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
&&
xhr
.
status
==
200
){
callback
&&
callback
(
xhr
.
responseText
);
}
}
//获取上传的进度
xhr
.
upload
.
onprogress
=
function
(
event
)
{
if
(
event
.
lengthComputable
){
var
percent
=
event
.
loaded
/
event
.
total
*
100
;
document
.
querySelector
(
"
.upload-file
"
).
innerHTML
=
Math
.
floor
(
percent
)
+
"
%
"
;
}
}
//将formdata上传
xhr
.
send
(
formData
);
}
</script>
</html>
\ No newline at end of file
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