import { defineComponent, nextTick, onMounted, reactive, ref, watch } from 'vue'; import styles from './index.module.less'; import { NButton, // NBreadcrumb, // NBreadcrumbItem, // NScrollbar, NSlider, NSpace, NSpin } from 'naive-ui'; import iconT from '/src/views/content-information/images/icon-t.png'; import iconAddT from '/src/views/content-information/images/icon-add-t.png'; import iconPlusT from '/src/views/content-information/images/icon-plus-t.png'; import { api_lessonCoursewareDetail_listKnowledge, api_lessonCoursewareKnowledgeDetail } from '/src/views/content-information/api'; import TheEmpty from '/src/components/TheEmpty'; // import { PageEnum } from '/src/enums/pageEnum'; import { useSpeak } from '/src/views/content-information/useSpeak'; export default defineComponent({ name: 'cotnent-knowledge', props: { id: { type: String, default: '' }, type: { type: String, default: '' }, activeStatus: { type: Boolean, default: false } }, emits: ['close', 'confirm'], setup(props, { expose }) { const content = ref(false); const musicContentRef = ref(); const speakMusicContent = 'musicContent' + new Date().getTime() + Math.floor(Math.random() * 100); const selectionCouser = 'selectionCouser' + new Date().getTime() + Math.floor(Math.random() * 100); const speak = useSpeak(speakMusicContent, selectionCouser); const state = reactive({ fontSize: 18, tableList: [] as any, selectKey: null, details: {} as any, domString: '', display: 'block' }); const getDetail = async () => { content.value = true; try { const { data } = await api_lessonCoursewareKnowledgeDetail({ id: props.id }); state.details = data; content.value = false; nextTick(async () => { // 使用 DOMParser 解析 HTML 字符串 // 获取 HTML 字符串 // const htmlString = tempDiv.innerHTML; // console.log(htmlString); const parser = new DOMParser(); const doc = parser.parseFromString(state.details.desc, 'text/html'); const childNodes = doc.body.childNodes; childNodes?.forEach((node: any) => { node?.classList.add('only-child-select'); }); // 提取并分割 HTML 文档中的内容 console.log( speakMusicContent, document.querySelector('#' + speakMusicContent), processNode(doc.body) ); // state.details.desc = ''; // state.display = 'none'; const node: any = speak.processNode(doc.body); document.querySelector('#' + speakMusicContent)?.appendChild(node); }); } catch { // } content.value = false; }; const onStopAll = (type: 'play' | 'pause' | 'pre' | 'next' | 'favitor') => { speak.onCloseSpeak(); }; onMounted(() => { getDetail(); }); watch( () => props.activeStatus, () => { if (!props.activeStatus) { onStopAll('pause'); } } ); expose({ handleChangeAudio: onStopAll }); return () => (
{/*
*/}
{speak.isSpeak.value ? ( 关闭朗读 ) : ( 全文朗读 )}
{state.details?.desc ? (
{/* 选中的内容 */}
开始朗读 只读这段
) : ( '' )} {!content.value && !state.details?.desc && }
{ if (state.fontSize >= 32) return; state.fontSize += 1; }} /> { if (state.fontSize <= 12) return; state.fontSize -= 1; }} />
{/*
*/}
); } });