Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yl01
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
yl01
Commits
65376b9c
Commit
65376b9c
authored
Apr 16, 2025
by
李维
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加音频上传
parent
19323dcb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
6 deletions
+95
-6
index.html
form/index.html
+15
-0
index.js
form/index.js
+80
-6
No files found.
form/index.html
View file @
65376b9c
...
@@ -28,6 +28,21 @@
...
@@ -28,6 +28,21 @@
<el-form-item
label=
"小写"
>
<el-form-item
label=
"小写"
>
<el-checkbox
v-model=
"data.lowerCase"
@
change=
"save"
></el-checkbox>
<el-checkbox
v-model=
"data.lowerCase"
@
change=
"save"
></el-checkbox>
</el-form-item>
</el-form-item>
<el-form-item
label=
"音频"
>
<div
class=
"audio-uploader"
>
<el-upload
:action=
"uploadUrl"
:data=
"uploadData"
:on-success=
"(res, file) => handleAudioSuccess(res, file)"
:before-upload=
"beforeAudioUpload"
:show-file-list=
"false"
>
<el-button
size=
"small"
type=
"primary"
>
{{ data.audio.url ? '重新上传' : '上传' }}
</el-button>
<span
v-if=
"data.audio.url"
class=
"filename"
@
click
.
stop=
"togglePlay()"
>
{{ data.audio.name }}(点击播放)
</span>
<audio
:ref=
"'audio'"
:src=
"data.audio.url"
@
ended
.
stop=
"audioEnded()"
style=
"display: none;"
></audio>
</el-upload>
</div>
</el-form-item>
</el-form>
</el-form>
</div>
</div>
</body>
</body>
...
...
form/index.js
View file @
65376b9c
...
@@ -18,12 +18,22 @@ new Vue({
...
@@ -18,12 +18,22 @@ new Vue({
window
.
courseware
.
getData
((
dt
)
=>
{
window
.
courseware
.
getData
((
dt
)
=>
{
if
(
dt
)
{
if
(
dt
)
{
this
.
data
=
dt
;
this
.
data
=
dt
;
if
(
!
this
.
data
.
audio
)
{
this
.
data
.
audio
=
{
url
:
''
,
name
:
''
,
size
:
0
,
duration
:
""
}
}
}
}
},
key
);
},
key
);
// window['air'].getUploadCallback = (url, data) => {
window
[
'
air
'
].
getUploadCallback
=
(
url
,
data
)
=>
{
// this.uploadUrl = url;
this
.
uploadUrl
=
url
;
// this.uploadData = data;
this
.
uploadData
=
data
;
// };
};
console
.
log
(
'
========== data ==========
'
);
console
.
log
(
this
.
data
);
},
},
data
()
{
data
()
{
return
{
return
{
...
@@ -31,8 +41,17 @@ new Vue({
...
@@ -31,8 +41,17 @@ new Vue({
data
:
{
data
:
{
letter
:
''
,
letter
:
''
,
upperCase
:
false
,
upperCase
:
false
,
lowerCase
:
false
lowerCase
:
false
,
audio
:
{
url
:
''
,
name
:
''
,
size
:
0
,
duration
:
""
}
},
},
uploadUrl
:
window
.
courseware
.
uploadUrl
(),
uploadData
:
window
.
courseware
.
uploadData
(),
isPlaying
:
false
,
options
:
[
options
:
[
{
label
:
'
A
'
,
value
:
'
A
'
},
{
label
:
'
A
'
,
value
:
'
A
'
},
{
label
:
'
B
'
,
value
:
'
B
'
},
{
label
:
'
B
'
,
value
:
'
B
'
},
...
@@ -60,10 +79,65 @@ new Vue({
...
@@ -60,10 +79,65 @@ new Vue({
{
label
:
'
X
'
,
value
:
'
X
'
},
{
label
:
'
X
'
,
value
:
'
X
'
},
{
label
:
'
Y
'
,
value
:
'
Y
'
},
{
label
:
'
Y
'
,
value
:
'
Y
'
},
{
label
:
'
Z
'
,
value
:
'
Z
'
},
{
label
:
'
Z
'
,
value
:
'
Z
'
},
]
]
,
}
}
},
},
methods
:
{
methods
:
{
handleAudioSuccess
(
res
,
file
)
{
// 假设上传接口返回的音频URL在 res.url 中
this
.
data
.
audio
.
url
=
res
.
url
;
this
.
data
.
audio
.
name
=
file
.
name
;
// 计算文件大小
const
size
=
file
.
size
;
if
(
size
<
1024
)
{
this
.
data
.
audio
.
size
=
size
+
'
B
'
;
}
else
if
(
size
<
1024
*
1024
)
{
this
.
data
.
audio
.
size
=
(
size
/
1024
).
toFixed
(
2
)
+
'
KB
'
;
}
else
{
this
.
data
.
audio
.
size
=
(
size
/
(
1024
*
1024
)).
toFixed
(
2
)
+
'
MB
'
;
}
// 获取音频时长
const
audio
=
new
Audio
(
res
.
url
);
audio
.
addEventListener
(
'
loadedmetadata
'
,
()
=>
{
const
duration
=
audio
.
duration
;
const
minutes
=
Math
.
floor
(
duration
/
60
);
const
seconds
=
Math
.
floor
(
duration
%
60
);
this
.
data
.
audio
.
duration
=
`
${
minutes
}
:
${
seconds
.
toString
().
padStart
(
2
,
'
0
'
)}
`
;
});
this
.
save
();
},
togglePlay
()
{
if
(
this
.
isPlaying
)
{
this
.
$refs
.
audio
.
pause
();
}
else
{
this
.
$refs
.
audio
.
play
();
}
this
.
isPlaying
=
!
this
.
isPlaying
;
},
audioEnded
()
{
this
.
isPlaying
=
false
;
},
beforeAudioUpload
(
file
)
{
const
isAudio
=
file
.
type
.
startsWith
(
'
audio/
'
);
const
isLt20M
=
file
.
size
/
1024
/
1024
<
20
;
if
(
!
isAudio
)
{
this
.
$message
.
error
(
'
只能上传音频文件!
'
);
return
false
;
}
if
(
!
isLt20M
)
{
this
.
$message
.
error
(
'
音频大小不能超过 20MB!
'
);
return
false
;
}
return
true
;
},
save
()
{
save
()
{
window
.
courseware
.
setData
(
this
.
data
,()
=>
{
window
.
courseware
.
setData
(
this
.
data
,()
=>
{
this
.
$message
.
success
(
'
保存成功!
'
);
this
.
$message
.
success
(
'
保存成功!
'
);
...
...
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