import { defineComponent, onMounted, reactive, ref } from 'vue'; import styles from './index.module.less'; import CardType from '/src/components/card-type'; import Pagination from '/src/components/pagination'; import SearchGroupResources from './search-group-resources'; import { favorite, materialQueryPage } from '../../api'; import { NModal, NSpin } from 'naive-ui'; import TheEmpty from '/src/components/TheEmpty'; import CardPreview from '/src/components/card-preview'; import AddTeaching from '../../model/add-teaching'; import ShareResourcesGuide from '@/custom-plugins/guide-page/shareResources-guide'; import { modalClickMask } from '/src/state'; export default defineComponent({ name: 'share-resources', setup() { const state = reactive({ searchWord: '', loading: false, pageTotal: 0, pagination: { page: 1, rows: 20 }, searchGroup: { type: 'MUSIC', // name: '', bookVersionId: null, subjectId: null, sourceType: 2 }, tableList: [] as any, teachingStatus: false, show: false, item: {} as any }); const showGuide = ref(false); const SearchGroupResourcesRef = ref(); const getList = async () => { try { state.loading = true; const { data } = await materialQueryPage({ ...state.searchGroup, ...state.pagination }); state.loading = false; state.pageTotal = Number(data.total); const tempRows = data.rows || []; const temp: any = []; tempRows.forEach((row: any) => { temp.push({ id: row.id, coverImg: row.coverImg, type: row.type, title: row.name, isCollect: !!row.favoriteFlag, isSelected: row.sourceFrom === 'PLATFORM' ? true : false, refFlag: row.refFlag, background: row.background, content: row.content }); }); state.tableList = temp || []; setTimeout(() => { showGuide.value = true; }, 500); } catch { state.loading = false; } }; const onSearch = async (item: any) => { state.pagination.page = 1; const { subjectId, ...res } = item; state.searchGroup = Object.assign(state.searchGroup, { ...res, musicalInstrumentId: subjectId, subjectId: null }); getList(); }; // 收藏 const onCollect = async (item: any) => { try { await favorite({ materialId: item.id, favoriteFlag: item.isCollect ? 0 : 1, type: item.type }); item.isCollect = !item.isCollect; } catch { // } }; onMounted(() => { // 会在搜索组件里面调用,因为有初始化搜索条件 // getList(); }); return () => ( <> onSearch(item)} onAdd={() => (state.teachingStatus = true)} />
{state.tableList.map((item: any, index: number) => (
{index == 0 ? ( { if (val.type === 'IMG') return; state.show = true; state.item = val; }} onCollect={(item: any) => onCollect(item)} /> ) : ( { if (val.type === 'IMG') return; state.show = true; state.item = val; }} onCollect={(item: any) => onCollect(item)} /> )}
))} {!state.loading && state.tableList.length <= 0 && ( )}
{/* 弹窗查看 */} {/* 添加自定义教材 */} (state.teachingStatus = false)} /> {showGuide.value ? : null} ); } });