index.tsx 6.1 KB

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