|
@@ -1,165 +1,63 @@
|
|
|
-import { NScrollbar, NSpin, NTabPane, NTabs } from 'naive-ui';
|
|
|
-import { PropType, defineComponent, onMounted, reactive } from 'vue';
|
|
|
+import { NTabPane, NTabs } from 'naive-ui';
|
|
|
+import { defineComponent, onMounted, ref, toRefs } from 'vue';
|
|
|
import styles from './index.module.less';
|
|
|
-import CardType from '@/components/card-type';
|
|
|
-import SearchGroup from './search-group';
|
|
|
-import TheEmpty from '/src/components/TheEmpty';
|
|
|
-import { useDebounceFn, useThrottleFn } from '@vueuse/core';
|
|
|
-import { usePrepareStore } from '/src/store/modules/prepareLessons';
|
|
|
-import { musicSheetPage } from '../../api';
|
|
|
-import CardPreview from '/src/components/card-preview';
|
|
|
+import SelectItem from './select-item';
|
|
|
+import { useResizeObserver } from '@vueuse/core';
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'select-music',
|
|
|
props: {
|
|
|
type: {
|
|
|
type: String,
|
|
|
+ default: 'myResources'
|
|
|
+ },
|
|
|
+ /** 从哪里使用 */
|
|
|
+ from: {
|
|
|
+ type: String,
|
|
|
default: ''
|
|
|
}
|
|
|
},
|
|
|
- emits: ['add'],
|
|
|
- setup(props, { emit }) {
|
|
|
- console.log(props.type);
|
|
|
- const prepareStore = usePrepareStore();
|
|
|
- const state = reactive({
|
|
|
- loading: false,
|
|
|
- finshed: false, // 是否加载完
|
|
|
- pagination: {
|
|
|
- page: 1,
|
|
|
- rows: 20
|
|
|
- },
|
|
|
- searchGroup: {
|
|
|
- name: '',
|
|
|
- musicSheetCategoriesId: '',
|
|
|
- status: 1,
|
|
|
- versionFlag: false,
|
|
|
- subjectId: null
|
|
|
- },
|
|
|
- tableList: [] as any,
|
|
|
- show: false,
|
|
|
- item: {} as any,
|
|
|
- isShowAddDisabled: !prepareStore.getIsEditTrain
|
|
|
- });
|
|
|
- const getList = async () => {
|
|
|
- try {
|
|
|
- if (state.pagination.page === 1) {
|
|
|
- state.loading = true;
|
|
|
- }
|
|
|
- const { data } = await musicSheetPage({
|
|
|
- ...state.searchGroup,
|
|
|
- ...state.pagination,
|
|
|
- subjectId: prepareStore.getSubjectId
|
|
|
- });
|
|
|
- state.loading = false;
|
|
|
- const tempRows = data.rows || [];
|
|
|
- const temp: any = [];
|
|
|
- tempRows.forEach((row: any) => {
|
|
|
- temp.push({
|
|
|
- id: row.id,
|
|
|
- coverImg: row.musicSvg,
|
|
|
- type: 'MUSIC',
|
|
|
- title: row.musicSheetName,
|
|
|
- isCollect: false,
|
|
|
- isSelected: true,
|
|
|
- content: row.id,
|
|
|
- xmlFileUrl: row.xmlFileUrl
|
|
|
- });
|
|
|
- });
|
|
|
- state.tableList.push(...temp);
|
|
|
-
|
|
|
- state.finshed = data.pages <= data.current ? true : false;
|
|
|
- } catch {
|
|
|
- state.loading = false;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // const onSearch = async (item: any) => {
|
|
|
- // state.pagination.page = 1;
|
|
|
- // state.tableList = [];
|
|
|
- // state.searchGroup = Object.assign(state.searchGroup, item);
|
|
|
- // getList();
|
|
|
- // };
|
|
|
- const throttledFnSearch = useDebounceFn(item => {
|
|
|
- state.pagination.page = 1;
|
|
|
- state.tableList = [];
|
|
|
- state.searchGroup = Object.assign(state.searchGroup, item);
|
|
|
- getList();
|
|
|
- }, 500);
|
|
|
-
|
|
|
- const throttledFn = useThrottleFn(() => {
|
|
|
- state.pagination.page = state.pagination.page + 1;
|
|
|
- getList();
|
|
|
- }, 500);
|
|
|
+ emits: ['select'],
|
|
|
+ setup(props) {
|
|
|
+ const { type } = toRefs(props);
|
|
|
+ const tabType = ref(type.value);
|
|
|
|
|
|
onMounted(() => {
|
|
|
- if (props.type === 'homework') {
|
|
|
- state.isShowAddDisabled = false;
|
|
|
- }
|
|
|
- getList();
|
|
|
+ useResizeObserver(
|
|
|
+ document.querySelector(
|
|
|
+ '.select-resource .n-tabs-nav--top'
|
|
|
+ ) as HTMLElement,
|
|
|
+ (entries: any) => {
|
|
|
+ const entry = entries[0];
|
|
|
+ const { height } = entry.contentRect;
|
|
|
+ document.documentElement.style.setProperty(
|
|
|
+ '--modal-lesson-tab-height',
|
|
|
+ height + 'px'
|
|
|
+ );
|
|
|
+ }
|
|
|
+ );
|
|
|
});
|
|
|
return () => (
|
|
|
- <div class={styles.selectMusic}>
|
|
|
+ <div class={[styles.selectMusic, 'select-resource']}>
|
|
|
<NTabs
|
|
|
animated
|
|
|
- defaultValue="shareResources"
|
|
|
+ value={tabType.value}
|
|
|
paneClass={styles.paneTitle}
|
|
|
justifyContent="center"
|
|
|
- paneWrapperClass={styles.paneWrapperContainer}>
|
|
|
- <NTabPane name="shareResources" tab="选择曲目">
|
|
|
- <SearchGroup onSearch={(item: any) => throttledFnSearch(item)} />
|
|
|
- <NScrollbar
|
|
|
- class={styles.listContainer}
|
|
|
- onScroll={(e: any) => {
|
|
|
- const clientHeight = e.target?.clientHeight;
|
|
|
- const scrollTop = e.target?.scrollTop;
|
|
|
- const scrollHeight = e.target?.scrollHeight;
|
|
|
- // 是否到底,是否加载完
|
|
|
- if (
|
|
|
- clientHeight + scrollTop + 20 >= scrollHeight &&
|
|
|
- !state.finshed &&
|
|
|
- !state.loading
|
|
|
- ) {
|
|
|
- throttledFn();
|
|
|
- }
|
|
|
- }}>
|
|
|
- <NSpin show={state.loading} size={'small'}>
|
|
|
- <div
|
|
|
- class={[
|
|
|
- styles.listSection,
|
|
|
- !state.loading && state.tableList.length <= 0
|
|
|
- ? styles.emptySection
|
|
|
- : ''
|
|
|
- ]}>
|
|
|
- {state.tableList.length > 0 && (
|
|
|
- <div class={styles.list}>
|
|
|
- {state.tableList.map((item: any) => (
|
|
|
- <CardType
|
|
|
- isShowAdd
|
|
|
- isShowCollect={false}
|
|
|
- item={item}
|
|
|
- // isShowAddDisabled={state.isShowAddDisabled}
|
|
|
- onAdd={() => emit('add', item)}
|
|
|
- disabledMouseHover={false}
|
|
|
- onClick={() => {
|
|
|
- if (item.type === 'IMG') return;
|
|
|
- state.show = true;
|
|
|
- state.item = item;
|
|
|
- }}
|
|
|
- />
|
|
|
- ))}
|
|
|
- </div>
|
|
|
- )}
|
|
|
- {!state.loading && state.tableList.length <= 0 && (
|
|
|
- <TheEmpty />
|
|
|
- )}
|
|
|
- </div>
|
|
|
- </NSpin>
|
|
|
- </NScrollbar>
|
|
|
+ paneWrapperClass={styles.paneWrapperContainer}
|
|
|
+ onUpdate:value={(val: string) => {
|
|
|
+ tabType.value = val;
|
|
|
+ }}>
|
|
|
+ <NTabPane name="myResources" tab={'我的曲目'}>
|
|
|
+ <SelectItem type="myResources" />
|
|
|
+ </NTabPane>
|
|
|
+ <NTabPane name="shareResources" tab={'共享曲目'}>
|
|
|
+ <SelectItem type="shareResources" />
|
|
|
+ </NTabPane>
|
|
|
+ <NTabPane name="myCollect" tab="收藏曲目">
|
|
|
+ <SelectItem type="myCollect" />
|
|
|
</NTabPane>
|
|
|
</NTabs>
|
|
|
-
|
|
|
- {/* 弹窗查看 */}
|
|
|
- <CardPreview v-model:show={state.show} item={state.item} />
|
|
|
</div>
|
|
|
);
|
|
|
}
|