123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- import { defineComponent, onMounted, reactive } from 'vue';
- import styles from './index.module.less';
- import CardType from '@/components/card-type';
- import Pagination from '@/components/pagination';
- import SearchGroupResources from './search-group-resources';
- import { favorite, materialQueryPage } from '../../api';
- import { NSpin } from 'naive-ui';
- import TheEmpty from '@/components/TheEmpty';
- import CardPreview from '@/components/card-preview';
- export default defineComponent({
- name: 'share-resources',
- setup() {
- const state = reactive({
- searchWord: '',
- loading: false,
- pageTotal: 0,
- pagination: {
- page: 1,
- rows: 20
- },
- searchGroup: {
- type: '', //
- keyword: '',
- bookVersionId: null,
- subjectId: null,
- sourceType: 4
- },
- tableList: [] as any,
- show: false,
- item: {} as any
- });
- const getList = async () => {
- try {
- state.loading = true;
- const { data } = await materialQueryPage({
- ...state.searchGroup,
- ...state.pagination
- });
- state.loading = false;
- state.pageTotal = Number(data.total);
- state.tableList = data.rows || [];
- } catch {
- state.loading = false;
- }
- };
- const onSearch = async (item: any) => {
- state.pagination.page = 1;
- state.searchGroup = Object.assign(state.searchGroup, item);
- getList();
- };
- // 收藏
- const onCollect = async (item: any) => {
- try {
- await favorite({
- materialId: item.id,
- favoriteFlag: item.isCollect ? 0 : 1,
- type: item.type
- });
- item.isCollect = !item.isCollect;
- onSearch();
- } catch {
- //
- }
- };
- onMounted(() => {
- getList();
- });
- return () => (
- <>
- <SearchGroupResources onSearch={(item: any) => onSearch(item)} />
- <NSpin v-model:show={state.loading}>
- <div class={styles.list}>
- {state.tableList.map((item: any) => {
- const tmpItem = {
- id: item.id,
- coverImg: item.coverImg,
- type: item.type,
- title: item.name,
- isCollect: !!item.favoriteFlag,
- isSelected: item.sourceFrom === 'PLATFORM' ? true : false
- };
- return (
- <CardType
- item={tmpItem}
- disabledMouseHover={false}
- onClick={(val: any) => {
- if (val.type === 'IMG') return;
- state.show = true;
- state.item = val;
- }}
- onCollect={(item: any) => onCollect(item)}
- />
- );
- })}
- {!state.loading && state.tableList.length <= 0 && (
- <TheEmpty description="暂无收藏资源" />
- )}
- </div>
- </NSpin>
- <Pagination
- v-model:page={state.pagination.page}
- v-model:pageSize={state.pagination.rows}
- v-model:pageTotal={state.pageTotal}
- onList={getList}
- />
- {/* 弹窗查看 */}
- <CardPreview v-model:show={state.show} item={state.item} />
- </>
- );
- }
- });
|