From c298e1c0a2020d7740a731e396573b9363b3cbe9 Mon Sep 17 00:00:00 2001 From: zdg Date: Mon, 16 Dec 2024 15:01:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ppt=20-=E4=BC=98=E5=8C=96=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/AixPPTist/src/api/index.ts | 11 +- .../ElementStylePanel/Active/index.vue | 156 +++++------------- 2 files changed, 51 insertions(+), 116 deletions(-) diff --git a/src/renderer/src/AixPPTist/src/api/index.ts b/src/renderer/src/AixPPTist/src/api/index.ts index ccf7909..685c367 100644 --- a/src/renderer/src/AixPPTist/src/api/index.ts +++ b/src/renderer/src/AixPPTist/src/api/index.ts @@ -158,11 +158,13 @@ export class PPTApi { } } } - // 更新幻灯片 - static updateSlide(data: object): Promise { + // 更新幻灯片 isThum 是否更新缩略图 + static updateSlide(data: object, isThum = true): Promise { return new Promise(async (resolve, reject) => { - const thumUrl = await this.getSlideThumUrl() - data.base64Code = thumUrl // 更新缩略图 + if (isThum) { // 更新缩略图 + const thumUrl = await this.getSlideThumUrl() + data.base64Code = thumUrl // 更新缩略图 + } const res: Result = await API_entpcoursefile.updateEntpcoursefileNew(data) if (res.code === 200) { resolve(true) @@ -222,7 +224,6 @@ export class PPTApi { // const workIds = res?.data?.activityContent||'' // workItem-获取作业id const workIds = workItem.find(o => o.id == slideId)?.activityContent - console.log('更新-活动列表', workItem, currentSlide, slideId, workIds) if (!workIds) return resolveData(resolve) // 获取作业列表 const resW = await API_classwork.homeworklist({ ids: workIds, pageSize: 1000 }) diff --git a/src/renderer/src/AixPPTist/src/views/Editor/Toolbar/ElementStylePanel/Active/index.vue b/src/renderer/src/AixPPTist/src/views/Editor/Toolbar/ElementStylePanel/Active/index.vue index 7bba00e..0b09412 100644 --- a/src/renderer/src/AixPPTist/src/views/Editor/Toolbar/ElementStylePanel/Active/index.vue +++ b/src/renderer/src/AixPPTist/src/views/Editor/Toolbar/ElementStylePanel/Active/index.vue @@ -39,7 +39,7 @@
{{item.uniquekey}}
- 删除 + 删除 @@ -94,7 +94,6 @@ import {useSlidesStore} from '../../../../../store' import { updateEntpcoursefileNew } from '@/api/education/entpcoursefile' const slidesStore = useSlidesStore() const { slides, slideIndex, currentSlide, workItem } = storeToRefs(slidesStore) -console.log('slidesStore',slidesStore.workList) interface CourseNode { rootid: number; parentNode: { id: number }; @@ -174,63 +173,27 @@ const type = ref([ } ]) -const objItem = ref({}) -// 作业列表 -const workList = ref([]) - // 获取所选择的作业列表 const selectedWorkList = ref([]) // 活动页面的loading框 const loadingActive = ref(false) - -const paramData = ref<{ id: number, activityContent: string }>({} as { id: number, activityContent: string }) - +// 选择活动列表 const selectable = (row: WorkItem, index: number): boolean => { return row.status === '10'; }; - -const formatClassWorkFile = async (postData: WorkItem[]): Promise => { - for (let i = 0; i < postData.length; i++) { - let item = postData[i]; - switch (item.worktype) { - case '框架梳理': { - } - break; - case '习题训练': { - // let workIds = item.quizlist!.map(items => items.id).join(','); - // let ress = await listEntpcoursework({ ids: workIds }); - // const arr = ress.rows.map((item:{id:number}) => { - // return item.id - // }) - - // processList(ress.rows); - } - break; - case '课堂展示': { - // item.base64 = JSON.parse(item.workcodes).base64; - } - break; - case '常规作业': { - // item.prevData = JSON.parse(item.workcodes); - } - } - workList.value.push(item) - loadingActive.value = false - } - await nextTick(); -}// 删除作业 -const handleRemoveDemoActivityClassWork = (item: WorkItem) => { +// 删除作业 +const removeWork = (item: WorkItem, index: number) => { ElMessageBox.confirm('是否确认删除?') - .then(() => { - workList.value = [] - const arr = paramData.value.activityContent.split(',') - const filterArr = arr.filter(itemId => itemId!== item.id.toString()) - paramData.value.activityContent = filterArr.join(',') - upDateData() - }) - .catch(() => { }); + .then(async() => { + // 从workList中删除 + // slidesStore.workList.splice(index, 1) + console.log('删除作业', item) + await upDateData('del', [item.id]) + ElMessage.success('删除成功') + }) + .catch(() => { }); } // 获取tag的样式 @@ -257,6 +220,7 @@ const showDialog = (item: string) => { dialogVisible.value = true } +// 打开活动引用列表 const openList = () => { activeVisible.value = true initHomeWork() @@ -264,65 +228,44 @@ const openList = () => { // 添加活动引用列表作业 const savePPtData = async () => { - if (selectedWorkList.value.length === 0) { - ElMessage.warning('请选择活动') - return - } - workList.value = [] - const arr = selectedWorkList.value.map(item => item.id) - // 应该是新加而不是覆盖 - const existingIds = paramData.value.activityContent ? paramData.value.activityContent.split(',') : [] - paramData.value.activityContent = Array.from(new Set([...existingIds, ...arr])).join(',') - upDateData() - activeVisible.value = false -} - -// 获取当前ppt页的数据 -const getCurrentPPtData = async () => { - workList.value = [] - objItem.value = workItem.value[slideIndex.value] - paramData.value.id = objItem.value.id - - paramData.value.activityContent = objItem.value?.activityContent - if (objItem.value?.activityContent) { - loadingActive.value = true - const res = await homeworklist({ ids: objItem.value?.activityContent, pageSize: 100 }) - await formatClassWorkFile(res.rows) - } + if (!selectedWorkList.value.length) { + ElMessage.warning('请选择活动') + return + } + const arr = selectedWorkList.value.map(item => item.id) + await upDateData('add', arr) + activeVisible.value = false } // 接收习题训练的值 const getData = async (data: WorkItem) => { - workList.value = [] - if(paramData.value.activityContent){ - const arr = paramData.value.activityContent.split(',') - arr.push(data.id.toString()) - const unitArr = Array.from(new Set(arr)) - paramData.value.activityContent = unitArr.join(',') - }else{ - paramData.value.activityContent = data.id.toString() - } - upDateData() - dialogVisible.value = false + await upDateData('add', [data.id]) + dialogVisible.value = false } -const upDateData = async () => { +// 更新数据-活动 type add/增加 | del/删除 ids 作业id +const upDateData = (type: string, ids: number[]): Promise => { + return new Promise(async (resolve, reject) => { loadingActive.value = true - await PPTApi.updateSlide(paramData.value) - // await updateEntpcoursefileNew(paramData.value) - const resource = sessionStore.get('curr.resource') - await PPTApi.getSlideList(resource.id) - const res = await homeworklist({ ids: paramData.value.activityContent, pageSize: 100 }) - await formatClassWorkFile(res.rows) -} -// 判断是否做操作 -const objectsAreEqual = (obj1: Record, obj2: Record) => { - const keys1 = Object.keys(obj1); - const keys2 = Object.keys(obj2); - if (keys1.length !== keys2.length) return false; - for (const key of keys1) { - if (obj1[key] !== obj2[key]) return false; + // 更新本地数据 + let workIds = slidesStore.workList.map((o:any) => o.id) + const id = slidesStore.currentSlide.id + if (type === 'del') { // 删除 + workIds = workIds.filter(id => !ids.includes(id)) + } else { // 增加 + workIds = Array.from(new Set([...workIds, ...ids])) } - return true; + // 保存到本地 + const wItem:any = slidesStore.workItem.find((o:any) => o.id === id) + const workIdsStr = workIds.join(',') // 作业id->字符串 + if (!!wItem) wItem.activityContent = workIdsStr + const data = { id, activityContent: workIdsStr } + // 修改数据库 + await PPTApi.updateSlide(data, false) + // 刷新活动列表 + await PPTApi.updateWorkList() + loadingActive.value = false + resolve(true) + }) } onMounted(() => { @@ -332,17 +275,8 @@ onMounted(() => { currentCourse.levelSecondId = curNode.id currentCourse.coursetitle = curNode.itemtitle currentCourse.node = curNode - // objItem.value = workItem.value[slideIndex.value] - // getCurrentPPtData() }) -watch(() => [workItem.value.length,workItem.value[slideIndex.value]?.id], (newVal,oldVal) => { - if(!objectsAreEqual(newVal,oldVal)) - if(workItem.value[slideIndex.value]) - getCurrentPPtData() -}) -// watch(() => workItem.value.length, () => { -// getCurrentPPtData() -// }) +