|
@@ -0,0 +1,126 @@
|
|
|
+import { PropType, defineComponent, onMounted, reactive, ref } from 'vue';
|
|
|
+import ResourceSearchGroup from './resource-search-group';
|
|
|
+import { NScrollbar, NSpin } from 'naive-ui';
|
|
|
+import styles from './index.module.less';
|
|
|
+import CardType from '/src/components/card-type';
|
|
|
+import { materialQueryPage } from '/src/views/natural-resources/api';
|
|
|
+import TheEmpty from '/src/components/TheEmpty';
|
|
|
+
|
|
|
+const formatType = (type: string) => {
|
|
|
+ if (type === 'shareResources') {
|
|
|
+ return 2;
|
|
|
+ } else if (type === 'myResources') {
|
|
|
+ return 3;
|
|
|
+ } else if (type === 'myCollect') {
|
|
|
+ return 4;
|
|
|
+ }
|
|
|
+};
|
|
|
+export default defineComponent({
|
|
|
+ name: 'share-resources',
|
|
|
+ props: {
|
|
|
+ type: {
|
|
|
+ type: String as PropType<'shareResources' | 'myResources' | 'myCollect'>,
|
|
|
+ default: 'shareResources'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ setup(props) {
|
|
|
+ const state = reactive({
|
|
|
+ loading: false,
|
|
|
+ finshed: false, // 是否加载完
|
|
|
+ pagination: {
|
|
|
+ page: 1,
|
|
|
+ rows: 20
|
|
|
+ },
|
|
|
+ searchGroup: {
|
|
|
+ type: props.type === 'shareResources' ? 'MUSIC' : '', //
|
|
|
+ keyword: '',
|
|
|
+ bookVersionId: null,
|
|
|
+ subjectId: null,
|
|
|
+ sourceType: formatType(props.type),
|
|
|
+ enableFlag: true
|
|
|
+ },
|
|
|
+ tableList: [] as any
|
|
|
+ });
|
|
|
+ const getList = async () => {
|
|
|
+ try {
|
|
|
+ if (state.pagination.page === 1) {
|
|
|
+ state.loading = true;
|
|
|
+ }
|
|
|
+ const { data } = await materialQueryPage({
|
|
|
+ ...state.searchGroup,
|
|
|
+ ...state.pagination
|
|
|
+ });
|
|
|
+ state.loading = false;
|
|
|
+ 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,
|
|
|
+ content: row.content
|
|
|
+ });
|
|
|
+ });
|
|
|
+ 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();
|
|
|
+ };
|
|
|
+
|
|
|
+ onMounted(() => {
|
|
|
+ getList();
|
|
|
+ });
|
|
|
+ return () => (
|
|
|
+ <div>
|
|
|
+ <ResourceSearchGroup onSearch={(item: any) => onSearch(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
|
|
|
+ ) {
|
|
|
+ state.pagination.page = state.pagination.page + 1;
|
|
|
+ getList();
|
|
|
+ }
|
|
|
+ }}>
|
|
|
+ <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 item={item} />
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ {!state.loading && state.tableList.length <= 0 && <TheEmpty />}
|
|
|
+ </div>
|
|
|
+ </NSpin>
|
|
|
+ </NScrollbar>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+});
|