index.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import { defineComponent, onMounted, reactive, ref } 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 { favorite, 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. import AddTeaching from '../../model/add-teaching';
  11. import ShareResourcesGuide from '@/custom-plugins/guide-page/shareResources-guide';
  12. export default defineComponent({
  13. name: 'share-resources',
  14. setup() {
  15. const state = reactive({
  16. searchWord: '',
  17. loading: false,
  18. pageTotal: 0,
  19. pagination: {
  20. page: 1,
  21. rows: 20
  22. },
  23. searchGroup: {
  24. type: 'MUSIC', //
  25. name: '',
  26. bookVersionId: null,
  27. subjectId: null,
  28. sourceType: 2
  29. },
  30. tableList: [] as any,
  31. teachingStatus: false,
  32. show: false,
  33. item: {} as any
  34. });
  35. const showGuide = ref(false);
  36. const getList = async () => {
  37. try {
  38. state.loading = true;
  39. const { data } = await materialQueryPage({
  40. ...state.searchGroup,
  41. ...state.pagination
  42. });
  43. state.loading = false;
  44. state.pageTotal = Number(data.total);
  45. const tempRows = data.rows || [];
  46. const temp: any = [];
  47. tempRows.forEach((row: any) => {
  48. temp.push({
  49. id: row.id,
  50. coverImg: row.coverImg,
  51. type: row.type,
  52. title: row.name,
  53. isCollect: !!row.favoriteFlag,
  54. isSelected: row.sourceFrom === 'PLATFORM' ? true : false,
  55. content: row.content
  56. });
  57. });
  58. state.tableList = temp || [];
  59. setTimeout(() => {
  60. showGuide.value = true;
  61. }, 500);
  62. } catch {
  63. state.loading = false;
  64. }
  65. };
  66. const onSearch = async (item: any) => {
  67. state.pagination.page = 1;
  68. state.searchGroup = Object.assign(state.searchGroup, item);
  69. getList();
  70. };
  71. // 收藏
  72. const onCollect = async (item: any) => {
  73. try {
  74. await favorite({
  75. materialId: item.id,
  76. favoriteFlag: item.isCollect ? 0 : 1,
  77. type: item.type
  78. });
  79. item.isCollect = !item.isCollect;
  80. } catch {
  81. //
  82. }
  83. };
  84. onMounted(() => {
  85. getList();
  86. });
  87. return () => (
  88. <>
  89. <SearchGroupResources
  90. onSearch={(item: any) => onSearch(item)}
  91. onAdd={() => (state.teachingStatus = true)}
  92. />
  93. <NSpin v-model:show={state.loading} style={{ 'min-height': '50vh' }}>
  94. <div class={styles.list}>
  95. {state.tableList.map((item: any, index: number) => (
  96. <>
  97. {index == 0 ? (
  98. <CardType
  99. {...{ id: 'shareResources-1' }}
  100. item={item}
  101. disabledMouseHover={false}
  102. onClick={(val: any) => {
  103. if (val.type === 'IMG') return;
  104. state.show = true;
  105. state.item = val;
  106. }}
  107. onCollect={(item: any) => onCollect(item)}
  108. />
  109. ) : (
  110. <CardType
  111. item={item}
  112. disabledMouseHover={false}
  113. onClick={(val: any) => {
  114. if (val.type === 'IMG') return;
  115. state.show = true;
  116. state.item = val;
  117. }}
  118. onCollect={(item: any) => onCollect(item)}
  119. />
  120. )}
  121. </>
  122. ))}
  123. {!state.loading && state.tableList.length <= 0 && (
  124. <TheEmpty description="暂无共享资源" />
  125. )}
  126. </div>
  127. </NSpin>
  128. <Pagination
  129. v-model:page={state.pagination.page}
  130. v-model:pageSize={state.pagination.rows}
  131. v-model:pageTotal={state.pageTotal}
  132. onList={getList}
  133. />
  134. {/* 弹窗查看 */}
  135. <CardPreview v-model:show={state.show} item={state.item} />
  136. {/* 添加自定义教材 */}
  137. <NModal
  138. v-model:show={state.teachingStatus}
  139. preset="card"
  140. showIcon={false}
  141. class={['modalTitle background', styles.teachingModal]}
  142. title={'自定义教材'}
  143. blockScroll={false}>
  144. <AddTeaching onClose={() => (state.teachingStatus = false)} />
  145. </NModal>
  146. {showGuide.value ? <ShareResourcesGuide></ShareResourcesGuide> : null}
  147. </>
  148. );
  149. }
  150. });