index.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { PropType, defineComponent, onMounted, reactive } from 'vue';
  2. import styles from './index.module.less';
  3. import SearchGroupResources from './search-group-resources';
  4. import { NImage, NSpin } from 'naive-ui';
  5. import TheEmpty from '/src/components/TheEmpty';
  6. import Pagination from '/src/components/pagination';
  7. import { api_knowledgeWiki_page } from '../../../api';
  8. import { useRouter } from 'vue-router';
  9. export default defineComponent({
  10. name: 'musician-list',
  11. props: {
  12. categoryId: {
  13. type: String,
  14. default: ''
  15. },
  16. categoryChildList: {
  17. type: Array as PropType<any>,
  18. default: () => []
  19. }
  20. },
  21. setup(props) {
  22. // 保存数据
  23. const operationCatch = (
  24. type: 'get' | 'set' = 'get',
  25. value: string = ''
  26. ): any => {
  27. const sessionName = 'content-musician-catch';
  28. if (type === 'get') {
  29. const result = sessionStorage.getItem(sessionName);
  30. return result ? JSON.parse(result) : null;
  31. } else if (type === 'set') {
  32. sessionStorage.setItem(sessionName, value);
  33. }
  34. };
  35. const router = useRouter();
  36. const catchData = operationCatch('get');
  37. const state = reactive({
  38. searchWord: '',
  39. loading: false,
  40. pageTotal: 0,
  41. pagination:catchData && catchData.pagination
  42. ? catchData.pagination
  43. : {
  44. page: 1,
  45. rows: 18
  46. },
  47. searchGroup: catchData && catchData.searchGroup
  48. ? catchData.searchGroup
  49. :{
  50. type: 'MUSICIAN', //
  51. keyword: '',
  52. wikiCategoryId: props.categoryId
  53. },
  54. tableList: [] as any,
  55. teachingStatus: false,
  56. show: false,
  57. item: {} as any
  58. });
  59. const getList = async () => {
  60. state.loading = true;
  61. // 缓存
  62. operationCatch('set', JSON.stringify({
  63. pagination: state.pagination,
  64. searchGroup: state.searchGroup
  65. }))
  66. try {
  67. const { data } = await api_knowledgeWiki_page({
  68. ...state.pagination,
  69. ...state.searchGroup
  70. });
  71. const temp = data.rows || [];
  72. temp.forEach((item: any) => {
  73. if (
  74. item.knowledgeWikiCategories &&
  75. item.knowledgeWikiCategories.length
  76. ) {
  77. item.categories =
  78. item.knowledgeWikiCategories[0].knowledgeWikiCategoryTypeName;
  79. }
  80. });
  81. state.tableList = temp || [];
  82. state.pageTotal = Number(data.total);
  83. } catch {
  84. //
  85. }
  86. state.loading = false;
  87. };
  88. const onSearch = async (item: any) => {
  89. state.pagination.page = 1;
  90. state.searchGroup = Object.assign(state.searchGroup, item);
  91. getList();
  92. };
  93. onMounted(() => {
  94. getList();
  95. });
  96. return () => (
  97. <div class={styles.instrumentList}>
  98. <SearchGroupResources
  99. categoryChildList={props.categoryChildList || []}
  100. wikiCategoryId={state.searchGroup.wikiCategoryId}
  101. defaultWikiCategoryId={props.categoryId}
  102. searchValue={state.searchGroup.keyword}
  103. onSearch={(item: any) => onSearch(item)}
  104. />
  105. <NSpin v-model:show={state.loading} style={{ 'min-height': '50vh' }}>
  106. <div class={styles.list}>
  107. {state.tableList.map((item: any) => (
  108. <div
  109. class={styles.itemWrap}
  110. onClick={() => {
  111. router.push({
  112. path: '/content-musician-detail',
  113. query: {
  114. type: 'MUSICIAN',
  115. id: item.id,
  116. name: item.name
  117. }
  118. });
  119. }}>
  120. <div class={styles.itemWrapBox}>
  121. <div class={styles.itemCard}>
  122. {item.categories ? (
  123. <span class={styles.itemTag}>{item.categories}</span>
  124. ) : (
  125. ''
  126. )}
  127. <div class={styles.itemImgSection}>
  128. <NImage
  129. src={item.avatar}
  130. class={styles.img}
  131. objectFit="cover"
  132. previewDisabled
  133. />
  134. </div>
  135. <div class={styles.itemTitle}>{item.name}</div>
  136. </div>
  137. </div>
  138. </div>
  139. ))}
  140. {!state.loading && state.tableList.length <= 0 && (
  141. <TheEmpty
  142. style={{ minHeight: '50vh' }}
  143. description="暂无音乐家"
  144. />
  145. )}
  146. </div>
  147. </NSpin>
  148. <Pagination
  149. v-model:page={state.pagination.page}
  150. v-model:pageSize={state.pagination.rows}
  151. v-model:pageTotal={state.pageTotal}
  152. pageSizes={[18, 24, 30, 36]}
  153. onList={getList}
  154. />
  155. </div>
  156. );
  157. }
  158. });