index.tsx 6.4 KB

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