index.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 {
  8. NButton,
  9. NModal,
  10. NSpace,
  11. NSpin,
  12. useDialog,
  13. useMessage
  14. } from 'naive-ui';
  15. import TheEmpty from '@/components/TheEmpty';
  16. import CardPreview from '@/components/card-preview';
  17. import MyCollogeGuide from '@/custom-plugins/guide-page/myColloge-guide';
  18. export default defineComponent({
  19. name: 'share-resources',
  20. setup() {
  21. const message = useMessage();
  22. const dialog = useDialog();
  23. const state = reactive({
  24. searchWord: '',
  25. loading: false,
  26. pageTotal: 0,
  27. pagination: {
  28. page: 1,
  29. rows: 20
  30. },
  31. searchGroup: {
  32. type: 'MUSIC', //
  33. name: '',
  34. bookVersionId: null,
  35. subjectId: null,
  36. sourceType: 4
  37. },
  38. tableList: [] as any,
  39. show: false,
  40. item: {} as any,
  41. removeVisiable: false,
  42. removeContent: '该资源已下架,是否删除?',
  43. removeItem: {} as any
  44. });
  45. const getList = async () => {
  46. try {
  47. state.loading = true;
  48. const { data } = await materialQueryPage({
  49. ...state.searchGroup,
  50. ...state.pagination
  51. });
  52. state.loading = false;
  53. state.pageTotal = Number(data.total);
  54. const tempRows = data.rows || [];
  55. const temp: any = [];
  56. tempRows.forEach((row: any) => {
  57. temp.push({
  58. id: row.id,
  59. coverImg: row.coverImg,
  60. type: row.type,
  61. title: row.name,
  62. isCollect: !!row.favoriteFlag,
  63. isSelected: row.sourceFrom === 'PLATFORM' ? true : false,
  64. refFlag: row.refFlag,
  65. content: row.content,
  66. subjectId: row.subjectIds,
  67. background: row.background,
  68. enableFlag: row.enableFlag ? 1 : 0,
  69. openFlag: row.openFlag
  70. });
  71. });
  72. state.tableList = temp || [];
  73. setTimeout(() => {
  74. showGuide.value = true;
  75. }, 500);
  76. } catch {
  77. state.loading = false;
  78. }
  79. };
  80. const showGuide = ref(false);
  81. const onSearch = async (item: any) => {
  82. state.pagination.page = 1;
  83. const { subjectId, ...res } = item;
  84. state.searchGroup = Object.assign(state.searchGroup, {
  85. ...res,
  86. musicalInstrumentId: subjectId,
  87. subjectId: null
  88. });
  89. getList();
  90. };
  91. // 收藏
  92. const onCollect = async (item: any) => {
  93. try {
  94. await favorite({
  95. materialId: item.id,
  96. favoriteFlag: item.isCollect ? 0 : 1,
  97. type: item.type
  98. });
  99. item.isCollect = !item.isCollect;
  100. // onSearch(state.searchGroup);
  101. } catch {
  102. //
  103. }
  104. };
  105. // 单个删除
  106. const onRemove = async () => {
  107. try {
  108. // await materialRemove({ ids: state.removeItem.id });
  109. await favorite({
  110. materialId: state.removeItem.id,
  111. favoriteFlag: 0,
  112. type: state.removeItem.type
  113. });
  114. message.success('删除成功');
  115. onSearch(state.searchGroup);
  116. } catch {
  117. //
  118. }
  119. };
  120. onMounted(() => {
  121. getList();
  122. });
  123. return () => (
  124. <>
  125. <SearchGroupResources onSearch={(item: any) => onSearch(item)} />
  126. <NSpin v-model:show={state.loading} style={{ 'min-height': '50vh' }}>
  127. <div class={styles.list} id="myColloge-0">
  128. {state.tableList.map((item: any) => (
  129. <div class={styles.itemWrap}>
  130. <div class={styles.itemWrapBox}>
  131. <CardType
  132. item={item}
  133. offShelf={item.enableFlag ? false : true}
  134. onOffShelf={() => {
  135. state.removeVisiable = true;
  136. state.removeItem = item;
  137. }}
  138. disabledMouseHover={false}
  139. onClick={(val: any) => {
  140. if (val.type === 'IMG' || !item.enableFlag) return;
  141. state.show = true;
  142. state.item = val;
  143. }}
  144. onCollect={(item: any) => onCollect(item)}
  145. />
  146. </div>
  147. </div>
  148. ))}
  149. {!state.loading && state.tableList.length <= 0 && (
  150. <TheEmpty
  151. style={{ minHeight: '50vh' }}
  152. description="暂无收藏资源"
  153. />
  154. )}
  155. </div>
  156. </NSpin>
  157. <Pagination
  158. v-model:page={state.pagination.page}
  159. v-model:pageSize={state.pagination.rows}
  160. v-model:pageTotal={state.pageTotal}
  161. onList={getList}
  162. />
  163. {/* 弹窗查看 */}
  164. <CardPreview v-model:show={state.show} item={state.item} />
  165. {showGuide.value ? <MyCollogeGuide></MyCollogeGuide> : null}
  166. <NModal
  167. v-model:show={state.removeVisiable}
  168. preset="card"
  169. class={['modalTitle', styles.removeVisiable]}
  170. title={'提示'}>
  171. <div class={styles.studentRemove}>
  172. <p>{state.removeContent}</p>
  173. <NSpace class={styles.btnGroupModal} justify="center">
  174. <NButton
  175. round
  176. type="primary"
  177. onClick={() => {
  178. onRemove();
  179. state.removeVisiable = false;
  180. }}>
  181. 确定
  182. </NButton>
  183. <NButton round onClick={() => (state.removeVisiable = false)}>
  184. 取消
  185. </NButton>
  186. </NSpace>
  187. </div>
  188. </NModal>
  189. </>
  190. );
  191. }
  192. });