index.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 SearchGroupResourcesRef = ref();
  37. const getList = async () => {
  38. try {
  39. state.loading = true;
  40. const { data } = await materialQueryPage({
  41. ...state.searchGroup,
  42. ...state.pagination
  43. });
  44. state.loading = false;
  45. state.pageTotal = Number(data.total);
  46. const tempRows = data.rows || [];
  47. const temp: any = [];
  48. tempRows.forEach((row: any) => {
  49. temp.push({
  50. id: row.id,
  51. coverImg: row.coverImg,
  52. type: row.type,
  53. title: row.name,
  54. isCollect: !!row.favoriteFlag,
  55. isSelected: row.sourceFrom === 'PLATFORM' ? true : false,
  56. refFlag: row.refFlag,
  57. background: row.background,
  58. content: row.content
  59. });
  60. });
  61. state.tableList = temp || [];
  62. setTimeout(() => {
  63. showGuide.value = true;
  64. }, 500);
  65. } catch {
  66. state.loading = false;
  67. }
  68. };
  69. const onSearch = async (item: any) => {
  70. state.pagination.page = 1;
  71. const { subjectId, ...res } = item;
  72. state.searchGroup = Object.assign(state.searchGroup, {
  73. ...res,
  74. musicalInstrumentId: subjectId,
  75. subjectId: null
  76. });
  77. getList();
  78. };
  79. // 收藏
  80. const onCollect = async (item: any) => {
  81. try {
  82. await favorite({
  83. materialId: item.id,
  84. favoriteFlag: item.isCollect ? 0 : 1,
  85. type: item.type
  86. });
  87. item.isCollect = !item.isCollect;
  88. } catch {
  89. //
  90. }
  91. };
  92. onMounted(() => {
  93. getList();
  94. });
  95. return () => (
  96. <>
  97. <SearchGroupResources
  98. ref={SearchGroupResourcesRef}
  99. onSearch={(item: any) => onSearch(item)}
  100. onAdd={() => (state.teachingStatus = true)}
  101. />
  102. <NSpin v-model:show={state.loading} style={{ 'min-height': '50vh' }}>
  103. <div class={styles.list}>
  104. {state.tableList.map((item: any, index: number) => (
  105. <div class={styles.itemWrap}>
  106. <div class={styles.itemWrapBox}>
  107. {index == 0 ? (
  108. <CardType
  109. {...{ id: 'shareResources-1' }}
  110. item={item}
  111. disabledMouseHover={false}
  112. onClick={(val: any) => {
  113. if (val.type === 'IMG') return;
  114. state.show = true;
  115. state.item = val;
  116. }}
  117. onCollect={(item: any) => onCollect(item)}
  118. />
  119. ) : (
  120. <CardType
  121. item={item}
  122. disabledMouseHover={false}
  123. onClick={(val: any) => {
  124. if (val.type === 'IMG') return;
  125. state.show = true;
  126. state.item = val;
  127. }}
  128. onCollect={(item: any) => onCollect(item)}
  129. />
  130. )}
  131. </div>
  132. </div>
  133. ))}
  134. {!state.loading && state.tableList.length <= 0 && (
  135. <TheEmpty
  136. style={{ minHeight: '50vh' }}
  137. description="暂无共享资源"
  138. />
  139. )}
  140. </div>
  141. </NSpin>
  142. <Pagination
  143. v-model:page={state.pagination.page}
  144. v-model:pageSize={state.pagination.rows}
  145. v-model:pageTotal={state.pageTotal}
  146. onList={getList}
  147. />
  148. {/* 弹窗查看 */}
  149. <CardPreview v-model:show={state.show} item={state.item} />
  150. {/* 添加自定义教材 */}
  151. <NModal
  152. v-model:show={state.teachingStatus}
  153. preset="card"
  154. showIcon={false}
  155. class={['modalTitle background', styles.teachingModal]}
  156. title={'自定义教材'}
  157. blockScroll={false}>
  158. <AddTeaching onClose={() => (state.teachingStatus = false)} />
  159. </NModal>
  160. {showGuide.value ? <ShareResourcesGuide></ShareResourcesGuide> : null}
  161. </>
  162. );
  163. }
  164. });