index.tsx 5.6 KB

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