|
@@ -1257,6 +1257,34 @@ const handleHomeworkSubmit = async () => {
|
|
|
throw new Error('无法创建canvas上下文')
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 将base64字符串转换为File对象
|
|
|
+ const base64ToFile = (base64String: string, filename: string): File => {
|
|
|
+ const arr = base64String.split(',')
|
|
|
+ const mime = arr[0].match(/:(.*?);/)?.[1] || 'image/png'
|
|
|
+ const bstr = atob(arr[1])
|
|
|
+ let n = bstr.length
|
|
|
+ const u8arr = new Uint8Array(n)
|
|
|
+ while (n--) {
|
|
|
+ u8arr[n] = bstr.charCodeAt(n)
|
|
|
+ }
|
|
|
+ return new File([u8arr], filename, { type: mime })
|
|
|
+ }
|
|
|
+
|
|
|
+ const imageFile = base64ToFile(imageData, `screenshot_${Date.now()}.png`)
|
|
|
+ const imageUrl = await uploadFile(imageFile)
|
|
|
+ // 提交截图
|
|
|
+ await submitWork(slideIndex.value, '73', imageUrl, '1') // 73表示截图工具,21表示图片类型
|
|
|
+ message.success('页面截图提交成功')
|
|
|
+ hasSubmitWork = true
|
|
|
+
|
|
|
+ // 发送作业提交成功的socket消息
|
|
|
+ sendMessage({
|
|
|
+ type: 'homework_submitted',
|
|
|
+ courseid: props.courseid,
|
|
|
+ slideIndex: slideIndex.value,
|
|
|
+ userid: props.userid
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
catch (error) {
|