|
|
@@ -369,7 +369,8 @@ import CountdownTimer from '@/views/Screen/CountdownTimer.vue'
|
|
|
import useSlideBackgroundStyle from '@/hooks/useSlideBackgroundStyle'
|
|
|
import useImport from '@/hooks/useImport'
|
|
|
import message from '@/utils/message'
|
|
|
-import api from '@/services/course'
|
|
|
+import api, { API_URL } from '@/services/course'
|
|
|
+import axios from '@/services/config'
|
|
|
import ShotWorkModal from './components/ShotWorkModal.vue'
|
|
|
import QAWorkModal from './components/QAWorkModal.vue'
|
|
|
import ChoiceWorkModal from './components/ChoiceWorkModal.vue'
|
|
|
@@ -382,6 +383,21 @@ import { Refresh } from '@icon-park/vue-next'
|
|
|
import answerTheResult from './components/answerTheResult.vue'
|
|
|
import choiceQuestionDetailDialog from './components/choiceQuestionDetailDialog.vue'
|
|
|
|
|
|
+// 生成标准 UUID v4 格式(36位,符合 [0-9a-fA-F-] 格式)
|
|
|
+const generateUUID = (): string => {
|
|
|
+ // 优先使用浏览器原生 API
|
|
|
+ if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
|
+ return crypto.randomUUID()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 降级方案:手动生成 UUID v4
|
|
|
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
|
+ const r = (Math.random() * 16) | 0
|
|
|
+ const v = c === 'x' ? r : (r & 0x3) | 0x8
|
|
|
+ return v.toString(16)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
// 导入图片资源
|
|
|
import homeworkIcon from '@/assets/img/homework.png'
|
|
|
@@ -2082,6 +2098,72 @@ const handleViewportSizeUpdated = (event: any) => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+const pptJsonFileid = ref<string>('')
|
|
|
+
|
|
|
+// 上传文件
|
|
|
+const uploadFile2 = async (file: File, pptid: string): Promise<void> => {
|
|
|
+ try {
|
|
|
+ const uuid = generateUUID()
|
|
|
+ const formData = new FormData()
|
|
|
+ const timestamp = Date.now()
|
|
|
+ const finalExtension = file.name.split('.').pop()?.toLowerCase() || ''
|
|
|
+ const baseName = file.name.slice(0, -(finalExtension.length + 1))
|
|
|
+
|
|
|
+ formData.append(
|
|
|
+ 'file',
|
|
|
+ new File([file], `${baseName}${timestamp}.${finalExtension}`)
|
|
|
+ )
|
|
|
+ formData.append('collection_ids', JSON.stringify([]))
|
|
|
+ formData.append('id', uuid)
|
|
|
+ formData.append('metadata', JSON.stringify({ title: file.name }))
|
|
|
+ formData.append('ingestion_mode', 'fast')
|
|
|
+ formData.append('run_with_orchestration', 'true')
|
|
|
+
|
|
|
+ // 同步知识库
|
|
|
+ await axios.post(
|
|
|
+ 'https://r2rserver.cocorobo.cn/v3/documents',
|
|
|
+ formData,
|
|
|
+ {
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'multipart/form-data',
|
|
|
+ },
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ const ptype = '1' // 根据实际业务定义类型
|
|
|
+ const fileid = uuid // 如果需要唯一fileid可以和pptid保持一致或按需更改
|
|
|
+
|
|
|
+ await axios.post(`${API_URL}addPPTFile`, [{
|
|
|
+ pptid: pptid,
|
|
|
+ ptype: ptype,
|
|
|
+ fileid: fileid,
|
|
|
+ classid: '',
|
|
|
+ task: '',
|
|
|
+ tool: ''
|
|
|
+ }])
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ console.error(err)
|
|
|
+ throw err
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const checkPPTFile = async (jsonObj: any) => {
|
|
|
+ const res = await api.getPPTFile(props.courseid as string, props.cid as string)
|
|
|
+ console.log(res)
|
|
|
+ const data1 = res[0]
|
|
|
+ const data2 = res[1]
|
|
|
+ const data3 = res[2]
|
|
|
+ console.log(data1, data2, data3)
|
|
|
+ if (res[0].length) {
|
|
|
+ pptJsonFileid.value = data1[0][0].fileid
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ const pptJsonFile = new File([jsonObj], courseDetail.value.courseName + '.json', { type: 'application/json' })
|
|
|
+ uploadFile2(pptJsonFile, props.courseid as string)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
const getCourseDetail = async () => {
|
|
|
isLoading.value = true
|
|
|
try {
|
|
|
@@ -2104,6 +2186,7 @@ const getCourseDetail = async () => {
|
|
|
jsonStr = new TextDecoder('utf-8').decode(uint8Array)
|
|
|
try {
|
|
|
const jsonObj = JSON.parse(jsonStr)
|
|
|
+ checkPPTFile(jsonObj)
|
|
|
importJSON(jsonObj)
|
|
|
}
|
|
|
catch (e) {
|