index.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import { defineComponent, onMounted, reactive, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import CardType from '@/components/card-type';
  4. import Pagination from '@/components/pagination';
  5. import SearchGroupResources from './search-group-resources';
  6. import { favorite, materialQueryPage, materialRemove } from '../../api';
  7. import { NSpin, useDialog, useMessage } from 'naive-ui';
  8. import TheEmpty from '@/components/TheEmpty';
  9. import CardPreview from '@/components/card-preview';
  10. import MyCollogeGuide from '@/custom-plugins/guide-page/myColloge-guide';
  11. export default defineComponent({
  12. name: 'share-resources',
  13. setup() {
  14. const message = useMessage();
  15. const dialog = useDialog();
  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: 4
  30. },
  31. tableList: [] as any,
  32. show: false,
  33. item: {} as any
  34. });
  35. const getList = async () => {
  36. try {
  37. state.loading = true;
  38. const { data } = await materialQueryPage({
  39. ...state.searchGroup,
  40. ...state.pagination
  41. });
  42. state.loading = false;
  43. state.pageTotal = Number(data.total);
  44. const tempRows = data.rows || [];
  45. const temp: any = [];
  46. tempRows.forEach((row: any) => {
  47. temp.push({
  48. id: row.id,
  49. coverImg: row.coverImg,
  50. type: row.type,
  51. title: row.name,
  52. isCollect: !!row.favoriteFlag,
  53. isSelected: row.sourceFrom === 'PLATFORM' ? true : false,
  54. refFlag: row.refFlag,
  55. content: row.content,
  56. subjectId: row.subjectIds,
  57. enableFlag: row.enableFlag ? 1 : 0,
  58. openFlag: row.openFlag
  59. });
  60. });
  61. state.tableList = temp || [];
  62. setTimeout(() => {
  63. showGuide.value = true;
  64. }, 500);
  65. } catch {
  66. state.loading = false;
  67. }
  68. };
  69. const showGuide = ref(false);
  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. // onSearch(state.searchGroup);
  90. } catch {
  91. //
  92. }
  93. };
  94. // 单个删除
  95. const onRemove = async (item: any) => {
  96. try {
  97. dialog.warning({
  98. title: '提示',
  99. content: '该资源已下架,是否删除?',
  100. positiveText: '确定',
  101. negativeText: '取消',
  102. onPositiveClick: async () => {
  103. await materialRemove({ id: item.id });
  104. message.success('删除成功');
  105. onSearch(state.searchGroup);
  106. }
  107. });
  108. } catch {
  109. //
  110. }
  111. };
  112. onMounted(() => {
  113. getList();
  114. });
  115. return () => (
  116. <>
  117. <SearchGroupResources onSearch={(item: any) => onSearch(item)} />
  118. <NSpin v-model:show={state.loading} style={{ 'min-height': '50vh' }}>
  119. <div class={styles.list} id="myColloge-0">
  120. {state.tableList.map((item: any) => (
  121. <div class={styles.itemWrap}>
  122. <div class={styles.itemWrapBox}>
  123. <CardType
  124. item={item}
  125. offShelf={item.enableFlag ? false : true}
  126. onOffShelf={() => onRemove(item)}
  127. disabledMouseHover={false}
  128. onClick={(val: any) => {
  129. if (val.type === 'IMG' || !item.enableFlag) return;
  130. state.show = true;
  131. state.item = val;
  132. }}
  133. onCollect={(item: any) => onCollect(item)}
  134. />
  135. </div>
  136. </div>
  137. ))}
  138. {!state.loading && state.tableList.length <= 0 && (
  139. <TheEmpty
  140. style={{ minHeight: '50vh' }}
  141. description="暂无收藏资源"
  142. />
  143. )}
  144. </div>
  145. </NSpin>
  146. <Pagination
  147. v-model:page={state.pagination.page}
  148. v-model:pageSize={state.pagination.rows}
  149. v-model:pageTotal={state.pageTotal}
  150. onList={getList}
  151. />
  152. {/* 弹窗查看 */}
  153. <CardPreview v-model:show={state.show} item={state.item} />
  154. {showGuide.value ? <MyCollogeGuide></MyCollogeGuide> : null}
  155. </>
  156. );
  157. }
  158. });