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 '@/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: '', //
  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. content: row.content,
  55. subjectId: row.subjectIds,
  56. enableFlag: row.enableFlag ? 1 : 0,
  57. openFlag: row.openFlag
  58. });
  59. });
  60. state.tableList = temp || [];
  61. setTimeout(() => {
  62. showGuide.value = true;
  63. }, 500);
  64. } catch {
  65. state.loading = false;
  66. }
  67. };
  68. const showGuide = ref(false);
  69. const onSearch = async (item: any) => {
  70. state.pagination.page = 1;
  71. state.searchGroup = Object.assign(state.searchGroup, item);
  72. getList();
  73. };
  74. // 收藏
  75. const onCollect = async (item: any) => {
  76. try {
  77. await favorite({
  78. materialId: item.id,
  79. favoriteFlag: item.isCollect ? 0 : 1,
  80. type: item.type
  81. });
  82. item.isCollect = !item.isCollect;
  83. // onSearch(state.searchGroup);
  84. } catch {
  85. //
  86. }
  87. };
  88. // 单个删除
  89. const onRemove = async (item: any) => {
  90. try {
  91. dialog.warning({
  92. title: '提示',
  93. content: '该资源已下架,是否删除?',
  94. positiveText: '确定',
  95. negativeText: '取消',
  96. onPositiveClick: async () => {
  97. await materialRemove({ id: item.id });
  98. message.success('删除成功');
  99. onSearch(state.searchGroup);
  100. }
  101. });
  102. } catch {
  103. //
  104. }
  105. };
  106. onMounted(() => {
  107. getList();
  108. });
  109. return () => (
  110. <>
  111. <SearchGroupResources onSearch={(item: any) => onSearch(item)} />
  112. <NSpin v-model:show={state.loading} style={{ 'min-height': '50vh' }}>
  113. <div class={styles.list} id="myColloge-0">
  114. {state.tableList.map((item: any) => (
  115. <div class={styles.itemWrap}>
  116. <div class={styles.itemWrapBox}>
  117. <CardType
  118. item={item}
  119. offShelf={item.enableFlag ? false : true}
  120. onOffShelf={() => onRemove(item)}
  121. disabledMouseHover={false}
  122. onClick={(val: any) => {
  123. if (val.type === 'IMG' || !item.enableFlag) return;
  124. state.show = true;
  125. state.item = val;
  126. }}
  127. onCollect={(item: any) => onCollect(item)}
  128. />
  129. </div>
  130. </div>
  131. ))}
  132. {!state.loading && state.tableList.length <= 0 && (
  133. <TheEmpty
  134. style={{ minHeight: '50vh' }}
  135. description="暂无收藏资源"
  136. />
  137. )}
  138. </div>
  139. </NSpin>
  140. <Pagination
  141. v-model:page={state.pagination.page}
  142. v-model:pageSize={state.pagination.rows}
  143. v-model:pageTotal={state.pageTotal}
  144. onList={getList}
  145. />
  146. {/* 弹窗查看 */}
  147. <CardPreview v-model:show={state.show} item={state.item} />
  148. {showGuide.value ? <MyCollogeGuide></MyCollogeGuide> : null}
  149. </>
  150. );
  151. }
  152. });