import { defineComponent, onMounted, reactive, ref } from 'vue'; import styles from './index.module.less'; import { NButton, NCascader, NInput, NSelect, NSwitch, NTooltip } from 'naive-ui'; import { usePrepareStore } from '/src/store/modules/prepareLessons'; import { eventGlobal } from '/src/utils'; import { useCatchStore } from '/src/store/modules/catchData'; import deepClone from '/src/helpers/deep-clone'; export default defineComponent({ name: 'courseware-head', setup(props, { emit, expose }) { const prepareStore = usePrepareStore(); // 第一个课件标题,第二个课件声部 const checkForms = ref(['', '']); const subjectList = ref([] as any); const forms = reactive({ subjects: [] as any, openFlagEnable: true, // 是否支持修改公开状态 autoPlay: true, name: '', openFlag: false }); // 全选 const chioseAll = (list: any) => { // 全选 const ids = [] as any; list.map((item: any) => { if (Array.isArray(item.instruments)) { item.instruments.forEach((c: any) => { ids.push(c.value); }); } }) as any; // item.instrumentIds = ids; forms.subjects = ids; }; const getForms = () => { return forms; }; const updateDefaultInfo = (item: any) => { forms.subjects = item.subjects; forms.openFlagEnable = item.openFlagEnable; forms.autoPlay = item.autoPlay; forms.name = item.name; forms.openFlag = item.openFlag; updateSubjectList(item.subjects || []); }; const checkCoursewareForm = () => { // checkForms.value[0] = forms.name ? '' : 'error'; checkForms.value[1] = forms.subjects?.length > 0 ? '' : 'error'; }; const updateSubjectList = (ids?: any[]) => { // 获取课件乐器编号 ,修改的乐器编号,集合 ids = ids || []; const courseIds: any = []; prepareStore.getInstrumentList.forEach((item: any) => { if (Array.isArray(item.instruments)) { item.instruments.forEach((child: any) => { courseIds.push(child.id); }); } }); const allIds = [...new Set([...courseIds, ...ids])]; const tempList: any = []; useCatchStore().getSubjectList.forEach((item: any) => { const temp = deepClone(item); temp.enableFlag = false; if (Array.isArray(temp.instruments)) { temp.instruments.forEach((child: any) => { child.enableFlag = false; if (allIds.includes(child.id)) { child.enableFlag = true; temp.enableFlag = true; } }); } tempList.push(temp); }); const tempSubjects: any[] = []; tempList.forEach((subject: any) => { if (subject.enableFlag) { const { instruments, ...r } = subject; if (instruments && instruments.length > 0) { const tempChild: any[] = []; instruments?.forEach((instrument: any) => { if (instrument.enableFlag) { tempChild.push(instrument); } }); if (tempChild.length > 0) tempSubjects.push({ ...r, instruments: tempChild }); } } }); subjectList.value = tempSubjects; }; onMounted(async () => { await useCatchStore().getSubjects(); updateSubjectList(); eventGlobal.on('updateCoursewareHeadInfo', updateDefaultInfo); eventGlobal.on('checkCoursewareForm', checkCoursewareForm); }); expose({ getForms }); return () => ( <>
{prepareStore.getSelectName}
*课件标题 { checkForms.value[0] = forms.name ? '' : 'error'; }} />
*课件乐器 {/* ( <> chioseAll(prepareStore.getSubjectList)}> 全选 ) }} onUpdate:value={() => { checkForms.value[1] = forms.subjects?.length > 0 ? '' : 'error'; }} /> */} { checkForms.value[1] = forms.subjects?.length > 0 ? '' : 'error'; }} v-slots={{ action: () => ( <> chioseAll(subjectList.value)}> 全选 ) }} />
自动播放 {{ trigger: () => , default: () => '开启自动播放后,课件内视频、音频资源将自动播放' }}
公开课件 {{ trigger: () => , default: () => '公开课件后,其它老师可以使用该课件上课' }} {!forms.openFlagEnable ? ( {{ trigger: () => ( ), default: () => '为尊重课件原作者,在“相关课件”中添加的课件不支持公开' }} ) : ( )}
); } });