index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { defineComponent, onMounted, reactive } from 'vue';
  2. import styles from './index.module.less';
  3. import CardType from '/src/components/card-type';
  4. import Pagination from '/src/components/pagination';
  5. import SearchGroupResources from './search-group-resources';
  6. import { materialQueryPage } from '../../api';
  7. import { NModal, NSpin } from 'naive-ui';
  8. import TheEmpty from '/src/components/TheEmpty';
  9. import CardPreview from '/src/components/card-preview';
  10. export default defineComponent({
  11. name: 'share-resources',
  12. setup() {
  13. const state = reactive({
  14. searchWord: '',
  15. loading: false,
  16. pageTotal: 0,
  17. pagination: {
  18. page: 1,
  19. rows: 20
  20. },
  21. searchGroup: {
  22. type: 'MUSIC', //
  23. keyword: '',
  24. bookVersionId: null,
  25. subjectId: null,
  26. sourceType: 2
  27. },
  28. tableList: [] as any,
  29. teachingStatus: false,
  30. show: false,
  31. item: {} as any
  32. });
  33. const getList = async () => {
  34. try {
  35. state.loading = true;
  36. const { data } = await materialQueryPage({
  37. ...state.searchGroup,
  38. ...state.pagination
  39. });
  40. state.loading = false;
  41. state.pageTotal = Number(data.total);
  42. state.tableList = data.rows || [];
  43. } catch {
  44. state.loading = false;
  45. }
  46. };
  47. const onSearch = async (item: any) => {
  48. state.pagination.page = 1;
  49. state.searchGroup = Object.assign(state.searchGroup, item);
  50. console.log(item, state.searchGroup);
  51. getList();
  52. };
  53. onMounted(() => {
  54. getList();
  55. });
  56. return () => (
  57. <>
  58. <SearchGroupResources
  59. onSearch={(item: any) => onSearch(item)}
  60. onAdd={() => (state.teachingStatus = true)}
  61. />
  62. <NSpin v-model:show={state.loading}>
  63. <div class={styles.list}>
  64. {state.tableList.map((item: any) => {
  65. const tmpItem = {
  66. id: item.id,
  67. coverImg: item.coverImg,
  68. type: item.type,
  69. title: item.name,
  70. isCollect: !!item.favoriteFlag,
  71. isSelected: item.sourceFrom === 'PLATFORM' ? true : false,
  72. content: item.content
  73. };
  74. return (
  75. <CardType
  76. item={tmpItem}
  77. onClick={(val: any) => {
  78. state.show = true;
  79. state.item = val;
  80. }}
  81. />
  82. );
  83. })}
  84. {!state.loading && state.tableList.length <= 0 && (
  85. <TheEmpty description="暂无共享资源" />
  86. )}
  87. </div>
  88. </NSpin>
  89. <Pagination
  90. v-model:page={state.pagination.page}
  91. v-model:pageSize={state.pagination.rows}
  92. v-model:pageTotal={state.pageTotal}
  93. onList={getList}
  94. />
  95. {/* 弹窗查看 */}
  96. <CardPreview v-model:show={state.show} item={state.item} />
  97. {/* 添加自定义教材 */}
  98. <NModal
  99. v-model:show={state.teachingStatus}
  100. preset="card"
  101. showIcon={false}
  102. class={['modalTitle background', styles.teachingModal]}
  103. title={'自定义教材'}
  104. blockScroll={false}>
  105. 1212
  106. </NModal>
  107. </>
  108. );
  109. }
  110. });