|
@@ -142,12 +142,20 @@ import message from '@/utils/message'
|
|
|
// 定义组件props
|
|
|
interface Props {
|
|
|
courseid?: string | null
|
|
|
+ userid?: string | null
|
|
|
+ oid?: string | null
|
|
|
+ org?: string | null
|
|
|
+ cid?: string | null
|
|
|
type?: string | null
|
|
|
}
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
courseid: null,
|
|
|
- type: null
|
|
|
+ userid: null,
|
|
|
+ oid: null,
|
|
|
+ org: null,
|
|
|
+ cid: null,
|
|
|
+ type: null,
|
|
|
})
|
|
|
|
|
|
// 图标组件通过全局注册,无需导入
|
|
@@ -329,6 +337,72 @@ const toggleLaserPen = () => {
|
|
|
// 获取导入导出功能
|
|
|
const { readJSON, exportJSON2 } = useImport()
|
|
|
|
|
|
+// 处理iframe链接,为包含workPage的iframe添加必要参数
|
|
|
+const processIframeLinks = () => {
|
|
|
+ try {
|
|
|
+ console.log('开始处理iframe链接')
|
|
|
+ console.log('当前props:', { courseid: props.courseid, userid: props.userid })
|
|
|
+
|
|
|
+ // 获取所有iframe元素
|
|
|
+ const iframes = document.querySelectorAll('iframe')
|
|
|
+ console.log('找到iframe元素数量:', iframes.length)
|
|
|
+
|
|
|
+ if (iframes.length === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历所有iframe元素
|
|
|
+ iframes.forEach((iframe, index) => {
|
|
|
+ const iframeSrc = iframe.src
|
|
|
+
|
|
|
+ if (iframeSrc && iframeSrc.includes('workPage')) {
|
|
|
+ console.log(`处理iframe ${index + 1}:`, iframeSrc)
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 解析URL,处理hash部分
|
|
|
+ let baseUrl = iframeSrc
|
|
|
+ let hashPart = ''
|
|
|
+
|
|
|
+ // 分离base URL和hash部分
|
|
|
+ if (iframeSrc.includes('#')) {
|
|
|
+ const parts = iframeSrc.split('#')
|
|
|
+ baseUrl = parts[0]
|
|
|
+ hashPart = parts[1]
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建新的hash部分,添加参数
|
|
|
+ // 为iframe设置固定的task值,避免每次切换都刷新
|
|
|
+ let newHash = hashPart
|
|
|
+ if (newHash.includes('?')) {
|
|
|
+ // 如果hash中已经有查询参数,添加&
|
|
|
+ newHash += `&courseid=${props.courseid || ''}&userid=${props.userid || ''}&stage=0&task=0&tool=0`
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // 如果hash中没有查询参数,添加?
|
|
|
+ newHash += `?courseid=${props.courseid || ''}&userid=${props.userid || ''}&stage=0&task=0&tool=0`
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建新的URL
|
|
|
+ const newUrl = `${baseUrl}#${newHash}`
|
|
|
+
|
|
|
+ // 更新iframe的src
|
|
|
+ iframe.src = newUrl
|
|
|
+
|
|
|
+ console.log(`iframe ${index + 1} 链接已更新:`, iframe.src)
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ console.error(`处理iframe ${index + 1} 链接时出错:`, error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ console.log('iframe链接处理完成')
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ console.error('处理iframe链接时出错:', error)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// 导入JSON功能
|
|
|
const importJSON = (jsonData: any) => {
|
|
|
try {
|
|
@@ -397,9 +471,57 @@ const backToEditor = () => {
|
|
|
// 作业提交功能
|
|
|
const handleHomeworkSubmit = () => {
|
|
|
console.log('作业提交按钮被点击')
|
|
|
- // 这里可以跳转到作业提交页面,并传递当前幻灯片的ID
|
|
|
- // 例如:window.location.href = `/course/${props.courseid}/homework/${currentSlide.value?.id}`
|
|
|
- message.info('作业提交功能暂未实现')
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取当前页面的所有iframe元素
|
|
|
+ const iframes = document.querySelectorAll('.viewer-canvas iframe')
|
|
|
+ console.log('找到iframe元素数量:', iframes.length)
|
|
|
+
|
|
|
+ if (iframes.length === 0) {
|
|
|
+ message.warning('当前页面没有找到iframe元素')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历所有iframe元素
|
|
|
+ for (let i = 0; i < iframes.length; i++) {
|
|
|
+ const iframe = iframes[i] as HTMLIFrameElement
|
|
|
+ const iframeSrc = iframe.src
|
|
|
+
|
|
|
+ console.log(`iframe ${i + 1} 链接:`, iframeSrc)
|
|
|
+
|
|
|
+ // 检查iframe链接是否包含workPage
|
|
|
+ if (iframeSrc && iframeSrc.includes('workPage')) {
|
|
|
+ console.log('找到包含workPage的iframe,尝试执行submitWork')
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取iframe的contentWindow
|
|
|
+ const iframeWindow = iframe.contentWindow as Window & { submitWork?: (...args: any[]) => void }
|
|
|
+
|
|
|
+ if (iframeWindow && typeof iframeWindow.submitWork === 'function') {
|
|
|
+ // 如果存在submitWork方法,执行它,参数可变
|
|
|
+ console.log('执行iframe中的submitWork方法,参数可变')
|
|
|
+ const submitArgs = [slideIndex.value]
|
|
|
+ iframeWindow.submitWork(...submitArgs)
|
|
|
+ message.success('作业提交成功')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log('iframe中没有找到submitWork方法')
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ console.error('访问iframe内容时出错:', error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有找到包含workPage的iframe或无法执行submitWork
|
|
|
+ message.info('未找到可用的作业提交功能')
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ console.error('作业提交过程中出错:', error)
|
|
|
+ message.error('作业提交失败')
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 获取作业提交按钮的右侧位置
|
|
@@ -456,6 +578,9 @@ const handleSlidesDataUpdated = () => {
|
|
|
setTimeout(() => {
|
|
|
showSlideList.value = true
|
|
|
console.log('组件重新渲染完成')
|
|
|
+
|
|
|
+ // 重新处理iframe链接
|
|
|
+ processIframeLinks()
|
|
|
}, 500)
|
|
|
|
|
|
console.log('slidesDataUpdated 事件处理完成')
|
|
@@ -495,6 +620,9 @@ onMounted(() => {
|
|
|
// 计算初始缩放比例
|
|
|
nextTick(() => {
|
|
|
calculateScale()
|
|
|
+
|
|
|
+ // 处理iframe链接
|
|
|
+ processIframeLinks()
|
|
|
})
|
|
|
|
|
|
// 监听窗口大小变化
|